@willbooster/tree-sitter-ruby 2.0.5 → 2.0.6
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 +291 -89
- 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,
|
|
@@ -86,6 +88,11 @@ module.exports = grammar({
|
|
|
86
88
|
|
|
87
89
|
word: ($) => $.identifier,
|
|
88
90
|
|
|
91
|
+
conflicts: ($) => [
|
|
92
|
+
[$._chained_primary, $._chained_lhs],
|
|
93
|
+
[$._array_pattern_n, $.as_pattern, $._find_pattern_body],
|
|
94
|
+
],
|
|
95
|
+
|
|
89
96
|
supertypes: ($) => [
|
|
90
97
|
$._statement,
|
|
91
98
|
$._arg,
|
|
@@ -139,7 +146,13 @@ module.exports = grammar({
|
|
|
139
146
|
singleton_method: ($) =>
|
|
140
147
|
seq(
|
|
141
148
|
'def',
|
|
142
|
-
seq(
|
|
149
|
+
seq(
|
|
150
|
+
choice(
|
|
151
|
+
field('object', choice($._variable, $.self, $._nonlocal_variable)),
|
|
152
|
+
seq('(', field('object', $._arg), ')')
|
|
153
|
+
),
|
|
154
|
+
choice('.', '::')
|
|
155
|
+
),
|
|
143
156
|
$._method_rest
|
|
144
157
|
),
|
|
145
158
|
|
|
@@ -173,7 +186,13 @@ module.exports = grammar({
|
|
|
173
186
|
_command_singleton_method: ($) =>
|
|
174
187
|
seq(
|
|
175
188
|
'def',
|
|
176
|
-
seq(
|
|
189
|
+
seq(
|
|
190
|
+
choice(
|
|
191
|
+
field('object', choice($._variable, $.self, $._nonlocal_variable)),
|
|
192
|
+
seq('(', field('object', $._arg), ')')
|
|
193
|
+
),
|
|
194
|
+
choice('.', '::')
|
|
195
|
+
),
|
|
177
196
|
$._command_method_rest
|
|
178
197
|
),
|
|
179
198
|
|
|
@@ -193,7 +212,9 @@ module.exports = grammar({
|
|
|
193
212
|
choice(
|
|
194
213
|
alias($.command_call, $.call),
|
|
195
214
|
alias($.command_call_with_block, $.call),
|
|
196
|
-
|
|
215
|
+
$._chained_arg,
|
|
216
|
+
alias($._chained_assignment, $.assignment),
|
|
217
|
+
alias($._chained_operator_assignment, $.operator_assignment),
|
|
197
218
|
alias($.return_command, $.return),
|
|
198
219
|
alias($.yield_command, $.yield),
|
|
199
220
|
alias($._endless_command_not, $.unary),
|
|
@@ -583,16 +604,54 @@ module.exports = grammar({
|
|
|
583
604
|
alias($.command_operator_assignment, $.operator_assignment),
|
|
584
605
|
alias($.command_call, $.call),
|
|
585
606
|
alias($.command_call_with_block, $.call),
|
|
586
|
-
|
|
607
|
+
$._chained_arg,
|
|
608
|
+
alias($._chained_assignment, $.assignment),
|
|
609
|
+
alias($._chained_operator_assignment, $.operator_assignment),
|
|
587
610
|
alias($.return_command, $.return),
|
|
588
611
|
alias($.yield_command, $.yield),
|
|
589
612
|
alias($.break_command, $.break),
|
|
590
613
|
alias($.next_command, $.next),
|
|
614
|
+
alias($._chained_match_pattern, $.match_pattern),
|
|
615
|
+
alias($._chained_test_pattern, $.test_pattern),
|
|
591
616
|
$.match_pattern,
|
|
592
617
|
$.test_pattern,
|
|
593
618
|
$._arg
|
|
594
619
|
),
|
|
595
620
|
|
|
621
|
+
_chained_match_pattern: ($) =>
|
|
622
|
+
prec(
|
|
623
|
+
100,
|
|
624
|
+
seq(
|
|
625
|
+
field(
|
|
626
|
+
'value',
|
|
627
|
+
choice(
|
|
628
|
+
$._chained_arg,
|
|
629
|
+
alias($._command_method, $.method),
|
|
630
|
+
alias($._command_singleton_method, $.singleton_method)
|
|
631
|
+
)
|
|
632
|
+
),
|
|
633
|
+
'=>',
|
|
634
|
+
field('pattern', $._pattern_top_expr_body)
|
|
635
|
+
)
|
|
636
|
+
),
|
|
637
|
+
_chained_test_pattern: ($) =>
|
|
638
|
+
prec(
|
|
639
|
+
100,
|
|
640
|
+
seq(
|
|
641
|
+
field(
|
|
642
|
+
'value',
|
|
643
|
+
choice(
|
|
644
|
+
$._chained_arg,
|
|
645
|
+
alias($._chained_command, $.call),
|
|
646
|
+
alias($._command_method, $.method),
|
|
647
|
+
alias($._command_singleton_method, $.singleton_method)
|
|
648
|
+
)
|
|
649
|
+
),
|
|
650
|
+
'in',
|
|
651
|
+
field('pattern', $._pattern_top_expr_body)
|
|
652
|
+
)
|
|
653
|
+
),
|
|
654
|
+
|
|
596
655
|
match_pattern: ($) => prec(100, seq(field('value', $._arg), '=>', field('pattern', $._pattern_top_expr_body))),
|
|
597
656
|
|
|
598
657
|
test_pattern: ($) => prec(100, seq(field('value', $._arg), 'in', field('pattern', $._pattern_top_expr_body))),
|
|
@@ -663,17 +722,7 @@ module.exports = grammar({
|
|
|
663
722
|
|
|
664
723
|
parenthesized_statements: ($) => seq('(', optional($._statements), ')'),
|
|
665
724
|
|
|
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
|
-
),
|
|
725
|
+
element_reference: ($) => elementReference($, $._primary),
|
|
677
726
|
|
|
678
727
|
scope_resolution: ($) =>
|
|
679
728
|
prec.left(
|
|
@@ -693,29 +742,75 @@ module.exports = grammar({
|
|
|
693
742
|
),
|
|
694
743
|
|
|
695
744
|
command_call: ($) =>
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
745
|
+
choice(
|
|
746
|
+
seq(
|
|
747
|
+
choice($._call, field('method', choice($._variable, $._function_identifier))),
|
|
748
|
+
field('arguments', alias($.command_argument_list, $.argument_list))
|
|
749
|
+
),
|
|
750
|
+
$._chained_command
|
|
699
751
|
),
|
|
700
752
|
|
|
753
|
+
_chained_command: ($) =>
|
|
754
|
+
seq($._chained_command_call, field('arguments', alias($._chained_command_argument_list, $.argument_list))),
|
|
755
|
+
|
|
701
756
|
command_call_with_block: ($) => {
|
|
702
757
|
const receiver = choice($._call, field('method', choice($._variable, $._function_identifier)));
|
|
703
758
|
const args = field('arguments', alias($.command_argument_list, $.argument_list));
|
|
759
|
+
const chainedArgs = field('arguments', alias($._chained_command_argument_list, $.argument_list));
|
|
704
760
|
const block = field('block', $.block);
|
|
705
761
|
const doBlock = field('block', $.do_block);
|
|
706
762
|
return choice(
|
|
707
763
|
seq(receiver, prec(PREC.CURLY_BLOCK, seq(args, block))),
|
|
708
|
-
seq(receiver, prec(PREC.DO_BLOCK, seq(args, doBlock)))
|
|
764
|
+
seq(receiver, prec(PREC.DO_BLOCK, seq(args, doBlock))),
|
|
765
|
+
seq($._chained_command_call, prec(PREC.CURLY_BLOCK, seq(chainedArgs, block))),
|
|
766
|
+
seq($._chained_command_call, prec(PREC.DO_BLOCK, seq(chainedArgs, doBlock)))
|
|
709
767
|
);
|
|
710
768
|
},
|
|
711
769
|
|
|
770
|
+
_chained_arg: ($) =>
|
|
771
|
+
choice(
|
|
772
|
+
$._chained_primary,
|
|
773
|
+
alias($._chained_binary, $.binary),
|
|
774
|
+
alias($._chained_conditional, $.conditional),
|
|
775
|
+
alias($._chained_range, $.range)
|
|
776
|
+
),
|
|
777
|
+
|
|
778
|
+
_chained_primary: ($) =>
|
|
779
|
+
choice(
|
|
780
|
+
prec.left(alias($._chained_command_call, $.call)),
|
|
781
|
+
alias($._chained_call, $.call),
|
|
782
|
+
alias($._chained_element_reference, $.element_reference),
|
|
783
|
+
alias($._chained_scope_resolution, $.scope_resolution)
|
|
784
|
+
),
|
|
785
|
+
|
|
712
786
|
_chained_command_call: ($) =>
|
|
713
787
|
seq(
|
|
714
|
-
field('receiver', alias($.command_call_with_block, $.call)),
|
|
788
|
+
field('receiver', choice(alias($.command_call_with_block, $.call), $._chained_primary)),
|
|
715
789
|
field('operator', $._call_operator),
|
|
716
790
|
field('method', choice($.identifier, $._function_identifier, $.operator, $.constant))
|
|
717
791
|
),
|
|
718
792
|
|
|
793
|
+
_chained_scope_resolution: ($) =>
|
|
794
|
+
prec.left(
|
|
795
|
+
PREC.CALL + 1,
|
|
796
|
+
seq(field('scope', $._chained_primary), token.immediate('::'), field('name', $.constant))
|
|
797
|
+
),
|
|
798
|
+
|
|
799
|
+
_chained_element_reference: ($) => elementReference($, $._chained_primary),
|
|
800
|
+
|
|
801
|
+
_chained_call: ($) => {
|
|
802
|
+
const receiver = $._chained_command_call;
|
|
803
|
+
const receiverArguments = seq(
|
|
804
|
+
choice(receiver, seq(field('receiver', $._chained_primary), field('operator', $._call_operator))),
|
|
805
|
+
field('arguments', $.argument_list)
|
|
806
|
+
);
|
|
807
|
+
return choice(
|
|
808
|
+
receiverArguments,
|
|
809
|
+
prec(PREC.CURLY_BLOCK, seq(choice(receiver, receiverArguments), field('block', $.block))),
|
|
810
|
+
prec(PREC.DO_BLOCK, seq(choice(receiver, receiverArguments), field('block', $.do_block)))
|
|
811
|
+
);
|
|
812
|
+
},
|
|
813
|
+
|
|
719
814
|
call: ($) => {
|
|
720
815
|
const receiver = choice($._call, field('method', choice($._variable, $._function_identifier)));
|
|
721
816
|
|
|
@@ -736,6 +831,28 @@ module.exports = grammar({
|
|
|
736
831
|
);
|
|
737
832
|
},
|
|
738
833
|
|
|
834
|
+
_chained_command_argument_list: ($) =>
|
|
835
|
+
prec.right(
|
|
836
|
+
choice(
|
|
837
|
+
commaSep1($._argument),
|
|
838
|
+
seq(choice($._chained_plus_arg, alias($._chained_plus_pair, $.pair)), repeat(seq(',', $._argument)))
|
|
839
|
+
)
|
|
840
|
+
),
|
|
841
|
+
|
|
842
|
+
_chained_plus_arg: ($) =>
|
|
843
|
+
choice(
|
|
844
|
+
alias($._chained_plus_argument, $.unary),
|
|
845
|
+
alias($._chained_plus_binary, $.binary),
|
|
846
|
+
alias($._chained_plus_conditional, $.conditional),
|
|
847
|
+
alias($._chained_plus_range, $.range)
|
|
848
|
+
),
|
|
849
|
+
_chained_plus_binary: ($) => binaryExpression($, $._chained_plus_arg),
|
|
850
|
+
_chained_plus_conditional: ($) => conditionalExpression($, $._chained_plus_arg),
|
|
851
|
+
_chained_plus_range: ($) => rangeExpression($, $._chained_plus_arg, false),
|
|
852
|
+
_chained_plus_pair: ($) => prec.right(seq(field('key', $._chained_plus_arg), '=>', field('value', $._arg))),
|
|
853
|
+
_chained_plus_argument: ($) =>
|
|
854
|
+
prec.right(PREC.COMPLEMENT, seq(field('operator', alias($._unary_plus, '+')), field('operand', $._arg))),
|
|
855
|
+
|
|
739
856
|
command_argument_list: ($) => prec.right(commaSep1($._argument)),
|
|
740
857
|
|
|
741
858
|
argument_list: ($) => prec.right(seq(token.immediate('('), optional($._argument_list_with_trailing_comma), ')')),
|
|
@@ -768,6 +885,51 @@ module.exports = grammar({
|
|
|
768
885
|
),
|
|
769
886
|
|
|
770
887
|
_arg_rhs: ($) => choice($._arg, alias($.rescue_modifier_arg, $.rescue_modifier)),
|
|
888
|
+
_chained_lhs: ($) =>
|
|
889
|
+
choice(
|
|
890
|
+
alias($._chained_command_call, $.call),
|
|
891
|
+
alias($._chained_element_reference, $.element_reference),
|
|
892
|
+
alias($._chained_scope_resolution, $.scope_resolution)
|
|
893
|
+
),
|
|
894
|
+
|
|
895
|
+
_chained_left_assignment_list: ($) =>
|
|
896
|
+
prec.left(
|
|
897
|
+
-1,
|
|
898
|
+
seq(
|
|
899
|
+
$._chained_lhs,
|
|
900
|
+
',',
|
|
901
|
+
optional(seq(commaSep1(choice($._lhs, $.rest_assignment, $.destructured_left_assignment)), optional(',')))
|
|
902
|
+
)
|
|
903
|
+
),
|
|
904
|
+
|
|
905
|
+
_chained_assignment: ($) =>
|
|
906
|
+
prec.right(
|
|
907
|
+
PREC.ASSIGN,
|
|
908
|
+
seq(
|
|
909
|
+
field('left', choice($._chained_lhs, alias($._chained_left_assignment_list, $.left_assignment_list))),
|
|
910
|
+
'=',
|
|
911
|
+
field(
|
|
912
|
+
'right',
|
|
913
|
+
choice(
|
|
914
|
+
$._expression,
|
|
915
|
+
$.splat_argument,
|
|
916
|
+
$.right_assignment_list,
|
|
917
|
+
alias($.rescue_modifier_expression, $.rescue_modifier)
|
|
918
|
+
)
|
|
919
|
+
)
|
|
920
|
+
)
|
|
921
|
+
),
|
|
922
|
+
|
|
923
|
+
_chained_operator_assignment: ($) =>
|
|
924
|
+
prec.right(
|
|
925
|
+
PREC.ASSIGN,
|
|
926
|
+
seq(
|
|
927
|
+
field('left', $._chained_lhs),
|
|
928
|
+
field('operator', choice('+=', '-=', '*=', '**=', '/=', '||=', '|=', '&&=', '&=', '%=', '>>=', '<<=', '^=')),
|
|
929
|
+
field('right', choice($._expression, alias($.rescue_modifier_expression, $.rescue_modifier)))
|
|
930
|
+
)
|
|
931
|
+
),
|
|
932
|
+
|
|
771
933
|
assignment: ($) =>
|
|
772
934
|
prec.right(
|
|
773
935
|
PREC.ASSIGN,
|
|
@@ -810,83 +972,29 @@ module.exports = grammar({
|
|
|
810
972
|
)
|
|
811
973
|
),
|
|
812
974
|
|
|
813
|
-
conditional: ($) =>
|
|
814
|
-
prec.right(
|
|
815
|
-
PREC.CONDITIONAL,
|
|
816
|
-
seq(field('condition', $._arg), '?', field('consequence', $._arg), ':', field('alternative', $._arg))
|
|
817
|
-
),
|
|
975
|
+
conditional: ($) => conditionalExpression($, $._arg),
|
|
818
976
|
|
|
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
|
-
},
|
|
977
|
+
_chained_conditional: ($) => conditionalExpression($, $._chained_arg),
|
|
825
978
|
|
|
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
|
|
979
|
+
range: ($) => rangeExpression($, $._arg, true),
|
|
844
980
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
981
|
+
_chained_range: ($) => rangeExpression($, $._chained_arg, false),
|
|
982
|
+
|
|
983
|
+
_range_sign: ($) =>
|
|
984
|
+
prec.right(PREC.UNARY_MINUS, seq(field('operator', alias($._binary_minus, '-')), field('operand', $._arg))),
|
|
985
|
+
|
|
986
|
+
_chained_binary: ($) => binaryExpression($, $._chained_arg, alias($._binary_plus, '+')),
|
|
987
|
+
|
|
988
|
+
binary: ($) => binaryExpression($, $._arg),
|
|
851
989
|
|
|
852
990
|
command_binary: ($) =>
|
|
853
991
|
prec.left(
|
|
854
992
|
seq(field('left', $._expression), field('operator', choice('or', 'and')), field('right', $._expression))
|
|
855
993
|
),
|
|
856
994
|
|
|
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
|
-
},
|
|
995
|
+
unary: ($) => unaryExpression($._arg, choice(alias($._unary_minus, '-'), '+')),
|
|
873
996
|
|
|
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
|
-
},
|
|
997
|
+
command_unary: ($) => unaryExpression($._expression, choice(alias($._unary_minus, '-'), '+')),
|
|
890
998
|
|
|
891
999
|
parenthesized_unary: ($) =>
|
|
892
1000
|
prec(PREC.CALL, seq(field('operator', choice('defined?', 'not')), field('operand', $.parenthesized_statements))),
|
|
@@ -916,10 +1024,20 @@ module.exports = grammar({
|
|
|
916
1024
|
_function_identifier_call: ($) => prec.left(field('method', $._function_identifier)),
|
|
917
1025
|
_lhs: ($) =>
|
|
918
1026
|
prec.left(
|
|
919
|
-
choice(
|
|
1027
|
+
choice(
|
|
1028
|
+
$._variable,
|
|
1029
|
+
$.self,
|
|
1030
|
+
$._nonlocal_variable,
|
|
1031
|
+
$.true,
|
|
1032
|
+
$.false,
|
|
1033
|
+
$.nil,
|
|
1034
|
+
$.scope_resolution,
|
|
1035
|
+
$.element_reference,
|
|
1036
|
+
alias($._call, $.call)
|
|
1037
|
+
)
|
|
920
1038
|
),
|
|
921
1039
|
|
|
922
|
-
_variable: ($) => prec.right(choice($.
|
|
1040
|
+
_variable: ($) => prec.right(choice($.super, $.identifier, $.constant)),
|
|
923
1041
|
|
|
924
1042
|
operator: () =>
|
|
925
1043
|
choice(
|
|
@@ -1162,3 +1280,87 @@ function commaSep1(rule) {
|
|
|
1162
1280
|
function commaSep(rule) {
|
|
1163
1281
|
return optional(commaSep1(rule));
|
|
1164
1282
|
}
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* @param {RuleOrLiteral} operand
|
|
1286
|
+
* @param {RuleOrLiteral} sign
|
|
1287
|
+
*/
|
|
1288
|
+
function unaryExpression(operand, sign) {
|
|
1289
|
+
return choice(
|
|
1290
|
+
prec(PREC.DEFINED, seq(field('operator', 'defined?'), field('operand', operand))),
|
|
1291
|
+
prec.right(PREC.NOT, seq(field('operator', 'not'), field('operand', operand))),
|
|
1292
|
+
prec.right(PREC.UNARY_MINUS, seq(field('operator', sign), field('operand', operand))),
|
|
1293
|
+
prec.right(PREC.COMPLEMENT, seq(field('operator', choice('!', '~')), field('operand', operand)))
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
/**
|
|
1298
|
+
* @param {GrammarSymbols<string>} $
|
|
1299
|
+
* @param {RuleOrLiteral} left
|
|
1300
|
+
* @param {RuleOrLiteral} plus
|
|
1301
|
+
*/
|
|
1302
|
+
function binaryExpression($, left, plus = '+') {
|
|
1303
|
+
// oxlint-disable typescript/unbound-method -- The DSL's `prec` functions do not use `this`.
|
|
1304
|
+
/** @type {[(precedence: number, rule: RuleOrLiteral) => Rule, number, RuleOrLiteral][]} */
|
|
1305
|
+
const operators = [
|
|
1306
|
+
[prec.left, PREC.AND, 'and'],
|
|
1307
|
+
[prec.left, PREC.OR, 'or'],
|
|
1308
|
+
[prec.left, PREC.BOOLEAN_OR, '||'],
|
|
1309
|
+
[prec.left, PREC.BOOLEAN_AND, '&&'],
|
|
1310
|
+
[prec.left, PREC.SHIFT, choice('<<', '>>')],
|
|
1311
|
+
[prec.left, PREC.COMPARISON, choice('<', '<=', '>', '>=')],
|
|
1312
|
+
[prec.left, PREC.BITWISE_AND, alias($._bitwise_and, '&')],
|
|
1313
|
+
[prec.left, PREC.BITWISE_OR, choice('^', '|')],
|
|
1314
|
+
[prec.left, PREC.ADDITIVE, choice(plus, alias($._binary_minus, '-'))],
|
|
1315
|
+
[prec.left, PREC.MULTIPLICATIVE, choice('/', '%', alias($._binary_star, '*'))],
|
|
1316
|
+
[prec.right, PREC.RELATIONAL, choice('==', '!=', '===', '<=>', '=~', '!~')],
|
|
1317
|
+
[prec.right, PREC.EXPONENTIAL, alias($._binary_star_star, '**')],
|
|
1318
|
+
];
|
|
1319
|
+
// oxlint-enable typescript/unbound-method
|
|
1320
|
+
|
|
1321
|
+
return choice(
|
|
1322
|
+
...operators.map(([fn, precedence, operator]) =>
|
|
1323
|
+
fn(precedence, seq(field('left', left), field('operator', operator), field('right', $._arg)))
|
|
1324
|
+
)
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* @param {GrammarSymbols<string>} $
|
|
1330
|
+
* @param {RuleOrLiteral} object
|
|
1331
|
+
*/
|
|
1332
|
+
function elementReference($, object) {
|
|
1333
|
+
return prec.left(
|
|
1334
|
+
1,
|
|
1335
|
+
seq(
|
|
1336
|
+
field('object', object),
|
|
1337
|
+
alias($._element_reference_bracket, '['),
|
|
1338
|
+
optional($._argument_list_with_trailing_comma),
|
|
1339
|
+
']',
|
|
1340
|
+
optional(field('block', choice($.block, $.do_block)))
|
|
1341
|
+
)
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* @param {GrammarSymbols<string>} $
|
|
1347
|
+
* @param {RuleOrLiteral} condition
|
|
1348
|
+
*/
|
|
1349
|
+
function conditionalExpression($, condition) {
|
|
1350
|
+
return prec.right(
|
|
1351
|
+
PREC.CONDITIONAL,
|
|
1352
|
+
seq(field('condition', condition), '?', field('consequence', $._arg), ':', field('alternative', $._arg))
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* @param {GrammarSymbols<string>} $
|
|
1358
|
+
* @param {RuleOrLiteral} begin
|
|
1359
|
+
* @param {boolean} allowBeginless
|
|
1360
|
+
*/
|
|
1361
|
+
function rangeExpression($, begin, allowBeginless) {
|
|
1362
|
+
const end = field('end', choice($._arg, alias($._range_sign, $.unary)));
|
|
1363
|
+
const operator = field('operator', choice('..', '...'));
|
|
1364
|
+
const bounded = seq(field('begin', begin), operator, optional(end));
|
|
1365
|
+
return prec.right(PREC.RANGE, allowBeginless ? choice(bounded, seq(operator, end)) : bounded);
|
|
1366
|
+
}
|
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
|