Skip to content

Commit

Permalink
update grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
1Kinoti committed May 7, 2023
1 parent efd0f3d commit c4eb352
Show file tree
Hide file tree
Showing 7 changed files with 255,815 additions and 258,516 deletions.
41 changes: 11 additions & 30 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ module.exports = grammar({
BRACK().open_brace,
field("parameters", $.parameter_pipes),
repeat(choice(
$._statement
$._statement,
$._declaration,
)),
BRACK().close_brace,
),
Expand Down Expand Up @@ -910,17 +911,9 @@ module.exports = grammar({
command: $ => prec.right(10, choice(
$.cmd_head,
$.cmd_head_sub,
$.cmd_prefix_head_sub,
)),

cmd_head_sub: $ => prec.right(3, seq(
field("head", seq(optional(PUNC().caret), $.cmd_identifier)),
field("sub", $.cmd_identifier),
prec.right(10, repeat($._cmd_arg)),
)),

cmd_prefix_head_sub: $ => prec.right(2, seq(
field("prefix", $.cmd_identifier),
cmd_head_sub: $ => prec.right(2, seq(
field("head", seq(optional(PUNC().caret), $.cmd_identifier)),
field("sub", $.cmd_identifier),
prec.right(10, repeat($._cmd_arg)),
Expand All @@ -933,10 +926,10 @@ module.exports = grammar({

_cmd_arg: $ => choice(
field("redir", prec.right(10, $.redirection)),
field("flag", prec.right(8, $._flag)),
field("arg", prec.right(9, $._value)),
field("flag", prec.right(9, $._flag)),
field("arg", prec.right(8, $._value)),
field("arg", prec.right(8, $.val_range)),
field("arg", prec.right(7, $.expr_parenthesized)),
field("arg", prec.right(6, $.val_range)),
// lowest precedence to make it a last resort
field("arg_str", alias($.unquoted, $.val_string)),
),
Expand All @@ -957,30 +950,18 @@ module.exports = grammar({
$.long_flag,
)),

short_flag: $ => seq(
"-",
field("name", token.immediate(/[a-zA-Z0-9]+/)),
),
short_flag: $ => token(/-[_\p{XID_Continue}]+/),

long_flag: $ => seq(
long_flag: $ => prec.right(10, choice(
"--",
optional(token.immediate(/[_\p{XID_Continue}]+/)),
),

flag_value: $ => seq(
PUNC().eq,
field("value", choice(
$.val_string,
$.cmd_identifier,
/[0-9][0-9_]*/i,
)),
),
seq("--", token.immediate(/[_\p{XID_Continue}]+/)),
)),

// because this catches almost anything, we want to ensure it is
// picked as the a last resort after everything else has failed.
// so we give it a ridiculously low precedence and place it at the
// very end
unquoted: $ => prec.left(-69, token(/[^-\$\s\n\t\r{}()\[\]"`';][^\s\n\t\r{}()\[\]"`';]+/)),
unquoted: $ => prec.left(-69, token(/[^-$\s\n\t\r{}()\[\]"`';][^\s\n\t\r{}()\[\]"`';]+/)),

/// Comments

Expand Down
8 changes: 3 additions & 5 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
] @punctuation.delimiter

(param_short_flag "-" @punctuation.delimiter)
(short_flag "-" @punctuation.delimiter)
(param_long_flag ["--"] @punctuation.delimiter)
(long_flag ["--"] @punctuation.delimiter)
(param_rest "..." @punctuation.delimiter)
Expand Down Expand Up @@ -248,13 +247,12 @@

(cmd_identifier) @function

(cmd_head_sub
(cmd_head
"^" @punctuation.delimiter
head: (_) @function
sub: (_) @function.method
)
(cmd_prefix_head_sub
prefix: (_) @namespace

(cmd_head_sub
"^" @punctuation.delimiter
head: (_) @function
sub: (_) @function.method
Expand Down
171 changes: 36 additions & 135 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -6060,6 +6060,10 @@
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "SYMBOL",
"name": "_declaration"
}
]
}
Expand Down Expand Up @@ -6200,81 +6204,16 @@
{
"type": "SYMBOL",
"name": "cmd_head_sub"
},
{
"type": "SYMBOL",
"name": "cmd_prefix_head_sub"
}
]
}
},
"cmd_head_sub": {
"type": "PREC_RIGHT",
"value": 3,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "head",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "^"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "cmd_identifier"
}
]
}
},
{
"type": "FIELD",
"name": "sub",
"content": {
"type": "SYMBOL",
"name": "cmd_identifier"
}
},
{
"type": "PREC_RIGHT",
"value": 10,
"content": {
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_cmd_arg"
}
}
}
]
}
},
"cmd_prefix_head_sub": {
"type": "PREC_RIGHT",
"value": 2,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "prefix",
"content": {
"type": "SYMBOL",
"name": "cmd_identifier"
}
},
{
"type": "FIELD",
"name": "head",
Expand Down Expand Up @@ -6387,7 +6326,7 @@
"name": "flag",
"content": {
"type": "PREC_RIGHT",
"value": 8,
"value": 9,
"content": {
"type": "SYMBOL",
"name": "_flag"
Expand All @@ -6399,7 +6338,7 @@
"name": "arg",
"content": {
"type": "PREC_RIGHT",
"value": 9,
"value": 8,
"content": {
"type": "SYMBOL",
"name": "_value"
Expand All @@ -6411,10 +6350,10 @@
"name": "arg",
"content": {
"type": "PREC_RIGHT",
"value": 7,
"value": 8,
"content": {
"type": "SYMBOL",
"name": "expr_parenthesized"
"name": "val_range"
}
}
},
Expand All @@ -6423,10 +6362,10 @@
"name": "arg",
"content": {
"type": "PREC_RIGHT",
"value": 6,
"value": 7,
"content": {
"type": "SYMBOL",
"name": "val_range"
"name": "expr_parenthesized"
}
}
},
Expand Down Expand Up @@ -6568,78 +6507,40 @@
}
},
"short_flag": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[a-zA-Z0-9]+"
}
}
}
]
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "-[_\\p{XID_Continue}]+"
}
},
"long_flag": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "--"
},
{
"type": "CHOICE",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[_\\p{XID_Continue}]+"
}
},
{
"type": "BLANK"
}
]
}
]
},
"flag_value": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "CHOICE",
"type": "PREC_RIGHT",
"value": 10,
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "--"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "val_string"
},
{
"type": "SYMBOL",
"name": "cmd_identifier"
"type": "STRING",
"value": "--"
},
{
"type": "PATTERN",
"value": "[0-9][0-9_]*"
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[_\\p{XID_Continue}]+"
}
}
]
}
}
]
]
}
},
"unquoted": {
"type": "PREC_LEFT",
Expand All @@ -6648,7 +6549,7 @@
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "[^-\\$\\s\\n\\t\\r{}()\\[\\]\"`';][^\\s\\n\\t\\r{}()\\[\\]\"`';]+"
"value": "[^-$\\s\\n\\t\\r{}()\\[\\]\"`';][^\\s\\n\\t\\r{}()\\[\\]\"`';]+"
}
}
},
Expand Down
Loading

0 comments on commit c4eb352

Please sign in to comment.