Skip to content

Commit 096e2fa

Browse files
committed
refactor!: cleanup rules that can be assimilated as commands
1 parent 6544c43 commit 096e2fa

File tree

12 files changed

+215887
-288355
lines changed

12 files changed

+215887
-288355
lines changed

grammar.js

Lines changed: 14 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports = grammar({
88
extras: ($) => [/[ \t]/, $.comment],
99

1010
inline: ($) => [
11-
$._do_expression,
1211
$._flag_value,
1312
$._item_expression,
1413
$._match_expression,
@@ -30,6 +29,7 @@ module.exports = grammar({
3029
[$._block_body, $.record_body, $.val_closure],
3130
[$._block_body, $.shebang],
3231
[$._block_body, $.val_closure],
32+
[$._block_body],
3333
[$._expression_parenthesized, $._expr_binary_expression_parenthesized],
3434
[$._match_pattern_list, $.val_list],
3535
[$._match_pattern_record, $._value],
@@ -40,7 +40,6 @@ module.exports = grammar({
4040
[$.block, $.val_closure],
4141
[$.block, $.val_record, $.val_closure],
4242
[$.command, $.record_entry],
43-
[$.ctrl_do_parenthesized],
4443
[$.ctrl_if_parenthesized],
4544
[$.ctrl_try_parenthesized],
4645
[$.expr_binary_parenthesized],
@@ -168,15 +167,12 @@ module.exports = grammar({
168167
decl_export: ($) => seq(keyword().export_env, field('body', $.block)),
169168

170169
decl_extern: ($) =>
171-
prec.right(
172-
1,
173-
seq(
174-
optional(modifier().visibility),
175-
keyword().extern,
176-
field('name', $._command_name),
177-
field('signature', choice($.parameter_parens, $.parameter_bracks)),
178-
field('body', optional($.block)),
179-
),
170+
seq(
171+
optional(modifier().visibility),
172+
keyword().extern,
173+
field('name', $._command_name),
174+
field('signature', choice($.parameter_parens, $.parameter_bracks)),
175+
field('body', optional($.block)),
180176
),
181177

182178
decl_module: ($) =>
@@ -188,14 +184,11 @@ module.exports = grammar({
188184
),
189185

190186
decl_use: ($) =>
191-
prec.right(
192-
1,
193-
seq(
194-
optional(modifier().visibility),
195-
keyword().use,
196-
field('module', choice($.unquoted, $._stringish)),
197-
optional(field('import_pattern', $.scope_pattern)),
198-
),
187+
seq(
188+
optional(modifier().visibility),
189+
keyword().use,
190+
field('module', choice($.unquoted, $._stringish)),
191+
optional(field('import_pattern', $.scope_pattern)),
199192
),
200193

201194
/// Return types
@@ -371,33 +364,19 @@ module.exports = grammar({
371364

372365
// control statements cannot be used in pipeline because they
373366
// do not return values
374-
_ctrl_statement: ($) =>
375-
choice($.ctrl_for, $.ctrl_loop, $.ctrl_while, $.ctrl_error),
367+
_ctrl_statement: ($) => choice($.ctrl_for, $.ctrl_loop, $.ctrl_while),
376368

377369
// control expressions *return values and can be used in pipelines
378370
//
379371
// * `break` and `continue` do not return values (yet?) but can be
380372
// used in pipelines
381-
_ctrl_expression: ($) =>
382-
choice(
383-
field('ctrl_break', keyword().break),
384-
field('ctrl_continue', keyword().continue),
385-
$.ctrl_do,
386-
$.ctrl_if,
387-
$.ctrl_try,
388-
$.ctrl_match,
389-
$.ctrl_return,
390-
),
373+
_ctrl_expression: ($) => choice($.ctrl_if, $.ctrl_try, $.ctrl_match),
391374

392375
_ctrl_expression_parenthesized: ($) =>
393376
choice(
394-
field('ctrl_break', keyword().break),
395-
field('ctrl_continue', keyword().continue),
396-
alias($.ctrl_do_parenthesized, $.ctrl_do),
397377
alias($.ctrl_if_parenthesized, $.ctrl_if),
398378
alias($.ctrl_try_parenthesized, $.ctrl_try),
399379
$.ctrl_match,
400-
$.ctrl_return,
401380
),
402381

403382
// Standalone Controls
@@ -413,47 +392,13 @@ module.exports = grammar({
413392

414393
ctrl_loop: ($) => seq(keyword().loop, field('body', $.block)),
415394

416-
ctrl_error: ($) =>
417-
seq(
418-
keyword().error,
419-
modifier().error_make,
420-
optional($._flag),
421-
field('error_record', $.val_record),
422-
),
423-
424395
ctrl_while: ($) =>
425396
seq(
426397
keyword().while,
427398
field('condition', $._expression),
428399
field('body', $.block),
429400
),
430401

431-
// Nestable Controls
432-
_do_expression: ($) =>
433-
choice(
434-
$._item_expression,
435-
$._flag,
436-
alias($.unquoted, $.val_string),
437-
alias($._unquoted_with_expr, $.val_string),
438-
),
439-
440-
ctrl_do: ($) =>
441-
seq(
442-
keyword().do,
443-
repeat($._flag),
444-
choice($._blosure, $.val_variable, $.expr_parenthesized),
445-
repeat($._do_expression),
446-
),
447-
448-
ctrl_do_parenthesized: ($) =>
449-
seq(
450-
keyword().do,
451-
repeat($._flags_parenthesized),
452-
repeat1($._separator),
453-
choice($._blosure, $.val_variable, $.expr_parenthesized),
454-
repeat(seq(optional($._repeat_newline), $._do_expression)),
455-
),
456-
457402
ctrl_if: _ctrl_if_rule(false),
458403
ctrl_if_parenthesized: _ctrl_if_rule(true),
459404

@@ -574,24 +519,6 @@ module.exports = grammar({
574519
ctrl_try: _ctrl_try_rule(false),
575520
ctrl_try_parenthesized: _ctrl_try_rule(true),
576521

577-
ctrl_return: ($) =>
578-
choice(
579-
prec(
580-
1,
581-
seq(
582-
keyword().return,
583-
choice(
584-
$._expression,
585-
$.ctrl_do,
586-
$.ctrl_if,
587-
$.ctrl_try,
588-
$.ctrl_match,
589-
),
590-
),
591-
),
592-
keyword().return,
593-
),
594-
595522
/// Pipelines
596523

597524
pipe_element: ($) =>
@@ -624,53 +551,6 @@ module.exports = grammar({
624551

625552
/// Scope Statements
626553

627-
stmt_source: ($) =>
628-
seq(
629-
choice(keyword().source, keyword().source_env),
630-
field('file', choice(alias($.unquoted, $.val_string), $._stringish)),
631-
),
632-
633-
_stmt_hide: ($) => choice($.hide_mod, $.hide_env),
634-
635-
hide_mod: ($) =>
636-
prec.right(
637-
1,
638-
seq(
639-
keyword().hide,
640-
field('module', $._command_name),
641-
optional($.scope_pattern),
642-
),
643-
),
644-
645-
hide_env: ($) =>
646-
seq(keyword().hide_env, repeat($._flag), repeat1($._variable_name)),
647-
648-
_stmt_overlay: ($) =>
649-
choice($.overlay_hide, $.overlay_list, $.overlay_new, $.overlay_use),
650-
651-
overlay_list: (_$) => seq(keyword().overlay, 'list'),
652-
653-
overlay_hide: ($) =>
654-
seq(
655-
keyword().overlay,
656-
'hide',
657-
repeat(choice($._flag, $.val_list)),
658-
field('overlay', choice($.unquoted, $._stringish)),
659-
repeat(choice($._flag, $.val_list)),
660-
),
661-
662-
overlay_new: ($) => seq(keyword().overlay, 'new', $._command_name),
663-
664-
overlay_use: ($) =>
665-
seq(
666-
keyword().overlay,
667-
'use',
668-
repeat($._flag),
669-
field('overlay', choice($.unquoted, $._stringish)),
670-
optional(seq(keyword().as, field('rename', $._command_name))),
671-
repeat($._flag),
672-
),
673-
674554
scope_pattern: ($) =>
675555
choice(
676556
field('wildcard', $.wild_card),
@@ -1641,9 +1521,6 @@ function _block_body_rules(suffix) {
16411521
['_statement' + suffix]: (/** @type {any} */ $) =>
16421522
choice(
16431523
$._ctrl_statement,
1644-
$._stmt_hide,
1645-
$._stmt_overlay,
1646-
$.stmt_source,
16471524
alias_for_suffix($, 'assignment', suffix),
16481525
alias_for_suffix($, 'stmt_let', suffix),
16491526
alias_for_suffix($, 'stmt_mut', suffix),
@@ -2071,32 +1948,16 @@ function keyword() {
20711948
mut: 'mut',
20721949
const: 'const',
20731950

2074-
hide: 'hide',
2075-
hide_env: 'hide-env',
2076-
2077-
source: 'source',
2078-
source_env: 'source-env',
2079-
2080-
overlay: 'overlay',
2081-
register: 'register',
2082-
20831951
for: 'for',
20841952
loop: 'loop',
20851953
while: 'while',
2086-
error: 'error',
20871954

2088-
do: 'do',
20891955
if: 'if',
20901956
else: 'else',
20911957
try: 'try',
20921958
catch: 'catch',
20931959
match: 'match',
20941960

2095-
break: 'break',
2096-
continue: 'continue',
2097-
return: 'return',
2098-
2099-
as: 'as',
21001961
in: 'in',
21011962
};
21021963
}
@@ -2107,7 +1968,6 @@ function keyword() {
21071968
*/
21081969
function modifier() {
21091970
return {
2110-
error_make: 'make',
21111971
visibility: 'export',
21121972
};
21131973
}

0 commit comments

Comments
 (0)