aboutsummaryrefslogtreecommitdiff
path: root/src/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast.rs')
-rw-r--r--src/ast.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/ast.rs b/src/ast.rs
index 96fe8ab..35bf6c3 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -59,7 +59,7 @@ pub enum Statement {
59#[derive(Debug, Eq, PartialEq, Clone)] 59#[derive(Debug, Eq, PartialEq, Clone)]
60pub enum Expr { 60pub enum Expr {
61 Node, 61 Node,
62 FieldAccess(Vec<Identifier>), 62 FieldAccess(Box<Expr>, Identifier),
63 Unit, 63 Unit,
64 Lit(Literal), 64 Lit(Literal),
65 Ident(Identifier), 65 Ident(Identifier),
@@ -67,7 +67,7 @@ pub enum Expr {
67 Bin(Box<Expr>, BinOp, Box<Expr>), 67 Bin(Box<Expr>, BinOp, Box<Expr>),
68 Unary(Box<Expr>, UnaryOp), 68 Unary(Box<Expr>, UnaryOp),
69 Call(Call), 69 Call(Call),
70 IfExpr(If), 70 If(IfExpr),
71 Block(Block), 71 Block(Block),
72} 72}
73 73
@@ -75,6 +75,13 @@ impl Expr {
75 pub fn boxed(self) -> Box<Expr> { 75 pub fn boxed(self) -> Box<Expr> {
76 Box::new(self) 76 Box::new(self)
77 } 77 }
78
79 pub fn as_ident(self) -> Option<Identifier> {
80 match self {
81 Self::Ident(i) => Some(i),
82 _ => None,
83 }
84 }
78} 85}
79 86
80#[derive(Debug, Eq, PartialEq, Clone, Copy)] 87#[derive(Debug, Eq, PartialEq, Clone, Copy)]
@@ -164,7 +171,7 @@ pub struct Declaration {
164} 171}
165 172
166#[derive(Debug, Eq, PartialEq, Clone)] 173#[derive(Debug, Eq, PartialEq, Clone)]
167pub struct If { 174pub struct IfExpr {
168 pub condition: Box<Expr>, 175 pub condition: Box<Expr>,
169 pub then: Block, 176 pub then: Block,
170 pub else_: Block, 177 pub else_: Block,