1
1
class Opal ::Parser
2
2
3
- token CLASS MODULE DEF UNDEF BEGIN RESCUE ENSURE END IF UNLESS
4
- THEN ELSIF ELSE CASE WHEN WHILE UNTIL FOR BREAK NEXT
5
- REDO RETRY IN DO DO_COND DO_BLOCK RETURN YIELD SUPER
6
- SELF NIL TRUE FALSE AND OR NOT IF_MOD UNLESS_MOD WHILE_MOD
7
- UNTIL_MOD RESCUE_MOD ALIAS DEFINED klBEGIN klEND LINE
8
- FILE IDENTIFIER FID GVAR IVAR CONSTANT CVAR NTH_REF
3
+ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
4
+ kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
5
+ kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kRETURN kYIELD kSUPER
6
+ kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
7
+ kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
8
+ k__FILE__ IDENTIFIER FID GVAR IVAR CONSTANT CVAR NTH_REF
9
9
BACK_REF STRING_CONTENT INTEGER FLOAT REGEXP_END ' +@'
10
10
' -@' ' -@NUM' ' **' ' <=>' ' ==' ' ===' ' !=' ' >=' ' <=' ' &&'
11
11
' ||' ' =~' ' !~' ' .' ' ..' ' ...' ' []' ' []=' ' <<' ' >>'
@@ -14,7 +14,7 @@ token CLASS MODULE DEF UNDEF BEGIN RESCUE ENSURE END IF UNLESS
14
14
' ~' ' %' ' /' ' +' ' -' ' <' ' >' ' |' ' !' ' ^'
15
15
LCURLY ' }' BACK_REF2 SYMBOL_BEG STRING_BEG XSTRING_BEG REGEXP_BEG
16
16
WORDS_BEG AWORDS_BEG STRING_DBEG STRING_DVAR STRING_END STRING
17
- SYMBOL ' \\ n' ' ?' ' :' ' ,' SPACE ' ;' LABEL LAMBDA LAMBEG DO_LAMBDA
17
+ SYMBOL ' \\ n' ' ?' ' :' ' ,' SPACE ' ;' LABEL LAMBDA LAMBEG kDO_LAMBDA
18
18
19
19
prechigh
20
20
right ' !' ' ~' ' +@'
@@ -31,12 +31,12 @@ prechigh
31
31
left ' ||'
32
32
nonassoc ' ..' ' ...'
33
33
right ' ?' ' :'
34
- left RESCUE_MOD
34
+ left kRESCUE_MOD
35
35
right ' =' OP_ASGN
36
- nonassoc DEFINED
37
- right NOT
38
- left OR AND
39
- nonassoc IF_MOD UNLESS_MOD WHILE_MOD UNTIL_MOD
36
+ nonassoc kDEFINED
37
+ right kNOT
38
+ left kOR kAND
39
+ nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
40
40
nonassoc tLBRACE_ARG
41
41
nonassoc LOWEST
42
42
preclow
@@ -83,44 +83,44 @@ stmts:
83
83
}
84
84
85
85
stmt:
86
- ALIAS fitem
86
+ kALIAS fitem
87
87
{
88
88
lexer.lex_state = :expr_fname
89
89
}
90
90
fitem
91
91
{
92
92
result = s(:alias, val[1 ], val[3 ])
93
93
}
94
- | ALIAS GVAR GVAR
94
+ | kALIAS GVAR GVAR
95
95
{
96
96
result = s(:valias, val[1 ].intern, val[2 ].intern)
97
97
}
98
- | ALIAS GVAR BACK_REF
99
- | ALIAS GVAR NTH_REF
98
+ | kALIAS GVAR BACK_REF
99
+ | kALIAS GVAR NTH_REF
100
100
{
101
101
result = s(:valias, val[1 ].intern, val[2 ].intern)
102
102
}
103
- | UNDEF undef_list
103
+ | kUNDEF undef_list
104
104
{
105
105
result = val[1 ]
106
106
}
107
- | stmt IF_MOD expr_value
107
+ | stmt kIF_MOD expr_value
108
108
{
109
109
result = new_if val[2 ], val[0 ], nil
110
110
}
111
- | stmt UNLESS_MOD expr_value
111
+ | stmt kUNLESS_MOD expr_value
112
112
{
113
113
result = new_if val[2 ], nil, val[0 ]
114
114
}
115
- | stmt WHILE_MOD expr_value
115
+ | stmt kWHILE_MOD expr_value
116
116
{
117
117
result = s(:while , val[2 ], val[0 ], true )
118
118
}
119
- | stmt UNTIL_MOD expr_value
119
+ | stmt kUNTIL_MOD expr_value
120
120
{
121
121
result = s(:until, val[2 ], val[0 ], true )
122
122
}
123
- | stmt RESCUE_MOD stmt
123
+ | stmt kRESCUE_MOD stmt
124
124
{
125
125
result = s(:rescue_mod, val[0 ], val[2 ])
126
126
}
@@ -165,17 +165,17 @@ stmt:
165
165
166
166
expr:
167
167
command_call
168
- | expr AND expr
168
+ | expr kAND expr
169
169
{
170
170
result = s(:and , val[0 ], val[2 ])
171
171
result.line = val[0 ].line
172
172
}
173
- | expr OR expr
173
+ | expr kOR expr
174
174
{
175
175
result = s(:or , val[0 ], val[2 ])
176
176
result.line = val[0 ].line
177
177
}
178
- | NOT expr
178
+ | kNOT expr
179
179
{
180
180
result = s(:not , val[1 ])
181
181
result.line = val[1 ].line
@@ -192,19 +192,19 @@ expr_value:
192
192
command_call:
193
193
command
194
194
| block_command
195
- | RETURN call_args
195
+ | kRETURN call_args
196
196
{
197
197
args = val[1 ]
198
198
args = args[1 ] if args.size == 2
199
199
result = s(:return , args)
200
200
}
201
- | BREAK call_args
201
+ | kBREAK call_args
202
202
{
203
203
args = val[1 ]
204
204
args = args[1 ] if args.size == 2
205
205
result = s(:break , args)
206
206
}
207
- | NEXT call_args
207
+ | kNEXT call_args
208
208
{
209
209
args = val[1 ]
210
210
args = args[1 ] if args.size == 2
@@ -235,11 +235,11 @@ command:
235
235
result = new_call val[0 ], val[2 ].intern , val[3 ]
236
236
}
237
237
| primary_value ' ::' operation2 command_args cmd_brace_block
238
- | SUPER command_args
238
+ | kSUPER command_args
239
239
{
240
240
result = new_super val[1 ]
241
241
}
242
- | YIELD command_args
242
+ | kYIELD command_args
243
243
{
244
244
result = new_yield val[1 ]
245
245
}
@@ -428,21 +428,21 @@ op:
428
428
| ' []=' | BACK_REF2 | ' !' | ' !='
429
429
430
430
reswords:
431
- LINE | FILE | klBEGIN | klEND | ALIAS | AND
432
- | BEGIN | BREAK | CASE | CLASS | DEF | DEFINED
433
- | DO | ELSE | ELSIF | END | ENSURE | FALSE
434
- | FOR | IN | MODULE | NEXT | NIL | NOT
435
- | OR | REDO | RESCUE | RETRY | RETURN | SELF
436
- | SUPER | THEN | TRUE | UNDEF | WHEN | YIELD
437
- | IF_MOD | UNLESS_MOD | WHILE_MOD | UNTIL_MOD | RESCUE_MOD
438
- | IF | WHILE | UNTIL | UNLESS
431
+ k__LINE__ | k__FILE__ | klBEGIN | klEND | kALIAS | kAND
432
+ | kBEGIN | kBREAK | kCASE | kCLASS | kDEF | kDEFINED
433
+ | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
434
+ | kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
435
+ | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF
436
+ | kSUPER | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
437
+ | kIF_MOD | kUNLESS_MOD | kWHILE_MOD | kUNTIL_MOD | kRESCUE_MOD
438
+ | kIF | kWHILE | kUNTIL | kUNLESS
439
439
440
440
arg:
441
441
lhs ' =' arg
442
442
{
443
443
result = new_assign val[0 ], val[2 ]
444
444
}
445
- | lhs ' =' arg RESCUE_MOD arg
445
+ | lhs ' =' arg kRESCUE_MOD arg
446
446
{
447
447
result = new_assign val[0 ], s (:rescue_mod, val[2 ], val[4 ])
448
448
}
596
596
result = s (:or , val[0 ], val[2 ])
597
597
result.line = val[0 ].line
598
598
}
599
- | DEFINED opt_nl arg
599
+ | kDEFINED opt_nl arg
600
600
{
601
601
result = s (:defined, val[2 ])
602
602
}
@@ -756,11 +756,11 @@ primary:
756
756
| var_ref
757
757
| backref
758
758
| FID
759
- | BEGIN
759
+ | kBEGIN
760
760
{
761
761
result = lexer.line
762
762
}
763
- bodystmt END
763
+ bodystmt kEND
764
764
{
765
765
result = s (:begin, val[2 ])
766
766
result.line = val[1 ]
@@ -793,32 +793,32 @@ primary:
793
793
{
794
794
result = s (:hash, *val[1 ])
795
795
}
796
- | RETURN
796
+ | kRETURN
797
797
{
798
798
result = s (:return )
799
799
}
800
- | YIELD ' (' call_args ' )'
800
+ | kYIELD ' (' call_args ' )'
801
801
{
802
802
result = new_yield val[2 ]
803
803
}
804
- | YIELD ' (' ' )'
804
+ | kYIELD ' (' ' )'
805
805
{
806
806
result = s (:yield)
807
807
}
808
- | YIELD
808
+ | kYIELD
809
809
{
810
810
result = s (:yield)
811
811
}
812
- | DEFINED opt_nl ' (' expr ' )'
812
+ | kDEFINED opt_nl ' (' expr ' )'
813
813
{
814
814
result = s (:defined, val[3 ])
815
815
}
816
- | NOT ' (' expr ' )'
816
+ | kNOT ' (' expr ' )'
817
817
{
818
818
result = s (:not , val[2 ])
819
819
result.line = val[2 ].line
820
820
}
821
- | NOT ' (' ' )'
821
+ | kNOT ' (' ' )'
822
822
{
823
823
result = s (:not , s (:nil))
824
824
}
@@ -837,15 +837,15 @@ primary:
837
837
{
838
838
result = val[1 ]
839
839
}
840
- | IF expr_value then compstmt if_tail END
840
+ | kIF expr_value then compstmt if_tail kEND
841
841
{
842
842
result = new_if val[1 ], val[3 ], val[4 ]
843
843
}
844
- | UNLESS expr_value then compstmt opt_else END
844
+ | kUNLESS expr_value then compstmt opt_else kEND
845
845
{
846
846
result = new_if val[1 ], val[4 ], val[3 ]
847
847
}
848
- | WHILE
848
+ | kWHILE
849
849
{
850
850
lexer.cond_push 1
851
851
result = lexer.line
@@ -854,12 +854,12 @@ primary:
854
854
{
855
855
lexer.cond_pop
856
856
}
857
- compstmt END
857
+ compstmt kEND
858
858
{
859
859
result = s (:while , val[2 ], val[5 ], true )
860
860
result.line = val[1 ]
861
861
}
862
- | UNTIL
862
+ | kUNTIL
863
863
{
864
864
lexer.cond_push 1
865
865
result = lexer.line
@@ -868,87 +868,87 @@ primary:
868
868
{
869
869
lexer.cond_pop
870
870
}
871
- compstmt END
871
+ compstmt kEND
872
872
{
873
873
result = s (:until, val[2 ], val[5 ], true )
874
874
result.line = val[1 ]
875
875
}
876
- | CASE expr_value opt_terms case_body END
876
+ | kCASE expr_value opt_terms case_body kEND
877
877
{
878
878
result = s (:case , val[1 ], *val[3 ])
879
879
result.line = val[1 ].line
880
880
}
881
- | CASE opt_terms case_body END
881
+ | kCASE opt_terms case_body kEND
882
882
{
883
883
result = s (:case , nil, *val[2 ])
884
884
# result.line = val[2 ].line
885
885
}
886
- | CASE opt_terms ELSE compstmt END
886
+ | kCASE opt_terms kELSE compstmt kEND
887
887
{
888
888
result = s (:case , nil, val[3 ])
889
889
# result.line = val[3 ].line
890
890
}
891
- | FOR mlhs IN
891
+ | kFOR mlhs kIN
892
892
{
893
- result = " this.cond_push(1); "
893
+ # ...
894
894
}
895
895
expr_value do
896
896
{
897
- result = " this.cond_pop(); "
897
+ # ...
898
898
}
899
- compstmt END
900
- | CLASS
899
+ compstmt kEND
900
+ | kCLASS
901
901
{
902
902
result = lexer.line
903
903
}
904
904
cpath superclass
905
905
{
906
906
# ...
907
907
}
908
- bodystmt END
908
+ bodystmt kEND
909
909
{
910
910
result = new_class val[2 ], val[3 ], val[5 ]
911
911
result.line = val[1 ]
912
912
result.end_line = lexer.line
913
913
}
914
- | CLASS ' <<'
914
+ | kCLASS ' <<'
915
915
{
916
916
result = lexer.line
917
917
}
918
918
expr term
919
919
{
920
920
# ...
921
921
}
922
- bodystmt END
922
+ bodystmt kEND
923
923
{
924
924
result = new_sclass val[3 ], val[6 ]
925
925
result.line = val[2 ]
926
926
}
927
- | MODULE
927
+ | kMODULE
928
928
{
929
929
result = lexer.line
930
930
}
931
931
cpath
932
932
{
933
933
# ...
934
934
}
935
- bodystmt END
935
+ bodystmt kEND
936
936
{
937
937
result = new_module val[2 ], val[4 ]
938
938
result.line = val[1 ]
939
939
result.end_line = lexer.line
940
940
}
941
- | DEF fname
941
+ | kDEF fname
942
942
{
943
943
result = lexer.scope_line
944
944
push_scope
945
945
}
946
- f_arglist bodystmt END
946
+ f_arglist bodystmt kEND
947
947
{
948
948
result = new_def val[2 ], nil, val[1 ], val[3 ], val[4 ]
949
949
pop_scope
950
950
}
951
- | DEF singleton dot_or_colon
951
+ | kDEF singleton dot_or_colon
952
952
{
953
953
lexer.lex_state = :expr_fname
954
954
}
@@ -957,38 +957,38 @@ primary:
957
957
result = lexer.scope_line
958
958
push_scope
959
959
}
960
- f_arglist bodystmt END
960
+ f_arglist bodystmt kEND
961
961
{
962
962
result = new_def val[5 ], val[1 ], val[4 ], val[6 ], val[7 ]
963
963
pop_scope
964
964
}
965
- | BREAK
965
+ | kBREAK
966
966
{
967
967
result = s (:break )
968
968
}
969
- | NEXT
969
+ | kNEXT
970
970
{
971
971
result = s (:next)
972
972
}
973
- | REDO
973
+ | kREDO
974
974
{
975
975
result = s (:redo)
976
976
}
977
- | RETRY
977
+ | kRETRY
978
978
979
979
primary_value:
980
980
primary
981
981
982
982
then:
983
983
term
984
984
| ' :'
985
- | THEN
986
- | term THEN
985
+ | kTHEN
986
+ | term kTHEN
987
987
988
988
do :
989
989
term
990
990
| ' :'
991
- | DO_COND
991
+ | kDO_COND
992
992
993
993
lambda:
994
994
f_larglist lambda_body
@@ -1014,7 +1014,7 @@ lambda_body:
1014
1014
{
1015
1015
result = val[1 ]
1016
1016
}
1017
- | DO_LAMBDA compstmt END
1017
+ | kDO_LAMBDA compstmt kEND
1018
1018
{
1019
1019
result = val[1 ]
1020
1020
}
@@ -1024,7 +1024,7 @@ if_tail:
1024
1024
{
1025
1025
result = val[0 ]
1026
1026
}
1027
- | ELSIF
1027
+ | kELSIF
1028
1028
{
1029
1029
result = lexer.line
1030
1030
}
@@ -1036,7 +1036,7 @@ if_tail:
1036
1036
1037
1037
opt_else:
1038
1038
none
1039
- | ELSE compstmt
1039
+ | kELSE compstmt
1040
1040
{
1041
1041
result = val[1 ]
1042
1042
}
@@ -1128,12 +1128,12 @@ block_param:
1128
1128
}
1129
1129
1130
1130
do_block:
1131
- DO_BLOCK
1131
+ kDO_BLOCK
1132
1132
{
1133
1133
push_scope :block
1134
1134
result = lexer.line
1135
1135
}
1136
- opt_block_var compstmt END
1136
+ opt_block_var compstmt kEND
1137
1137
{
1138
1138
result = new_iter val[2 ], val[3 ]
1139
1139
result.line = val[1 ]
@@ -1170,11 +1170,11 @@ method_call:
1170
1170
{
1171
1171
result = new_call val[0 ], val[2 ].intern , s (:arglist)
1172
1172
}
1173
- | SUPER paren_args
1173
+ | kSUPER paren_args
1174
1174
{
1175
1175
result = new_super val[1 ]
1176
1176
}
1177
- | SUPER
1177
+ | kSUPER
1178
1178
{
1179
1179
result = s (:super, nil)
1180
1180
}
@@ -1191,20 +1191,20 @@ brace_block:
1191
1191
result.line = val[1 ]
1192
1192
pop_scope
1193
1193
}
1194
- | DO
1194
+ | kDO
1195
1195
{
1196
1196
push_scope :block
1197
1197
result = lexer.line
1198
1198
}
1199
- opt_block_var compstmt END
1199
+ opt_block_var compstmt kEND
1200
1200
{
1201
1201
result = new_iter val[2 ], val[3 ]
1202
1202
result.line = val[1 ]
1203
1203
pop_scope
1204
1204
}
1205
1205
1206
1206
case_body:
1207
- WHEN
1207
+ kWHEN
1208
1208
{
1209
1209
result = lexer.line
1210
1210
}
@@ -1224,7 +1224,7 @@ cases:
1224
1224
| case_body
1225
1225
1226
1226
opt_rescue:
1227
- RESCUE exc_list exc_var then compstmt opt_rescue
1227
+ kRESCUE exc_list exc_var then compstmt opt_rescue
1228
1228
{
1229
1229
exc = val[1 ] || s (:array)
1230
1230
exc << new_assign (val[2 ], s (:gvar, ' $!' .intern )) if val[2 ]
@@ -1255,7 +1255,7 @@ exc_var:
1255
1255
}
1256
1256
1257
1257
opt_ensure:
1258
- ENSURE compstmt
1258
+ kENSURE compstmt
1259
1259
{
1260
1260
result = val[1 ].nil ? ? s (:nil) : val[1 ]
1261
1261
}
@@ -1472,27 +1472,27 @@ variable:
1472
1472
{
1473
1473
result = s (:cvar, val[0 ].intern )
1474
1474
}
1475
- | NIL
1475
+ | kNIL
1476
1476
{
1477
1477
result = s (:nil)
1478
1478
}
1479
- | SELF
1479
+ | kSELF
1480
1480
{
1481
1481
result = s (:self)
1482
1482
}
1483
- | TRUE
1483
+ | kTRUE
1484
1484
{
1485
1485
result = s (:true )
1486
1486
}
1487
- | FALSE
1487
+ | kFALSE
1488
1488
{
1489
1489
result = s (:false )
1490
1490
}
1491
- | FILE
1491
+ | k__FILE__
1492
1492
{
1493
1493
result = s (:str, self.file )
1494
1494
}
1495
- | LINE
1495
+ | k__LINE__
1496
1496
{
1497
1497
result = s (:int , lexer.line )
1498
1498
}
0 commit comments