Skip to content

Commit

Permalink
fix: whitespace issues of if/for/error/alias
Browse files Browse the repository at this point in the history
  • Loading branch information
blindFS committed Dec 10, 2024
1 parent a94fdf1 commit b20966c
Show file tree
Hide file tree
Showing 4 changed files with 300,985 additions and 337,827 deletions.
18 changes: 5 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ module.exports = grammar({
[$._block_body, $.record_body, $.val_closure],
[$._block_body, $.shebang],
[$._block_body, $.val_closure],
[$._expression, $._expr_binary_expression],
[$._expression_parenthesized, $._expr_binary_expression_parenthesized],
[$._match_pattern_list, $.val_list],
[$._match_pattern_record, $.val_record],
[$._match_pattern_record_variable, $._value],
[$._match_pattern_value, $._value],
[$._parenthesized_body],
[$._val_number_decimal],
[$.block, $.val_closure],
[$.block, $.val_record],
[$.command, $.record_entry],
[$.ctrl_if_parenthesized],
[$.ctrl_try_parenthesized],
[$.expr_binary_parenthesized],
Expand Down Expand Up @@ -365,15 +364,10 @@ module.exports = grammar({

ctrl_for: ($) =>
seq(
// `for` has the `--numbered` flag
KEYWORD().for,
optional($._flag),
field("looping_var", $._variable_name),
optional($._flag),
KEYWORD().in,
optional($._flag),
field("iterable", $._expression),
optional($._flag),
field("body", $.block),
),

Expand Down Expand Up @@ -591,6 +585,7 @@ module.exports = grammar({
_env_variable_rule(true, $),
alias($._command_parenthesized, $.command),
),

$._ctrl_expression_parenthesized,
alias($.where_command_parenthesized, $.where_command),
),
Expand Down Expand Up @@ -1163,7 +1158,7 @@ module.exports = grammar({
"key",
choice(
// Without $.cmd_identifier, cannot correctly distinguish between record and closure
alias($.cmd_identifier, $.identifier),
seq(alias($.cmd_identifier, $.identifier), repeat($._separator)),
alias($._record_key, $.identifier),
$.val_string,
$.val_number,
Expand All @@ -1175,10 +1170,7 @@ module.exports = grammar({
...Object.values(MODIFIER()).map((x) => alias(x, $.identifier)),
),
),
alias(
token(prec(PREC().higher, seq(/\s*/, PUNC().colon))),
PUNC().colon,
),
token(prec(PREC().higher, PUNC().colon)),
field(
"value",
choice(
Expand Down Expand Up @@ -1236,7 +1228,7 @@ module.exports = grammar({
);

return seq(
token.immediate(PUNC().dot),
PUNC().dot,
choice(
field("raw_path", path),
field("protected_path", seq(path, PUNC().question)),
Expand Down
118 changes: 31 additions & 87 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3453,18 +3453,6 @@
"type": "STRING",
"value": "for"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_flag"
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "looping_var",
Expand All @@ -3473,34 +3461,10 @@
"name": "_variable_name"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_flag"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "in"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_flag"
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "iterable",
Expand All @@ -3509,18 +3473,6 @@
"name": "_expression"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_flag"
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "body",
Expand Down Expand Up @@ -13906,13 +13858,25 @@
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "cmd_identifier"
},
"named": true,
"value": "identifier"
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "cmd_identifier"
},
"named": true,
"value": "identifier"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_separator"
}
}
]
},
{
"type": "ALIAS",
Expand Down Expand Up @@ -14240,29 +14204,15 @@
}
},
{
"type": "ALIAS",
"type": "TOKEN",
"content": {
"type": "TOKEN",
"type": "PREC",
"value": 20,
"content": {
"type": "PREC",
"value": 20,
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "\\s*"
},
{
"type": "STRING",
"value": ":"
}
]
}
"type": "STRING",
"value": ":"
}
},
"named": false,
"value": ":"
}
},
{
"type": "FIELD",
Expand Down Expand Up @@ -14515,11 +14465,8 @@
"type": "SEQ",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "."
}
"type": "STRING",
"value": "."
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -20319,10 +20266,6 @@
"_block_body",
"val_closure"
],
[
"_expression",
"_expr_binary_expression"
],
[
"_expression_parenthesized",
"_expr_binary_expression_parenthesized"
Expand All @@ -20346,9 +20289,6 @@
[
"_parenthesized_body"
],
[
"_val_number_decimal"
],
[
"block",
"val_closure"
Expand All @@ -20357,6 +20297,10 @@
"block",
"val_record"
],
[
"command",
"record_entry"
],
[
"ctrl_if_parenthesized"
],
Expand Down
16 changes: 1 addition & 15 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,20 +678,6 @@
}
]
}
},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "long_flag",
"named": true
},
{
"type": "short_flag",
"named": true
}
]
}
},
{
Expand Down Expand Up @@ -3746,7 +3732,7 @@
"named": true,
"fields": {
"key": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
Expand Down
Loading

0 comments on commit b20966c

Please sign in to comment.