Split up and expand ast
This commit is contained in:
parent
4e94c13351
commit
037a0f69a3
9 changed files with 614 additions and 414 deletions
48
src/ast/table_constr.rs
Normal file
48
src/ast/table_constr.rs
Normal 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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue