Parser - Variable references in expressions
This commit is contained in:
parent
a90b1529ad
commit
d821331fa2
1 changed files with 4 additions and 0 deletions
|
@ -214,6 +214,7 @@ impl Parser {
|
||||||
/// ```
|
/// ```
|
||||||
/// primary := "(" expression ")"
|
/// primary := "(" expression ")"
|
||||||
/// primary := FALSE | TRUE | NIL | STRING | NUMBER
|
/// primary := FALSE | TRUE | NIL | STRING | NUMBER
|
||||||
|
/// primary := IDENTIFIER
|
||||||
/// ```
|
/// ```
|
||||||
fn parse_primary(&mut self) -> Result<ast::ExprNode, ParserError> {
|
fn parse_primary(&mut self) -> Result<ast::ExprNode, ParserError> {
|
||||||
if self.expect(&[TokenType::LeftParen]).is_some() {
|
if self.expect(&[TokenType::LeftParen]).is_some() {
|
||||||
|
@ -231,6 +232,9 @@ impl Parser {
|
||||||
TokenType::Number(_) | &TokenType::String(_) => Ok(ast::ExprNode::Litteral {
|
TokenType::Number(_) | &TokenType::String(_) => Ok(ast::ExprNode::Litteral {
|
||||||
value: self.advance().clone(),
|
value: self.advance().clone(),
|
||||||
}),
|
}),
|
||||||
|
TokenType::Identifier(_) => Ok(ast::ExprNode::Variable {
|
||||||
|
name: self.advance().clone(),
|
||||||
|
}),
|
||||||
_ => Err(ParserError::new(self.peek(), "expected expression")),
|
_ => Err(ParserError::new(self.peek(), "expected expression")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue