mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibJS: Implement update expressions
Note that currently only the non-prefixed variant is supported (i.e i++ not ++i), this variant returns the value of the argument before the update.
This commit is contained in:
parent
dc9a702aa8
commit
8557bc56f7
3 changed files with 69 additions and 1 deletions
|
@ -174,6 +174,12 @@ NonnullOwnPtr<Expression> Parser::parse_secondary_expression(NonnullOwnPtr<Expre
|
|||
case TokenType::Period:
|
||||
consume();
|
||||
return make<MemberExpression>(move(lhs), parse_expression());
|
||||
case TokenType::PlusPlus:
|
||||
consume();
|
||||
return make<UpdateExpression>(UpdateOp::Increment, move(lhs));
|
||||
case TokenType::MinusMinus:
|
||||
consume();
|
||||
return make<UpdateExpression>(UpdateOp::Decrement, move(lhs));
|
||||
default:
|
||||
m_has_errors = true;
|
||||
expected("secondary expression (missing switch case)");
|
||||
|
@ -352,7 +358,9 @@ bool Parser::match_secondary_expression() const
|
|||
|| type == TokenType::LessThan
|
||||
|| type == TokenType::LessThanEquals
|
||||
|| type == TokenType::ParenOpen
|
||||
|| type == TokenType::Period;
|
||||
|| type == TokenType::Period
|
||||
|| type == TokenType::PlusPlus
|
||||
|| type == TokenType::MinusMinus;
|
||||
}
|
||||
|
||||
bool Parser::match_statement() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue