This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparse.y
3255 lines (2976 loc) · 59.2 KB
/
parse.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
// at first, read this: http://whitequark.org/blog/2013/04/01/ruby-hacking-guide-ch-11-finite-state-lexer/
// Help on nodes generation is around line 185 ;)
%{
#if DEBUG
// #define DEV 1
#define DEV 1
#endif // DEBUG
;(function(){ // whole parser and lexer namespace start
"use strict";
// returns own property or `undefined`
// used at least in Lexer
var hasOwnProperty = Object.prototype.hasOwnProperty;
function ownProperty (obj, prop)
{
if (hasOwnProperty.call(obj, prop))
return obj[prop];
// has no such property
return undefined;
}
// useful when adding an array elements to the end of array
var Array_push = Array.prototype.push;
// char to code shortcut
function $ (c) { return c.charCodeAt(0) }
function $$ (code) { return String.fromCharCode(code) }
#include "builder.js"
%}
%code lexer {
// here we know all the token numbers as a list of constant variables
//
// var END_OF_INPUT = 0;
// var keyword_class = 258;
// var keyword_module = 259;
//
// and so on.
#include "lexer.js"
}
%code actions {
// here goes the code needed in rules only, when generating nodes,
// we still know all the token numbers here too.
var lexer, parser, builder, scope;
// public:
this.setLexer = function (v) { lexer = v; }
this.setParser = function (v) { parser = v; }
this.setBuilder = function (v) { builder = v; }
this.setScope = function (v) { scope = v; }
}
%skeleton "./lalr1.js"
%token <id> 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_in keyword_do keyword_do_cond keyword_do_block keyword_do_LAMBDA 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__
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
%token <node> tINTEGER tFLOAT tSTRING_CONTENT tCHAR
%token <node> tNTH_REF tBACK_REF
%token <num> tREGEXP_END
%type <node> singleton strings string string1 xstring regexp
%type <node> string_contents xstring_contents regexp_contents string_content
%type <node> words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
%type <node> literal numeric dsym cpath
%type <node> top_compstmt top_stmts top_stmt
%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
%type <node> expr_value arg_value primary_value fcall
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
%type <node> args call_args opt_call_args
%type <node> paren_args opt_paren_args args_tail opt_args_tail block_args_tail opt_block_args_tail
%type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs
%type <node> command_asgn mrhs superclass block_call block_command
%type <node> f_block_optarg f_block_opt
%type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
%type <node> block_param opt_block_param block_param_def f_opt
%type <node> f_kwarg f_kw f_block_kwarg f_block_kw
%type <node> bv_decls opt_bv_decl bvar
%type <node> lambda f_larglist lambda_body
%type <node> brace_block cmd_brace_block do_block lhs none fitem
%type <node> mlhs mlhs_head mlhs_basic mlhs_item mlhs_node mlhs_post mlhs_inner
%type <node> fsym
%type <id> keyword_variable user_variable sym
%type <node> symbol
%type <id> operation operation2 operation3
%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
%type <id> f_kwrest
%type <id> k_end
/*%%%*/
/*%
%type <val> program reswords then do dot_or_colon
%*/
%type <id> dot_or_colon
%token <id> END_OF_INPUT 0 "end-of-input"
%token <id> tUPLUS "unary+"
%token <id> tUMINUS "unary-"
%token <id> tPOW "**"
%token <id> tCMP "<=>"
%token <id> tEQ "=="
%token <id> tEQQ "==="
%token <id> tNEQ "!="
%token <id> tGEQ ">="
%token <id> tLEQ "<="
%token <id> tANDOP "&&"
%token <id> tOROP "||"
%token <id> tMATCH "=~"
%token <id> tNMATCH "!~"
%token <id> tDOT2 ".."
%token <id> tDOT3 "..."
%token <id> tAREF "[]"
%token <id> tASET "[]="
%token <id> tLSHFT "<<"
%token <id> tRSHFT ">>"
%token <id> tCOLON2 "::"
%token <id >tCOLON3 ":: at EXPR_BEG"
%token <id> tOP_ASGN /* +=, -= etc. */
%token <id> tASSOC "=>"
%token <id> tLPAREN "("
%token <id> tLPAREN_ARG "( arg"
%token <id> tRPAREN ")"
%token <id> tLBRACK "["
%token <id> tLBRACE "{"
%token <id> tLBRACE_ARG "{ arg"
%token <id> tSTAR "*"
%token <id> tDSTAR "**arg"
%token <id> tAMPER "&"
%token <id> tLAMBDA "->"
%token <id> tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG
%token <id> tSTRING_DBEG tSTRING_DEND tSTRING_DVAR tSTRING_END tLAMBEG
/*
* 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
%left tOROP
%left tANDOP
%nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
%left '>' tGEQ '<' tLEQ
%left '|' '^'
%left '&'
%left tLSHFT tRSHFT
%left '+' '-'
%left '*' '/' '%'
%right tUMINUS_NUM tUMINUS
%right tPOW
%right '!' '~' tUPLUS
%token <id> '?' '>' '<' '|' '^' '&' '+' '-' '*' '/' '%' '{' '}' '[' '.' ',' '~' '`' '(' ')' ']' ';' '\n' '!'
// must be last indeed
%token tLAST_TOKEN
// in rules (and generator) we have access to those things:
// * all the code from prologue (not much though);
// * `lexer`: instance of our Lexer class from the lexer code block;
// * `parser`: instance of our Parser class;
// * $$ and $N through the `yyval` and `yystack` local variables
// * all the code and variables from `rules` code block.
//
// Repeated in generator.js
// The main pattern here is to user plain arrays for all nodes lists
// like `args_tail`, `stmts`, `word_list`, fill them with nodes
// one node by one reduction like `top_stmts.push(top_stmt)`
// and then, in a topmost rule of this list kind, create a node
// with children of this plain array of list items.
// Another pattern here is nesting nodes, obviosly.
// It is done everywhere through the code like this:
// find a block call like this `x.each {…}`
// and create a method call node within a block node like this:
// block(call("x", "each"), block(…)). Slightly complicated, but works.
// Think of it as of an old fasioned HTML tree. If you need red italic
// you nest <i> into <font> to get <font color=red><i>tIDENTIFIER</i></font>
%%
program:
{
lexer.lex_state = EXPR_BEG;
// creates a new chain link of `lvtbl`es
scope.push_dynamic();
}
top_compstmt
{
scope.pop();
builder.resulting_ast = $2;
};
top_compstmt:
top_stmts opt_terms
{
// was: void_stmts($1);
// was: fixup_nodes(deferred_nodes);
$$ = builder.compstmt($1);
};
top_stmts:
none
{
$$ = []; // statements accumulator
}
| top_stmt
{
$$ = [$1];
}
| top_stmts terms top_stmt
{
$1.push($3);
$$ = $1;
}
| error top_stmt
{
$$ = [$2];
};
top_stmt
:
stmt
|
keyword_BEGIN
{
// RIPPER
}
'{' top_compstmt '}'
{
$$ = builder.preexe($4);
}
;
bodystmt:
compstmt opt_rescue opt_else opt_ensure
{
var rescue_bodies = $2;
var else_ = $3;
var ensure = $4;
if (else_ != null && rescue_bodies.length == 0)
{
// TODO
// diagnostic :warning, :useless_else, else_t
lexer.warn("else without rescue is useless");
}
$$ = builder.begin_body($1, rescue_bodies, else_, ensure);
};
compstmt:
stmts opt_terms
{
$$ = builder.compstmt($1);
};
stmts:
none
{
$$ = [];
}
| stmt_or_begin
{
$$ = [$1];
}
| stmts terms stmt_or_begin
{
var stmts = $1;
stmts.push($3);
$$ = stmts;
}
| error stmt
{
$$ = [ $2 ];
};
stmt_or_begin:
stmt
|
keyword_BEGIN
{
if (lexer.in_def)
{
lexer.yyerror("BEGIN is permitted only at toplevel");
}
}
'{' top_compstmt '}'
{
$$ = builder.preexe($4);
};
stmt:
keyword_alias fitem
{
lexer.lex_state = EXPR_FNAME;
}
fitem
{
$$ = builder.alias($2, $4);
}
|
keyword_alias tGVAR tGVAR
{
$$ = builder.alias_gvar_gvar($2, $3);
}
|
keyword_alias tGVAR tBACK_REF
{
$$ = builder.alias_gvar_backref($2, $3);
}
|
keyword_alias tGVAR tNTH_REF
{
lexer.yyerror("can't make alias for the number variables");
// $$ = NEW_BEGIN(null);
}
|
keyword_undef undef_list
{
$$ = builder.undef_method($2);
}
|
stmt modifier_if expr_value
{
// true branch, null, the body
$$ = builder.condition_mod($1, null, $3);
}
|
stmt modifier_unless expr_value
{
// null, false branch, the body
$$ = builder.condition_mod(null, $1, $3);
}
|
stmt modifier_while expr_value
{
$$ = builder.loop_mod('while', $1, $3);
}
|
stmt modifier_until expr_value
{
$$ = builder.loop_mod('until', $1, $3);
}
|
stmt modifier_rescue stmt
{
// exc_list, exc_var, compound_stmt
var rescue_body = builder.rescue_body(null, null, $3);
$$ = builder.begin_body($1, [ rescue_body ]);
}
|
keyword_END '{' compstmt '}'
{
if (lexer.in_def || lexer.in_single)
{
lexer.warn("END in method; use at_exit");
}
$$ = builder.postexe($3);
}
|
command_asgn
|
mlhs '=' command_call
{
$$ = builder.multi_assign($1, $3);
}
|
var_lhs tOP_ASGN command_call
{
$$ = builder.op_assign($1, $2, $3);
}
|
primary_value '[' opt_call_args rbracket tOP_ASGN command_call
{
$$ = builder.op_assign(builder.index($1, $3), $5, $6);
}
|
primary_value '.' tIDENTIFIER tOP_ASGN command_call
{
$$ = builder.op_assign(builder.call_method($1, $2, $3), $4, $5);
}
|
primary_value '.' tCONSTANT tOP_ASGN command_call
{
$$ = builder.op_assign(builder.call_method($1, $2, $3), $4, $5);
}
|
primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
{
$$ = builder.op_assign(builder.call_method($1, $2, $3), $4, $5);
}
|
primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
{
$$ = builder.op_assign(builder.call_method($1, $2, $3), $4, $5);
}
|
backref tOP_ASGN command_call
{
// expected to return `null` as Ruby doesn't allow backref assignment
$$ = builder.op_assign($1, $2, $3);
}
|
lhs '=' mrhs
{
// mrhs is an array
$$ = builder.assign($1, builder.array($3));
}
|
mlhs '=' arg_value
{
$$ = builder.multi_assign($1, $3);
}
|
mlhs '=' mrhs
{
$$ = builder.multi_assign($1, builder.array($3));
}
|
expr
;
command_asgn:
lhs '=' command_call
{
$$ = builder.assign($1, $3);
}
|
lhs '=' command_asgn
{
$$ = builder.assign($1, $3);
}
;
expr
:
command_call
|
expr keyword_and expr
{
$$ = builder.logical_op('and', $1, $3);
}
| expr keyword_or expr
{
$$ = builder.logical_op('or', $1, $3);
}
|
keyword_not opt_nl expr
{
$$ = builder.not_op($3);
}
|
'!' command_call
{
$$ = builder.not_op($2);
}
|
arg
;
expr_value:
expr
;
command_call
:
command
|
block_command
;
block_command
:
block_call
|
block_call dot_or_colon operation2 command_args
{
$$ = builder.call_method($1, $2, $3, $4);
}
;
cmd_brace_block:
tLBRACE_ARG
{
scope.push_dynamic();
// $<num>$ = lexer.ruby_sourceline;
}
opt_block_param compstmt '}'
{
$$ = { args: $3, body: $4 };
// touching this alters the parse.output
$<num>2; // nd_set_line($$, $<num>2);
scope.pop();
}
;
fcall:
operation
{
// nd_set_line($$, tokline); TODO
}
;
command:
fcall command_args %prec tLOWEST
{
$$ = builder.call_method(null, null, $1, $2);
}
|
fcall command_args cmd_brace_block
{
var method_call = builder.call_method(null, null, $1, $2);
var block = $3;
$$ = builder.block(method_call, block.args, block.body);
}
|
primary_value '.' operation2 command_args %prec tLOWEST
{
$$ = builder.call_method($1, $2, $3, $4);
}
|
primary_value '.' operation2 command_args cmd_brace_block
{
var method_call = builder.call_method($1, $2, $3, $4);
var block = $5;
$$ = builder.block(method_call, block.args, block.body);
}
|
primary_value tCOLON2 operation2 command_args %prec tLOWEST
{
$$ = builder.call_method($1, $2, $3, $4);
}
|
primary_value tCOLON2 operation2 command_args cmd_brace_block
{
var method_call = builder.call_method($1, $2, $3, $4);
var block = $5;
$$ = builder.block(method_call, block.args, block.body);
}
|
keyword_super command_args
{
$$ = builder.keyword_cmd('super', $2);
}
|
keyword_yield command_args
{
$$ = builder.keyword_cmd('yield', $2);
}
|
keyword_return call_args
{
$$ = builder.keyword_cmd('return', $2);
}
|
keyword_break call_args
{
$$ = builder.keyword_cmd('break', $2);
}
|
keyword_next call_args
{
$$ = builder.keyword_cmd('next', $2);
}
;
mlhs
:
mlhs_basic
{
$$ = builder.multi_lhs($1);
}
|
tLPAREN mlhs_inner rparen
{
$$ = builder.begin($2);
}
;
mlhs_inner:
mlhs_basic
{
$$ = builder.multi_lhs($1);
}
|
tLPAREN mlhs_inner rparen
{
$$ = builder.multi_lhs($2);
}
;
mlhs_basic:
mlhs_head
|
mlhs_head mlhs_item
{
var mlhs_head = $1;
mlhs_head.push($2);
$$ = mlhs_head;
}
|
mlhs_head tSTAR mlhs_node
{
var mlhs_head = $1;
mlhs_head.push(builder.splat($3));
$$ = mlhs_head;
}
|
mlhs_head tSTAR mlhs_node ',' mlhs_post
{
var mlhs_head = $1;
mlhs_head.push(builder.splat($3));
Array_push.apply(mlhs_head, $5);
$$ = mlhs_head;
}
|
mlhs_head tSTAR
{
var mlhs_head = $1;
mlhs_head.push(builder.splat_empty());
$$ = mlhs_head;
}
|
mlhs_head tSTAR ',' mlhs_post
{
var mlhs_head = $1;
mlhs_head.push(builder.splat_empty());
Array_push.apply(mlhs_head, $4);
$$ = mlhs_head;
}
|
tSTAR mlhs_node
{
$$ = [ builder.splat($2) ];
}
|
tSTAR mlhs_node ',' mlhs_post
{
var ary = [ builder.splat($2) ];
Array_push.apply(ary, $4);
$$ = ary;
}
|
tSTAR
{
$$ = [ builder.splat_empty() ];
}
| tSTAR ',' mlhs_post
{
var ary = [ builder.splat_empty() ];
Array_push.apply(ary, $3);
$$ = ary;
}
;
mlhs_item
:
mlhs_node
|
tLPAREN mlhs_inner rparen
{
$$ = builder.begin($2);
}
;
mlhs_head
:
mlhs_item ','
{
$$ = [ $1 ];
}
|
mlhs_head mlhs_item ','
{
var mlhs_head = $1;
mlhs_head.push($2);
$$ = mlhs_head;
}
;
mlhs_post
:
mlhs_item
{
$$ = [ $1 ];
}
|
mlhs_post ',' mlhs_item
{
var mlhs_post = $1;
mlhs_post.push($3);
$$ = mlhs_post;
}
;
mlhs_node
:
user_variable
{
$$ = builder.assignable($1);
}
|
keyword_variable
{
$$ = builder.assignable($1);
}
|
primary_value '[' opt_call_args rbracket
{
$$ = builder.index_asgn($1, $3);
}
|
primary_value '.' tIDENTIFIER
{
$$ = builder.attr_asgn($1, $2, $3);
}
|
primary_value tCOLON2 tIDENTIFIER
{
$$ = builder.attr_asgn($1, $2, $3);
}
|
primary_value '.' tCONSTANT
{
$$ = builder.attr_asgn($1, $2, $3);
}
|
primary_value tCOLON2 tCONSTANT
{
$$ = builder.assignable(builder.const_fetch($1, $2, $3));
}
|
tCOLON3 tCONSTANT
{
$$ = builder.assignable(builder.const_global($2));
}
|
backref
{
$$ = builder.assignable($1);
}
;
lhs:
user_variable
{
$$ = builder.assignable($1);
}
|
keyword_variable
{
$$ = builder.assignable($1);
}
|
primary_value '[' opt_call_args rbracket
{
$$ = builder.index_asgn($1, $3);
}
|
primary_value '.' tIDENTIFIER
{
$$ = builder.attr_asgn($1, $2, $3);
}
|
primary_value tCOLON2 tIDENTIFIER
{
$$ = builder.attr_asgn($1, $2, $3);
}
|
primary_value '.' tCONSTANT
{
$$ = builder.attr_asgn($1, $2, $3);
}
|
primary_value tCOLON2 tCONSTANT
{
$$ = builder.assignable(builder.const_fetch($1, $2, $3));
}
|
tCOLON3 tCONSTANT
{
$$ = builder.assignable(builder.const_global($2));
}
|
backref
{
$$ = builder.assignable($1);
}
;
cname
:
tIDENTIFIER
{
lexer.yyerror("class/module name must be CONSTANT");
}
|
tCONSTANT
;
cpath
:
tCOLON3 cname
{
$$ = builder.const_global($2);
}
|
cname
{
$$ = builder.const_($1);
}
|
primary_value tCOLON2 cname
{
$$ = builder.const_fetch($1, $2, $3);
}
;
fname:
tIDENTIFIER
|
tCONSTANT
|
tFID
|
op
{
lexer.lex_state = EXPR_ENDFN;
}
|
reswords
{
lexer.lex_state = EXPR_ENDFN;
}
;
fsym:
fname
{
$$ = builder.symbol($1);
}
|
symbol
;
fitem
:
fsym
{}
|
dsym
;
undef_list
:
fitem
{
$$ = [ $1 ];
}
|
undef_list ','
{
lexer.lex_state = EXPR_FNAME;
}
fitem
{
var undef_list = $1;
undef_list.push($4);
$$ = undef_list;
}
;
op
: '|'
| '^'
| '&'
| tCMP
| tEQ
| tEQQ
| tMATCH
| tNMATCH
| '>'
| tGEQ
| '<'
| tLEQ
| tNEQ
| tLSHFT
| tRSHFT
| '+'
| '-'
| '*'
| tSTAR
| '/'
| '%'
| tPOW
| tDSTAR
| '!'
| '~'
| tUPLUS
| tUMINUS
| tAREF
| tASET
| '`'
;
reswords
: keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
| keyword_BEGIN | keyword_END
| keyword_alias | keyword_and | keyword_begin
| keyword_break | keyword_case | keyword_class | keyword_def
| keyword_defined | keyword_do | keyword_else | keyword_elsif
| keyword_end | keyword_ensure | keyword_false
| keyword_for | keyword_in | keyword_module | keyword_next
| keyword_nil | keyword_not | keyword_or | keyword_redo
| keyword_rescue | keyword_retry | keyword_return | keyword_self
| keyword_super | keyword_then | keyword_true | keyword_undef
| keyword_when | keyword_yield | keyword_if | keyword_unless
| keyword_while | keyword_until
;
arg:
lhs '=' arg
{
$$ = builder.assign($1, $3);
}
|
lhs '=' arg modifier_rescue arg
{
var rescue_body = builder.rescue_body(null, null, $5);
var rescue = builder.begin_body($3, [ rescue_body ]);
$$ = builder.assign($1, rescue);
}
|
var_lhs tOP_ASGN arg
{
$$ = builder.op_assign($1, $2, $3);
}
|
var_lhs tOP_ASGN arg modifier_rescue arg
{
var rescue_body = builder.rescue_body(null, null, $5);
var rescue = builder.begin_body($3, [ rescue_body ]);
$$ = builder.op_assign($1, $2, rescue);
}
|
primary_value '[' opt_call_args rbracket tOP_ASGN arg
{
var index = builder.index($1, $3);
$$ = builder.op_assign(index, $5, $6);
}
|
primary_value '.' tIDENTIFIER tOP_ASGN arg
{
var call_method = builder.call_method($1, $2, $3);
$$ = builder.op_assign(call_method, $4, $5);
}
|
primary_value '.' tCONSTANT tOP_ASGN arg
{
var call_method = builder.call_method($1, $2, $3);
$$ = builder.op_assign(call_method, $4, $5);
}
|
primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
{