Split up and expand ast

This commit is contained in:
Joscha 2022-11-18 19:36:41 +01:00
parent 4e94c13351
commit 037a0f69a3
9 changed files with 614 additions and 414 deletions

65
src/ast/table_destr.rs Normal file
View file

@ -0,0 +1,65 @@
use crate::span::{HasSpan, Span};
use super::basic::{Ident, Space};
use super::expr::Expr;
#[derive(Debug, Clone)]
pub enum TablePatternElem {
/// `foo`
Positional(Ident),
/// `foo: bar`
///
/// Structure: `name s0 : s1 ident`
Named {
name: Ident,
s0: Space,
s1: Space,
ident: Ident,
span: Span,
},
}
impl HasSpan for TablePatternElem {
fn span(&self) -> Span {
match self {
TablePatternElem::Positional(ident) => ident.span(),
TablePatternElem::Named { span, .. } => *span,
}
}
}
/// `'{ foo, bar: baz }`
#[derive(Debug, Clone)]
pub struct TablePattern {
pub elems: Vec<(Space, TablePatternElem, Space)>,
/// `Some` if there is a trailing comma, `None` otherwise.
pub trailing_comma: Option<Space>,
pub span: Span,
}
impl HasSpan for TablePattern {
fn span(&self) -> Span {
self.span
}
}
/// - `{ foo, bar: baz } = a`
/// - `local { foo, bar: baz } = a`
///
/// Structure: `local pattern s0 = s1 value`
#[derive(Debug, Clone)]
pub struct TableDestr {
pub local: Option<Space>,
pub pattern: TablePattern,
pub s0: Space,
pub s1: Space,
pub value: Box<Expr>,
pub span: Span,
}
impl HasSpan for TableDestr {
fn span(&self) -> Span {
self.span
}
}