Skip to content

Commit 7ec4b5a

Browse files
committedDec 9, 2024·
Format with commas
1 parent 8d635aa commit 7ec4b5a

File tree

2 files changed

+115
-112
lines changed

2 files changed

+115
-112
lines changed
 

‎grammar.js

Lines changed: 113 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const ALL_OPS = [
5656

5757
// Ignore word literals and "=>" which is not a valid atom
5858
const ATOM_OPERATOR_LITERALS = ALL_OPS.filter(
59-
(operator) => !/[a-z]/.test(operator) && operator !== "=>"
59+
(operator) => !/[a-z]/.test(operator) && operator !== "=>",
6060
);
6161

6262
const ATOM_SPECIAL_LITERALS = ["...", "%{}", "{}", "%", "<<>>", "..//"];
@@ -188,8 +188,8 @@ module.exports = grammar({
188188
seq(
189189
optional($._terminator),
190190
optional(
191-
seq(sep1($._expression, $._terminator), optional($._terminator))
192-
)
191+
seq(sep1($._expression, $._terminator), optional($._terminator)),
192+
),
193193
),
194194

195195
_terminator: ($) =>
@@ -220,7 +220,7 @@ module.exports = grammar({
220220
$.dot,
221221
$.call,
222222
$.access_call,
223-
$.anonymous_function
223+
$.anonymous_function,
224224
),
225225

226226
block: ($) =>
@@ -232,18 +232,18 @@ module.exports = grammar({
232232
sep1(choice($.stab_clause), $._terminator),
233233
seq(
234234
sep1(choice($._expression), $._terminator),
235-
optional($._terminator)
236-
)
237-
)
235+
optional($._terminator),
236+
),
237+
),
238238
),
239-
")"
239+
")",
240240
),
241241

242242
identifier: ($) =>
243243
choice(
244244
// See Ref 6. in the docs
245245
/[_\p{Ll}\p{Lm}\p{Lo}\p{Nl}\u1885\u1886\u2118\u212E\u309B\u309C][\p{ID_Continue}]*[?!]?/u,
246-
"..."
246+
"...",
247247
),
248248

249249
alias: ($) => token(sep1(/[A-Z][_a-zA-Z0-9]*/, /\s*\.\s*/)),
@@ -267,15 +267,15 @@ module.exports = grammar({
267267
choice(
268268
ATOM_WORD_LITERAL,
269269
...ATOM_OPERATOR_LITERALS,
270-
...ATOM_SPECIAL_LITERALS
271-
)
272-
)
270+
...ATOM_SPECIAL_LITERALS,
271+
),
272+
),
273273
),
274274

275275
quoted_atom: ($) =>
276276
seq(
277277
alias($._quoted_atom_start, ":"),
278-
choice($._quoted_i_double, $._quoted_i_single)
278+
choice($._quoted_i_double, $._quoted_i_single),
279279
),
280280

281281
// Defines $._quoted_content_i_{name} and $._quoted_content_{name} rules,
@@ -309,9 +309,9 @@ module.exports = grammar({
309309
/x\{[0-9a-fA-F]+\}/,
310310
// Unicode code point
311311
/u\{[0-9a-fA-F]+\}/,
312-
/u[0-9a-fA-F]{4}/
313-
)
314-
)
312+
/u[0-9a-fA-F]{4}/,
313+
),
314+
),
315315
),
316316

317317
sigil: ($) =>
@@ -330,8 +330,8 @@ module.exports = grammar({
330330
$._quoted_i_square,
331331
$._quoted_i_angle,
332332
$._quoted_i_bar,
333-
$._quoted_i_slash
334-
)
333+
$._quoted_i_slash,
334+
),
335335
),
336336
seq(
337337
alias(token.immediate(/[A-Z][A-Z0-9]*/), $.sigil_name),
@@ -345,11 +345,11 @@ module.exports = grammar({
345345
$._quoted_square,
346346
$._quoted_angle,
347347
$._quoted_bar,
348-
$._quoted_slash
349-
)
350-
)
348+
$._quoted_slash,
349+
),
350+
),
351351
),
352-
optional(alias(token.immediate(/[a-zA-Z0-9]+/), $.sigil_modifiers))
352+
optional(alias(token.immediate(/[a-zA-Z0-9]+/), $.sigil_modifiers)),
353353
),
354354

355355
keywords: ($) =>
@@ -371,16 +371,16 @@ module.exports = grammar({
371371
choice(
372372
ATOM_WORD_LITERAL,
373373
...ATOM_OPERATOR_LITERALS.filter((op) => op !== "::"),
374-
...ATOM_SPECIAL_LITERALS
374+
...ATOM_SPECIAL_LITERALS,
375375
),
376-
/:\s/
377-
)
376+
/:\s/,
377+
),
378378
),
379379

380380
quoted_keyword: ($) =>
381381
seq(
382382
choice($._quoted_i_double, $._quoted_i_single),
383-
token.immediate(/:\s/)
383+
token.immediate(/:\s/),
384384
),
385385

386386
list: ($) => seq("[", optional($._items_with_trailing_separator), "]"),
@@ -399,8 +399,8 @@ module.exports = grammar({
399399
optional($.struct),
400400
"{",
401401
optional(alias($._items_with_trailing_separator, $.map_content)),
402-
"}"
403-
)
402+
"}",
403+
),
404404
),
405405

406406
struct: ($) =>
@@ -413,8 +413,8 @@ module.exports = grammar({
413413
$.identifier,
414414
$.unary_operator,
415415
$.dot,
416-
alias($._call_with_parentheses, $.call)
417-
)
416+
alias($._call_with_parentheses, $.call),
417+
),
418418
),
419419

420420
_items_with_trailing_separator: ($) =>
@@ -423,9 +423,9 @@ module.exports = grammar({
423423
seq(sep1($._expression, ","), optional(",")),
424424
seq(
425425
optional(seq(sep1($._expression, ","), ",")),
426-
alias($._keywords_with_trailing_separator, $.keywords)
427-
)
428-
)
426+
alias($._keywords_with_trailing_separator, $.keywords),
427+
),
428+
),
429429
),
430430

431431
_nullary_operator: ($) =>
@@ -439,7 +439,7 @@ module.exports = grammar({
439439
unaryOp($, prec, PREC.UNARY_OPS, choice(...UNARY_OPS)),
440440
unaryOp($, prec, PREC.AT_OP, "@"),
441441
// Capture operand like &1 is a special case with higher precedence
442-
unaryOp($, prec, PREC.CAPTURE_OPERAND, "&", $.integer)
442+
unaryOp($, prec, PREC.CAPTURE_OPERAND, "&", $.integer),
443443
),
444444

445445
_capture_expression: ($) =>
@@ -448,7 +448,7 @@ module.exports = grammar({
448448
// so we have an explicit sequence with the parentheses and higher
449449
// precedence
450450
prec(1, seq("(", $._expression, ")")),
451-
$._expression
451+
$._expression,
452452
),
453453

454454
binary_operator: ($) =>
@@ -460,7 +460,7 @@ module.exports = grammar({
460460
PREC.WHEN_OP,
461461
"when",
462462
$._expression,
463-
choice($._expression, $.keywords)
463+
choice($._expression, $.keywords),
464464
),
465465
binaryOp($, prec.right, PREC.TYPE_OP, "::"),
466466
binaryOp(
@@ -469,7 +469,7 @@ module.exports = grammar({
469469
PREC.BAR_OP,
470470
"|",
471471
$._expression,
472-
choice($._expression, $.keywords)
472+
choice($._expression, $.keywords),
473473
),
474474
binaryOp($, prec.right, PREC.ASSOC_OP, "=>"),
475475
binaryOp($, prec.right, PREC.MATCH_OP, "="),
@@ -482,7 +482,7 @@ module.exports = grammar({
482482
$,
483483
prec.left,
484484
PREC.IN_OPS,
485-
choice("in", alias($._not_in, "not in"))
485+
choice("in", alias($._not_in, "not in")),
486486
),
487487
binaryOp($, prec.left, PREC.XOR_OP, "^^^"),
488488
binaryOp($, prec.right, PREC.TERNARY_OP, "//"),
@@ -498,8 +498,8 @@ module.exports = grammar({
498498
PREC.MULT_OPS,
499499
"/",
500500
$.operator_identifier,
501-
$.integer
502-
)
501+
$.integer,
502+
),
503503
),
504504

505505
operator_identifier: ($) =>
@@ -538,7 +538,7 @@ module.exports = grammar({
538538
// ".."
539539
...MULT_OPS,
540540
"**",
541-
"->"
541+
"->",
542542
),
543543

544544
dot: ($) =>
@@ -547,8 +547,8 @@ module.exports = grammar({
547547
seq(
548548
field("left", $._expression),
549549
field("operator", "."),
550-
field("right", choice($.alias, $.tuple))
551-
)
550+
field("right", choice($.alias, $.tuple)),
551+
),
552552
),
553553

554554
call: ($) => choice($._call_without_parentheses, $._call_with_parentheses),
@@ -557,15 +557,15 @@ module.exports = grammar({
557557
choice(
558558
$._local_call_without_parentheses,
559559
$._local_call_just_do_block,
560-
$._remote_call_without_parentheses
560+
$._remote_call_without_parentheses,
561561
),
562562

563563
_call_with_parentheses: ($) =>
564564
choice(
565565
$._local_call_with_parentheses,
566566
$._remote_call_with_parentheses,
567567
$._anonymous_call,
568-
$._double_call
568+
$._double_call,
569569
),
570570

571571
// Note, calls have left precedence, so that `do end` block sticks to
@@ -576,17 +576,17 @@ module.exports = grammar({
576576
seq(
577577
field("target", $.identifier),
578578
alias($._call_arguments_without_parentheses, $.arguments),
579-
optional(seq(optional($._newline_before_do), $.do_block))
580-
)
579+
optional(seq(optional($._newline_before_do), $.do_block)),
580+
),
581581
),
582582

583583
_local_call_with_parentheses: ($) =>
584584
prec.left(
585585
seq(
586586
field("target", $.identifier),
587587
alias($._call_arguments_with_parentheses_immediate, $.arguments),
588-
optional(seq(optional($._newline_before_do), $.do_block))
589-
)
588+
optional(seq(optional($._newline_before_do), $.do_block)),
589+
),
590590
),
591591

592592
_local_call_just_do_block: ($) =>
@@ -598,17 +598,17 @@ module.exports = grammar({
598598
seq(
599599
field("target", alias($._remote_dot, $.dot)),
600600
optional(alias($._call_arguments_without_parentheses, $.arguments)),
601-
optional(seq(optional($._newline_before_do), $.do_block))
602-
)
601+
optional(seq(optional($._newline_before_do), $.do_block)),
602+
),
603603
),
604604

605605
_remote_call_with_parentheses: ($) =>
606606
prec.left(
607607
seq(
608608
field("target", alias($._remote_dot, $.dot)),
609609
alias($._call_arguments_with_parentheses_immediate, $.arguments),
610-
optional(seq(optional($._newline_before_do), $.do_block))
611-
)
610+
optional(seq(optional($._newline_before_do), $.do_block)),
611+
),
612612
),
613613

614614
_remote_dot: ($) =>
@@ -624,22 +624,22 @@ module.exports = grammar({
624624
alias(choice(...RESERVED_WORD_TOKENS), $.identifier),
625625
$.operator_identifier,
626626
alias($._quoted_i_double, $.string),
627-
alias($._quoted_i_single, $.charlist)
628-
)
629-
)
630-
)
627+
alias($._quoted_i_single, $.charlist),
628+
),
629+
),
630+
),
631631
),
632632

633633
_anonymous_call: ($) =>
634634
seq(
635635
field("target", alias($._anonymous_dot, $.dot)),
636-
alias($._call_arguments_with_parentheses, $.arguments)
636+
alias($._call_arguments_with_parentheses, $.arguments),
637637
),
638638

639639
_anonymous_dot: ($) =>
640640
prec(
641641
PREC.DOT_OP,
642-
seq(field("left", $._expression), field("operator", "."))
642+
seq(field("left", $._expression), field("operator", ".")),
643643
),
644644

645645
_double_call: ($) =>
@@ -651,14 +651,14 @@ module.exports = grammar({
651651
choice(
652652
$._local_call_with_parentheses,
653653
$._remote_call_with_parentheses,
654-
$._anonymous_call
654+
$._anonymous_call,
655655
),
656-
$.call
657-
)
656+
$.call,
657+
),
658658
),
659659
alias($._call_arguments_with_parentheses, $.arguments),
660-
optional(seq(optional($._newline_before_do), $.do_block))
661-
)
660+
optional(seq(optional($._newline_before_do), $.do_block)),
661+
),
662662
),
663663

664664
_call_arguments_with_parentheses: ($) =>
@@ -668,18 +668,18 @@ module.exports = grammar({
668668
seq(
669669
token.immediate("("),
670670
optional($._call_arguments_with_trailing_separator),
671-
")"
671+
")",
672672
),
673673

674674
_call_arguments_with_trailing_separator: ($) =>
675675
choice(
676676
seq(
677677
sep1($._expression, ","),
678678
optional(
679-
seq(",", alias($._keywords_with_trailing_separator, $.keywords))
680-
)
679+
seq(",", alias($._keywords_with_trailing_separator, $.keywords)),
680+
),
681681
),
682-
alias($._keywords_with_trailing_separator, $.keywords)
682+
alias($._keywords_with_trailing_separator, $.keywords),
683683
),
684684

685685
_call_arguments_without_parentheses: ($) =>
@@ -697,18 +697,18 @@ module.exports = grammar({
697697
prec.right(
698698
choice(
699699
seq(sep1($._expression, ","), optional(seq(",", $.keywords))),
700-
$.keywords
701-
)
702-
)
700+
$.keywords,
701+
),
702+
),
703703
),
704704

705705
do_block: ($) =>
706706
seq(
707707
callKeywordBlock($, "do"),
708708
repeat(
709-
choice($.after_block, $.rescue_block, $.catch_block, $.else_block)
709+
choice($.after_block, $.rescue_block, $.catch_block, $.else_block),
710710
),
711-
"end"
711+
"end",
712712
),
713713

714714
after_block: ($) => callKeywordBlock($, "after"),
@@ -723,8 +723,8 @@ module.exports = grammar({
723723
field("target", $._expression),
724724
token.immediate("["),
725725
field("key", $._expression),
726-
"]"
727-
)
726+
"]",
727+
),
728728
),
729729

730730
stab_clause: ($) =>
@@ -733,22 +733,22 @@ module.exports = grammar({
733733
seq(
734734
optional(field("left", $._stab_clause_left)),
735735
field("operator", "->"),
736-
optional(field("right", $.body))
737-
)
736+
optional(field("right", $.body)),
737+
),
738738
),
739739

740740
_stab_clause_left: ($) =>
741741
choice(
742742
alias($._stab_clause_arguments_with_parentheses, $.arguments),
743743
alias(
744744
$._stab_clause_arguments_with_parentheses_with_guard,
745-
$.binary_operator
745+
$.binary_operator,
746746
),
747747
alias($._stab_clause_arguments_without_parentheses, $.arguments),
748748
alias(
749749
$._stab_clause_arguments_without_parentheses_with_guard,
750-
$.binary_operator
751-
)
750+
$.binary_operator,
751+
),
752752
),
753753

754754
_stab_clause_arguments_with_parentheses: ($) =>
@@ -764,13 +764,13 @@ module.exports = grammar({
764764
// discard this rule in favour of the one below. We use right precedence,
765765
// because in this case we can consume expression until the next comma
766766
sep1(prec.right(PREC.WHEN_OP, $._expression), ","),
767-
optional(seq(",", $.keywords))
767+
optional(seq(",", $.keywords)),
768768
),
769-
$.keywords
770-
)
769+
$.keywords,
770+
),
771771
),
772-
")"
773-
)
772+
")",
773+
),
774774
),
775775

776776
_stab_clause_arguments_without_parentheses: ($) =>
@@ -782,20 +782,20 @@ module.exports = grammar({
782782
choice(
783783
seq(
784784
sep1(prec(PREC.WHEN_OP, $._expression), ","),
785-
optional(seq(",", $.keywords))
785+
optional(seq(",", $.keywords)),
786786
),
787-
$.keywords
788-
)
787+
$.keywords,
788+
),
789789
),
790790

791791
_stab_clause_arguments_with_parentheses_with_guard: ($) =>
792792
seq(
793793
field(
794794
"left",
795-
alias($._stab_clause_arguments_with_parentheses, $.arguments)
795+
alias($._stab_clause_arguments_with_parentheses, $.arguments),
796796
),
797797
field("operator", "when"),
798-
field("right", $._expression)
798+
field("right", $._expression),
799799
),
800800

801801
_stab_clause_arguments_without_parentheses_with_guard: ($) =>
@@ -808,11 +808,11 @@ module.exports = grammar({
808808
seq(
809809
field(
810810
"left",
811-
alias($._stab_clause_arguments_without_parentheses, $.arguments)
811+
alias($._stab_clause_arguments_without_parentheses, $.arguments),
812812
),
813813
field("operator", "when"),
814-
field("right", $._expression)
815-
)
814+
field("right", $._expression),
815+
),
816816
),
817817

818818
body: ($) =>
@@ -821,8 +821,8 @@ module.exports = grammar({
821821
seq(
822822
optional($._terminator),
823823
sep1($._expression, $._terminator),
824-
optional($._terminator)
825-
)
824+
optional($._terminator),
825+
),
826826
),
827827

828828
anonymous_function: ($) =>
@@ -831,7 +831,7 @@ module.exports = grammar({
831831
optional($._terminator),
832832
// See Ref 8. in the docs
833833
optional(sep1($.stab_clause, $._terminator)),
834-
"end"
834+
"end",
835835
),
836836

837837
// A comment may be anywhere, we give it a lower precedence,
@@ -856,9 +856,9 @@ function unaryOp($, assoc, precedence, operator, right = null) {
856856
seq(
857857
optional($._before_unary_op),
858858
field("operator", operator),
859-
field("operand", right || $._expression)
860-
)
861-
)
859+
field("operand", right || $._expression),
860+
),
861+
),
862862
);
863863
}
864864

@@ -868,8 +868,8 @@ function binaryOp($, assoc, precedence, operator, left = null, right = null) {
868868
seq(
869869
field("left", left || $._expression),
870870
field("operator", operator),
871-
field("right", right || $._expression)
872-
)
871+
field("right", right || $._expression),
872+
),
873873
);
874874
}
875875

@@ -880,9 +880,12 @@ function callKeywordBlock($, start) {
880880
optional(
881881
choice(
882882
sep1(choice($.stab_clause), $._terminator),
883-
seq(sep1(choice($._expression), $._terminator), optional($._terminator))
884-
)
885-
)
883+
seq(
884+
sep1(choice($._expression), $._terminator),
885+
optional($._terminator),
886+
),
887+
),
888+
),
886889
);
887890
}
888891

@@ -895,10 +898,10 @@ function defineQuoted(start, end, name) {
895898
repeat(
896899
seq(
897900
choice($.interpolation, $.escape_sequence),
898-
optional(alias($[`_quoted_content_i_${name}`], $.quoted_content))
899-
)
901+
optional(alias($[`_quoted_content_i_${name}`], $.quoted_content)),
902+
),
900903
),
901-
field("quoted_end", end)
904+
field("quoted_end", end),
902905
),
903906

904907
[`_quoted_${name}`]: ($) =>
@@ -909,10 +912,10 @@ function defineQuoted(start, end, name) {
909912
seq(
910913
// The end delimiter may be escaped in non-interpolating strings too
911914
$.escape_sequence,
912-
optional(alias($[`_quoted_content_${name}`], $.quoted_content))
913-
)
915+
optional(alias($[`_quoted_content_${name}`], $.quoted_content)),
916+
),
914917
),
915-
field("quoted_end", end)
918+
field("quoted_end", end),
916919
),
917920
};
918921
}

‎package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"scripts": {
2727
"build": "tree-sitter generate",
2828
"test": "tree-sitter test",
29-
"format": "prettier --trailing-comma es5 --write grammar.js && clang-format -i src/scanner.c",
30-
"format-check": "prettier --trailing-comma es5 --check grammar.js && cat src/scanner.c | clang-format src/scanner.c | diff src/scanner.c -",
29+
"format": "prettier --write grammar.js && clang-format -i src/scanner.c",
30+
"format-check": "prettier --check grammar.js && cat src/scanner.c | clang-format src/scanner.c | diff src/scanner.c -",
3131
"install": "node-gyp-build",
3232
"prestart": "tree-sitter build --wasm",
3333
"start": "tree-sitter playground"

0 commit comments

Comments
 (0)
Please sign in to comment.