diff options
Diffstat (limited to 'users/tazjin/rlox')
-rw-r--r-- | users/tazjin/rlox/src/bytecode/compiler/mod.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/users/tazjin/rlox/src/bytecode/compiler/mod.rs b/users/tazjin/rlox/src/bytecode/compiler/mod.rs index fab06fe39cf2..58a5c1b98a02 100644 --- a/users/tazjin/rlox/src/bytecode/compiler/mod.rs +++ b/users/tazjin/rlox/src/bytecode/compiler/mod.rs @@ -183,12 +183,26 @@ impl<T: Iterator<Item = Token>> Compiler<T> { fn parse_precedence(&mut self, precedence: Precedence) -> LoxResult<()> { self.advance(); let rule: ParseRule<T> = rule_for(&self.previous().kind); - - if let Some(func) = rule.prefix { - func(self)?; + let prefix_fn = match rule.prefix { + None => unimplemented!("expected expression or something, unclear"), + Some(func) => func, + }; + + prefix_fn(self)?; + + while precedence <= rule_for::<T>(&self.current().kind).precedence { + self.advance(); + match rule_for::<T>(&self.previous().kind).infix { + Some(func) => { + func(self)?; + } + None => { + unreachable!("invalid compiler state: error in parse rules") + } + } } - unimplemented!("expect expression?") + Ok(()) } fn consume( @@ -224,6 +238,12 @@ impl<T: Iterator<Item = Token>> Compiler<T> { .expect("invalid internal compiler state: missing previous token") } + fn current(&self) -> &Token { + self.current + .as_ref() + .expect("invalid internal compiler state: missing current token") + } + fn error_at(&mut self, token: &Token, kind: ErrorKind) { if self.panic { return; |