@willbooster/tree-sitter-ruby 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grammar.js +315 -95
- package/package.json +1 -1
- package/src/node-types.json +132 -8
- package/tree-sitter-ruby.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -65,6 +65,8 @@ module.exports = grammar({
|
|
|
65
65
|
'/',
|
|
66
66
|
$._block_ampersand,
|
|
67
67
|
$._splat_star,
|
|
68
|
+
$._unary_plus,
|
|
69
|
+
$._binary_plus,
|
|
68
70
|
$._unary_minus,
|
|
69
71
|
$._unary_minus_num,
|
|
70
72
|
$._binary_minus,
|
|
@@ -76,6 +78,7 @@ module.exports = grammar({
|
|
|
76
78
|
$._constant_suffix,
|
|
77
79
|
$._hash_splat_star_star,
|
|
78
80
|
$._binary_star_star,
|
|
81
|
+
$._modulo_assignment,
|
|
79
82
|
$._element_reference_bracket,
|
|
80
83
|
$._short_interpolation,
|
|
81
84
|
$._line_comment,
|
|
@@ -86,6 +89,11 @@ module.exports = grammar({
|
|
|
86
89
|
|
|
87
90
|
word: ($) => $.identifier,
|
|
88
91
|
|
|
92
|
+
conflicts: ($) => [
|
|
93
|
+
[$._chained_primary, $._chained_lhs],
|
|
94
|
+
[$._array_pattern_n, $.as_pattern, $._find_pattern_body],
|
|
95
|
+
],
|
|
96
|
+
|
|
89
97
|
supertypes: ($) => [
|
|
90
98
|
$._statement,
|
|
91
99
|
$._arg,
|
|
@@ -139,7 +147,13 @@ module.exports = grammar({
|
|
|
139
147
|
singleton_method: ($) =>
|
|
140
148
|
seq(
|
|
141
149
|
'def',
|
|
142
|
-
seq(
|
|
150
|
+
seq(
|
|
151
|
+
choice(
|
|
152
|
+
field('object', choice($._variable, $.self, $._nonlocal_variable)),
|
|
153
|
+
seq('(', field('object', $._arg), ')')
|
|
154
|
+
),
|
|
155
|
+
choice('.', '::')
|
|
156
|
+
),
|
|
143
157
|
$._method_rest
|
|
144
158
|
),
|
|
145
159
|
|
|
@@ -173,7 +187,13 @@ module.exports = grammar({
|
|
|
173
187
|
_command_singleton_method: ($) =>
|
|
174
188
|
seq(
|
|
175
189
|
'def',
|
|
176
|
-
seq(
|
|
190
|
+
seq(
|
|
191
|
+
choice(
|
|
192
|
+
field('object', choice($._variable, $.self, $._nonlocal_variable)),
|
|
193
|
+
seq('(', field('object', $._arg), ')')
|
|
194
|
+
),
|
|
195
|
+
choice('.', '::')
|
|
196
|
+
),
|
|
177
197
|
$._command_method_rest
|
|
178
198
|
),
|
|
179
199
|
|
|
@@ -193,7 +213,9 @@ module.exports = grammar({
|
|
|
193
213
|
choice(
|
|
194
214
|
alias($.command_call, $.call),
|
|
195
215
|
alias($.command_call_with_block, $.call),
|
|
196
|
-
|
|
216
|
+
$._chained_arg,
|
|
217
|
+
alias($._chained_assignment, $.assignment),
|
|
218
|
+
alias($._chained_operator_assignment, $.operator_assignment),
|
|
197
219
|
alias($.return_command, $.return),
|
|
198
220
|
alias($.yield_command, $.yield),
|
|
199
221
|
alias($._endless_command_not, $.unary),
|
|
@@ -583,16 +605,54 @@ module.exports = grammar({
|
|
|
583
605
|
alias($.command_operator_assignment, $.operator_assignment),
|
|
584
606
|
alias($.command_call, $.call),
|
|
585
607
|
alias($.command_call_with_block, $.call),
|
|
586
|
-
|
|
608
|
+
$._chained_arg,
|
|
609
|
+
alias($._chained_assignment, $.assignment),
|
|
610
|
+
alias($._chained_operator_assignment, $.operator_assignment),
|
|
587
611
|
alias($.return_command, $.return),
|
|
588
612
|
alias($.yield_command, $.yield),
|
|
589
613
|
alias($.break_command, $.break),
|
|
590
614
|
alias($.next_command, $.next),
|
|
615
|
+
alias($._chained_match_pattern, $.match_pattern),
|
|
616
|
+
alias($._chained_test_pattern, $.test_pattern),
|
|
591
617
|
$.match_pattern,
|
|
592
618
|
$.test_pattern,
|
|
593
619
|
$._arg
|
|
594
620
|
),
|
|
595
621
|
|
|
622
|
+
_chained_match_pattern: ($) =>
|
|
623
|
+
prec(
|
|
624
|
+
100,
|
|
625
|
+
seq(
|
|
626
|
+
field(
|
|
627
|
+
'value',
|
|
628
|
+
choice(
|
|
629
|
+
$._chained_arg,
|
|
630
|
+
alias($._command_method, $.method),
|
|
631
|
+
alias($._command_singleton_method, $.singleton_method)
|
|
632
|
+
)
|
|
633
|
+
),
|
|
634
|
+
'=>',
|
|
635
|
+
field('pattern', $._pattern_top_expr_body)
|
|
636
|
+
)
|
|
637
|
+
),
|
|
638
|
+
_chained_test_pattern: ($) =>
|
|
639
|
+
prec(
|
|
640
|
+
100,
|
|
641
|
+
seq(
|
|
642
|
+
field(
|
|
643
|
+
'value',
|
|
644
|
+
choice(
|
|
645
|
+
$._chained_arg,
|
|
646
|
+
alias($._chained_command, $.call),
|
|
647
|
+
alias($._command_method, $.method),
|
|
648
|
+
alias($._command_singleton_method, $.singleton_method)
|
|
649
|
+
)
|
|
650
|
+
),
|
|
651
|
+
'in',
|
|
652
|
+
field('pattern', $._pattern_top_expr_body)
|
|
653
|
+
)
|
|
654
|
+
),
|
|
655
|
+
|
|
596
656
|
match_pattern: ($) => prec(100, seq(field('value', $._arg), '=>', field('pattern', $._pattern_top_expr_body))),
|
|
597
657
|
|
|
598
658
|
test_pattern: ($) => prec(100, seq(field('value', $._arg), 'in', field('pattern', $._pattern_top_expr_body))),
|
|
@@ -663,17 +723,7 @@ module.exports = grammar({
|
|
|
663
723
|
|
|
664
724
|
parenthesized_statements: ($) => seq('(', optional($._statements), ')'),
|
|
665
725
|
|
|
666
|
-
element_reference: ($) =>
|
|
667
|
-
prec.left(
|
|
668
|
-
1,
|
|
669
|
-
seq(
|
|
670
|
-
field('object', $._primary),
|
|
671
|
-
alias($._element_reference_bracket, '['),
|
|
672
|
-
optional($._argument_list_with_trailing_comma),
|
|
673
|
-
']',
|
|
674
|
-
optional(field('block', choice($.block, $.do_block)))
|
|
675
|
-
)
|
|
676
|
-
),
|
|
726
|
+
element_reference: ($) => elementReference($, $._primary),
|
|
677
727
|
|
|
678
728
|
scope_resolution: ($) =>
|
|
679
729
|
prec.left(
|
|
@@ -693,29 +743,75 @@ module.exports = grammar({
|
|
|
693
743
|
),
|
|
694
744
|
|
|
695
745
|
command_call: ($) =>
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
746
|
+
choice(
|
|
747
|
+
seq(
|
|
748
|
+
choice($._call, field('method', choice($._variable, $._function_identifier))),
|
|
749
|
+
field('arguments', alias($.command_argument_list, $.argument_list))
|
|
750
|
+
),
|
|
751
|
+
$._chained_command
|
|
699
752
|
),
|
|
700
753
|
|
|
754
|
+
_chained_command: ($) =>
|
|
755
|
+
seq($._chained_command_call, field('arguments', alias($._chained_command_argument_list, $.argument_list))),
|
|
756
|
+
|
|
701
757
|
command_call_with_block: ($) => {
|
|
702
758
|
const receiver = choice($._call, field('method', choice($._variable, $._function_identifier)));
|
|
703
759
|
const args = field('arguments', alias($.command_argument_list, $.argument_list));
|
|
760
|
+
const chainedArgs = field('arguments', alias($._chained_command_argument_list, $.argument_list));
|
|
704
761
|
const block = field('block', $.block);
|
|
705
762
|
const doBlock = field('block', $.do_block);
|
|
706
763
|
return choice(
|
|
707
764
|
seq(receiver, prec(PREC.CURLY_BLOCK, seq(args, block))),
|
|
708
|
-
seq(receiver, prec(PREC.DO_BLOCK, seq(args, doBlock)))
|
|
765
|
+
seq(receiver, prec(PREC.DO_BLOCK, seq(args, doBlock))),
|
|
766
|
+
seq($._chained_command_call, prec(PREC.CURLY_BLOCK, seq(chainedArgs, block))),
|
|
767
|
+
seq($._chained_command_call, prec(PREC.DO_BLOCK, seq(chainedArgs, doBlock)))
|
|
709
768
|
);
|
|
710
769
|
},
|
|
711
770
|
|
|
771
|
+
_chained_arg: ($) =>
|
|
772
|
+
choice(
|
|
773
|
+
$._chained_primary,
|
|
774
|
+
alias($._chained_binary, $.binary),
|
|
775
|
+
alias($._chained_conditional, $.conditional),
|
|
776
|
+
alias($._chained_range, $.range)
|
|
777
|
+
),
|
|
778
|
+
|
|
779
|
+
_chained_primary: ($) =>
|
|
780
|
+
choice(
|
|
781
|
+
prec.left(alias($._chained_command_call, $.call)),
|
|
782
|
+
alias($._chained_call, $.call),
|
|
783
|
+
alias($._chained_element_reference, $.element_reference),
|
|
784
|
+
alias($._chained_scope_resolution, $.scope_resolution)
|
|
785
|
+
),
|
|
786
|
+
|
|
712
787
|
_chained_command_call: ($) =>
|
|
713
788
|
seq(
|
|
714
|
-
field('receiver', alias($.command_call_with_block, $.call)),
|
|
789
|
+
field('receiver', choice(alias($.command_call_with_block, $.call), $._chained_primary)),
|
|
715
790
|
field('operator', $._call_operator),
|
|
716
791
|
field('method', choice($.identifier, $._function_identifier, $.operator, $.constant))
|
|
717
792
|
),
|
|
718
793
|
|
|
794
|
+
_chained_scope_resolution: ($) =>
|
|
795
|
+
prec.left(
|
|
796
|
+
PREC.CALL + 1,
|
|
797
|
+
seq(field('scope', $._chained_primary), token.immediate('::'), field('name', $.constant))
|
|
798
|
+
),
|
|
799
|
+
|
|
800
|
+
_chained_element_reference: ($) => elementReference($, $._chained_primary),
|
|
801
|
+
|
|
802
|
+
_chained_call: ($) => {
|
|
803
|
+
const receiver = $._chained_command_call;
|
|
804
|
+
const receiverArguments = seq(
|
|
805
|
+
choice(receiver, seq(field('receiver', $._chained_primary), field('operator', $._call_operator))),
|
|
806
|
+
field('arguments', $.argument_list)
|
|
807
|
+
);
|
|
808
|
+
return choice(
|
|
809
|
+
receiverArguments,
|
|
810
|
+
prec(PREC.CURLY_BLOCK, seq(choice(receiver, receiverArguments), field('block', $.block))),
|
|
811
|
+
prec(PREC.DO_BLOCK, seq(choice(receiver, receiverArguments), field('block', $.do_block)))
|
|
812
|
+
);
|
|
813
|
+
},
|
|
814
|
+
|
|
719
815
|
call: ($) => {
|
|
720
816
|
const receiver = choice($._call, field('method', choice($._variable, $._function_identifier)));
|
|
721
817
|
|
|
@@ -736,6 +832,28 @@ module.exports = grammar({
|
|
|
736
832
|
);
|
|
737
833
|
},
|
|
738
834
|
|
|
835
|
+
_chained_command_argument_list: ($) =>
|
|
836
|
+
prec.right(
|
|
837
|
+
choice(
|
|
838
|
+
commaSep1($._argument),
|
|
839
|
+
seq(choice($._chained_plus_arg, alias($._chained_plus_pair, $.pair)), repeat(seq(',', $._argument)))
|
|
840
|
+
)
|
|
841
|
+
),
|
|
842
|
+
|
|
843
|
+
_chained_plus_arg: ($) =>
|
|
844
|
+
choice(
|
|
845
|
+
alias($._chained_plus_argument, $.unary),
|
|
846
|
+
alias($._chained_plus_binary, $.binary),
|
|
847
|
+
alias($._chained_plus_conditional, $.conditional),
|
|
848
|
+
alias($._chained_plus_range, $.range)
|
|
849
|
+
),
|
|
850
|
+
_chained_plus_binary: ($) => binaryExpression($, $._chained_plus_arg),
|
|
851
|
+
_chained_plus_conditional: ($) => conditionalExpression($, $._chained_plus_arg),
|
|
852
|
+
_chained_plus_range: ($) => rangeExpression($, $._chained_plus_arg, false),
|
|
853
|
+
_chained_plus_pair: ($) => prec.right(seq(field('key', $._chained_plus_arg), '=>', field('value', $._arg))),
|
|
854
|
+
_chained_plus_argument: ($) =>
|
|
855
|
+
prec.right(PREC.COMPLEMENT, seq(field('operator', alias($._unary_plus, '+')), field('operand', $._arg))),
|
|
856
|
+
|
|
739
857
|
command_argument_list: ($) => prec.right(commaSep1($._argument)),
|
|
740
858
|
|
|
741
859
|
argument_list: ($) => prec.right(seq(token.immediate('('), optional($._argument_list_with_trailing_comma), ')')),
|
|
@@ -768,6 +886,51 @@ module.exports = grammar({
|
|
|
768
886
|
),
|
|
769
887
|
|
|
770
888
|
_arg_rhs: ($) => choice($._arg, alias($.rescue_modifier_arg, $.rescue_modifier)),
|
|
889
|
+
_chained_lhs: ($) =>
|
|
890
|
+
choice(
|
|
891
|
+
alias($._chained_command_call, $.call),
|
|
892
|
+
alias($._chained_element_reference, $.element_reference),
|
|
893
|
+
alias($._chained_scope_resolution, $.scope_resolution)
|
|
894
|
+
),
|
|
895
|
+
|
|
896
|
+
_chained_left_assignment_list: ($) =>
|
|
897
|
+
prec.left(
|
|
898
|
+
-1,
|
|
899
|
+
seq(
|
|
900
|
+
$._chained_lhs,
|
|
901
|
+
',',
|
|
902
|
+
optional(seq(commaSep1(choice($._lhs, $.rest_assignment, $.destructured_left_assignment)), optional(',')))
|
|
903
|
+
)
|
|
904
|
+
),
|
|
905
|
+
|
|
906
|
+
_chained_assignment: ($) =>
|
|
907
|
+
prec.right(
|
|
908
|
+
PREC.ASSIGN,
|
|
909
|
+
seq(
|
|
910
|
+
field('left', choice($._chained_lhs, alias($._chained_left_assignment_list, $.left_assignment_list))),
|
|
911
|
+
'=',
|
|
912
|
+
field(
|
|
913
|
+
'right',
|
|
914
|
+
choice(
|
|
915
|
+
$._expression,
|
|
916
|
+
$.splat_argument,
|
|
917
|
+
$.right_assignment_list,
|
|
918
|
+
alias($.rescue_modifier_expression, $.rescue_modifier)
|
|
919
|
+
)
|
|
920
|
+
)
|
|
921
|
+
)
|
|
922
|
+
),
|
|
923
|
+
|
|
924
|
+
_chained_operator_assignment: ($) =>
|
|
925
|
+
prec.right(
|
|
926
|
+
PREC.ASSIGN,
|
|
927
|
+
seq(
|
|
928
|
+
field('left', $._chained_lhs),
|
|
929
|
+
field('operator', assignmentOperator($)),
|
|
930
|
+
field('right', choice($._expression, alias($.rescue_modifier_expression, $.rescue_modifier)))
|
|
931
|
+
)
|
|
932
|
+
),
|
|
933
|
+
|
|
771
934
|
assignment: ($) =>
|
|
772
935
|
prec.right(
|
|
773
936
|
PREC.ASSIGN,
|
|
@@ -793,11 +956,7 @@ module.exports = grammar({
|
|
|
793
956
|
operator_assignment: ($) =>
|
|
794
957
|
prec.right(
|
|
795
958
|
PREC.ASSIGN,
|
|
796
|
-
seq(
|
|
797
|
-
field('left', $._lhs),
|
|
798
|
-
field('operator', choice('+=', '-=', '*=', '**=', '/=', '||=', '|=', '&&=', '&=', '%=', '>>=', '<<=', '^=')),
|
|
799
|
-
field('right', $._arg_rhs)
|
|
800
|
-
)
|
|
959
|
+
seq(field('left', $._lhs), field('operator', assignmentOperator($)), field('right', $._arg_rhs))
|
|
801
960
|
),
|
|
802
961
|
|
|
803
962
|
command_operator_assignment: ($) =>
|
|
@@ -805,88 +964,34 @@ module.exports = grammar({
|
|
|
805
964
|
PREC.ASSIGN,
|
|
806
965
|
seq(
|
|
807
966
|
field('left', $._lhs),
|
|
808
|
-
field('operator',
|
|
967
|
+
field('operator', assignmentOperator($)),
|
|
809
968
|
field('right', choice($._expression, alias($.rescue_modifier_expression, $.rescue_modifier)))
|
|
810
969
|
)
|
|
811
970
|
),
|
|
812
971
|
|
|
813
|
-
conditional: ($) =>
|
|
814
|
-
prec.right(
|
|
815
|
-
PREC.CONDITIONAL,
|
|
816
|
-
seq(field('condition', $._arg), '?', field('consequence', $._arg), ':', field('alternative', $._arg))
|
|
817
|
-
),
|
|
972
|
+
conditional: ($) => conditionalExpression($, $._arg),
|
|
818
973
|
|
|
819
|
-
|
|
820
|
-
const begin = field('begin', $._arg);
|
|
821
|
-
const end = field('end', $._arg);
|
|
822
|
-
const operator = field('operator', choice('..', '...'));
|
|
823
|
-
return prec.right(PREC.RANGE, choice(seq(begin, operator, end), seq(operator, end), seq(begin, operator)));
|
|
824
|
-
},
|
|
974
|
+
_chained_conditional: ($) => conditionalExpression($, $._chained_arg),
|
|
825
975
|
|
|
826
|
-
|
|
827
|
-
// oxlint-disable typescript/unbound-method -- The DSL's `prec` functions do not use `this`.
|
|
828
|
-
/** @type {[(precedence: number, rule: RuleOrLiteral) => Rule, number, RuleOrLiteral][]} */
|
|
829
|
-
const operators = [
|
|
830
|
-
[prec.left, PREC.AND, 'and'],
|
|
831
|
-
[prec.left, PREC.OR, 'or'],
|
|
832
|
-
[prec.left, PREC.BOOLEAN_OR, '||'],
|
|
833
|
-
[prec.left, PREC.BOOLEAN_AND, '&&'],
|
|
834
|
-
[prec.left, PREC.SHIFT, choice('<<', '>>')],
|
|
835
|
-
[prec.left, PREC.COMPARISON, choice('<', '<=', '>', '>=')],
|
|
836
|
-
[prec.left, PREC.BITWISE_AND, alias($._bitwise_and, '&')],
|
|
837
|
-
[prec.left, PREC.BITWISE_OR, choice('^', '|')],
|
|
838
|
-
[prec.left, PREC.ADDITIVE, choice('+', alias($._binary_minus, '-'))],
|
|
839
|
-
[prec.left, PREC.MULTIPLICATIVE, choice('/', '%', alias($._binary_star, '*'))],
|
|
840
|
-
[prec.right, PREC.RELATIONAL, choice('==', '!=', '===', '<=>', '=~', '!~')],
|
|
841
|
-
[prec.right, PREC.EXPONENTIAL, alias($._binary_star_star, '**')],
|
|
842
|
-
];
|
|
843
|
-
// oxlint-enable typescript/unbound-method
|
|
976
|
+
range: ($) => rangeExpression($, $._arg, true),
|
|
844
977
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
978
|
+
_chained_range: ($) => rangeExpression($, $._chained_arg, false),
|
|
979
|
+
|
|
980
|
+
_range_sign: ($) =>
|
|
981
|
+
prec.right(PREC.UNARY_MINUS, seq(field('operator', alias($._binary_minus, '-')), field('operand', $._arg))),
|
|
982
|
+
|
|
983
|
+
_chained_binary: ($) => binaryExpression($, $._chained_arg, alias($._binary_plus, '+')),
|
|
984
|
+
|
|
985
|
+
binary: ($) => binaryExpression($, $._arg),
|
|
851
986
|
|
|
852
987
|
command_binary: ($) =>
|
|
853
988
|
prec.left(
|
|
854
989
|
seq(field('left', $._expression), field('operator', choice('or', 'and')), field('right', $._expression))
|
|
855
990
|
),
|
|
856
991
|
|
|
857
|
-
unary: ($) =>
|
|
858
|
-
// oxlint-disable typescript/unbound-method -- The DSL's `prec` functions do not use `this`.
|
|
859
|
-
/** @type {[(precedence: number, rule: RuleOrLiteral) => Rule, number, RuleOrLiteral][]} */
|
|
860
|
-
const operators = [
|
|
861
|
-
[prec, PREC.DEFINED, 'defined?'],
|
|
862
|
-
[prec.right, PREC.NOT, 'not'],
|
|
863
|
-
[prec.right, PREC.UNARY_MINUS, choice(alias($._unary_minus, '-'), alias($._binary_minus, '-'), '+')],
|
|
864
|
-
[prec.right, PREC.COMPLEMENT, choice('!', '~')],
|
|
865
|
-
];
|
|
866
|
-
// oxlint-enable typescript/unbound-method
|
|
867
|
-
return choice(
|
|
868
|
-
...operators.map(([fn, precedence, operator]) =>
|
|
869
|
-
fn(precedence, seq(field('operator', operator), field('operand', $._arg)))
|
|
870
|
-
)
|
|
871
|
-
);
|
|
872
|
-
},
|
|
992
|
+
unary: ($) => unaryExpression($._arg, choice(alias($._unary_minus, '-'), '+')),
|
|
873
993
|
|
|
874
|
-
command_unary: ($) =>
|
|
875
|
-
// oxlint-disable typescript/unbound-method -- The DSL's `prec` functions do not use `this`.
|
|
876
|
-
/** @type {[(precedence: number, rule: RuleOrLiteral) => Rule, number, RuleOrLiteral][]} */
|
|
877
|
-
const operators = [
|
|
878
|
-
[prec, PREC.DEFINED, 'defined?'],
|
|
879
|
-
[prec.right, PREC.NOT, 'not'],
|
|
880
|
-
[prec.right, PREC.UNARY_MINUS, choice(alias($._unary_minus, '-'), '+')],
|
|
881
|
-
[prec.right, PREC.COMPLEMENT, choice('!', '~')],
|
|
882
|
-
];
|
|
883
|
-
// oxlint-enable typescript/unbound-method
|
|
884
|
-
return choice(
|
|
885
|
-
...operators.map(([fn, precedence, operator]) =>
|
|
886
|
-
fn(precedence, seq(field('operator', operator), field('operand', $._expression)))
|
|
887
|
-
)
|
|
888
|
-
);
|
|
889
|
-
},
|
|
994
|
+
command_unary: ($) => unaryExpression($._expression, choice(alias($._unary_minus, '-'), '+')),
|
|
890
995
|
|
|
891
996
|
parenthesized_unary: ($) =>
|
|
892
997
|
prec(PREC.CALL, seq(field('operator', choice('defined?', 'not')), field('operand', $.parenthesized_statements))),
|
|
@@ -916,10 +1021,20 @@ module.exports = grammar({
|
|
|
916
1021
|
_function_identifier_call: ($) => prec.left(field('method', $._function_identifier)),
|
|
917
1022
|
_lhs: ($) =>
|
|
918
1023
|
prec.left(
|
|
919
|
-
choice(
|
|
1024
|
+
choice(
|
|
1025
|
+
$._variable,
|
|
1026
|
+
$.self,
|
|
1027
|
+
$._nonlocal_variable,
|
|
1028
|
+
$.true,
|
|
1029
|
+
$.false,
|
|
1030
|
+
$.nil,
|
|
1031
|
+
$.scope_resolution,
|
|
1032
|
+
$.element_reference,
|
|
1033
|
+
alias($._call, $.call)
|
|
1034
|
+
)
|
|
920
1035
|
),
|
|
921
1036
|
|
|
922
|
-
_variable: ($) => prec.right(choice($.
|
|
1037
|
+
_variable: ($) => prec.right(choice($.super, $.identifier, $.constant)),
|
|
923
1038
|
|
|
924
1039
|
operator: () =>
|
|
925
1040
|
choice(
|
|
@@ -1162,3 +1277,108 @@ function commaSep1(rule) {
|
|
|
1162
1277
|
function commaSep(rule) {
|
|
1163
1278
|
return optional(commaSep1(rule));
|
|
1164
1279
|
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* @param {GrammarSymbols<string>} $
|
|
1283
|
+
*/
|
|
1284
|
+
function assignmentOperator($) {
|
|
1285
|
+
return choice(
|
|
1286
|
+
'+=',
|
|
1287
|
+
'-=',
|
|
1288
|
+
'*=',
|
|
1289
|
+
'**=',
|
|
1290
|
+
'/=',
|
|
1291
|
+
'||=',
|
|
1292
|
+
'|=',
|
|
1293
|
+
'&&=',
|
|
1294
|
+
'&=',
|
|
1295
|
+
alias($._modulo_assignment, '%='),
|
|
1296
|
+
'>>=',
|
|
1297
|
+
'<<=',
|
|
1298
|
+
'^='
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* @param {RuleOrLiteral} operand
|
|
1304
|
+
* @param {RuleOrLiteral} sign
|
|
1305
|
+
*/
|
|
1306
|
+
function unaryExpression(operand, sign) {
|
|
1307
|
+
return choice(
|
|
1308
|
+
prec(PREC.DEFINED, seq(field('operator', 'defined?'), field('operand', operand))),
|
|
1309
|
+
prec.right(PREC.NOT, seq(field('operator', 'not'), field('operand', operand))),
|
|
1310
|
+
prec.right(PREC.UNARY_MINUS, seq(field('operator', sign), field('operand', operand))),
|
|
1311
|
+
prec.right(PREC.COMPLEMENT, seq(field('operator', choice('!', '~')), field('operand', operand)))
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/**
|
|
1316
|
+
* @param {GrammarSymbols<string>} $
|
|
1317
|
+
* @param {RuleOrLiteral} left
|
|
1318
|
+
* @param {RuleOrLiteral} plus
|
|
1319
|
+
*/
|
|
1320
|
+
function binaryExpression($, left, plus = '+') {
|
|
1321
|
+
// oxlint-disable typescript/unbound-method -- The DSL's `prec` functions do not use `this`.
|
|
1322
|
+
/** @type {[(precedence: number, rule: RuleOrLiteral) => Rule, number, RuleOrLiteral][]} */
|
|
1323
|
+
const operators = [
|
|
1324
|
+
[prec.left, PREC.AND, 'and'],
|
|
1325
|
+
[prec.left, PREC.OR, 'or'],
|
|
1326
|
+
[prec.left, PREC.BOOLEAN_OR, '||'],
|
|
1327
|
+
[prec.left, PREC.BOOLEAN_AND, '&&'],
|
|
1328
|
+
[prec.left, PREC.SHIFT, choice('<<', '>>')],
|
|
1329
|
+
[prec.left, PREC.COMPARISON, choice('<', '<=', '>', '>=')],
|
|
1330
|
+
[prec.left, PREC.BITWISE_AND, alias($._bitwise_and, '&')],
|
|
1331
|
+
[prec.left, PREC.BITWISE_OR, choice('^', '|')],
|
|
1332
|
+
[prec.left, PREC.ADDITIVE, choice(plus, alias($._binary_minus, '-'))],
|
|
1333
|
+
[prec.left, PREC.MULTIPLICATIVE, choice('/', '%', alias($._binary_star, '*'))],
|
|
1334
|
+
[prec.right, PREC.RELATIONAL, choice('==', '!=', '===', '<=>', '=~', '!~')],
|
|
1335
|
+
[prec.right, PREC.EXPONENTIAL, alias($._binary_star_star, '**')],
|
|
1336
|
+
];
|
|
1337
|
+
// oxlint-enable typescript/unbound-method
|
|
1338
|
+
|
|
1339
|
+
return choice(
|
|
1340
|
+
...operators.map(([fn, precedence, operator]) =>
|
|
1341
|
+
fn(precedence, seq(field('left', left), field('operator', operator), field('right', $._arg)))
|
|
1342
|
+
)
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* @param {GrammarSymbols<string>} $
|
|
1348
|
+
* @param {RuleOrLiteral} object
|
|
1349
|
+
*/
|
|
1350
|
+
function elementReference($, object) {
|
|
1351
|
+
return prec.left(
|
|
1352
|
+
1,
|
|
1353
|
+
seq(
|
|
1354
|
+
field('object', object),
|
|
1355
|
+
alias($._element_reference_bracket, '['),
|
|
1356
|
+
optional($._argument_list_with_trailing_comma),
|
|
1357
|
+
']',
|
|
1358
|
+
optional(field('block', choice($.block, $.do_block)))
|
|
1359
|
+
)
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* @param {GrammarSymbols<string>} $
|
|
1365
|
+
* @param {RuleOrLiteral} condition
|
|
1366
|
+
*/
|
|
1367
|
+
function conditionalExpression($, condition) {
|
|
1368
|
+
return prec.right(
|
|
1369
|
+
PREC.CONDITIONAL,
|
|
1370
|
+
seq(field('condition', condition), '?', field('consequence', $._arg), ':', field('alternative', $._arg))
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* @param {GrammarSymbols<string>} $
|
|
1376
|
+
* @param {RuleOrLiteral} begin
|
|
1377
|
+
* @param {boolean} allowBeginless
|
|
1378
|
+
*/
|
|
1379
|
+
function rangeExpression($, begin, allowBeginless) {
|
|
1380
|
+
const end = field('end', choice($._arg, alias($._range_sign, $.unary)));
|
|
1381
|
+
const operator = field('operator', choice('..', '...'));
|
|
1382
|
+
const bounded = seq(field('begin', begin), operator, optional(end));
|
|
1383
|
+
return prec.right(PREC.RANGE, allowBeginless ? choice(bounded, seq(operator, end)) : bounded);
|
|
1384
|
+
}
|
package/package.json
CHANGED
package/src/node-types.json
CHANGED
|
@@ -57,6 +57,14 @@
|
|
|
57
57
|
"type": "call",
|
|
58
58
|
"named": true
|
|
59
59
|
},
|
|
60
|
+
{
|
|
61
|
+
"type": "conditional",
|
|
62
|
+
"named": true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "element_reference",
|
|
66
|
+
"named": true
|
|
67
|
+
},
|
|
60
68
|
{
|
|
61
69
|
"type": "match_pattern",
|
|
62
70
|
"named": true
|
|
@@ -73,10 +81,18 @@
|
|
|
73
81
|
"type": "operator_assignment",
|
|
74
82
|
"named": true
|
|
75
83
|
},
|
|
84
|
+
{
|
|
85
|
+
"type": "range",
|
|
86
|
+
"named": true
|
|
87
|
+
},
|
|
76
88
|
{
|
|
77
89
|
"type": "return",
|
|
78
90
|
"named": true
|
|
79
91
|
},
|
|
92
|
+
{
|
|
93
|
+
"type": "scope_resolution",
|
|
94
|
+
"named": true
|
|
95
|
+
},
|
|
80
96
|
{
|
|
81
97
|
"type": "singleton_method",
|
|
82
98
|
"named": true
|
|
@@ -99,6 +115,10 @@
|
|
|
99
115
|
"type": "_lhs",
|
|
100
116
|
"named": true,
|
|
101
117
|
"subtypes": [
|
|
118
|
+
{
|
|
119
|
+
"type": "_nonlocal_variable",
|
|
120
|
+
"named": true
|
|
121
|
+
},
|
|
102
122
|
{
|
|
103
123
|
"type": "_variable",
|
|
104
124
|
"named": true
|
|
@@ -123,6 +143,10 @@
|
|
|
123
143
|
"type": "scope_resolution",
|
|
124
144
|
"named": true
|
|
125
145
|
},
|
|
146
|
+
{
|
|
147
|
+
"type": "self",
|
|
148
|
+
"named": true
|
|
149
|
+
},
|
|
126
150
|
{
|
|
127
151
|
"type": "true",
|
|
128
152
|
"named": true
|
|
@@ -585,10 +609,6 @@
|
|
|
585
609
|
"type": "_variable",
|
|
586
610
|
"named": true,
|
|
587
611
|
"subtypes": [
|
|
588
|
-
{
|
|
589
|
-
"type": "_nonlocal_variable",
|
|
590
|
-
"named": true
|
|
591
|
-
},
|
|
592
612
|
{
|
|
593
613
|
"type": "constant",
|
|
594
614
|
"named": true
|
|
@@ -597,10 +617,6 @@
|
|
|
597
617
|
"type": "identifier",
|
|
598
618
|
"named": true
|
|
599
619
|
},
|
|
600
|
-
{
|
|
601
|
-
"type": "self",
|
|
602
|
-
"named": true
|
|
603
|
-
},
|
|
604
620
|
{
|
|
605
621
|
"type": "super",
|
|
606
622
|
"named": true
|
|
@@ -1296,6 +1312,14 @@
|
|
|
1296
1312
|
{
|
|
1297
1313
|
"type": "_primary",
|
|
1298
1314
|
"named": true
|
|
1315
|
+
},
|
|
1316
|
+
{
|
|
1317
|
+
"type": "element_reference",
|
|
1318
|
+
"named": true
|
|
1319
|
+
},
|
|
1320
|
+
{
|
|
1321
|
+
"type": "scope_resolution",
|
|
1322
|
+
"named": true
|
|
1299
1323
|
}
|
|
1300
1324
|
]
|
|
1301
1325
|
}
|
|
@@ -1472,6 +1496,18 @@
|
|
|
1472
1496
|
{
|
|
1473
1497
|
"type": "_arg",
|
|
1474
1498
|
"named": true
|
|
1499
|
+
},
|
|
1500
|
+
{
|
|
1501
|
+
"type": "call",
|
|
1502
|
+
"named": true
|
|
1503
|
+
},
|
|
1504
|
+
{
|
|
1505
|
+
"type": "element_reference",
|
|
1506
|
+
"named": true
|
|
1507
|
+
},
|
|
1508
|
+
{
|
|
1509
|
+
"type": "scope_resolution",
|
|
1510
|
+
"named": true
|
|
1475
1511
|
}
|
|
1476
1512
|
]
|
|
1477
1513
|
},
|
|
@@ -1655,6 +1691,14 @@
|
|
|
1655
1691
|
{
|
|
1656
1692
|
"type": "_primary",
|
|
1657
1693
|
"named": true
|
|
1694
|
+
},
|
|
1695
|
+
{
|
|
1696
|
+
"type": "element_reference",
|
|
1697
|
+
"named": true
|
|
1698
|
+
},
|
|
1699
|
+
{
|
|
1700
|
+
"type": "scope_resolution",
|
|
1701
|
+
"named": true
|
|
1658
1702
|
}
|
|
1659
1703
|
]
|
|
1660
1704
|
}
|
|
@@ -2386,6 +2430,26 @@
|
|
|
2386
2430
|
{
|
|
2387
2431
|
"type": "_arg",
|
|
2388
2432
|
"named": true
|
|
2433
|
+
},
|
|
2434
|
+
{
|
|
2435
|
+
"type": "call",
|
|
2436
|
+
"named": true
|
|
2437
|
+
},
|
|
2438
|
+
{
|
|
2439
|
+
"type": "element_reference",
|
|
2440
|
+
"named": true
|
|
2441
|
+
},
|
|
2442
|
+
{
|
|
2443
|
+
"type": "method",
|
|
2444
|
+
"named": true
|
|
2445
|
+
},
|
|
2446
|
+
{
|
|
2447
|
+
"type": "scope_resolution",
|
|
2448
|
+
"named": true
|
|
2449
|
+
},
|
|
2450
|
+
{
|
|
2451
|
+
"type": "singleton_method",
|
|
2452
|
+
"named": true
|
|
2389
2453
|
}
|
|
2390
2454
|
]
|
|
2391
2455
|
}
|
|
@@ -2411,6 +2475,10 @@
|
|
|
2411
2475
|
"type": "call",
|
|
2412
2476
|
"named": true
|
|
2413
2477
|
},
|
|
2478
|
+
{
|
|
2479
|
+
"type": "element_reference",
|
|
2480
|
+
"named": true
|
|
2481
|
+
},
|
|
2414
2482
|
{
|
|
2415
2483
|
"type": "method",
|
|
2416
2484
|
"named": true
|
|
@@ -2423,6 +2491,10 @@
|
|
|
2423
2491
|
"type": "return",
|
|
2424
2492
|
"named": true
|
|
2425
2493
|
},
|
|
2494
|
+
{
|
|
2495
|
+
"type": "scope_resolution",
|
|
2496
|
+
"named": true
|
|
2497
|
+
},
|
|
2426
2498
|
{
|
|
2427
2499
|
"type": "singleton_method",
|
|
2428
2500
|
"named": true
|
|
@@ -2797,6 +2869,18 @@
|
|
|
2797
2869
|
{
|
|
2798
2870
|
"type": "_pattern_primitive",
|
|
2799
2871
|
"named": true
|
|
2872
|
+
},
|
|
2873
|
+
{
|
|
2874
|
+
"type": "call",
|
|
2875
|
+
"named": true
|
|
2876
|
+
},
|
|
2877
|
+
{
|
|
2878
|
+
"type": "element_reference",
|
|
2879
|
+
"named": true
|
|
2880
|
+
},
|
|
2881
|
+
{
|
|
2882
|
+
"type": "scope_resolution",
|
|
2883
|
+
"named": true
|
|
2800
2884
|
}
|
|
2801
2885
|
]
|
|
2802
2886
|
},
|
|
@@ -3038,6 +3122,10 @@
|
|
|
3038
3122
|
{
|
|
3039
3123
|
"type": "_primary",
|
|
3040
3124
|
"named": true
|
|
3125
|
+
},
|
|
3126
|
+
{
|
|
3127
|
+
"type": "element_reference",
|
|
3128
|
+
"named": true
|
|
3041
3129
|
}
|
|
3042
3130
|
]
|
|
3043
3131
|
}
|
|
@@ -3105,6 +3193,10 @@
|
|
|
3105
3193
|
"type": "call",
|
|
3106
3194
|
"named": true
|
|
3107
3195
|
},
|
|
3196
|
+
{
|
|
3197
|
+
"type": "element_reference",
|
|
3198
|
+
"named": true
|
|
3199
|
+
},
|
|
3108
3200
|
{
|
|
3109
3201
|
"type": "method",
|
|
3110
3202
|
"named": true
|
|
@@ -3117,6 +3209,10 @@
|
|
|
3117
3209
|
"type": "return",
|
|
3118
3210
|
"named": true
|
|
3119
3211
|
},
|
|
3212
|
+
{
|
|
3213
|
+
"type": "scope_resolution",
|
|
3214
|
+
"named": true
|
|
3215
|
+
},
|
|
3120
3216
|
{
|
|
3121
3217
|
"type": "singleton_method",
|
|
3122
3218
|
"named": true
|
|
@@ -3145,9 +3241,17 @@
|
|
|
3145
3241
|
"type": "_arg",
|
|
3146
3242
|
"named": true
|
|
3147
3243
|
},
|
|
3244
|
+
{
|
|
3245
|
+
"type": "_nonlocal_variable",
|
|
3246
|
+
"named": true
|
|
3247
|
+
},
|
|
3148
3248
|
{
|
|
3149
3249
|
"type": "_variable",
|
|
3150
3250
|
"named": true
|
|
3251
|
+
},
|
|
3252
|
+
{
|
|
3253
|
+
"type": "self",
|
|
3254
|
+
"named": true
|
|
3151
3255
|
}
|
|
3152
3256
|
]
|
|
3153
3257
|
},
|
|
@@ -3306,6 +3410,26 @@
|
|
|
3306
3410
|
{
|
|
3307
3411
|
"type": "_arg",
|
|
3308
3412
|
"named": true
|
|
3413
|
+
},
|
|
3414
|
+
{
|
|
3415
|
+
"type": "call",
|
|
3416
|
+
"named": true
|
|
3417
|
+
},
|
|
3418
|
+
{
|
|
3419
|
+
"type": "element_reference",
|
|
3420
|
+
"named": true
|
|
3421
|
+
},
|
|
3422
|
+
{
|
|
3423
|
+
"type": "method",
|
|
3424
|
+
"named": true
|
|
3425
|
+
},
|
|
3426
|
+
{
|
|
3427
|
+
"type": "scope_resolution",
|
|
3428
|
+
"named": true
|
|
3429
|
+
},
|
|
3430
|
+
{
|
|
3431
|
+
"type": "singleton_method",
|
|
3432
|
+
"named": true
|
|
3309
3433
|
}
|
|
3310
3434
|
]
|
|
3311
3435
|
}
|
package/tree-sitter-ruby.wasm
CHANGED
|
Binary file
|