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

48
src/ast/table_constr.rs Normal file
View file

@ -0,0 +1,48 @@
use crate::span::{HasSpan, Span};
use super::basic::Space;
use super::expr::Expr;
use super::lit::TableLitElem;
#[derive(Debug, Clone)]
pub enum TableConstrElem {
/// See [`TableLitElem`].
Lit(TableLitElem),
/// `[a]: b`
///
/// Structure: `[ s0 index s1 ] s2 : s3 value`
Indexed {
s0: Space,
index: Box<Expr>,
s1: Space,
s2: Space,
s3: Space,
value: Box<Expr>,
span: Span,
},
}
impl HasSpan for TableConstrElem {
fn span(&self) -> Span {
match self {
TableConstrElem::Lit(lit) => lit.span(),
TableConstrElem::Indexed { span, .. } => *span,
}
}
}
/// `{ a, b, foo: c, [d]: e }`
#[derive(Debug, Clone)]
pub struct TableConstr {
pub elems: Vec<(Space, TableConstrElem, Space)>,
/// `Some` if there is a trailing comma, `None` otherwise.
pub trailing_comma: Option<Space>,
pub span: Span,
}
impl HasSpan for TableConstr {
fn span(&self) -> Span {
self.span
}
}