Split up and expand ast
This commit is contained in:
parent
4e94c13351
commit
037a0f69a3
9 changed files with 614 additions and 414 deletions
70
src/ast/field.rs
Normal file
70
src/ast/field.rs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
use crate::span::{HasSpan, Span};
|
||||
|
||||
use super::basic::{Ident, Space};
|
||||
use super::expr::Expr;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Field {
|
||||
/// `a[b]`
|
||||
///
|
||||
/// Structure: `expr s0 [ s1 index s2 ]`
|
||||
Access {
|
||||
expr: Box<Expr>,
|
||||
s0: Space,
|
||||
s1: Space,
|
||||
index: Box<Expr>,
|
||||
s2: Space,
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// `a[b] = c`
|
||||
///
|
||||
/// Structure: `expr s0 [ s1 index s2 ] s3 = s4 value`
|
||||
Assign {
|
||||
expr: Box<Expr>,
|
||||
s0: Space,
|
||||
s1: Space,
|
||||
index: Box<Expr>,
|
||||
s2: Space,
|
||||
s3: Space,
|
||||
s4: Space,
|
||||
value: Box<Expr>,
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// `a.foo`
|
||||
///
|
||||
/// Structure: `expr s0 . s1 ident`
|
||||
AccessIdent {
|
||||
expr: Box<Expr>,
|
||||
s0: Space,
|
||||
s1: Space,
|
||||
ident: Ident,
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// `a.foo = b`
|
||||
///
|
||||
/// Structure: `expr s0 . s1 ident s2 = s3 value`
|
||||
AssignIdent {
|
||||
expr: Box<Expr>,
|
||||
s0: Space,
|
||||
s1: Space,
|
||||
ident: Ident,
|
||||
s2: Space,
|
||||
s3: Space,
|
||||
value: Box<Expr>,
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
impl HasSpan for Field {
|
||||
fn span(&self) -> Span {
|
||||
match self {
|
||||
Field::Access { span, .. } => *span,
|
||||
Field::Assign { span, .. } => *span,
|
||||
Field::AccessIdent { span, .. } => *span,
|
||||
Field::AssignIdent { span, .. } => *span,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue