From 3911c45dde4088b190a8eca756dc3ca58d2b19bd Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 17 Feb 2017 21:13:57 -0800 Subject: [PATCH] Introduced index notation --- src/schala_lang/eval.rs | 3 +++ src/schala_lang/parser.rs | 6 +++++- src/schala_lang/tokenizer.rs | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/schala_lang/eval.rs b/src/schala_lang/eval.rs index 4fd24a8..8677e66 100644 --- a/src/schala_lang/eval.rs +++ b/src/schala_lang/eval.rs @@ -310,6 +310,9 @@ impl<'a> Evaluator<'a> { } } } + Index(box expr, box index_expr) => { + (Null, None) + } } } diff --git a/src/schala_lang/parser.rs b/src/schala_lang/parser.rs index 064f7c6..446137c 100644 --- a/src/schala_lang/parser.rs +++ b/src/schala_lang/parser.rs @@ -72,6 +72,7 @@ pub enum Expression { Lambda(Function), Block(VecDeque), While(Box, Vec), + Index(Box, Box), } #[derive(Clone, Debug)] @@ -402,7 +403,10 @@ impl Parser { } }, Some(LSquareBracket) => { - unimplemented!() + expect!(self, LSquareBracket); + let index_expr = self.expression()?; + expect!(self, RSquareBracket); + Index(Box::new(expr), Box::new(index_expr)) }, _ => { expr diff --git a/src/schala_lang/tokenizer.rs b/src/schala_lang/tokenizer.rs index aff6435..3b8e9a4 100644 --- a/src/schala_lang/tokenizer.rs +++ b/src/schala_lang/tokenizer.rs @@ -120,7 +120,7 @@ fn tokenize_identifier(c: char, iter: &mut Peekable) -> Result bool { let c = *c; char::is_whitespace(c) || is_digit(&c) || c == ';' || c == '(' || c == ')' || - c == ',' || c == '.' || c == ',' || c == ':' + c == ',' || c == '.' || c == ',' || c == ':' || c == '[' || c == ']' } use self::Token::*;