diff options
author | Vincent Ambo <mail@tazj.in> | 2020-12-06T14·49+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-12-06T14·58+0000 |
commit | 1835b2be990f51f4111c847aa8ad3c8477191eba (patch) | |
tree | 7a8a6af22267f427f59a3accd8a075a56dada11b /users/tazjin/rlox/src/parser.rs | |
parent | 4812fc2ee64536502093da04ea8a0efe616ffb26 (diff) |
feat(tazjin/rlox): Wire up parser to the REPL r/1990
Change-Id: I940448c63ce105d53a0f281b6320ffb01378f207 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2235 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.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/users/tazjin/rlox/src/parser.rs b/users/tazjin/rlox/src/parser.rs index e7266c2352b4..cf96981e5b41 100644 --- a/users/tazjin/rlox/src/parser.rs +++ b/users/tazjin/rlox/src/parser.rs @@ -11,17 +11,17 @@ use crate::scanner::{Token, TokenKind}; // AST #[derive(Debug)] -struct Binary<'a> { +pub struct Binary<'a> { left: Box<Expr<'a>>, operator: Token<'a>, right: Box<Expr<'a>>, } #[derive(Debug)] -struct Grouping<'a>(Box<Expr<'a>>); +pub struct Grouping<'a>(Box<Expr<'a>>); #[derive(Debug)] -enum Literal { +pub enum Literal { Boolean(bool), Number(f64), String(String), @@ -29,13 +29,13 @@ enum Literal { } #[derive(Debug)] -struct Unary<'a> { +pub struct Unary<'a> { operator: Token<'a>, right: Box<Expr<'a>>, } #[derive(Debug)] -enum Expr<'a> { +pub enum Expr<'a> { Binary(Binary<'a>), Grouping(Grouping<'a>), Literal(Literal), @@ -200,3 +200,9 @@ impl<'a> Parser<'a> { return Ok(expr); } } + +pub fn parse<'a>(tokens: Vec<Token<'a>>) -> ExprResult<'a> { + let mut parser = Parser { tokens, current: 0 }; + + parser.expression() +} |