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 {
|
||||
value: self.advance().clone(),
|
||||
}),
|
||||
TokenType::Identifier(_) => Ok(ExprNode::Variable(VariableExpr {
|
||||
token: self.advance().clone(),
|
||||
id: self.make_id(),
|
||||
})),
|
||||
TokenType::Identifier(_) => Ok(ExprNode::Variable(self.make_var_expr())),
|
||||
TokenType::This => Ok(ExprNode::This(self.make_var_expr())),
|
||||
_ => self.error("expected expression"),
|
||||
}
|
||||
}
|
||||
|
@ -766,6 +764,14 @@ impl Parser {
|
|||
* 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
|
||||
/// pointer is moved and a clone of the token is returned.
|
||||
fn expect(&mut self, accepts: &[TokenType]) -> Option<Token> {
|
||||
|
|
Loading…
Reference in a new issue