Skip to content

Commit

Permalink
Fix: Don't mix a sequence of parenthesis with an indirect access.
Browse files Browse the repository at this point in the history
`[(1) (2)]` was being mistaken as an indirect access. Lowering the precedence makes
so that it only matches inside field_expressions, which is the only place it is
actually valid.
  • Loading branch information
acristoffers committed Jul 21, 2023
1 parent 676117e commit 1558d8f
Show file tree
Hide file tree
Showing 5 changed files with 3,939 additions and 3,918 deletions.
31 changes: 17 additions & 14 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,23 @@ module.exports = grammar({
),

indirect_access: ($) =>
seq(
'(',
choice(
$.binary_operator,
$.field_expression,
$.function_call,
$.identifier,
$.matrix,
$.parenthesis,
$.postfix_operator,
$.string,
$.unary_operator
),
')'
prec(
-2,
seq(
'(',
choice(
$.binary_operator,
$.field_expression,
$.function_call,
$.identifier,
$.matrix,
$.parenthesis,
$.postfix_operator,
$.string,
$.unary_operator
),
')'
)
),
field_expression: ($) =>
prec.left(
Expand Down
108 changes: 56 additions & 52 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -811,58 +811,62 @@
}
},
"indirect_access": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "binary_operator"
},
{
"type": "SYMBOL",
"name": "field_expression"
},
{
"type": "SYMBOL",
"name": "function_call"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "matrix"
},
{
"type": "SYMBOL",
"name": "parenthesis"
},
{
"type": "SYMBOL",
"name": "postfix_operator"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "unary_operator"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
"type": "PREC",
"value": -2,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "binary_operator"
},
{
"type": "SYMBOL",
"name": "field_expression"
},
{
"type": "SYMBOL",
"name": "function_call"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "matrix"
},
{
"type": "SYMBOL",
"name": "parenthesis"
},
{
"type": "SYMBOL",
"name": "postfix_operator"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "unary_operator"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
},
"field_expression": {
"type": "PREC_LEFT",
Expand Down
Loading

0 comments on commit 1558d8f

Please sign in to comment.