Parser - Handle the "this" keyword
This commit is contained in:
parent
c9f74cdc55
commit
7e7c8ffc37
1 changed files with 10 additions and 4 deletions
|
@ -725,10 +725,8 @@ impl Parser {
|
||||||
TokenType::Number(_) | &TokenType::String(_) => Ok(ExprNode::Litteral {
|
TokenType::Number(_) | &TokenType::String(_) => Ok(ExprNode::Litteral {
|
||||||
value: self.advance().clone(),
|
value: self.advance().clone(),
|
||||||
}),
|
}),
|
||||||
TokenType::Identifier(_) => Ok(ExprNode::Variable(VariableExpr {
|
TokenType::Identifier(_) => Ok(ExprNode::Variable(self.make_var_expr())),
|
||||||
token: self.advance().clone(),
|
TokenType::This => Ok(ExprNode::This(self.make_var_expr())),
|
||||||
id: self.make_id(),
|
|
||||||
})),
|
|
||||||
_ => self.error("expected expression"),
|
_ => self.error("expected expression"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -766,6 +764,14 @@ impl Parser {
|
||||||
* HELPER METHODS *
|
* HELPER METHODS *
|
||||||
* -------------- */
|
* -------------- */
|
||||||
|
|
||||||
|
/// Generate a variable reference record based on the current token.
|
||||||
|
fn make_var_expr(&mut self) -> VariableExpr {
|
||||||
|
VariableExpr {
|
||||||
|
token: self.advance().clone(),
|
||||||
|
id: self.make_id(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Expect a token of some types. If a matching token is found, the read
|
/// Expect a token of some types. If a matching token is found, the read
|
||||||
/// pointer is moved and a clone of the token is returned.
|
/// pointer is moved and a clone of the token is returned.
|
||||||
fn expect(&mut self, accepts: &[TokenType]) -> Option<Token> {
|
fn expect(&mut self, accepts: &[TokenType]) -> Option<Token> {
|
||||||
|
|
Loading…
Reference in a new issue