Introduced index notation

This commit is contained in:
greg 2017-02-17 21:13:57 -08:00
parent f3c3d4595e
commit 3911c45dde
3 changed files with 9 additions and 2 deletions

View File

@ -310,6 +310,9 @@ impl<'a> Evaluator<'a> {
} }
} }
} }
Index(box expr, box index_expr) => {
(Null, None)
}
} }
} }

View File

@ -72,6 +72,7 @@ pub enum Expression {
Lambda(Function), Lambda(Function),
Block(VecDeque<Expression>), Block(VecDeque<Expression>),
While(Box<Expression>, Vec<Expression>), While(Box<Expression>, Vec<Expression>),
Index(Box<Expression>, Box<Expression>),
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -402,7 +403,10 @@ impl Parser {
} }
}, },
Some(LSquareBracket) => { Some(LSquareBracket) => {
unimplemented!() expect!(self, LSquareBracket);
let index_expr = self.expression()?;
expect!(self, RSquareBracket);
Index(Box::new(expr), Box::new(index_expr))
}, },
_ => { _ => {
expr expr

View File

@ -120,7 +120,7 @@ fn tokenize_identifier(c: char, iter: &mut Peekable<Chars>) -> Result<Token, Tok
fn ends_identifier(c: &char) -> bool { fn ends_identifier(c: &char) -> bool {
let c = *c; let c = *c;
char::is_whitespace(c) || is_digit(&c) || c == ';' || 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::*; use self::Token::*;