Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
run: |-
git clone https://github.com/nushell/nu_scripts examples/nu_scripts -q --single-branch --depth=1
- name: Run tests
uses: tree-sitter/parser-test-action@v2
uses: tree-sitter/parser-test-action@v3
with:
generate: false
test-rust: true
test-node: true
test-node: false
test-python: true
test-go: true
test-swift: false
Expand Down
54 changes: 38 additions & 16 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,32 @@ module.exports = grammar({
[$._block_body, $.shebang],
[$._block_body, $.val_closure],
[$._block_body],
[$._command_list_body],
[$._expression_parenthesized, $._expr_binary_expression_parenthesized],
[$._match_pattern_list, $.val_list],
[
$._match_pattern_list_body,
$._match_pattern_list_body_or_empty,
$._table_head,
],
[
$._match_pattern_list_body,
$._match_pattern_list_body_or_empty,
$.list_body,
$._list_body_or_empty,
$._table_head,
],
[
$._match_pattern_list_body,
$._match_pattern_list_body_or_empty,
$.list_body,
$._list_body_or_empty,
],
[$._match_pattern_list_body, $._match_pattern_list_body_or_empty],
[$._match_pattern_list_body, $._table_head],
[$._match_pattern_list_body, $.list_body, $._table_head],
[$._match_pattern_list_body, $.list_body],
[$._match_pattern_list_body, $.val_entry],
[$._match_pattern_list_body],
[$._match_pattern_list_body_or_empty, $._list_body_or_empty],
[$._match_pattern_record, $.val_record, $.val_closure],
[$._match_pattern_record, $.val_record],
[$._match_pattern_record_body, $.record_body],
Expand All @@ -48,8 +67,9 @@ module.exports = grammar({
[$.ctrl_if_parenthesized],
[$.ctrl_try_parenthesized],
[$.expr_binary_parenthesized],
[$.list_body, $._list_body_or_empty, $._table_head],
[$.list_body, $._list_body_or_empty],
[$.list_body, $._table_head],
[$.list_body],
[$.parameter, $.param_type, $.param_value],
[$.pipeline],
[$.pipeline_parenthesized],
Expand Down Expand Up @@ -498,14 +518,18 @@ module.exports = grammar({
),
$._entry_separator,
$._newline,
null,
choice($._newline, punc().comma),
),

_match_pattern_list_body_or_empty: ($) =>
choice(
alias($._match_pattern_list_body, $.list_body),
repeat1(choice($._newline, punc().comma)),
),

_match_pattern_list: ($) =>
seq(
brack().open_brack,
optional(alias($._match_pattern_list_body, $.list_body)),
optional($._match_pattern_list_body_or_empty),
optional(
field(
'rest',
Expand Down Expand Up @@ -590,6 +614,8 @@ module.exports = grammar({
$._command_name,
$._entry_separator,
$._newline,
null,
choice($._newline, punc().comma),
),

command_list: ($) =>
Expand Down Expand Up @@ -1024,15 +1050,15 @@ module.exports = grammar({
val_list: ($) =>
seq(
brack().open_brack,
optional($.list_body),
optional($._list_body_or_empty),
brack().close_brack,
optional($.cell_path),
),

_spread_list: ($) =>
seq(
brack().spread_open_brack,
optional($.list_body),
optional($._list_body_or_empty),
brack().close_brack,
optional($.cell_path),
),
Expand All @@ -1045,14 +1071,10 @@ module.exports = grammar({
),

list_body: ($) =>
general_body_rules(
'entry',
$.val_entry,
$._entry_separator,
$._newline,
null,
choice($._newline, punc().comma),
),
general_body_rules('entry', $.val_entry, $._entry_separator, $._newline),

_list_body_or_empty: ($) =>
Copy link
Contributor

@mkatychev mkatychev Nov 26, 2025

Choose a reason for hiding this comment

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

going more off of #234 (comment)

the presences of rules like _list_body_or_empty feels like a smell because such a type should be simply handled by a repeat.

Ideally a list should have as simple a rule as possible so that most edge cases are handled within the _*_entry rule:

  • list: ($) => seq('[', repeat(choice($._list_entry, ',')), ']'),

Handling newlines explicitly where their presence does not matter feels like a design problem (exclusion from extras).

choice($.list_body, repeat1(choice($._newline, punc().comma))),

val_entry: ($) =>
prec(
Expand Down
111 changes: 51 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading