about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/parser.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-01-14T15·16+0300
committertazjin <mail@tazj.in>2021-01-14T15·19+0000
commit1d8e3f4f8b4479a47e744b3d153fe0e624958817 (patch)
tree06d2747cf725fe6e2606c90355c8c1af25305e9c /users/tazjin/rlox/src/parser.rs
parent56d8fa97ed936aacb66b13bb4a8c849a9797db93 (diff)
feat(tazjin/rlox): Implement function definitions r/2106
... with this, functions now work.

Note that this bubbled up another weird code structure nit: The
parser::Function type should probably not carry its name directly.

However this doesn't matter much and I don't care right now.

Change-Id: If8e3b23f07033260433b9acd45f37c0e61fd2ff8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2393
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/parser.rs')
-rw-r--r--users/tazjin/rlox/src/parser.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/users/tazjin/rlox/src/parser.rs b/users/tazjin/rlox/src/parser.rs
index 626eda641c..78aaec105e 100644
--- a/users/tazjin/rlox/src/parser.rs
+++ b/users/tazjin/rlox/src/parser.rs
@@ -7,6 +7,7 @@
 // have real types.
 use crate::errors::{Error, ErrorKind};
 use crate::scanner::{Token, TokenKind};
+use std::rc::Rc;
 
 // AST
 
@@ -108,7 +109,7 @@ pub enum Statement<'a> {
     Block(Block<'a>),
     If(If<'a>),
     While(While<'a>),
-    Function(Function<'a>),
+    Function(Rc<Function<'a>>),
 }
 
 // Parser
@@ -221,11 +222,11 @@ impl<'a> Parser<'a> {
             ErrorKind::ExpectedToken("Expect '{' before function body."),
         )?;
 
-        Ok(Statement::Function(Function {
+        Ok(Statement::Function(Rc::new(Function {
             name,
             params,
             body: self.block_statement()?,
-        }))
+        })))
     }
 
     fn var_declaration(&mut self) -> StmtResult<'a> {