/
RubyParser.y
3264 lines (3014 loc) · 133 KB
/
RubyParser.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%{
package org.truffleruby.parser.parser;
import com.oracle.truffle.api.strings.TruffleString;
import java.util.Set;
import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.truffleruby.Layouts;
import org.truffleruby.annotations.SuppressFBWarnings;
import org.truffleruby.core.encoding.Encodings;
import org.truffleruby.core.encoding.RubyEncoding;
import org.truffleruby.core.encoding.TStringUtils;
import org.truffleruby.core.string.TStringConstants;
import org.truffleruby.language.SourceIndexLength;
import org.truffleruby.parser.RubyDeferredWarnings;
import org.truffleruby.parser.ast.ArgsParseNode;
import org.truffleruby.parser.ast.ArgumentParseNode;
import org.truffleruby.parser.ast.ArrayParseNode;
import org.truffleruby.parser.ast.ArrayPatternParseNode;
import org.truffleruby.parser.ast.AssignableParseNode;
import org.truffleruby.parser.ast.BackRefParseNode;
import org.truffleruby.parser.ast.BeginParseNode;
import org.truffleruby.parser.ast.BlockAcceptingParseNode;
import org.truffleruby.parser.ast.BlockArgParseNode;
import org.truffleruby.parser.ast.BlockParseNode;
import org.truffleruby.parser.ast.BlockPassParseNode;
import org.truffleruby.parser.ast.BreakParseNode;
import org.truffleruby.parser.ast.ClassParseNode;
import org.truffleruby.parser.ast.ClassVarAsgnParseNode;
import org.truffleruby.parser.ast.ClassVarParseNode;
import org.truffleruby.parser.ast.Colon3ParseNode;
import org.truffleruby.parser.ast.ConstDeclParseNode;
import org.truffleruby.parser.ast.ConstParseNode;
import org.truffleruby.parser.ast.DStrParseNode;
import org.truffleruby.parser.ast.DSymbolParseNode;
import org.truffleruby.parser.ast.DXStrParseNode;
import org.truffleruby.parser.ast.DefnParseNode;
import org.truffleruby.parser.ast.DefsParseNode;
import org.truffleruby.parser.ast.DotParseNode;
import org.truffleruby.parser.ast.DVarParseNode;
import org.truffleruby.parser.ast.EncodingParseNode;
import org.truffleruby.parser.ast.EnsureParseNode;
import org.truffleruby.parser.ast.EvStrParseNode;
import org.truffleruby.parser.ast.FCallParseNode;
import org.truffleruby.parser.ast.FalseParseNode;
import org.truffleruby.parser.ast.FileParseNode;
import org.truffleruby.parser.ast.FindPatternParseNode;
import org.truffleruby.parser.ast.FixnumParseNode;
import org.truffleruby.parser.ast.FloatParseNode;
import org.truffleruby.parser.ast.ForParseNode;
import org.truffleruby.parser.ast.GlobalAsgnParseNode;
import org.truffleruby.parser.ast.GlobalVarParseNode;
import org.truffleruby.parser.ast.HashParseNode;
import org.truffleruby.parser.ast.HashPatternParseNode;
import org.truffleruby.parser.ast.IfParseNode;
import org.truffleruby.parser.ast.InParseNode;
import org.truffleruby.parser.ast.InstAsgnParseNode;
import org.truffleruby.parser.ast.InstVarParseNode;
import org.truffleruby.parser.ast.IterParseNode;
import org.truffleruby.parser.ast.LambdaParseNode;
import org.truffleruby.parser.ast.ListParseNode;
import org.truffleruby.parser.ast.LiteralParseNode;
import org.truffleruby.parser.ast.LocalVarParseNode;
import org.truffleruby.parser.ast.ModuleParseNode;
import org.truffleruby.parser.ast.MultipleAsgnParseNode;
import org.truffleruby.parser.ast.NextParseNode;
import org.truffleruby.parser.ast.NilImplicitParseNode;
import org.truffleruby.parser.ast.NilParseNode;
import org.truffleruby.parser.ast.NonLocalControlFlowParseNode;
import org.truffleruby.parser.ast.NumericParseNode;
import org.truffleruby.parser.ast.OpAsgnAndParseNode;
import org.truffleruby.parser.ast.OpAsgnOrParseNode;
import org.truffleruby.parser.ast.OptArgParseNode;
import org.truffleruby.parser.ast.ParseNode;
import org.truffleruby.parser.ast.PostExeParseNode;
import org.truffleruby.parser.ast.PreExe19ParseNode;
import org.truffleruby.parser.ast.RationalParseNode;
import org.truffleruby.parser.ast.RedoParseNode;
import org.truffleruby.parser.ast.RegexpParseNode;
import org.truffleruby.parser.ast.RequiredKeywordArgumentValueParseNode;
import org.truffleruby.parser.ast.RescueBodyParseNode;
import org.truffleruby.parser.ast.RescueParseNode;
import org.truffleruby.parser.ast.RestArgParseNode;
import org.truffleruby.parser.ast.RetryParseNode;
import org.truffleruby.parser.ast.ReturnParseNode;
import org.truffleruby.parser.ast.SClassParseNode;
import org.truffleruby.parser.ast.SelfParseNode;
import org.truffleruby.parser.ast.SplatParseNode;
import org.truffleruby.parser.ast.StarParseNode;
import org.truffleruby.parser.ast.StrParseNode;
import org.truffleruby.parser.ast.TrueParseNode;
import org.truffleruby.parser.ast.UnnamedRestArgParseNode;
import org.truffleruby.parser.ast.UntilParseNode;
import org.truffleruby.parser.ast.VAliasParseNode;
import org.truffleruby.parser.ast.WhileParseNode;
import org.truffleruby.parser.ast.XStrParseNode;
import org.truffleruby.parser.ast.YieldParseNode;
import org.truffleruby.parser.ast.ZArrayParseNode;
import org.truffleruby.parser.ast.ZSuperParseNode;
import org.truffleruby.parser.ast.types.ILiteralNode;
import org.truffleruby.parser.lexer.LexerSource;
import org.truffleruby.parser.lexer.RubyLexer;
import org.truffleruby.parser.lexer.StrTerm;
import org.truffleruby.parser.lexer.SyntaxException.PID;
import static org.truffleruby.parser.lexer.RubyLexer.EXPR_BEG;
import static org.truffleruby.parser.lexer.RubyLexer.EXPR_END;
import static org.truffleruby.parser.lexer.RubyLexer.EXPR_ENDARG;
import static org.truffleruby.parser.lexer.RubyLexer.EXPR_ENDFN;
import static org.truffleruby.parser.lexer.RubyLexer.EXPR_FITEM;
import static org.truffleruby.parser.lexer.RubyLexer.EXPR_FNAME;
import static org.truffleruby.parser.lexer.RubyLexer.EXPR_LABEL;
import static org.truffleruby.parser.parser.ParserSupport.value_expr;
// @formatter:off
// CheckStyle: start generated
@SuppressFBWarnings("IP")
@SuppressWarnings({"unchecked", "fallthrough", "cast"})
public class RubyParser {
protected final ParserSupport support;
protected final RubyLexer lexer;
public RubyParser(LexerSource source, RubyDeferredWarnings warnings) {
this.support = new ParserSupport(source, warnings);
this.lexer = new RubyLexer(support, source, warnings);
support.setLexer(lexer);
}
%}
%token <SourceIndexLength> keyword_class keyword_module keyword_def keyword_undef
keyword_begin keyword_rescue keyword_ensure keyword_end keyword_if
keyword_unless keyword_then keyword_elsif keyword_else keyword_case
keyword_when keyword_while keyword_until keyword_for keyword_break
keyword_next keyword_redo keyword_retry keyword_do
keyword_do_cond keyword_do_block keyword_return keyword_yield keyword_super
keyword_self keyword_nil keyword_true keyword_false keyword_and keyword_or
keyword_not modifier_if modifier_unless modifier_while modifier_until
modifier_rescue keyword_alias keyword_defined keyword_BEGIN keyword_END
keyword__LINE__ keyword__FILE__ keyword__ENCODING__ keyword_do_lambda
%token <TruffleString> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
%token <StrParseNode> tCHAR
%type <TruffleString> sym symbol operation operation2 operation3 op fname cname
%type <TruffleString> f_norm_arg restarg_mark
%type <TruffleString> dot_or_colon blkarg_mark
%token <TruffleString> tUPLUS /* unary+ */
%token <TruffleString> tUMINUS /* unary- */
%token <TruffleString> tUMINUS_NUM /* unary- */
%token <TruffleString> tPOW /* ** */
%token <TruffleString> tCMP /* <=> */
%token <TruffleString> tEQ /* == */
%token <TruffleString> tEQQ /* === */
%token <TruffleString> tNEQ /* != */
%token <TruffleString> tGEQ /* >= */
%token <TruffleString> tLEQ /* <= */
%token <TruffleString> tANDOP tOROP /* && and || */
%token <TruffleString> tMATCH tNMATCH /* =~ and !~ */
%token <TruffleString> tDOT /* Is just '.' in ruby and not a token */
%token <TruffleString> tDOT2 tDOT3 /* .. and ... */
%token <TruffleString> tBDOT2 tBDOT3 /* (.. and (... */
%token <TruffleString> tAREF tASET /* [] and []= */
%token <TruffleString> tLSHFT tRSHFT /* << and >> */
%token <TruffleString> tANDDOT /* &. */
%token <TruffleString> tCOLON2 /* :: */
%token <TruffleString> tCOLON3 /* :: at EXPR_BEG */
%token <TruffleString> tOP_ASGN /* +=, -= etc. */
%token <TruffleString> tASSOC /* => */
%token <SourceIndexLength> tLPAREN /* ( */
%token <SourceIndexLength> tLPAREN2 /* ( Is just '(' in ruby and not a token */
%token <TruffleString> tRPAREN /* ) */
%token <SourceIndexLength> tLPAREN_ARG /* ( */
%token <TruffleString> tLBRACK /* [ */
%token <TruffleString> tRBRACK /* ] */
%token <Object> tLBRACE /* { */
%token <SourceIndexLength> tLBRACE_ARG /* { */
%token <TruffleString> tSTAR /* * */
%token <TruffleString> tSTAR2 /* * Is just '*' in ruby and not a token */
%token <TruffleString> tAMPER /* & */
%token <TruffleString> tAMPER2 /* & Is just '&' in ruby and not a token */
%token <TruffleString> tTILDE /* ` is just '`' in ruby and not a token */
%token <TruffleString> tPERCENT /* % is just '%' in ruby and not a token */
%token <TruffleString> tDIVIDE /* / is just '/' in ruby and not a token */
%token <TruffleString> tPLUS /* + is just '+' in ruby and not a token */
%token <TruffleString> tMINUS /* - is just '-' in ruby and not a token */
%token <TruffleString> tLT /* < is just '<' in ruby and not a token */
%token <TruffleString> tGT /* > is just '>' in ruby and not a token */
%token <TruffleString> tPIPE /* | is just '|' in ruby and not a token */
%token <TruffleString> tBANG /* ! is just '!' in ruby and not a token */
%token <TruffleString> tCARET /* ^ is just '^' in ruby and not a token */
%token <SourceIndexLength> tLCURLY /* { is just '{' in ruby and not a token */
%token <TruffleString> tRCURLY /* } is just '}' in ruby and not a token */
%token <TruffleString> tBACK_REF2 /* { is just '`' in ruby and not a token */
%token <TruffleString> tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
%token <TruffleString> tSTRING_DBEG tSTRING_DVAR tSTRING_END
%token <TruffleString> tLAMBDA tLAMBEG
%token <ParseNode> tNTH_REF tBACK_REF tSTRING_CONTENT tINTEGER tIMAGINARY
%token <FloatParseNode> tFLOAT
%token <RationalParseNode> tRATIONAL
%token <RegexpParseNode> tREGEXP_END
%type <RestArgParseNode> f_rest_arg
%type <ParseNode> singleton strings string string1 xstring regexp
%type <ParseNode> string_contents xstring_contents method_call
%type <Object> string_content
%type <ParseNode> regexp_contents
%type <ParseNode> words qwords word literal dsym cpath command_asgn command_call
%type <NumericParseNode> numeric simple_numeric
%type <ParseNode> mrhs_arg
%type <ParseNode> compstmt bodystmt stmts stmt expr arg primary command
%type <ParseNode> stmt_or_begin
%type <ParseNode> expr_value primary_value opt_else cases p_cases if_tail exc_var rel_expr
%type <ParseNode> call_args opt_ensure paren_args superclass
%type <ParseNode> command_args var_ref opt_paren_args block_call block_command
%type <ParseNode> command_rhs arg_rhs
%type <ParseNode> f_opt
%type <ParseNode> undef_list
%type <ParseNode> string_dvar backref
%type <ArgsParseNode> f_args f_args_any f_larglist block_param block_param_def opt_block_param
%type <Object> f_arglist
%type <ParseNode> mrhs mlhs_item mlhs_node arg_value case_body exc_list aref_args
%type <ParseNode> lhs none args
%type <ListParseNode> qword_list word_list
%type <ListParseNode> f_arg f_optarg
%type <ListParseNode> f_marg_list symbol_list
%type <ListParseNode> qsym_list symbols qsymbols
// FIXME: These are node until a better understanding of underlying type
%type <ArgsTailHolder> opt_args_tail opt_block_args_tail block_args_tail args_tail
%type <ParseNode> f_kw f_block_kw
%type <ListParseNode> f_block_kwarg f_kwarg
%type <HashParseNode> assoc_list
%type <HashParseNode> assocs
%type <ParseNodeTuple> assoc
%type <ListParseNode> mlhs_head mlhs_post
%type <ListParseNode> f_block_optarg
%type <BlockPassParseNode> opt_block_arg block_arg none_block_pass
%type <BlockArgParseNode> opt_f_block_arg f_block_arg
%type <IterParseNode> brace_block do_block cmd_brace_block brace_body do_body
%type <MultipleAsgnParseNode> mlhs mlhs_basic
%type <RescueBodyParseNode> opt_rescue
%type <AssignableParseNode> var_lhs
%type <LiteralParseNode> fsym
%type <ParseNode> fitem
%type <ParseNode> f_arg_item
%type <ParseNode> bv_decls
%type <ParseNode> opt_bv_decl lambda_body
%type <LambdaParseNode> lambda
%type <ParseNode> mlhs_inner f_block_opt for_var
%type <ParseNode> opt_call_args f_marg f_margs
%type <TruffleString> bvar
%type <TruffleString> reswords f_bad_arg relop
%type <TruffleString> rparen rbracket
%type <ParseNode> top_compstmt top_stmts top_stmt
%token <TruffleString> tSYMBOLS_BEG
%token <TruffleString> tQSYMBOLS_BEG
%token <TruffleString> tDSTAR
%token <TruffleString> tSTRING_DEND
%type <TruffleString> kwrest_mark f_kwrest f_label
%type <TruffleString> args_forward
%type <TruffleString> call_op call_op2
%type <ArgumentParseNode> f_arg_asgn
%type <FCallParseNode> fcall
%token <TruffleString> tLABEL_END
%type <SourceIndexLength> k_return k_class k_module
%type <InParseNode> p_case_body
%type <ParseNode> p_cases p_top_expr p_top_expr_body
%type <ParseNode> p_expr p_as p_alt p_expr_basic
%type <FindPatternParseNode> p_find
%type <ArrayPatternParseNode> p_args
%type <ListParseNode> p_args_head
%type <ArrayPatternParseNode> p_args_tail
%type <ListParseNode> p_args_post p_arg
%type <ParseNode> p_value p_primitive p_variable p_var_ref p_expr_ref p_const
%type <HashPatternParseNode> p_kwargs
%type <HashParseNode> p_kwarg
%type <ParseNodeTuple> p_kw
%type <TruffleString> p_rest p_kwrest p_kwnorest p_any_kwrest p_kw_label
%type <ParseNode> p_lparen p_lbracket
%type <TruffleString> nonlocal_var
%type <Integer> rbrace
%token <Object> keyword_in
/*
* precedence table
*/
%nonassoc tLOWEST
%nonassoc tLBRACE_ARG
%nonassoc modifier_if modifier_unless modifier_while modifier_until
%left keyword_or keyword_and
%right keyword_not
%nonassoc keyword_defined
%right '=' tOP_ASGN
%left modifier_rescue
%right '?' ':'
%nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
%left tOROP
%left tANDOP
%nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
%left tGT tGEQ tLT tLEQ
%left tPIPE tCARET
%left tAMPER2
%left tLSHFT tRSHFT
%left tPLUS tMINUS
%left tSTAR2 tDIVIDE tPERCENT
%right tUMINUS_NUM tUMINUS
%right tPOW
%right tBANG tTILDE tUPLUS
//%token <Integer> tLAST_TOKEN
%%
program : {
lexer.setState(EXPR_BEG);
support.initTopLocalVariables();
} top_compstmt {
// ENEBO: Removed !compile_for_eval which probably is to reduce warnings
if ($2 != null) {
/* last expression should not be void */
if ($2 instanceof BlockParseNode) {
support.checkUselessStatement($<BlockParseNode>2.getLast());
} else {
support.checkUselessStatement($2);
}
}
support.getResult().setAST(support.addRootNode($2));
}
top_compstmt : top_stmts opt_terms {
if ($1 instanceof BlockParseNode) {
support.checkUselessStatements($<BlockParseNode>1);
}
$$ = $1;
}
top_stmts : none
| top_stmt {
$$ = support.newline_node($1, support.getPosition($1));
}
| top_stmts terms top_stmt {
$$ = support.appendToBlock($1, support.newline_node($3, support.getPosition($3)));
}
| error top_stmt {
$$ = $2;
}
top_stmt : stmt
| keyword_BEGIN tLCURLY top_compstmt tRCURLY {
support.getResult().addBeginNode(new PreExe19ParseNode($1, support.getCurrentScope(), $3));
$$ = null;
}
bodystmt : compstmt opt_rescue opt_else opt_ensure {
ParseNode node = $1;
if ($2 != null) {
node = new RescueParseNode(support.getPosition($1), $1, $2, $3);
} else if ($3 != null) {
support.warn(support.getPosition($1), "else without rescue is useless");
node = support.appendToBlock($1, $3);
}
if ($4 != null) {
if (node != null) {
node = new EnsureParseNode(support.extendedUntil(support.getPosition($1), support.getPosition($4)), support.makeNullNil(node), $4);
} else {
node = support.appendToBlock($4, NilImplicitParseNode.NIL);
}
}
$$ = node;
}
compstmt : stmts opt_terms {
if ($1 instanceof BlockParseNode) {
support.checkUselessStatements($<BlockParseNode>1);
}
$$ = $1;
}
stmts : none
| stmt_or_begin {
$$ = support.newline_node($1, support.getPosition($1));
}
| stmts terms stmt_or_begin {
$$ = support.appendToBlock($1, support.newline_node($3, support.getPosition($3)));
}
| error stmt {
$$ = $2;
}
stmt_or_begin : stmt {
$$ = $1;
}
// FIXME: How can this new begin ever work? is yyerror conditional in MRI?
| keyword_begin {
support.yyerror("BEGIN is permitted only at toplevel");
} tLCURLY top_compstmt tRCURLY {
$$ = new BeginParseNode($1, support.makeNullNil($2));
}
stmt : keyword_alias fitem {
lexer.setState(EXPR_FNAME|EXPR_FITEM);
} fitem {
$$ = support.newAlias($1, $2, $4);
}
| keyword_alias tGVAR tGVAR {
$$ = new VAliasParseNode($1, support.symbolID($2), support.symbolID($3));
}
| keyword_alias tGVAR tBACK_REF {
$$ = new VAliasParseNode($1, support.symbolID($2), support.symbolID($<BackRefParseNode>3.getByteName()));
}
| keyword_alias tGVAR tNTH_REF {
support.yyerror("can't make alias for the number variables");
}
| keyword_undef undef_list {
$$ = $2;
}
| stmt modifier_if expr_value {
$$ = new IfParseNode(support.getPosition($1), support.getConditionNode($3), $1, null);
$<ParseNode>$.extendPosition($3);
}
| stmt modifier_unless expr_value {
$$ = new IfParseNode(support.getPosition($1), support.getConditionNode($3), null, $1);
$<ParseNode>$.extendPosition($3);
}
| stmt modifier_while expr_value {
if ($1 != null && $1 instanceof BeginParseNode) {
$$ = new WhileParseNode(support.getPosition($1), support.getConditionNode($3), $<BeginParseNode>1.getBodyNode(), false);
} else {
$$ = new WhileParseNode(support.getPosition($1), support.getConditionNode($3), $1, true);
}
}
| stmt modifier_until expr_value {
if ($1 != null && $1 instanceof BeginParseNode) {
$$ = new UntilParseNode(support.getPosition($1), support.getConditionNode($3), $<BeginParseNode>1.getBodyNode(), false);
} else {
$$ = new UntilParseNode(support.getPosition($1), support.getConditionNode($3), $1, true);
}
}
| stmt modifier_rescue stmt {
$$ = support.newRescueModNode($1, $3);
}
| keyword_END tLCURLY compstmt tRCURLY {
if (support.isInDef()) {
support.warn($1, "END in method; use at_exit");
}
$$ = new PostExeParseNode($1, $3);
}
| command_asgn
| mlhs '=' command_call {
value_expr(lexer, $3);
$1.setValueNode($3);
$$ = $1;
}
| lhs '=' mrhs {
value_expr(lexer, $3);
$$ = support.node_assign($1, $3);
}
| mlhs '=' mrhs_arg modifier_rescue stmt {
value_expr(lexer, $3);
$$ = support.node_assign($1, support.newRescueModNode($3, $5));
}
| mlhs '=' mrhs_arg {
$<AssignableParseNode>1.setValueNode($3);
$$ = $1;
}
| expr
command_asgn : lhs '=' command_rhs {
value_expr(lexer, $3);
$$ = support.node_assign($1, $3);
}
| var_lhs tOP_ASGN command_rhs {
value_expr(lexer, $3);
SourceIndexLength pos = $1.getPosition();
TruffleString asgnOp = $2;
if (asgnOp == TStringConstants.OR_OR) {
$1.setValueNode($3);
$$ = new OpAsgnOrParseNode(pos, support.gettable2($1), $1);
} else if (asgnOp == TStringConstants.AMPERSAND_AMPERSAND) {
$1.setValueNode($3);
$$ = new OpAsgnAndParseNode(pos, support.gettable2($1), $1);
} else {
$1.setValueNode(support.getOperatorCallNode(support.gettable2($1), asgnOp, $3));
$$ = $1;
}
}
| primary_value '[' opt_call_args rbracket tOP_ASGN command_rhs {
// FIXME: arg_concat logic missing for opt_call_args
$$ = support.new_opElementAsgnNode($1, $5, $3, $6);
}
| primary_value call_op tIDENTIFIER tOP_ASGN command_rhs {
value_expr(lexer, $5);
$$ = support.newOpAsgn(support.getPosition($1), $1, $2, $5, $3, $4);
}
| primary_value call_op tCONSTANT tOP_ASGN command_rhs {
value_expr(lexer, $5);
$$ = support.newOpAsgn(support.getPosition($1), $1, $2, $5, $3, $4);
}
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs {
SourceIndexLength pos = $1.getPosition();
$$ = support.newOpConstAsgn(pos, support.new_colon2(pos, $1, $3), $4, $5);
}
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs {
value_expr(lexer, $5);
$$ = support.newOpAsgn(support.getPosition($1), $1, $2, $5, $3, $4);
}
| backref tOP_ASGN command_rhs {
support.backrefAssignError($1);
}
command_rhs : command_call %prec tOP_ASGN {
value_expr(lexer, $1);
$$ = $1;
}
| command_call modifier_rescue stmt {
value_expr(lexer, $1);
$$ = support.newRescueModNode($1, $3);
}
| command_asgn
// Node:expr *CURRENT* all but arg so far
expr : command_call
| expr keyword_and expr {
$$ = support.newAndNode(support.getPosition($1), $1, $3);
}
| expr keyword_or expr {
$$ = support.newOrNode(support.getPosition($1), $1, $3);
}
| keyword_not opt_nl expr {
$$ = support.getOperatorCallNode(support.getConditionNode($3), TStringConstants.BANG);
}
| tBANG command_call {
$$ = support.getOperatorCallNode(support.getConditionNode($2), $1);
}
| arg
expr_value : expr {
value_expr(lexer, $1);
}
// Node:command - call with or with block on end [!null]
command_call : command
| block_command
// Node:block_command - A call with a block (foo.bar {...}, foo::bar {...}, bar {...}) [!null]
block_command : block_call
| block_call call_op2 operation2 command_args {
$$ = support.new_call($1, $2, $3, $4, null);
}
// :brace_block - [!null]
cmd_brace_block : tLBRACE_ARG brace_body tRCURLY {
$$ = $2;
}
fcall : operation {
$$ = support.new_fcall($1);
}
// Node:command - fcall/call/yield/super [!null]
command : fcall command_args %prec tLOWEST {
support.frobnicate_fcall_args($1, $2, null);
$$ = $1;
}
| fcall command_args cmd_brace_block {
support.frobnicate_fcall_args($1, $2, $3);
$$ = $1;
}
| primary_value call_op operation2 command_args %prec tLOWEST {
$$ = support.new_call($1, $2, $3, $4, null);
}
| primary_value call_op operation2 command_args cmd_brace_block {
$$ = support.new_call($1, $2, $3, $4, $5);
}
| primary_value tCOLON2 operation2 command_args %prec tLOWEST {
$$ = support.new_call($1, $3, $4, null);
}
| primary_value tCOLON2 operation2 command_args cmd_brace_block {
$$ = support.new_call($1, $3, $4, $5);
}
| keyword_super command_args {
$$ = support.new_super($1, $2);
}
| keyword_yield command_args {
$$ = support.new_yield($1, $2);
}
| k_return call_args {
$$ = new ReturnParseNode($1, support.ret_args($2, $1));
}
| keyword_break call_args {
$$ = new BreakParseNode($1, support.ret_args($2, $1));
}
| keyword_next call_args {
$$ = new NextParseNode($1, support.ret_args($2, $1));
}
// MultipleAssigNode:mlhs - [!null]
mlhs : mlhs_basic
| tLPAREN mlhs_inner rparen {
$$ = $2;
}
// MultipleAssignNode:mlhs_entry - mlhs w or w/o parens [!null]
mlhs_inner : mlhs_basic {
$$ = $1;
}
| tLPAREN mlhs_inner rparen {
$$ = new MultipleAsgnParseNode($1, support.newArrayNode($1, $2), null, null);
}
// MultipleAssignNode:mlhs_basic - multiple left hand side (basic because used in multiple context) [!null]
mlhs_basic : mlhs_head {
$$ = new MultipleAsgnParseNode($1.getPosition(), $1, null, null);
}
| mlhs_head mlhs_item {
$$ = new MultipleAsgnParseNode($1.getPosition(), $1.add($2), null, null);
}
| mlhs_head tSTAR mlhs_node {
$$ = new MultipleAsgnParseNode($1.getPosition(), $1, $3, (ListParseNode) null);
}
| mlhs_head tSTAR mlhs_node ',' mlhs_post {
$$ = new MultipleAsgnParseNode($1.getPosition(), $1, $3, $5);
}
| mlhs_head tSTAR {
$$ = new MultipleAsgnParseNode($1.getPosition(), $1, new StarParseNode(lexer.getPosition()), null);
}
| mlhs_head tSTAR ',' mlhs_post {
$$ = new MultipleAsgnParseNode($1.getPosition(), $1, new StarParseNode(lexer.getPosition()), $4);
}
| tSTAR mlhs_node {
$$ = new MultipleAsgnParseNode($2.getPosition(), null, $2, null);
}
| tSTAR mlhs_node ',' mlhs_post {
$$ = new MultipleAsgnParseNode($2.getPosition(), null, $2, $4);
}
| tSTAR {
$$ = new MultipleAsgnParseNode(lexer.getPosition(), null, new StarParseNode(lexer.getPosition()), null);
}
| tSTAR ',' mlhs_post {
$$ = new MultipleAsgnParseNode(lexer.getPosition(), null, new StarParseNode(lexer.getPosition()), $3);
}
mlhs_item : mlhs_node
| tLPAREN mlhs_inner rparen {
$$ = $2;
}
// Set of mlhs terms at front of mlhs (a, *b, d, e = arr # a is head)
mlhs_head : mlhs_item ',' {
$$ = support.newArrayNode($1.getPosition(), $1);
}
| mlhs_head mlhs_item ',' {
$$ = $1.add($2);
}
// Set of mlhs terms at end of mlhs (a, *b, d, e = arr # d,e is post)
mlhs_post : mlhs_item {
$$ = support.newArrayNode($1.getPosition(), $1);
}
| mlhs_post ',' mlhs_item {
$$ = $1.add($3);
}
mlhs_node : /*mri:user_variable*/ tIDENTIFIER {
$$ = support.assignableLabelOrIdentifier($1, null);
}
| tIVAR {
$$ = new InstAsgnParseNode(lexer.tokline, support.symbolID($1), NilImplicitParseNode.NIL);
}
| tGVAR {
$$ = new GlobalAsgnParseNode(lexer.tokline, support.symbolID($1), NilImplicitParseNode.NIL);
}
| tCONSTANT {
if (support.isInDef()) support.compile_error("dynamic constant assignment");
$$ = new ConstDeclParseNode(lexer.tokline, support.symbolID($1), null, NilImplicitParseNode.NIL);
}
| tCVAR {
$$ = new ClassVarAsgnParseNode(lexer.tokline, support.symbolID($1), NilImplicitParseNode.NIL);
} /*mri:user_variable*/
| /*mri:keyword_variable*/ keyword_nil {
support.compile_error("Can't assign to nil");
$$ = null;
}
| keyword_self {
support.compile_error("Can't change the value of self");
$$ = null;
}
| keyword_true {
support.compile_error("Can't assign to true");
$$ = null;
}
| keyword_false {
support.compile_error("Can't assign to false");
$$ = null;
}
| keyword__FILE__ {
support.compile_error("Can't assign to __FILE__");
$$ = null;
}
| keyword__LINE__ {
support.compile_error("Can't assign to __LINE__");
$$ = null;
}
| keyword__ENCODING__ {
support.compile_error("Can't assign to __ENCODING__");
$$ = null;
} /*mri:keyword_variable*/
| primary_value '[' opt_call_args rbracket {
$$ = support.aryset($1, $3);
}
| primary_value call_op tIDENTIFIER {
$$ = support.attrset($1, $2, $3);
}
| primary_value tCOLON2 tIDENTIFIER {
$$ = support.attrset($1, $3);
}
| primary_value call_op tCONSTANT {
$$ = support.attrset($1, $2, $3);
}
| primary_value tCOLON2 tCONSTANT {
if (support.isInDef()) support.yyerror("dynamic constant assignment");
SourceIndexLength position = support.getPosition($1);
$$ = new ConstDeclParseNode(position, (TruffleString) null, support.new_colon2(position, $1, $3), NilImplicitParseNode.NIL);
}
| tCOLON3 tCONSTANT {
if (support.isInDef()) {
support.yyerror("dynamic constant assignment");
}
SourceIndexLength position = lexer.tokline;
$$ = new ConstDeclParseNode(position, (TruffleString) null, support.new_colon3(position, $2), NilImplicitParseNode.NIL);
}
| backref {
support.backrefAssignError($1);
}
// [!null or throws]
lhs : /*mri:user_variable*/ tIDENTIFIER {
$$ = support.assignableLabelOrIdentifier($1, null);
}
| tIVAR {
$$ = new InstAsgnParseNode(lexer.tokline, support.symbolID($1), NilImplicitParseNode.NIL);
}
| tGVAR {
$$ = new GlobalAsgnParseNode(lexer.tokline, support.symbolID($1), NilImplicitParseNode.NIL);
}
| tCONSTANT {
if (support.isInDef()) support.compile_error("dynamic constant assignment");
$$ = new ConstDeclParseNode(lexer.tokline, support.symbolID($1), null, NilImplicitParseNode.NIL);
}
| tCVAR {
$$ = new ClassVarAsgnParseNode(lexer.tokline, support.symbolID($1), NilImplicitParseNode.NIL);
} /*mri:user_variable*/
| /*mri:keyword_variable*/ keyword_nil {
support.compile_error("Can't assign to nil");
$$ = null;
}
| keyword_self {
support.compile_error("Can't change the value of self");
$$ = null;
}
| keyword_true {
support.compile_error("Can't assign to true");
$$ = null;
}
| keyword_false {
support.compile_error("Can't assign to false");
$$ = null;
}
| keyword__FILE__ {
support.compile_error("Can't assign to __FILE__");
$$ = null;
}
| keyword__LINE__ {
support.compile_error("Can't assign to __LINE__");
$$ = null;
}
| keyword__ENCODING__ {
support.compile_error("Can't assign to __ENCODING__");
$$ = null;
} /*mri:keyword_variable*/
| primary_value '[' opt_call_args rbracket {
$$ = support.aryset($1, $3);
}
| primary_value call_op tIDENTIFIER {
$$ = support.attrset($1, $2, $3);
}
| primary_value tCOLON2 tIDENTIFIER {
$$ = support.attrset($1, $3);
}
| primary_value call_op tCONSTANT {
$$ = support.attrset($1, $2, $3);
}
| primary_value tCOLON2 tCONSTANT {
if (support.isInDef()) {
support.yyerror("dynamic constant assignment");
}
SourceIndexLength position = support.getPosition($1);
$$ = new ConstDeclParseNode(position, (TruffleString) null, support.new_colon2(position, $1, $3), NilImplicitParseNode.NIL);
}
| tCOLON3 tCONSTANT {
if (support.isInDef()) {
support.yyerror("dynamic constant assignment");
}
SourceIndexLength position = lexer.tokline;
$$ = new ConstDeclParseNode(position, (TruffleString) null, support.new_colon3(position, $2), NilImplicitParseNode.NIL);
}
| backref {
support.backrefAssignError($1);
}
cname : tIDENTIFIER {
support.yyerror("class/module name must be CONSTANT");
}
| tCONSTANT {
$$ = $1;
}
cpath : tCOLON3 cname {
$$ = support.new_colon3(lexer.tokline, $2);
}
| cname {
$$ = support.new_colon2(lexer.tokline, null, $1);
}
| primary_value tCOLON2 cname {
$$ = support.new_colon2(support.getPosition($1), $1, $3);
}
// ByteList:fname - A function name [!null]
fname : tIDENTIFIER {
$$ = $1;
}
| tCONSTANT {
$$ = $1;
}
| tFID {
$$ = $1;
}
| op {
lexer.setState(EXPR_ENDFN);
$$ = $1;
}
| reswords {
lexer.setState(EXPR_ENDFN);
$$ = $1;
}
// LiteralNode:fsym
fsym : fname {
$$ = new LiteralParseNode(lexer.getPosition(), support.symbolID($1));
}
| symbol {
$$ = new LiteralParseNode(lexer.getPosition(), support.symbolID($1));
}
// Node:fitem
fitem : fsym { // LiteralNode
$$ = $1;
}
| dsym { // SymbolNode/DSymbolNode
$$ = $1;
}
undef_list : fitem {
$$ = support.newUndef($1.getPosition(), $1);
}
| undef_list ',' {
lexer.setState(EXPR_FNAME|EXPR_FITEM);
} fitem {
$$ = support.appendToBlock($1, support.newUndef($1.getPosition(), $4));
}
// ByteList:op
op : tPIPE {
$$ = $1;
}
| tCARET {
$$ = $1;
}
| tAMPER2 {
$$ = $1;
}
| tCMP {
$$ = $1;
}
| tEQ {
$$ = $1;
}
| tEQQ {
$$ = $1;
}
| tMATCH {
$$ = $1;
}
| tNMATCH {
$$ = $1;
}
| tGT {
$$ = $1;
}
| tGEQ {
$$ = $1;
}
| tLT {
$$ = $1;
}
| tLEQ {
$$ = $1;
}
| tNEQ {
$$ = $1;
}
| tLSHFT {
$$ = $1;
}
| tRSHFT{
$$ = $1;
}
| tDSTAR {
$$ = $1;
}
| tPLUS {
$$ = $1;
}
| tMINUS {
$$ = $1;
}
| tSTAR2 {
$$ = $1;
}
| tSTAR {
$$ = $1;
}
| tDIVIDE {
$$ = $1;
}
| tPERCENT {
$$ = $1;
}
| tPOW {
$$ = $1;
}
| tBANG {
$$ = $1;
}
| tTILDE {
$$ = $1;
}
| tUPLUS {
$$ = $1;
}
| tUMINUS {
$$ = $1;
}
| tAREF {
$$ = $1;
}
| tASET {
$$ = $1;
}
| tBACK_REF2 {
$$ = $1;
}
// String:op
reswords : keyword__LINE__ {
$$ = RubyLexer.Keyword.__LINE__.bytes;
}
| keyword__FILE__ {
$$ = RubyLexer.Keyword.__FILE__.bytes;
}
| keyword__ENCODING__ {
$$ = RubyLexer.Keyword.__ENCODING__.bytes;
}
| keyword_BEGIN {
$$ = RubyLexer.Keyword.LBEGIN.bytes;
}
| keyword_END {
$$ = RubyLexer.Keyword.LEND.bytes;
}
| keyword_alias {
$$ = RubyLexer.Keyword.ALIAS.bytes;
}
| keyword_and {
$$ = RubyLexer.Keyword.AND.bytes;
}