Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _lvalue_expression to include pointer indirection #272

Merged
merged 2 commits into from Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions corpus/expressions.txt
Expand Up @@ -339,6 +339,7 @@ var x = new A
[b] = 1
};
(a) = 1;
*p = 0;

--------------------------------------------------------------------------------

Expand Down Expand Up @@ -424,6 +425,13 @@ var x = new A
(parenthesized_expression
(identifier))
(assignment_operator)
(integer_literal))))
(global_statement
(expression_statement
(assignment_expression
(prefix_unary_expression
(identifier))
(assignment_operator)
(integer_literal)))))

================================================================================
Expand Down
8 changes: 6 additions & 2 deletions grammar.js
Expand Up @@ -112,6 +112,8 @@ module.exports = grammar({
[$.constant_pattern, $._lvalue_expression],
[$.constant_pattern, $._expression_statement_expression],

[$.assignment_expression, $._expression],

],

inline: $ => [
Expand Down Expand Up @@ -1254,7 +1256,7 @@ module.exports = grammar({
))
)),

element_access_expression: $ => prec.right(PREC.UNARY, seq(
element_access_expression: $ => prec.right(PREC.POSTFIX, seq(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed to not have conflict in *p[i]. The precedence was not matching https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/#operator-precedence.

field('expression', $._expression),
field('subscript', $.bracketed_argument_list)
)),
Expand Down Expand Up @@ -1395,7 +1397,6 @@ module.exports = grammar({
...[
'!',
'&',
'*',
'+',
'++',
'-',
Expand All @@ -1404,6 +1405,8 @@ module.exports = grammar({
'~'
].map(operator => seq(operator, $._expression)))),

_pointer_indirection_expression: $ => prec(PREC.UNARY, seq('*', $._expression)),

query_expression: $ => seq($.from_clause, $._query_body),

from_clause: $ => seq(
Expand Down Expand Up @@ -1603,6 +1606,7 @@ module.exports = grammar({
$._simple_name,
$.element_access_expression,
$.element_binding_expression,
alias($._pointer_indirection_expression, $.prefix_unary_expression),
alias($._parenthesized_lvalue_expression, $.parenthesized_expression),
),

Expand Down