Skip to content

Commit

Permalink
fix: ctrl_do_parenthesized associativity
Browse files Browse the repository at this point in the history
  • Loading branch information
blindFS committed Dec 21, 2024
1 parent 0921525 commit afef898
Show file tree
Hide file tree
Showing 4 changed files with 30,898 additions and 30,903 deletions.
35 changes: 12 additions & 23 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = grammar({
[$.block, $.val_closure],
[$.block, $.val_record],
[$.command, $.record_entry],
[$.ctrl_do_parenthesized],
[$.ctrl_if_parenthesized],
[$.ctrl_try_parenthesized],
[$.expr_binary_parenthesized],
Expand Down Expand Up @@ -322,12 +323,6 @@ module.exports = grammar({

/// Controls

_control: ($) =>
prec(
STATEMENT_PREC().control,
choice($._ctrl_statement, $._ctrl_expression),
),

// control statements cannot be used in pipeline because they
// do not return values
_ctrl_statement: ($) =>
Expand Down Expand Up @@ -397,26 +392,20 @@ module.exports = grammar({
),

ctrl_do: ($) =>
prec.left(
PREC().low,
seq(
KEYWORD().do,
repeat($._flag),
choice($._blosure, $.val_variable),
repeat($._do_expression),
),
seq(
KEYWORD().do,
repeat($._flag),
choice($._blosure, $.val_variable),
repeat($._do_expression),
),

ctrl_do_parenthesized: ($) =>
prec.left(
PREC().low,
seq(
KEYWORD().do,
repeat($._flags_parenthesized),
repeat1($._separator),
choice($._blosure, $.val_variable),
repeat(seq(repeat($._newline), $._do_expression)),
),
seq(
KEYWORD().do,
repeat($._flags_parenthesized),
repeat1($._separator),
choice($._blosure, $.val_variable),
repeat(seq(repeat($._newline), $._do_expression)),
),

ctrl_if: _ctrl_if_rule(false),
Expand Down
172 changes: 75 additions & 97 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3311,23 +3311,6 @@
"value": "[\\p{Punctuation}\\p{Symbol}\\p{XID_Continue}]"
}
},
"_control": {
"type": "PREC",
"value": 1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ctrl_statement"
},
{
"type": "SYMBOL",
"name": "_ctrl_expression"
}
]
}
},
"_ctrl_statement": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -3590,103 +3573,95 @@
]
},
"ctrl_do": {
"type": "PREC_LEFT",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "do"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "do"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_flag"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_flag"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_blosure"
},
{
"type": "SYMBOL",
"name": "val_variable"
}
]
},
{
"type": "REPEAT",
"content": {
"name": "_blosure"
},
{
"type": "SYMBOL",
"name": "_do_expression"
"name": "val_variable"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_do_expression"
}
]
}
}
]
},
"ctrl_do_parenthesized": {
"type": "PREC_LEFT",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "do"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "do"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_flags_parenthesized"
}
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_separator"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_flags_parenthesized"
}
},
{
"type": "REPEAT1",
"content": {
"name": "_blosure"
},
{
"type": "SYMBOL",
"name": "_separator"
"name": "val_variable"
}
},
{
"type": "CHOICE",
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_blosure"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
}
},
{
"type": "SYMBOL",
"name": "val_variable"
"name": "_do_expression"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
}
},
{
"type": "SYMBOL",
"name": "_do_expression"
}
]
}
}
]
}
}
]
},
"ctrl_if": {
"type": "SEQ",
Expand Down Expand Up @@ -20305,6 +20280,9 @@
"command",
"record_entry"
],
[
"ctrl_do_parenthesized"
],
[
"ctrl_if_parenthesized"
],
Expand Down
Loading

0 comments on commit afef898

Please sign in to comment.