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

70
src/ast/field.rs Normal file
View 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,
}
}
}