diff options
Diffstat (limited to 'src/compiler.rs')
| -rw-r--r-- | src/compiler.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 6fc8e78..0ddae1a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -315,6 +315,8 @@ impl Compiler { | Token::NotEqual => self.binary(block), + Token::LeftBracket => self.index(block), + _ => { return false; }, } return true; @@ -384,6 +386,15 @@ impl Compiler { expect!(self, Token::RightParen, "Expected ')' around expression."); } + fn index(&mut self, block: &mut Block) { + expect!(self, Token::LeftBracket, "Expected ']' around index."); + + self.expression(block); + block.add(Op::Index, self.line()); + + expect!(self, Token::RightBracket, "Expected '[' around index."); + } + fn unary(&mut self, block: &mut Block) { let op = match self.eat() { Token::Minus => Op::Neg, @@ -797,6 +808,22 @@ impl Compiler { let f = Type::Function(params, Box::new(return_type)); Ok(f) } + Token::LeftParen => { + self.eat(); + let mut element = Vec::new(); + loop { + element.push(self.parse_type()?); + if self.peek() == Token::RightParen { + self.eat(); + return Ok(Type::Tuple(element)); + } + if !expect!(self, + Token::Comma, + "Expect comma efter element in tuple.") { + return Err(()); + } + } + } Token::Identifier(x) => { self.eat(); match x.as_str() { |
