diff options
Diffstat (limited to 'users/tazjin/rlox/src/bytecode/compiler.rs')
-rw-r--r-- | users/tazjin/rlox/src/bytecode/compiler.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/bytecode/compiler.rs b/users/tazjin/rlox/src/bytecode/compiler.rs index 8d3f716d1647..39bb2f4907a7 100644 --- a/users/tazjin/rlox/src/bytecode/compiler.rs +++ b/users/tazjin/rlox/src/bytecode/compiler.rs @@ -144,6 +144,10 @@ fn rule_for<T: Iterator<Item = Token>>(token: &TokenKind) -> ParseRule<T> { ParseRule::new(None, Some(Compiler::binary), Precedence::Comparison) } + TokenKind::String(_) => { + ParseRule::new(Some(Compiler::string), None, Precedence::None) + }, + _ => ParseRule::new(None, None, Precedence::None), } } @@ -255,6 +259,18 @@ impl<T: Iterator<Item = Token>> Compiler<T> { Ok(()) } + fn string(&mut self) -> LoxResult<()> { + match &self.previous().kind { + TokenKind::String(s) => { + let s = s.clone(); + self.emit_constant(Value::String(s)); + } + _ => unreachable!("only called for strings"), + } + + Ok(()) + } + fn parse_precedence(&mut self, precedence: Precedence) -> LoxResult<()> { self.advance(); let rule: ParseRule<T> = rule_for(&self.previous().kind); |