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