Expression parsing work
This commit is contained in:
parent
fff9cb7d25
commit
31da25a66e
@ -192,10 +192,19 @@ impl Parser {
|
|||||||
|
|
||||||
fn expression(&mut self) -> ParseResult<Expression> {
|
fn expression(&mut self) -> ParseResult<Expression> {
|
||||||
use tokenizer::Token::*;
|
use tokenizer::Token::*;
|
||||||
let expr: Expression = match self.next() {
|
let mut lhr: Expression = try!(self.primary_expression());
|
||||||
Some(Identifier(s)) => Expression::StringLiteral(s),
|
Ok(lhr)
|
||||||
_ => panic!("bad expression parse"),
|
}
|
||||||
|
|
||||||
|
fn primary_expression(&mut self) -> ParseResult<Expression> {
|
||||||
|
use tokenizer::Token::*;
|
||||||
|
let expr = match self.peek() {
|
||||||
|
Some(NumLiteral(n)) => { self.next(); Expression::Number(n) },
|
||||||
|
Some(StrLiteral(s)) => { self.next(); Expression::StringLiteral(s) },
|
||||||
|
Some(Identifier(var)) => { self.next(); Expression::Variable(var) },
|
||||||
|
_ => unimplemented!()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(expr)
|
Ok(expr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,4 +213,3 @@ pub fn parse(tokens: &[Token], _parsed_tree: &[ASTNode]) -> ParseResult<AST> {
|
|||||||
let mut parser = Parser::initialize(tokens);
|
let mut parser = Parser::initialize(tokens);
|
||||||
parser.program()
|
parser.program()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user