parser 2.5.0.5 → 2.5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +18 -0
- data/Rakefile +1 -0
- data/lib/parser/all.rb +1 -0
- data/lib/parser/builders/default.rb +1 -1
- data/lib/parser/context.rb +9 -0
- data/lib/parser/current.rb +13 -4
- data/lib/parser/lexer.rl +61 -19
- data/lib/parser/lexer/dedenter.rb +31 -3
- data/lib/parser/lexer/literal.rb +8 -0
- data/lib/parser/macruby.y +2 -2
- data/lib/parser/ruby18.y +2 -2
- data/lib/parser/ruby19.y +2 -2
- data/lib/parser/ruby20.y +2 -2
- data/lib/parser/ruby21.y +2 -2
- data/lib/parser/ruby22.y +2 -2
- data/lib/parser/ruby23.y +2 -2
- data/lib/parser/ruby24.y +20 -22
- data/lib/parser/ruby25.y +28 -30
- data/lib/parser/ruby26.y +2392 -0
- data/lib/parser/rubymotion.y +2 -2
- data/lib/parser/runner.rb +5 -0
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +1 -0
- data/test/helper.rb +13 -2
- data/test/parse_helper.rb +2 -1
- data/test/test_current.rb +2 -0
- data/test/test_lexer.rb +38 -2
- data/test/test_parser.rb +133 -10
- metadata +4 -2
data/lib/parser/ruby22.y
CHANGED
@@ -1114,7 +1114,7 @@ rule
|
|
1114
1114
|
}
|
1115
1115
|
bodystmt kEND
|
1116
1116
|
{
|
1117
|
-
|
1117
|
+
unless @context.class_definition_allowed?
|
1118
1118
|
diagnostic :error, :class_in_def, nil, val[0]
|
1119
1119
|
end
|
1120
1120
|
|
@@ -1149,7 +1149,7 @@ rule
|
|
1149
1149
|
}
|
1150
1150
|
bodystmt kEND
|
1151
1151
|
{
|
1152
|
-
|
1152
|
+
unless @context.module_definition_allowed?
|
1153
1153
|
diagnostic :error, :module_in_def, nil, val[0]
|
1154
1154
|
end
|
1155
1155
|
|
data/lib/parser/ruby23.y
CHANGED
@@ -1114,7 +1114,7 @@ rule
|
|
1114
1114
|
}
|
1115
1115
|
bodystmt kEND
|
1116
1116
|
{
|
1117
|
-
|
1117
|
+
unless @context.class_definition_allowed?
|
1118
1118
|
diagnostic :error, :class_in_def, nil, val[0]
|
1119
1119
|
end
|
1120
1120
|
|
@@ -1149,7 +1149,7 @@ rule
|
|
1149
1149
|
}
|
1150
1150
|
bodystmt kEND
|
1151
1151
|
{
|
1152
|
-
|
1152
|
+
unless @context.module_definition_allowed?
|
1153
1153
|
diagnostic :error, :module_in_def, nil, val[0]
|
1154
1154
|
end
|
1155
1155
|
|
data/lib/parser/ruby24.y
CHANGED
@@ -946,12 +946,11 @@ rule
|
|
946
946
|
}
|
947
947
|
| kBEGIN
|
948
948
|
{
|
949
|
-
|
950
|
-
@lexer.cmdarg.clear
|
949
|
+
@lexer.cmdarg.push(false)
|
951
950
|
}
|
952
951
|
bodystmt kEND
|
953
952
|
{
|
954
|
-
@lexer.cmdarg
|
953
|
+
@lexer.cmdarg.pop
|
955
954
|
|
956
955
|
result = @builder.begin_keyword(val[0], val[2], val[3])
|
957
956
|
}
|
@@ -1116,12 +1115,12 @@ rule
|
|
1116
1115
|
| kCLASS cpath superclass
|
1117
1116
|
{
|
1118
1117
|
@static_env.extend_static
|
1119
|
-
@lexer.
|
1118
|
+
@lexer.cmdarg.push(false)
|
1120
1119
|
@context.push(:class)
|
1121
1120
|
}
|
1122
1121
|
bodystmt kEND
|
1123
1122
|
{
|
1124
|
-
|
1123
|
+
unless @context.class_definition_allowed?
|
1125
1124
|
diagnostic :error, :class_in_def, nil, val[0]
|
1126
1125
|
end
|
1127
1126
|
|
@@ -1130,14 +1129,14 @@ rule
|
|
1130
1129
|
lt_t, superclass,
|
1131
1130
|
val[4], val[5])
|
1132
1131
|
|
1133
|
-
@lexer.
|
1132
|
+
@lexer.cmdarg.pop
|
1134
1133
|
@static_env.unextend
|
1135
1134
|
@context.pop
|
1136
1135
|
}
|
1137
1136
|
| kCLASS tLSHFT expr term
|
1138
1137
|
{
|
1139
1138
|
@static_env.extend_static
|
1140
|
-
@lexer.
|
1139
|
+
@lexer.cmdarg.push(false)
|
1141
1140
|
@context.push(:sclass)
|
1142
1141
|
}
|
1143
1142
|
bodystmt kEND
|
@@ -1145,31 +1144,31 @@ rule
|
|
1145
1144
|
result = @builder.def_sclass(val[0], val[1], val[2],
|
1146
1145
|
val[5], val[6])
|
1147
1146
|
|
1148
|
-
@lexer.
|
1147
|
+
@lexer.cmdarg.pop
|
1149
1148
|
@static_env.unextend
|
1150
1149
|
@context.pop
|
1151
1150
|
}
|
1152
1151
|
| kMODULE cpath
|
1153
1152
|
{
|
1154
1153
|
@static_env.extend_static
|
1155
|
-
@lexer.
|
1154
|
+
@lexer.cmdarg.push(false)
|
1156
1155
|
}
|
1157
1156
|
bodystmt kEND
|
1158
1157
|
{
|
1159
|
-
|
1158
|
+
unless @context.module_definition_allowed?
|
1160
1159
|
diagnostic :error, :module_in_def, nil, val[0]
|
1161
1160
|
end
|
1162
1161
|
|
1163
1162
|
result = @builder.def_module(val[0], val[1],
|
1164
1163
|
val[3], val[4])
|
1165
1164
|
|
1166
|
-
@lexer.
|
1165
|
+
@lexer.cmdarg.pop
|
1167
1166
|
@static_env.unextend
|
1168
1167
|
}
|
1169
1168
|
| kDEF fname
|
1170
1169
|
{
|
1171
1170
|
@static_env.extend_static
|
1172
|
-
@lexer.
|
1171
|
+
@lexer.cmdarg.push(false)
|
1173
1172
|
@context.push(:def)
|
1174
1173
|
}
|
1175
1174
|
f_arglist bodystmt kEND
|
@@ -1177,7 +1176,7 @@ rule
|
|
1177
1176
|
result = @builder.def_method(val[0], val[1],
|
1178
1177
|
val[3], val[4], val[5])
|
1179
1178
|
|
1180
|
-
@lexer.
|
1179
|
+
@lexer.cmdarg.pop
|
1181
1180
|
@static_env.unextend
|
1182
1181
|
@context.pop
|
1183
1182
|
}
|
@@ -1188,7 +1187,7 @@ rule
|
|
1188
1187
|
fname
|
1189
1188
|
{
|
1190
1189
|
@static_env.extend_static
|
1191
|
-
@lexer.
|
1190
|
+
@lexer.cmdarg.push(false)
|
1192
1191
|
@context.push(:defs)
|
1193
1192
|
}
|
1194
1193
|
f_arglist bodystmt kEND
|
@@ -1196,7 +1195,7 @@ rule
|
|
1196
1195
|
result = @builder.def_singleton(val[0], val[1], val[2],
|
1197
1196
|
val[4], val[6], val[7], val[8])
|
1198
1197
|
|
1199
|
-
@lexer.
|
1198
|
+
@lexer.cmdarg.pop
|
1200
1199
|
@static_env.unextend
|
1201
1200
|
@context.pop
|
1202
1201
|
}
|
@@ -1638,15 +1637,14 @@ opt_block_args_tail:
|
|
1638
1637
|
@static_env.extend_dynamic
|
1639
1638
|
}
|
1640
1639
|
{
|
1641
|
-
|
1642
|
-
@lexer.cmdarg.clear
|
1640
|
+
@lexer.cmdarg.push(false)
|
1643
1641
|
}
|
1644
1642
|
opt_block_param compstmt
|
1645
1643
|
{
|
1646
1644
|
result = [ val[2], val[3] ]
|
1647
1645
|
|
1648
1646
|
@static_env.unextend
|
1649
|
-
@lexer.cmdarg
|
1647
|
+
@lexer.cmdarg.pop
|
1650
1648
|
}
|
1651
1649
|
|
1652
1650
|
case_body: kWHEN args then compstmt cases
|
@@ -1845,13 +1843,13 @@ regexp_contents: # nothing
|
|
1845
1843
|
}
|
1846
1844
|
| tSTRING_DBEG
|
1847
1845
|
{
|
1848
|
-
@lexer.
|
1849
|
-
@lexer.
|
1846
|
+
@lexer.cmdarg.push(false)
|
1847
|
+
@lexer.cond.push(false)
|
1850
1848
|
}
|
1851
1849
|
compstmt tSTRING_DEND
|
1852
1850
|
{
|
1853
|
-
@lexer.
|
1854
|
-
@lexer.
|
1851
|
+
@lexer.cmdarg.pop
|
1852
|
+
@lexer.cond.pop
|
1855
1853
|
|
1856
1854
|
result = @builder.begin(val[0], val[2], val[3])
|
1857
1855
|
}
|
data/lib/parser/ruby25.y
CHANGED
@@ -956,12 +956,11 @@ rule
|
|
956
956
|
}
|
957
957
|
| kBEGIN
|
958
958
|
{
|
959
|
-
|
960
|
-
@lexer.cmdarg.clear
|
959
|
+
@lexer.cmdarg.push(false)
|
961
960
|
}
|
962
961
|
bodystmt kEND
|
963
962
|
{
|
964
|
-
@lexer.cmdarg
|
963
|
+
@lexer.cmdarg.pop
|
965
964
|
|
966
965
|
result = @builder.begin_keyword(val[0], val[2], val[3])
|
967
966
|
}
|
@@ -1098,13 +1097,13 @@ rule
|
|
1098
1097
|
| kCLASS cpath superclass
|
1099
1098
|
{
|
1100
1099
|
@static_env.extend_static
|
1101
|
-
@lexer.
|
1102
|
-
@lexer.
|
1100
|
+
@lexer.cmdarg.push(false)
|
1101
|
+
@lexer.cond.push(false)
|
1103
1102
|
@context.push(:class)
|
1104
1103
|
}
|
1105
1104
|
bodystmt kEND
|
1106
1105
|
{
|
1107
|
-
|
1106
|
+
unless @context.class_definition_allowed?
|
1108
1107
|
diagnostic :error, :class_in_def, nil, val[0]
|
1109
1108
|
end
|
1110
1109
|
|
@@ -1113,16 +1112,16 @@ rule
|
|
1113
1112
|
lt_t, superclass,
|
1114
1113
|
val[4], val[5])
|
1115
1114
|
|
1116
|
-
@lexer.
|
1117
|
-
@lexer.
|
1115
|
+
@lexer.cmdarg.pop
|
1116
|
+
@lexer.cond.pop
|
1118
1117
|
@static_env.unextend
|
1119
1118
|
@context.pop
|
1120
1119
|
}
|
1121
1120
|
| kCLASS tLSHFT expr term
|
1122
1121
|
{
|
1123
1122
|
@static_env.extend_static
|
1124
|
-
@lexer.
|
1125
|
-
@lexer.
|
1123
|
+
@lexer.cmdarg.push(false)
|
1124
|
+
@lexer.cond.push(false)
|
1126
1125
|
@context.push(:sclass)
|
1127
1126
|
}
|
1128
1127
|
bodystmt kEND
|
@@ -1130,33 +1129,33 @@ rule
|
|
1130
1129
|
result = @builder.def_sclass(val[0], val[1], val[2],
|
1131
1130
|
val[5], val[6])
|
1132
1131
|
|
1133
|
-
@lexer.
|
1134
|
-
@lexer.
|
1132
|
+
@lexer.cmdarg.pop
|
1133
|
+
@lexer.cond.pop
|
1135
1134
|
@static_env.unextend
|
1136
1135
|
@context.pop
|
1137
1136
|
}
|
1138
1137
|
| kMODULE cpath
|
1139
1138
|
{
|
1140
1139
|
@static_env.extend_static
|
1141
|
-
@lexer.
|
1140
|
+
@lexer.cmdarg.push(false)
|
1142
1141
|
}
|
1143
1142
|
bodystmt kEND
|
1144
1143
|
{
|
1145
|
-
|
1144
|
+
unless @context.module_definition_allowed?
|
1146
1145
|
diagnostic :error, :module_in_def, nil, val[0]
|
1147
1146
|
end
|
1148
1147
|
|
1149
1148
|
result = @builder.def_module(val[0], val[1],
|
1150
1149
|
val[3], val[4])
|
1151
1150
|
|
1152
|
-
@lexer.
|
1151
|
+
@lexer.cmdarg.pop
|
1153
1152
|
@static_env.unextend
|
1154
1153
|
}
|
1155
1154
|
| kDEF fname
|
1156
1155
|
{
|
1157
1156
|
@static_env.extend_static
|
1158
|
-
@lexer.
|
1159
|
-
@lexer.
|
1157
|
+
@lexer.cmdarg.push(false)
|
1158
|
+
@lexer.cond.push(false)
|
1160
1159
|
@context.push(:def)
|
1161
1160
|
}
|
1162
1161
|
f_arglist bodystmt kEND
|
@@ -1164,8 +1163,8 @@ rule
|
|
1164
1163
|
result = @builder.def_method(val[0], val[1],
|
1165
1164
|
val[3], val[4], val[5])
|
1166
1165
|
|
1167
|
-
@lexer.
|
1168
|
-
@lexer.
|
1166
|
+
@lexer.cmdarg.pop
|
1167
|
+
@lexer.cond.pop
|
1169
1168
|
@static_env.unextend
|
1170
1169
|
@context.pop
|
1171
1170
|
}
|
@@ -1176,8 +1175,8 @@ rule
|
|
1176
1175
|
fname
|
1177
1176
|
{
|
1178
1177
|
@static_env.extend_static
|
1179
|
-
@lexer.
|
1180
|
-
@lexer.
|
1178
|
+
@lexer.cmdarg.push(false)
|
1179
|
+
@lexer.cond.push(false)
|
1181
1180
|
@context.push(:defs)
|
1182
1181
|
}
|
1183
1182
|
f_arglist bodystmt kEND
|
@@ -1185,8 +1184,8 @@ rule
|
|
1185
1184
|
result = @builder.def_singleton(val[0], val[1], val[2],
|
1186
1185
|
val[4], val[6], val[7], val[8])
|
1187
1186
|
|
1188
|
-
@lexer.
|
1189
|
-
@lexer.
|
1187
|
+
@lexer.cmdarg.pop
|
1188
|
+
@lexer.cond.pop
|
1190
1189
|
@static_env.unextend
|
1191
1190
|
@context.pop
|
1192
1191
|
}
|
@@ -1635,15 +1634,14 @@ opt_block_args_tail:
|
|
1635
1634
|
@static_env.extend_dynamic
|
1636
1635
|
}
|
1637
1636
|
{
|
1638
|
-
|
1639
|
-
@lexer.cmdarg.clear
|
1637
|
+
@lexer.cmdarg.push(false)
|
1640
1638
|
}
|
1641
1639
|
opt_block_param bodystmt
|
1642
1640
|
{
|
1643
1641
|
result = [ val[2], val[3] ]
|
1644
1642
|
|
1645
1643
|
@static_env.unextend
|
1646
|
-
@lexer.cmdarg
|
1644
|
+
@lexer.cmdarg.pop
|
1647
1645
|
}
|
1648
1646
|
|
1649
1647
|
case_body: kWHEN args then compstmt cases
|
@@ -1842,13 +1840,13 @@ regexp_contents: # nothing
|
|
1842
1840
|
}
|
1843
1841
|
| tSTRING_DBEG
|
1844
1842
|
{
|
1845
|
-
@lexer.
|
1846
|
-
@lexer.
|
1843
|
+
@lexer.cmdarg.push(false)
|
1844
|
+
@lexer.cond.push(false)
|
1847
1845
|
}
|
1848
1846
|
compstmt tSTRING_DEND
|
1849
1847
|
{
|
1850
|
-
@lexer.
|
1851
|
-
@lexer.
|
1848
|
+
@lexer.cmdarg.pop
|
1849
|
+
@lexer.cond.pop
|
1852
1850
|
|
1853
1851
|
result = @builder.begin(val[0], val[2], val[3])
|
1854
1852
|
}
|
data/lib/parser/ruby26.y
ADDED
@@ -0,0 +1,2392 @@
|
|
1
|
+
class Parser::Ruby26
|
2
|
+
|
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 kDO_LAMBDA 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__ k__ENCODING__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT
|
9
|
+
tLABEL tCVAR tNTH_REF tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT
|
10
|
+
tUPLUS tUMINUS tUNARY_NUM tPOW tCMP tEQ tEQQ tNEQ
|
11
|
+
tGEQ tLEQ tANDOP tOROP tMATCH tNMATCH tDOT tDOT2 tDOT3 tAREF
|
12
|
+
tASET tLSHFT tRSHFT tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN
|
13
|
+
tLPAREN2 tRPAREN tLPAREN_ARG tLBRACK tLBRACK2 tRBRACK tLBRACE
|
14
|
+
tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2 tTILDE tPERCENT tDIVIDE
|
15
|
+
tDSTAR tPLUS tMINUS tLT tGT tPIPE tBANG tCARET tLCURLY tRCURLY
|
16
|
+
tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tREGEXP_OPT
|
17
|
+
tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DBEG
|
18
|
+
tSTRING_DVAR tSTRING_END tSTRING_DEND tSTRING tSYMBOL
|
19
|
+
tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA tLAMBEG tCHARACTER
|
20
|
+
tRATIONAL tIMAGINARY tLABEL_END tANDDOT
|
21
|
+
|
22
|
+
prechigh
|
23
|
+
right tBANG tTILDE tUPLUS
|
24
|
+
right tPOW
|
25
|
+
right tUNARY_NUM tUMINUS
|
26
|
+
left tSTAR2 tDIVIDE tPERCENT
|
27
|
+
left tPLUS tMINUS
|
28
|
+
left tLSHFT tRSHFT
|
29
|
+
left tAMPER2
|
30
|
+
left tPIPE tCARET
|
31
|
+
left tGT tGEQ tLT tLEQ
|
32
|
+
nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
|
33
|
+
left tANDOP
|
34
|
+
left tOROP
|
35
|
+
nonassoc tDOT2 tDOT3
|
36
|
+
right tEH tCOLON
|
37
|
+
left kRESCUE_MOD
|
38
|
+
right tEQL tOP_ASGN
|
39
|
+
nonassoc kDEFINED
|
40
|
+
right kNOT
|
41
|
+
left kOR kAND
|
42
|
+
nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
|
43
|
+
nonassoc tLBRACE_ARG
|
44
|
+
nonassoc tLOWEST
|
45
|
+
preclow
|
46
|
+
|
47
|
+
rule
|
48
|
+
|
49
|
+
program: top_compstmt
|
50
|
+
|
51
|
+
top_compstmt: top_stmts opt_terms
|
52
|
+
{
|
53
|
+
result = @builder.compstmt(val[0])
|
54
|
+
}
|
55
|
+
|
56
|
+
top_stmts: # nothing
|
57
|
+
{
|
58
|
+
result = []
|
59
|
+
}
|
60
|
+
| top_stmt
|
61
|
+
{
|
62
|
+
result = [ val[0] ]
|
63
|
+
}
|
64
|
+
| top_stmts terms top_stmt
|
65
|
+
{
|
66
|
+
result = val[0] << val[2]
|
67
|
+
}
|
68
|
+
| error top_stmt
|
69
|
+
{
|
70
|
+
result = [ val[1] ]
|
71
|
+
}
|
72
|
+
|
73
|
+
top_stmt: stmt
|
74
|
+
| klBEGIN begin_block
|
75
|
+
{
|
76
|
+
result = @builder.preexe(val[0], *val[1])
|
77
|
+
}
|
78
|
+
|
79
|
+
begin_block: tLCURLY top_compstmt tRCURLY
|
80
|
+
{
|
81
|
+
result = val
|
82
|
+
}
|
83
|
+
|
84
|
+
bodystmt: compstmt opt_rescue opt_else opt_ensure
|
85
|
+
{
|
86
|
+
rescue_bodies = val[1]
|
87
|
+
else_t, else_ = val[2]
|
88
|
+
ensure_t, ensure_ = val[3]
|
89
|
+
|
90
|
+
if rescue_bodies.empty? && !else_.nil?
|
91
|
+
diagnostic :error, :useless_else, nil, else_t
|
92
|
+
end
|
93
|
+
|
94
|
+
result = @builder.begin_body(val[0],
|
95
|
+
rescue_bodies,
|
96
|
+
else_t, else_,
|
97
|
+
ensure_t, ensure_)
|
98
|
+
}
|
99
|
+
|
100
|
+
compstmt: stmts opt_terms
|
101
|
+
{
|
102
|
+
result = @builder.compstmt(val[0])
|
103
|
+
}
|
104
|
+
|
105
|
+
stmts: # nothing
|
106
|
+
{
|
107
|
+
result = []
|
108
|
+
}
|
109
|
+
| stmt_or_begin
|
110
|
+
{
|
111
|
+
result = [ val[0] ]
|
112
|
+
}
|
113
|
+
| stmts terms stmt_or_begin
|
114
|
+
{
|
115
|
+
result = val[0] << val[2]
|
116
|
+
}
|
117
|
+
| error stmt
|
118
|
+
{
|
119
|
+
result = [ val[1] ]
|
120
|
+
}
|
121
|
+
|
122
|
+
stmt_or_begin: stmt
|
123
|
+
| klBEGIN begin_block
|
124
|
+
{
|
125
|
+
diagnostic :error, :begin_in_method, nil, val[0]
|
126
|
+
}
|
127
|
+
|
128
|
+
stmt: kALIAS fitem
|
129
|
+
{
|
130
|
+
@lexer.state = :expr_fname
|
131
|
+
}
|
132
|
+
fitem
|
133
|
+
{
|
134
|
+
result = @builder.alias(val[0], val[1], val[3])
|
135
|
+
}
|
136
|
+
| kALIAS tGVAR tGVAR
|
137
|
+
{
|
138
|
+
result = @builder.alias(val[0],
|
139
|
+
@builder.gvar(val[1]),
|
140
|
+
@builder.gvar(val[2]))
|
141
|
+
}
|
142
|
+
| kALIAS tGVAR tBACK_REF
|
143
|
+
{
|
144
|
+
result = @builder.alias(val[0],
|
145
|
+
@builder.gvar(val[1]),
|
146
|
+
@builder.back_ref(val[2]))
|
147
|
+
}
|
148
|
+
| kALIAS tGVAR tNTH_REF
|
149
|
+
{
|
150
|
+
diagnostic :error, :nth_ref_alias, nil, val[2]
|
151
|
+
}
|
152
|
+
| kUNDEF undef_list
|
153
|
+
{
|
154
|
+
result = @builder.undef_method(val[0], val[1])
|
155
|
+
}
|
156
|
+
| stmt kIF_MOD expr_value
|
157
|
+
{
|
158
|
+
result = @builder.condition_mod(val[0], nil,
|
159
|
+
val[1], val[2])
|
160
|
+
}
|
161
|
+
| stmt kUNLESS_MOD expr_value
|
162
|
+
{
|
163
|
+
result = @builder.condition_mod(nil, val[0],
|
164
|
+
val[1], val[2])
|
165
|
+
}
|
166
|
+
| stmt kWHILE_MOD expr_value
|
167
|
+
{
|
168
|
+
result = @builder.loop_mod(:while, val[0], val[1], val[2])
|
169
|
+
}
|
170
|
+
| stmt kUNTIL_MOD expr_value
|
171
|
+
{
|
172
|
+
result = @builder.loop_mod(:until, val[0], val[1], val[2])
|
173
|
+
}
|
174
|
+
| stmt kRESCUE_MOD stmt
|
175
|
+
{
|
176
|
+
rescue_body = @builder.rescue_body(val[1],
|
177
|
+
nil, nil, nil,
|
178
|
+
nil, val[2])
|
179
|
+
|
180
|
+
result = @builder.begin_body(val[0], [ rescue_body ])
|
181
|
+
}
|
182
|
+
| klEND tLCURLY compstmt tRCURLY
|
183
|
+
{
|
184
|
+
result = @builder.postexe(val[0], val[1], val[2], val[3])
|
185
|
+
}
|
186
|
+
| command_asgn
|
187
|
+
| mlhs tEQL command_call
|
188
|
+
{
|
189
|
+
result = @builder.multi_assign(val[0], val[1], val[2])
|
190
|
+
}
|
191
|
+
| lhs tEQL mrhs
|
192
|
+
{
|
193
|
+
result = @builder.assign(val[0], val[1],
|
194
|
+
@builder.array(nil, val[2], nil))
|
195
|
+
}
|
196
|
+
| mlhs tEQL mrhs_arg
|
197
|
+
{
|
198
|
+
result = @builder.multi_assign(val[0], val[1], val[2])
|
199
|
+
}
|
200
|
+
| expr
|
201
|
+
|
202
|
+
command_asgn: lhs tEQL command_rhs
|
203
|
+
{
|
204
|
+
result = @builder.assign(val[0], val[1], val[2])
|
205
|
+
}
|
206
|
+
| var_lhs tOP_ASGN command_rhs
|
207
|
+
{
|
208
|
+
result = @builder.op_assign(val[0], val[1], val[2])
|
209
|
+
}
|
210
|
+
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_rhs
|
211
|
+
{
|
212
|
+
result = @builder.op_assign(
|
213
|
+
@builder.index(
|
214
|
+
val[0], val[1], val[2], val[3]),
|
215
|
+
val[4], val[5])
|
216
|
+
}
|
217
|
+
| primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
|
218
|
+
{
|
219
|
+
result = @builder.op_assign(
|
220
|
+
@builder.call_method(
|
221
|
+
val[0], val[1], val[2]),
|
222
|
+
val[3], val[4])
|
223
|
+
}
|
224
|
+
| primary_value call_op tCONSTANT tOP_ASGN command_rhs
|
225
|
+
{
|
226
|
+
result = @builder.op_assign(
|
227
|
+
@builder.call_method(
|
228
|
+
val[0], val[1], val[2]),
|
229
|
+
val[3], val[4])
|
230
|
+
}
|
231
|
+
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
|
232
|
+
{
|
233
|
+
const = @builder.const_op_assignable(
|
234
|
+
@builder.const_fetch(val[0], val[1], val[2]))
|
235
|
+
result = @builder.op_assign(const, val[3], val[4])
|
236
|
+
}
|
237
|
+
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
|
238
|
+
{
|
239
|
+
result = @builder.op_assign(
|
240
|
+
@builder.call_method(
|
241
|
+
val[0], val[1], val[2]),
|
242
|
+
val[3], val[4])
|
243
|
+
}
|
244
|
+
| backref tOP_ASGN command_rhs
|
245
|
+
{
|
246
|
+
@builder.op_assign(val[0], val[1], val[2])
|
247
|
+
}
|
248
|
+
|
249
|
+
command_rhs: command_call =tOP_ASGN
|
250
|
+
| command_call kRESCUE_MOD stmt
|
251
|
+
{
|
252
|
+
rescue_body = @builder.rescue_body(val[1],
|
253
|
+
nil, nil, nil,
|
254
|
+
nil, val[2])
|
255
|
+
|
256
|
+
result = @builder.begin_body(val[0], [ rescue_body ])
|
257
|
+
}
|
258
|
+
| command_asgn
|
259
|
+
|
260
|
+
expr: command_call
|
261
|
+
| expr kAND expr
|
262
|
+
{
|
263
|
+
result = @builder.logical_op(:and, val[0], val[1], val[2])
|
264
|
+
}
|
265
|
+
| expr kOR expr
|
266
|
+
{
|
267
|
+
result = @builder.logical_op(:or, val[0], val[1], val[2])
|
268
|
+
}
|
269
|
+
| kNOT opt_nl expr
|
270
|
+
{
|
271
|
+
result = @builder.not_op(val[0], nil, val[2], nil)
|
272
|
+
}
|
273
|
+
| tBANG command_call
|
274
|
+
{
|
275
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
276
|
+
}
|
277
|
+
| arg
|
278
|
+
|
279
|
+
expr_value: expr
|
280
|
+
|
281
|
+
expr_value_do: {
|
282
|
+
@lexer.cond.push(true)
|
283
|
+
}
|
284
|
+
expr_value do
|
285
|
+
{
|
286
|
+
@lexer.cond.pop
|
287
|
+
result = [ val[1], val[2] ]
|
288
|
+
}
|
289
|
+
|
290
|
+
command_call: command
|
291
|
+
| block_command
|
292
|
+
|
293
|
+
block_command: block_call
|
294
|
+
| block_call dot_or_colon operation2 command_args
|
295
|
+
{
|
296
|
+
result = @builder.call_method(val[0], val[1], val[2],
|
297
|
+
nil, val[3], nil)
|
298
|
+
}
|
299
|
+
|
300
|
+
cmd_brace_block: tLBRACE_ARG
|
301
|
+
{
|
302
|
+
@context.push(:block)
|
303
|
+
}
|
304
|
+
brace_body tRCURLY
|
305
|
+
{
|
306
|
+
result = [ val[0], *val[2], val[3] ]
|
307
|
+
@context.pop
|
308
|
+
}
|
309
|
+
|
310
|
+
fcall: operation
|
311
|
+
|
312
|
+
command: fcall command_args =tLOWEST
|
313
|
+
{
|
314
|
+
result = @builder.call_method(nil, nil, val[0],
|
315
|
+
nil, val[1], nil)
|
316
|
+
}
|
317
|
+
| fcall command_args cmd_brace_block
|
318
|
+
{
|
319
|
+
method_call = @builder.call_method(nil, nil, val[0],
|
320
|
+
nil, val[1], nil)
|
321
|
+
|
322
|
+
begin_t, args, body, end_t = val[2]
|
323
|
+
result = @builder.block(method_call,
|
324
|
+
begin_t, args, body, end_t)
|
325
|
+
}
|
326
|
+
| primary_value call_op operation2 command_args =tLOWEST
|
327
|
+
{
|
328
|
+
result = @builder.call_method(val[0], val[1], val[2],
|
329
|
+
nil, val[3], nil)
|
330
|
+
}
|
331
|
+
| primary_value call_op operation2 command_args cmd_brace_block
|
332
|
+
{
|
333
|
+
method_call = @builder.call_method(val[0], val[1], val[2],
|
334
|
+
nil, val[3], nil)
|
335
|
+
|
336
|
+
begin_t, args, body, end_t = val[4]
|
337
|
+
result = @builder.block(method_call,
|
338
|
+
begin_t, args, body, end_t)
|
339
|
+
}
|
340
|
+
| primary_value tCOLON2 operation2 command_args =tLOWEST
|
341
|
+
{
|
342
|
+
result = @builder.call_method(val[0], val[1], val[2],
|
343
|
+
nil, val[3], nil)
|
344
|
+
}
|
345
|
+
| primary_value tCOLON2 operation2 command_args cmd_brace_block
|
346
|
+
{
|
347
|
+
method_call = @builder.call_method(val[0], val[1], val[2],
|
348
|
+
nil, val[3], nil)
|
349
|
+
|
350
|
+
begin_t, args, body, end_t = val[4]
|
351
|
+
result = @builder.block(method_call,
|
352
|
+
begin_t, args, body, end_t)
|
353
|
+
}
|
354
|
+
| kSUPER command_args
|
355
|
+
{
|
356
|
+
result = @builder.keyword_cmd(:super, val[0],
|
357
|
+
nil, val[1], nil)
|
358
|
+
}
|
359
|
+
| kYIELD command_args
|
360
|
+
{
|
361
|
+
result = @builder.keyword_cmd(:yield, val[0],
|
362
|
+
nil, val[1], nil)
|
363
|
+
}
|
364
|
+
| k_return call_args
|
365
|
+
{
|
366
|
+
result = @builder.keyword_cmd(:return, val[0],
|
367
|
+
nil, val[1], nil)
|
368
|
+
}
|
369
|
+
| kBREAK call_args
|
370
|
+
{
|
371
|
+
result = @builder.keyword_cmd(:break, val[0],
|
372
|
+
nil, val[1], nil)
|
373
|
+
}
|
374
|
+
| kNEXT call_args
|
375
|
+
{
|
376
|
+
result = @builder.keyword_cmd(:next, val[0],
|
377
|
+
nil, val[1], nil)
|
378
|
+
}
|
379
|
+
|
380
|
+
mlhs: mlhs_basic
|
381
|
+
{
|
382
|
+
result = @builder.multi_lhs(nil, val[0], nil)
|
383
|
+
}
|
384
|
+
| tLPAREN mlhs_inner rparen
|
385
|
+
{
|
386
|
+
result = @builder.begin(val[0], val[1], val[2])
|
387
|
+
}
|
388
|
+
|
389
|
+
mlhs_inner: mlhs_basic
|
390
|
+
{
|
391
|
+
result = @builder.multi_lhs(nil, val[0], nil)
|
392
|
+
}
|
393
|
+
| tLPAREN mlhs_inner rparen
|
394
|
+
{
|
395
|
+
result = @builder.multi_lhs(val[0], val[1], val[2])
|
396
|
+
}
|
397
|
+
|
398
|
+
mlhs_basic: mlhs_head
|
399
|
+
| mlhs_head mlhs_item
|
400
|
+
{
|
401
|
+
result = val[0].
|
402
|
+
push(val[1])
|
403
|
+
}
|
404
|
+
| mlhs_head tSTAR mlhs_node
|
405
|
+
{
|
406
|
+
result = val[0].
|
407
|
+
push(@builder.splat(val[1], val[2]))
|
408
|
+
}
|
409
|
+
| mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
|
410
|
+
{
|
411
|
+
result = val[0].
|
412
|
+
push(@builder.splat(val[1], val[2])).
|
413
|
+
concat(val[4])
|
414
|
+
}
|
415
|
+
| mlhs_head tSTAR
|
416
|
+
{
|
417
|
+
result = val[0].
|
418
|
+
push(@builder.splat(val[1]))
|
419
|
+
}
|
420
|
+
| mlhs_head tSTAR tCOMMA mlhs_post
|
421
|
+
{
|
422
|
+
result = val[0].
|
423
|
+
push(@builder.splat(val[1])).
|
424
|
+
concat(val[3])
|
425
|
+
}
|
426
|
+
| tSTAR mlhs_node
|
427
|
+
{
|
428
|
+
result = [ @builder.splat(val[0], val[1]) ]
|
429
|
+
}
|
430
|
+
| tSTAR mlhs_node tCOMMA mlhs_post
|
431
|
+
{
|
432
|
+
result = [ @builder.splat(val[0], val[1]),
|
433
|
+
*val[3] ]
|
434
|
+
}
|
435
|
+
| tSTAR
|
436
|
+
{
|
437
|
+
result = [ @builder.splat(val[0]) ]
|
438
|
+
}
|
439
|
+
| tSTAR tCOMMA mlhs_post
|
440
|
+
{
|
441
|
+
result = [ @builder.splat(val[0]),
|
442
|
+
*val[2] ]
|
443
|
+
}
|
444
|
+
|
445
|
+
mlhs_item: mlhs_node
|
446
|
+
| tLPAREN mlhs_inner rparen
|
447
|
+
{
|
448
|
+
result = @builder.begin(val[0], val[1], val[2])
|
449
|
+
}
|
450
|
+
|
451
|
+
mlhs_head: mlhs_item tCOMMA
|
452
|
+
{
|
453
|
+
result = [ val[0] ]
|
454
|
+
}
|
455
|
+
| mlhs_head mlhs_item tCOMMA
|
456
|
+
{
|
457
|
+
result = val[0] << val[1]
|
458
|
+
}
|
459
|
+
|
460
|
+
mlhs_post: mlhs_item
|
461
|
+
{
|
462
|
+
result = [ val[0] ]
|
463
|
+
}
|
464
|
+
| mlhs_post tCOMMA mlhs_item
|
465
|
+
{
|
466
|
+
result = val[0] << val[2]
|
467
|
+
}
|
468
|
+
|
469
|
+
mlhs_node: user_variable
|
470
|
+
{
|
471
|
+
result = @builder.assignable(val[0])
|
472
|
+
}
|
473
|
+
| keyword_variable
|
474
|
+
{
|
475
|
+
result = @builder.assignable(val[0])
|
476
|
+
}
|
477
|
+
| primary_value tLBRACK2 opt_call_args rbracket
|
478
|
+
{
|
479
|
+
result = @builder.index_asgn(val[0], val[1], val[2], val[3])
|
480
|
+
}
|
481
|
+
| primary_value call_op tIDENTIFIER
|
482
|
+
{
|
483
|
+
result = @builder.attr_asgn(val[0], val[1], val[2])
|
484
|
+
}
|
485
|
+
| primary_value tCOLON2 tIDENTIFIER
|
486
|
+
{
|
487
|
+
result = @builder.attr_asgn(val[0], val[1], val[2])
|
488
|
+
}
|
489
|
+
| primary_value call_op tCONSTANT
|
490
|
+
{
|
491
|
+
result = @builder.attr_asgn(val[0], val[1], val[2])
|
492
|
+
}
|
493
|
+
| primary_value tCOLON2 tCONSTANT
|
494
|
+
{
|
495
|
+
result = @builder.assignable(
|
496
|
+
@builder.const_fetch(val[0], val[1], val[2]))
|
497
|
+
}
|
498
|
+
| tCOLON3 tCONSTANT
|
499
|
+
{
|
500
|
+
result = @builder.assignable(
|
501
|
+
@builder.const_global(val[0], val[1]))
|
502
|
+
}
|
503
|
+
| backref
|
504
|
+
{
|
505
|
+
result = @builder.assignable(val[0])
|
506
|
+
}
|
507
|
+
|
508
|
+
lhs: user_variable
|
509
|
+
{
|
510
|
+
result = @builder.assignable(val[0])
|
511
|
+
}
|
512
|
+
| keyword_variable
|
513
|
+
{
|
514
|
+
result = @builder.assignable(val[0])
|
515
|
+
}
|
516
|
+
| primary_value tLBRACK2 opt_call_args rbracket
|
517
|
+
{
|
518
|
+
result = @builder.index_asgn(val[0], val[1], val[2], val[3])
|
519
|
+
}
|
520
|
+
| primary_value call_op tIDENTIFIER
|
521
|
+
{
|
522
|
+
result = @builder.attr_asgn(val[0], val[1], val[2])
|
523
|
+
}
|
524
|
+
| primary_value tCOLON2 tIDENTIFIER
|
525
|
+
{
|
526
|
+
result = @builder.attr_asgn(val[0], val[1], val[2])
|
527
|
+
}
|
528
|
+
| primary_value call_op tCONSTANT
|
529
|
+
{
|
530
|
+
result = @builder.attr_asgn(val[0], val[1], val[2])
|
531
|
+
}
|
532
|
+
| primary_value tCOLON2 tCONSTANT
|
533
|
+
{
|
534
|
+
result = @builder.assignable(
|
535
|
+
@builder.const_fetch(val[0], val[1], val[2]))
|
536
|
+
}
|
537
|
+
| tCOLON3 tCONSTANT
|
538
|
+
{
|
539
|
+
result = @builder.assignable(
|
540
|
+
@builder.const_global(val[0], val[1]))
|
541
|
+
}
|
542
|
+
| backref
|
543
|
+
{
|
544
|
+
result = @builder.assignable(val[0])
|
545
|
+
}
|
546
|
+
|
547
|
+
cname: tIDENTIFIER
|
548
|
+
{
|
549
|
+
diagnostic :error, :module_name_const, nil, val[0]
|
550
|
+
}
|
551
|
+
| tCONSTANT
|
552
|
+
|
553
|
+
cpath: tCOLON3 cname
|
554
|
+
{
|
555
|
+
result = @builder.const_global(val[0], val[1])
|
556
|
+
}
|
557
|
+
| cname
|
558
|
+
{
|
559
|
+
result = @builder.const(val[0])
|
560
|
+
}
|
561
|
+
| primary_value tCOLON2 cname
|
562
|
+
{
|
563
|
+
result = @builder.const_fetch(val[0], val[1], val[2])
|
564
|
+
}
|
565
|
+
|
566
|
+
fname: tIDENTIFIER | tCONSTANT | tFID
|
567
|
+
| op
|
568
|
+
| reswords
|
569
|
+
|
570
|
+
fsym: fname
|
571
|
+
{
|
572
|
+
result = @builder.symbol(val[0])
|
573
|
+
}
|
574
|
+
| symbol
|
575
|
+
|
576
|
+
fitem: fsym
|
577
|
+
| dsym
|
578
|
+
|
579
|
+
undef_list: fitem
|
580
|
+
{
|
581
|
+
result = [ val[0] ]
|
582
|
+
}
|
583
|
+
| undef_list tCOMMA
|
584
|
+
{
|
585
|
+
@lexer.state = :expr_fname
|
586
|
+
}
|
587
|
+
fitem
|
588
|
+
{
|
589
|
+
result = val[0] << val[3]
|
590
|
+
}
|
591
|
+
|
592
|
+
op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
|
593
|
+
| tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
|
594
|
+
| tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
|
595
|
+
| tSTAR | tDIVIDE | tPERCENT | tPOW | tBANG | tTILDE
|
596
|
+
| tUPLUS | tUMINUS | tAREF | tASET | tDSTAR | tBACK_REF2
|
597
|
+
|
598
|
+
reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
|
599
|
+
| kALIAS | kAND | kBEGIN | kBREAK | kCASE
|
600
|
+
| kCLASS | kDEF | kDEFINED | kDO | kELSE
|
601
|
+
| kELSIF | kEND | kENSURE | kFALSE | kFOR
|
602
|
+
| kIN | kMODULE | kNEXT | kNIL | kNOT
|
603
|
+
| kOR | kREDO | kRESCUE | kRETRY | kRETURN
|
604
|
+
| kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
|
605
|
+
| kWHEN | kYIELD | kIF | kUNLESS | kWHILE
|
606
|
+
| kUNTIL
|
607
|
+
|
608
|
+
arg: lhs tEQL arg_rhs
|
609
|
+
{
|
610
|
+
result = @builder.assign(val[0], val[1], val[2])
|
611
|
+
}
|
612
|
+
| var_lhs tOP_ASGN arg_rhs
|
613
|
+
{
|
614
|
+
result = @builder.op_assign(val[0], val[1], val[2])
|
615
|
+
}
|
616
|
+
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg_rhs
|
617
|
+
{
|
618
|
+
result = @builder.op_assign(
|
619
|
+
@builder.index(
|
620
|
+
val[0], val[1], val[2], val[3]),
|
621
|
+
val[4], val[5])
|
622
|
+
}
|
623
|
+
| primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
|
624
|
+
{
|
625
|
+
result = @builder.op_assign(
|
626
|
+
@builder.call_method(
|
627
|
+
val[0], val[1], val[2]),
|
628
|
+
val[3], val[4])
|
629
|
+
}
|
630
|
+
| primary_value call_op tCONSTANT tOP_ASGN arg_rhs
|
631
|
+
{
|
632
|
+
result = @builder.op_assign(
|
633
|
+
@builder.call_method(
|
634
|
+
val[0], val[1], val[2]),
|
635
|
+
val[3], val[4])
|
636
|
+
}
|
637
|
+
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
|
638
|
+
{
|
639
|
+
result = @builder.op_assign(
|
640
|
+
@builder.call_method(
|
641
|
+
val[0], val[1], val[2]),
|
642
|
+
val[3], val[4])
|
643
|
+
}
|
644
|
+
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
|
645
|
+
{
|
646
|
+
const = @builder.const_op_assignable(
|
647
|
+
@builder.const_fetch(val[0], val[1], val[2]))
|
648
|
+
result = @builder.op_assign(const, val[3], val[4])
|
649
|
+
}
|
650
|
+
| tCOLON3 tCONSTANT tOP_ASGN arg_rhs
|
651
|
+
{
|
652
|
+
const = @builder.const_op_assignable(
|
653
|
+
@builder.const_global(val[0], val[1]))
|
654
|
+
result = @builder.op_assign(const, val[2], val[3])
|
655
|
+
}
|
656
|
+
| backref tOP_ASGN arg_rhs
|
657
|
+
{
|
658
|
+
result = @builder.op_assign(val[0], val[1], val[2])
|
659
|
+
}
|
660
|
+
| arg tDOT2 arg
|
661
|
+
{
|
662
|
+
result = @builder.range_inclusive(val[0], val[1], val[2])
|
663
|
+
}
|
664
|
+
| arg tDOT3 arg
|
665
|
+
{
|
666
|
+
result = @builder.range_exclusive(val[0], val[1], val[2])
|
667
|
+
}
|
668
|
+
| arg tPLUS arg
|
669
|
+
{
|
670
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
671
|
+
}
|
672
|
+
| arg tMINUS arg
|
673
|
+
{
|
674
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
675
|
+
}
|
676
|
+
| arg tSTAR2 arg
|
677
|
+
{
|
678
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
679
|
+
}
|
680
|
+
| arg tDIVIDE arg
|
681
|
+
{
|
682
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
683
|
+
}
|
684
|
+
| arg tPERCENT arg
|
685
|
+
{
|
686
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
687
|
+
}
|
688
|
+
| arg tPOW arg
|
689
|
+
{
|
690
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
691
|
+
}
|
692
|
+
| tUNARY_NUM simple_numeric tPOW arg
|
693
|
+
{
|
694
|
+
result = @builder.unary_op(val[0],
|
695
|
+
@builder.binary_op(
|
696
|
+
val[1], val[2], val[3]))
|
697
|
+
}
|
698
|
+
| tUPLUS arg
|
699
|
+
{
|
700
|
+
result = @builder.unary_op(val[0], val[1])
|
701
|
+
}
|
702
|
+
| tUMINUS arg
|
703
|
+
{
|
704
|
+
result = @builder.unary_op(val[0], val[1])
|
705
|
+
}
|
706
|
+
| arg tPIPE arg
|
707
|
+
{
|
708
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
709
|
+
}
|
710
|
+
| arg tCARET arg
|
711
|
+
{
|
712
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
713
|
+
}
|
714
|
+
| arg tAMPER2 arg
|
715
|
+
{
|
716
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
717
|
+
}
|
718
|
+
| arg tCMP arg
|
719
|
+
{
|
720
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
721
|
+
}
|
722
|
+
| rel_expr =tCMP
|
723
|
+
| arg tEQ arg
|
724
|
+
{
|
725
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
726
|
+
}
|
727
|
+
| arg tEQQ arg
|
728
|
+
{
|
729
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
730
|
+
}
|
731
|
+
| arg tNEQ arg
|
732
|
+
{
|
733
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
734
|
+
}
|
735
|
+
| arg tMATCH arg
|
736
|
+
{
|
737
|
+
result = @builder.match_op(val[0], val[1], val[2])
|
738
|
+
}
|
739
|
+
| arg tNMATCH arg
|
740
|
+
{
|
741
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
742
|
+
}
|
743
|
+
| tBANG arg
|
744
|
+
{
|
745
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
746
|
+
}
|
747
|
+
| tTILDE arg
|
748
|
+
{
|
749
|
+
result = @builder.unary_op(val[0], val[1])
|
750
|
+
}
|
751
|
+
| arg tLSHFT arg
|
752
|
+
{
|
753
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
754
|
+
}
|
755
|
+
| arg tRSHFT arg
|
756
|
+
{
|
757
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
758
|
+
}
|
759
|
+
| arg tANDOP arg
|
760
|
+
{
|
761
|
+
result = @builder.logical_op(:and, val[0], val[1], val[2])
|
762
|
+
}
|
763
|
+
| arg tOROP arg
|
764
|
+
{
|
765
|
+
result = @builder.logical_op(:or, val[0], val[1], val[2])
|
766
|
+
}
|
767
|
+
| kDEFINED opt_nl arg
|
768
|
+
{
|
769
|
+
result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
|
770
|
+
}
|
771
|
+
| arg tEH arg opt_nl tCOLON arg
|
772
|
+
{
|
773
|
+
result = @builder.ternary(val[0], val[1],
|
774
|
+
val[2], val[4], val[5])
|
775
|
+
}
|
776
|
+
| primary
|
777
|
+
|
778
|
+
relop: tGT | tLT | tGEQ | tLEQ
|
779
|
+
|
780
|
+
rel_expr: arg relop arg =tGT
|
781
|
+
{
|
782
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
783
|
+
}
|
784
|
+
| rel_expr relop arg =tGT
|
785
|
+
{
|
786
|
+
result = @builder.binary_op(val[0], val[1], val[2])
|
787
|
+
}
|
788
|
+
|
789
|
+
arg_value: arg
|
790
|
+
|
791
|
+
aref_args: none
|
792
|
+
| args trailer
|
793
|
+
| args tCOMMA assocs trailer
|
794
|
+
{
|
795
|
+
result = val[0] << @builder.associate(nil, val[2], nil)
|
796
|
+
}
|
797
|
+
| assocs trailer
|
798
|
+
{
|
799
|
+
result = [ @builder.associate(nil, val[0], nil) ]
|
800
|
+
}
|
801
|
+
|
802
|
+
arg_rhs: arg =tOP_ASGN
|
803
|
+
| arg kRESCUE_MOD arg
|
804
|
+
{
|
805
|
+
rescue_body = @builder.rescue_body(val[1],
|
806
|
+
nil, nil, nil,
|
807
|
+
nil, val[2])
|
808
|
+
|
809
|
+
result = @builder.begin_body(val[0], [ rescue_body ])
|
810
|
+
}
|
811
|
+
|
812
|
+
paren_args: tLPAREN2 opt_call_args rparen
|
813
|
+
{
|
814
|
+
result = val
|
815
|
+
}
|
816
|
+
|
817
|
+
opt_paren_args: # nothing
|
818
|
+
{
|
819
|
+
result = [ nil, [], nil ]
|
820
|
+
}
|
821
|
+
| paren_args
|
822
|
+
|
823
|
+
opt_call_args: # nothing
|
824
|
+
{
|
825
|
+
result = []
|
826
|
+
}
|
827
|
+
| call_args
|
828
|
+
| args tCOMMA
|
829
|
+
| args tCOMMA assocs tCOMMA
|
830
|
+
{
|
831
|
+
result = val[0] << @builder.associate(nil, val[2], nil)
|
832
|
+
}
|
833
|
+
| assocs tCOMMA
|
834
|
+
{
|
835
|
+
result = [ @builder.associate(nil, val[0], nil) ]
|
836
|
+
}
|
837
|
+
|
838
|
+
call_args: command
|
839
|
+
{
|
840
|
+
result = [ val[0] ]
|
841
|
+
}
|
842
|
+
| args opt_block_arg
|
843
|
+
{
|
844
|
+
result = val[0].concat(val[1])
|
845
|
+
}
|
846
|
+
| assocs opt_block_arg
|
847
|
+
{
|
848
|
+
result = [ @builder.associate(nil, val[0], nil) ]
|
849
|
+
result.concat(val[1])
|
850
|
+
}
|
851
|
+
| args tCOMMA assocs opt_block_arg
|
852
|
+
{
|
853
|
+
assocs = @builder.associate(nil, val[2], nil)
|
854
|
+
result = val[0] << assocs
|
855
|
+
result.concat(val[3])
|
856
|
+
}
|
857
|
+
| block_arg
|
858
|
+
{
|
859
|
+
result = [ val[0] ]
|
860
|
+
}
|
861
|
+
|
862
|
+
command_args: {
|
863
|
+
# When branch gets invoked by RACC's lookahead
|
864
|
+
# and command args start with '[' or '('
|
865
|
+
# we need to put `true` to the cmdarg stack
|
866
|
+
# **before** `false` pushed by lexer
|
867
|
+
# m [], n
|
868
|
+
# ^
|
869
|
+
# Right here we have cmdarg [...0] because
|
870
|
+
# lexer pushed it on '['
|
871
|
+
# We need to modify cmdarg stack to [...10]
|
872
|
+
#
|
873
|
+
# For all other cases (like `m n` or `m n, []`) we simply put 1 to the stack
|
874
|
+
# and later lexer pushes corresponding bits on top of it.
|
875
|
+
last_token = @last_token[0]
|
876
|
+
lookahead = last_token == :tLBRACK || last_token == :tLPAREN_ARG
|
877
|
+
|
878
|
+
if lookahead
|
879
|
+
top = @lexer.cmdarg.pop
|
880
|
+
@lexer.cmdarg.push(true)
|
881
|
+
@lexer.cmdarg.push(top)
|
882
|
+
else
|
883
|
+
@lexer.cmdarg.push(true)
|
884
|
+
end
|
885
|
+
}
|
886
|
+
call_args
|
887
|
+
{
|
888
|
+
@lexer.cmdarg.pop
|
889
|
+
|
890
|
+
result = val[1]
|
891
|
+
}
|
892
|
+
|
893
|
+
block_arg: tAMPER arg_value
|
894
|
+
{
|
895
|
+
result = @builder.block_pass(val[0], val[1])
|
896
|
+
}
|
897
|
+
|
898
|
+
opt_block_arg: tCOMMA block_arg
|
899
|
+
{
|
900
|
+
result = [ val[1] ]
|
901
|
+
}
|
902
|
+
| # nothing
|
903
|
+
{
|
904
|
+
result = []
|
905
|
+
}
|
906
|
+
|
907
|
+
args: arg_value
|
908
|
+
{
|
909
|
+
result = [ val[0] ]
|
910
|
+
}
|
911
|
+
| tSTAR arg_value
|
912
|
+
{
|
913
|
+
result = [ @builder.splat(val[0], val[1]) ]
|
914
|
+
}
|
915
|
+
| args tCOMMA arg_value
|
916
|
+
{
|
917
|
+
result = val[0] << val[2]
|
918
|
+
}
|
919
|
+
| args tCOMMA tSTAR arg_value
|
920
|
+
{
|
921
|
+
result = val[0] << @builder.splat(val[2], val[3])
|
922
|
+
}
|
923
|
+
|
924
|
+
mrhs_arg: mrhs
|
925
|
+
{
|
926
|
+
result = @builder.array(nil, val[0], nil)
|
927
|
+
}
|
928
|
+
| arg_value
|
929
|
+
|
930
|
+
mrhs: args tCOMMA arg_value
|
931
|
+
{
|
932
|
+
result = val[0] << val[2]
|
933
|
+
}
|
934
|
+
| args tCOMMA tSTAR arg_value
|
935
|
+
{
|
936
|
+
result = val[0] << @builder.splat(val[2], val[3])
|
937
|
+
}
|
938
|
+
| tSTAR arg_value
|
939
|
+
{
|
940
|
+
result = [ @builder.splat(val[0], val[1]) ]
|
941
|
+
}
|
942
|
+
|
943
|
+
primary: literal
|
944
|
+
| strings
|
945
|
+
| xstring
|
946
|
+
| regexp
|
947
|
+
| words
|
948
|
+
| qwords
|
949
|
+
| symbols
|
950
|
+
| qsymbols
|
951
|
+
| var_ref
|
952
|
+
| backref
|
953
|
+
| tFID
|
954
|
+
{
|
955
|
+
result = @builder.call_method(nil, nil, val[0])
|
956
|
+
}
|
957
|
+
| kBEGIN
|
958
|
+
{
|
959
|
+
@lexer.cmdarg.push(false)
|
960
|
+
}
|
961
|
+
bodystmt kEND
|
962
|
+
{
|
963
|
+
@lexer.cmdarg.pop
|
964
|
+
|
965
|
+
result = @builder.begin_keyword(val[0], val[2], val[3])
|
966
|
+
}
|
967
|
+
| tLPAREN_ARG stmt
|
968
|
+
{
|
969
|
+
@lexer.state = :expr_endarg
|
970
|
+
}
|
971
|
+
rparen
|
972
|
+
{
|
973
|
+
result = @builder.begin(val[0], val[1], val[3])
|
974
|
+
}
|
975
|
+
| tLPAREN_ARG
|
976
|
+
{
|
977
|
+
@lexer.state = :expr_endarg
|
978
|
+
}
|
979
|
+
opt_nl tRPAREN
|
980
|
+
{
|
981
|
+
result = @builder.begin(val[0], nil, val[3])
|
982
|
+
}
|
983
|
+
| tLPAREN compstmt tRPAREN
|
984
|
+
{
|
985
|
+
result = @builder.begin(val[0], val[1], val[2])
|
986
|
+
}
|
987
|
+
| primary_value tCOLON2 tCONSTANT
|
988
|
+
{
|
989
|
+
result = @builder.const_fetch(val[0], val[1], val[2])
|
990
|
+
}
|
991
|
+
| tCOLON3 tCONSTANT
|
992
|
+
{
|
993
|
+
result = @builder.const_global(val[0], val[1])
|
994
|
+
}
|
995
|
+
| tLBRACK aref_args tRBRACK
|
996
|
+
{
|
997
|
+
result = @builder.array(val[0], val[1], val[2])
|
998
|
+
}
|
999
|
+
| tLBRACE assoc_list tRCURLY
|
1000
|
+
{
|
1001
|
+
result = @builder.associate(val[0], val[1], val[2])
|
1002
|
+
}
|
1003
|
+
| k_return
|
1004
|
+
{
|
1005
|
+
result = @builder.keyword_cmd(:return, val[0])
|
1006
|
+
}
|
1007
|
+
| kYIELD tLPAREN2 call_args rparen
|
1008
|
+
{
|
1009
|
+
result = @builder.keyword_cmd(:yield, val[0], val[1], val[2], val[3])
|
1010
|
+
}
|
1011
|
+
| kYIELD tLPAREN2 rparen
|
1012
|
+
{
|
1013
|
+
result = @builder.keyword_cmd(:yield, val[0], val[1], [], val[2])
|
1014
|
+
}
|
1015
|
+
| kYIELD
|
1016
|
+
{
|
1017
|
+
result = @builder.keyword_cmd(:yield, val[0])
|
1018
|
+
}
|
1019
|
+
| kDEFINED opt_nl tLPAREN2 expr rparen
|
1020
|
+
{
|
1021
|
+
result = @builder.keyword_cmd(:defined?, val[0],
|
1022
|
+
val[2], [ val[3] ], val[4])
|
1023
|
+
}
|
1024
|
+
| kNOT tLPAREN2 expr rparen
|
1025
|
+
{
|
1026
|
+
result = @builder.not_op(val[0], val[1], val[2], val[3])
|
1027
|
+
}
|
1028
|
+
| kNOT tLPAREN2 rparen
|
1029
|
+
{
|
1030
|
+
result = @builder.not_op(val[0], val[1], nil, val[2])
|
1031
|
+
}
|
1032
|
+
| fcall brace_block
|
1033
|
+
{
|
1034
|
+
method_call = @builder.call_method(nil, nil, val[0])
|
1035
|
+
|
1036
|
+
begin_t, args, body, end_t = val[1]
|
1037
|
+
result = @builder.block(method_call,
|
1038
|
+
begin_t, args, body, end_t)
|
1039
|
+
}
|
1040
|
+
| method_call
|
1041
|
+
| method_call brace_block
|
1042
|
+
{
|
1043
|
+
begin_t, args, body, end_t = val[1]
|
1044
|
+
result = @builder.block(val[0],
|
1045
|
+
begin_t, args, body, end_t)
|
1046
|
+
}
|
1047
|
+
| tLAMBDA lambda
|
1048
|
+
{
|
1049
|
+
lambda_call = @builder.call_lambda(val[0])
|
1050
|
+
|
1051
|
+
args, (begin_t, body, end_t) = val[1]
|
1052
|
+
result = @builder.block(lambda_call,
|
1053
|
+
begin_t, args, body, end_t)
|
1054
|
+
}
|
1055
|
+
| kIF expr_value then compstmt if_tail kEND
|
1056
|
+
{
|
1057
|
+
else_t, else_ = val[4]
|
1058
|
+
result = @builder.condition(val[0], val[1], val[2],
|
1059
|
+
val[3], else_t,
|
1060
|
+
else_, val[5])
|
1061
|
+
}
|
1062
|
+
| kUNLESS expr_value then compstmt opt_else kEND
|
1063
|
+
{
|
1064
|
+
else_t, else_ = val[4]
|
1065
|
+
result = @builder.condition(val[0], val[1], val[2],
|
1066
|
+
else_, else_t,
|
1067
|
+
val[3], val[5])
|
1068
|
+
}
|
1069
|
+
| kWHILE expr_value_do compstmt kEND
|
1070
|
+
{
|
1071
|
+
result = @builder.loop(:while, val[0], *val[1], val[2], val[3])
|
1072
|
+
}
|
1073
|
+
| kUNTIL expr_value_do compstmt kEND
|
1074
|
+
{
|
1075
|
+
result = @builder.loop(:until, val[0], *val[1], val[2], val[3])
|
1076
|
+
}
|
1077
|
+
| kCASE expr_value opt_terms case_body kEND
|
1078
|
+
{
|
1079
|
+
*when_bodies, (else_t, else_body) = *val[3]
|
1080
|
+
|
1081
|
+
result = @builder.case(val[0], val[1],
|
1082
|
+
when_bodies, else_t, else_body,
|
1083
|
+
val[4])
|
1084
|
+
}
|
1085
|
+
| kCASE opt_terms case_body kEND
|
1086
|
+
{
|
1087
|
+
*when_bodies, (else_t, else_body) = *val[2]
|
1088
|
+
|
1089
|
+
result = @builder.case(val[0], nil,
|
1090
|
+
when_bodies, else_t, else_body,
|
1091
|
+
val[3])
|
1092
|
+
}
|
1093
|
+
| kFOR for_var kIN expr_value_do compstmt kEND
|
1094
|
+
{
|
1095
|
+
result = @builder.for(val[0], val[1], val[2], *val[3], val[4], val[5])
|
1096
|
+
}
|
1097
|
+
| kCLASS cpath superclass
|
1098
|
+
{
|
1099
|
+
@static_env.extend_static
|
1100
|
+
@lexer.cmdarg.push(false)
|
1101
|
+
@lexer.cond.push(false)
|
1102
|
+
@context.push(:class)
|
1103
|
+
}
|
1104
|
+
bodystmt kEND
|
1105
|
+
{
|
1106
|
+
unless @context.class_definition_allowed?
|
1107
|
+
diagnostic :error, :class_in_def, nil, val[0]
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
lt_t, superclass = val[2]
|
1111
|
+
result = @builder.def_class(val[0], val[1],
|
1112
|
+
lt_t, superclass,
|
1113
|
+
val[4], val[5])
|
1114
|
+
|
1115
|
+
@lexer.cmdarg.pop
|
1116
|
+
@lexer.cond.pop
|
1117
|
+
@static_env.unextend
|
1118
|
+
@context.pop
|
1119
|
+
}
|
1120
|
+
| kCLASS tLSHFT expr term
|
1121
|
+
{
|
1122
|
+
@static_env.extend_static
|
1123
|
+
@lexer.cmdarg.push(false)
|
1124
|
+
@lexer.cond.push(false)
|
1125
|
+
@context.push(:sclass)
|
1126
|
+
}
|
1127
|
+
bodystmt kEND
|
1128
|
+
{
|
1129
|
+
result = @builder.def_sclass(val[0], val[1], val[2],
|
1130
|
+
val[5], val[6])
|
1131
|
+
|
1132
|
+
@lexer.cmdarg.pop
|
1133
|
+
@lexer.cond.pop
|
1134
|
+
@static_env.unextend
|
1135
|
+
@context.pop
|
1136
|
+
}
|
1137
|
+
| kMODULE cpath
|
1138
|
+
{
|
1139
|
+
@static_env.extend_static
|
1140
|
+
@lexer.cmdarg.push(false)
|
1141
|
+
}
|
1142
|
+
bodystmt kEND
|
1143
|
+
{
|
1144
|
+
unless @context.module_definition_allowed?
|
1145
|
+
diagnostic :error, :module_in_def, nil, val[0]
|
1146
|
+
end
|
1147
|
+
|
1148
|
+
result = @builder.def_module(val[0], val[1],
|
1149
|
+
val[3], val[4])
|
1150
|
+
|
1151
|
+
@lexer.cmdarg.pop
|
1152
|
+
@static_env.unextend
|
1153
|
+
}
|
1154
|
+
| kDEF fname
|
1155
|
+
{
|
1156
|
+
@static_env.extend_static
|
1157
|
+
@lexer.cmdarg.push(false)
|
1158
|
+
@lexer.cond.push(false)
|
1159
|
+
@context.push(:def)
|
1160
|
+
}
|
1161
|
+
f_arglist bodystmt kEND
|
1162
|
+
{
|
1163
|
+
result = @builder.def_method(val[0], val[1],
|
1164
|
+
val[3], val[4], val[5])
|
1165
|
+
|
1166
|
+
@lexer.cmdarg.pop
|
1167
|
+
@lexer.cond.pop
|
1168
|
+
@static_env.unextend
|
1169
|
+
@context.pop
|
1170
|
+
}
|
1171
|
+
| kDEF singleton dot_or_colon
|
1172
|
+
{
|
1173
|
+
@lexer.state = :expr_fname
|
1174
|
+
}
|
1175
|
+
fname
|
1176
|
+
{
|
1177
|
+
@static_env.extend_static
|
1178
|
+
@lexer.cmdarg.push(false)
|
1179
|
+
@lexer.cond.push(false)
|
1180
|
+
@context.push(:defs)
|
1181
|
+
}
|
1182
|
+
f_arglist bodystmt kEND
|
1183
|
+
{
|
1184
|
+
result = @builder.def_singleton(val[0], val[1], val[2],
|
1185
|
+
val[4], val[6], val[7], val[8])
|
1186
|
+
|
1187
|
+
@lexer.cmdarg.pop
|
1188
|
+
@lexer.cond.pop
|
1189
|
+
@static_env.unextend
|
1190
|
+
@context.pop
|
1191
|
+
}
|
1192
|
+
| kBREAK
|
1193
|
+
{
|
1194
|
+
result = @builder.keyword_cmd(:break, val[0])
|
1195
|
+
}
|
1196
|
+
| kNEXT
|
1197
|
+
{
|
1198
|
+
result = @builder.keyword_cmd(:next, val[0])
|
1199
|
+
}
|
1200
|
+
| kREDO
|
1201
|
+
{
|
1202
|
+
result = @builder.keyword_cmd(:redo, val[0])
|
1203
|
+
}
|
1204
|
+
| kRETRY
|
1205
|
+
{
|
1206
|
+
result = @builder.keyword_cmd(:retry, val[0])
|
1207
|
+
}
|
1208
|
+
|
1209
|
+
primary_value: primary
|
1210
|
+
|
1211
|
+
k_return: kRETURN
|
1212
|
+
{
|
1213
|
+
if @context.in_class?
|
1214
|
+
diagnostic :error, :invalid_return, nil, val[0]
|
1215
|
+
end
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
then: term
|
1219
|
+
| kTHEN
|
1220
|
+
| term kTHEN
|
1221
|
+
{
|
1222
|
+
result = val[1]
|
1223
|
+
}
|
1224
|
+
|
1225
|
+
do: term
|
1226
|
+
| kDO_COND
|
1227
|
+
|
1228
|
+
if_tail: opt_else
|
1229
|
+
| kELSIF expr_value then compstmt if_tail
|
1230
|
+
{
|
1231
|
+
else_t, else_ = val[4]
|
1232
|
+
result = [ val[0],
|
1233
|
+
@builder.condition(val[0], val[1], val[2],
|
1234
|
+
val[3], else_t,
|
1235
|
+
else_, nil),
|
1236
|
+
]
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
opt_else: none
|
1240
|
+
| kELSE compstmt
|
1241
|
+
{
|
1242
|
+
result = val
|
1243
|
+
}
|
1244
|
+
|
1245
|
+
for_var: lhs
|
1246
|
+
| mlhs
|
1247
|
+
|
1248
|
+
f_marg: f_norm_arg
|
1249
|
+
{
|
1250
|
+
result = @builder.arg(val[0])
|
1251
|
+
}
|
1252
|
+
| tLPAREN f_margs rparen
|
1253
|
+
{
|
1254
|
+
result = @builder.multi_lhs(val[0], val[1], val[2])
|
1255
|
+
}
|
1256
|
+
|
1257
|
+
f_marg_list: f_marg
|
1258
|
+
{
|
1259
|
+
result = [ val[0] ]
|
1260
|
+
}
|
1261
|
+
| f_marg_list tCOMMA f_marg
|
1262
|
+
{
|
1263
|
+
result = val[0] << val[2]
|
1264
|
+
}
|
1265
|
+
|
1266
|
+
f_margs: f_marg_list
|
1267
|
+
| f_marg_list tCOMMA tSTAR f_norm_arg
|
1268
|
+
{
|
1269
|
+
result = val[0].
|
1270
|
+
push(@builder.restarg(val[2], val[3]))
|
1271
|
+
}
|
1272
|
+
| f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
|
1273
|
+
{
|
1274
|
+
result = val[0].
|
1275
|
+
push(@builder.restarg(val[2], val[3])).
|
1276
|
+
concat(val[5])
|
1277
|
+
}
|
1278
|
+
| f_marg_list tCOMMA tSTAR
|
1279
|
+
{
|
1280
|
+
result = val[0].
|
1281
|
+
push(@builder.restarg(val[2]))
|
1282
|
+
}
|
1283
|
+
| f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
|
1284
|
+
{
|
1285
|
+
result = val[0].
|
1286
|
+
push(@builder.restarg(val[2])).
|
1287
|
+
concat(val[4])
|
1288
|
+
}
|
1289
|
+
| tSTAR f_norm_arg
|
1290
|
+
{
|
1291
|
+
result = [ @builder.restarg(val[0], val[1]) ]
|
1292
|
+
}
|
1293
|
+
| tSTAR f_norm_arg tCOMMA f_marg_list
|
1294
|
+
{
|
1295
|
+
result = [ @builder.restarg(val[0], val[1]),
|
1296
|
+
*val[3] ]
|
1297
|
+
}
|
1298
|
+
| tSTAR
|
1299
|
+
{
|
1300
|
+
result = [ @builder.restarg(val[0]) ]
|
1301
|
+
}
|
1302
|
+
| tSTAR tCOMMA f_marg_list
|
1303
|
+
{
|
1304
|
+
result = [ @builder.restarg(val[0]),
|
1305
|
+
*val[2] ]
|
1306
|
+
}
|
1307
|
+
|
1308
|
+
block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
|
1309
|
+
{
|
1310
|
+
result = val[0].concat(val[2]).concat(val[3])
|
1311
|
+
}
|
1312
|
+
| f_block_kwarg opt_f_block_arg
|
1313
|
+
{
|
1314
|
+
result = val[0].concat(val[1])
|
1315
|
+
}
|
1316
|
+
| f_kwrest opt_f_block_arg
|
1317
|
+
{
|
1318
|
+
result = val[0].concat(val[1])
|
1319
|
+
}
|
1320
|
+
| f_block_arg
|
1321
|
+
{
|
1322
|
+
result = [ val[0] ]
|
1323
|
+
}
|
1324
|
+
|
1325
|
+
opt_block_args_tail:
|
1326
|
+
tCOMMA block_args_tail
|
1327
|
+
{
|
1328
|
+
result = val[1]
|
1329
|
+
}
|
1330
|
+
| # nothing
|
1331
|
+
{
|
1332
|
+
result = []
|
1333
|
+
}
|
1334
|
+
|
1335
|
+
block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
|
1336
|
+
{
|
1337
|
+
result = val[0].
|
1338
|
+
concat(val[2]).
|
1339
|
+
concat(val[4]).
|
1340
|
+
concat(val[5])
|
1341
|
+
}
|
1342
|
+
| f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
|
1343
|
+
{
|
1344
|
+
result = val[0].
|
1345
|
+
concat(val[2]).
|
1346
|
+
concat(val[4]).
|
1347
|
+
concat(val[6]).
|
1348
|
+
concat(val[7])
|
1349
|
+
}
|
1350
|
+
| f_arg tCOMMA f_block_optarg opt_block_args_tail
|
1351
|
+
{
|
1352
|
+
result = val[0].
|
1353
|
+
concat(val[2]).
|
1354
|
+
concat(val[3])
|
1355
|
+
}
|
1356
|
+
| f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
|
1357
|
+
{
|
1358
|
+
result = val[0].
|
1359
|
+
concat(val[2]).
|
1360
|
+
concat(val[4]).
|
1361
|
+
concat(val[5])
|
1362
|
+
}
|
1363
|
+
| f_arg tCOMMA f_rest_arg opt_block_args_tail
|
1364
|
+
{
|
1365
|
+
result = val[0].
|
1366
|
+
concat(val[2]).
|
1367
|
+
concat(val[3])
|
1368
|
+
}
|
1369
|
+
| f_arg tCOMMA
|
1370
|
+
| f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
|
1371
|
+
{
|
1372
|
+
result = val[0].
|
1373
|
+
concat(val[2]).
|
1374
|
+
concat(val[4]).
|
1375
|
+
concat(val[5])
|
1376
|
+
}
|
1377
|
+
| f_arg opt_block_args_tail
|
1378
|
+
{
|
1379
|
+
if val[1].empty? && val[0].size == 1
|
1380
|
+
result = [@builder.procarg0(val[0][0])]
|
1381
|
+
else
|
1382
|
+
result = val[0].concat(val[1])
|
1383
|
+
end
|
1384
|
+
}
|
1385
|
+
| f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
|
1386
|
+
{
|
1387
|
+
result = val[0].
|
1388
|
+
concat(val[2]).
|
1389
|
+
concat(val[3])
|
1390
|
+
}
|
1391
|
+
| f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
|
1392
|
+
{
|
1393
|
+
result = val[0].
|
1394
|
+
concat(val[2]).
|
1395
|
+
concat(val[4]).
|
1396
|
+
concat(val[5])
|
1397
|
+
}
|
1398
|
+
| f_block_optarg opt_block_args_tail
|
1399
|
+
{
|
1400
|
+
result = val[0].
|
1401
|
+
concat(val[1])
|
1402
|
+
}
|
1403
|
+
| f_block_optarg tCOMMA f_arg opt_block_args_tail
|
1404
|
+
{
|
1405
|
+
result = val[0].
|
1406
|
+
concat(val[2]).
|
1407
|
+
concat(val[3])
|
1408
|
+
}
|
1409
|
+
| f_rest_arg opt_block_args_tail
|
1410
|
+
{
|
1411
|
+
result = val[0].
|
1412
|
+
concat(val[1])
|
1413
|
+
}
|
1414
|
+
| f_rest_arg tCOMMA f_arg opt_block_args_tail
|
1415
|
+
{
|
1416
|
+
result = val[0].
|
1417
|
+
concat(val[2]).
|
1418
|
+
concat(val[3])
|
1419
|
+
}
|
1420
|
+
| block_args_tail
|
1421
|
+
|
1422
|
+
opt_block_param: # nothing
|
1423
|
+
{
|
1424
|
+
result = @builder.args(nil, [], nil)
|
1425
|
+
}
|
1426
|
+
| block_param_def
|
1427
|
+
{
|
1428
|
+
@lexer.state = :expr_value
|
1429
|
+
}
|
1430
|
+
|
1431
|
+
block_param_def: tPIPE opt_bv_decl tPIPE
|
1432
|
+
{
|
1433
|
+
result = @builder.args(val[0], val[1], val[2])
|
1434
|
+
}
|
1435
|
+
| tOROP
|
1436
|
+
{
|
1437
|
+
result = @builder.args(val[0], [], val[0])
|
1438
|
+
}
|
1439
|
+
| tPIPE block_param opt_bv_decl tPIPE
|
1440
|
+
{
|
1441
|
+
result = @builder.args(val[0], val[1].concat(val[2]), val[3])
|
1442
|
+
}
|
1443
|
+
|
1444
|
+
opt_bv_decl: opt_nl
|
1445
|
+
{
|
1446
|
+
result = []
|
1447
|
+
}
|
1448
|
+
| opt_nl tSEMI bv_decls opt_nl
|
1449
|
+
{
|
1450
|
+
result = val[2]
|
1451
|
+
}
|
1452
|
+
|
1453
|
+
bv_decls: bvar
|
1454
|
+
{
|
1455
|
+
result = [ val[0] ]
|
1456
|
+
}
|
1457
|
+
| bv_decls tCOMMA bvar
|
1458
|
+
{
|
1459
|
+
result = val[0] << val[2]
|
1460
|
+
}
|
1461
|
+
|
1462
|
+
bvar: tIDENTIFIER
|
1463
|
+
{
|
1464
|
+
@static_env.declare val[0][0]
|
1465
|
+
result = @builder.shadowarg(val[0])
|
1466
|
+
}
|
1467
|
+
| f_bad_arg
|
1468
|
+
|
1469
|
+
lambda: {
|
1470
|
+
@static_env.extend_dynamic
|
1471
|
+
}
|
1472
|
+
f_larglist
|
1473
|
+
{
|
1474
|
+
@lexer.cmdarg.push(false)
|
1475
|
+
}
|
1476
|
+
lambda_body
|
1477
|
+
{
|
1478
|
+
@lexer.cmdarg.pop
|
1479
|
+
|
1480
|
+
result = [ val[1], val[3] ]
|
1481
|
+
|
1482
|
+
@static_env.unextend
|
1483
|
+
}
|
1484
|
+
|
1485
|
+
f_larglist: tLPAREN2 f_args opt_bv_decl tRPAREN
|
1486
|
+
{
|
1487
|
+
result = @builder.args(val[0], val[1].concat(val[2]), val[3])
|
1488
|
+
}
|
1489
|
+
| f_args
|
1490
|
+
{
|
1491
|
+
result = @builder.args(nil, val[0], nil)
|
1492
|
+
}
|
1493
|
+
|
1494
|
+
lambda_body: tLAMBEG
|
1495
|
+
{
|
1496
|
+
@context.push(:lambda)
|
1497
|
+
}
|
1498
|
+
compstmt tRCURLY
|
1499
|
+
{
|
1500
|
+
result = [ val[0], val[2], val[3] ]
|
1501
|
+
@context.pop
|
1502
|
+
}
|
1503
|
+
| kDO_LAMBDA
|
1504
|
+
{
|
1505
|
+
@context.push(:lambda)
|
1506
|
+
}
|
1507
|
+
bodystmt kEND
|
1508
|
+
{
|
1509
|
+
result = [ val[0], val[2], val[3] ]
|
1510
|
+
@context.pop
|
1511
|
+
}
|
1512
|
+
|
1513
|
+
do_block: kDO_BLOCK
|
1514
|
+
{
|
1515
|
+
@context.push(:block)
|
1516
|
+
}
|
1517
|
+
do_body kEND
|
1518
|
+
{
|
1519
|
+
result = [ val[0], *val[2], val[3] ]
|
1520
|
+
@context.pop
|
1521
|
+
}
|
1522
|
+
|
1523
|
+
block_call: command do_block
|
1524
|
+
{
|
1525
|
+
begin_t, block_args, body, end_t = val[1]
|
1526
|
+
result = @builder.block(val[0],
|
1527
|
+
begin_t, block_args, body, end_t)
|
1528
|
+
}
|
1529
|
+
| block_call dot_or_colon operation2 opt_paren_args
|
1530
|
+
{
|
1531
|
+
lparen_t, args, rparen_t = val[3]
|
1532
|
+
result = @builder.call_method(val[0], val[1], val[2],
|
1533
|
+
lparen_t, args, rparen_t)
|
1534
|
+
}
|
1535
|
+
| block_call dot_or_colon operation2 opt_paren_args brace_block
|
1536
|
+
{
|
1537
|
+
lparen_t, args, rparen_t = val[3]
|
1538
|
+
method_call = @builder.call_method(val[0], val[1], val[2],
|
1539
|
+
lparen_t, args, rparen_t)
|
1540
|
+
|
1541
|
+
begin_t, args, body, end_t = val[4]
|
1542
|
+
result = @builder.block(method_call,
|
1543
|
+
begin_t, args, body, end_t)
|
1544
|
+
}
|
1545
|
+
| block_call dot_or_colon operation2 command_args do_block
|
1546
|
+
{
|
1547
|
+
method_call = @builder.call_method(val[0], val[1], val[2],
|
1548
|
+
nil, val[3], nil)
|
1549
|
+
|
1550
|
+
begin_t, args, body, end_t = val[4]
|
1551
|
+
result = @builder.block(method_call,
|
1552
|
+
begin_t, args, body, end_t)
|
1553
|
+
}
|
1554
|
+
|
1555
|
+
method_call: fcall paren_args
|
1556
|
+
{
|
1557
|
+
lparen_t, args, rparen_t = val[1]
|
1558
|
+
result = @builder.call_method(nil, nil, val[0],
|
1559
|
+
lparen_t, args, rparen_t)
|
1560
|
+
}
|
1561
|
+
| primary_value call_op operation2 opt_paren_args
|
1562
|
+
{
|
1563
|
+
lparen_t, args, rparen_t = val[3]
|
1564
|
+
result = @builder.call_method(val[0], val[1], val[2],
|
1565
|
+
lparen_t, args, rparen_t)
|
1566
|
+
}
|
1567
|
+
| primary_value tCOLON2 operation2 paren_args
|
1568
|
+
{
|
1569
|
+
lparen_t, args, rparen_t = val[3]
|
1570
|
+
result = @builder.call_method(val[0], val[1], val[2],
|
1571
|
+
lparen_t, args, rparen_t)
|
1572
|
+
}
|
1573
|
+
| primary_value tCOLON2 operation3
|
1574
|
+
{
|
1575
|
+
result = @builder.call_method(val[0], val[1], val[2])
|
1576
|
+
}
|
1577
|
+
| primary_value call_op paren_args
|
1578
|
+
{
|
1579
|
+
lparen_t, args, rparen_t = val[2]
|
1580
|
+
result = @builder.call_method(val[0], val[1], nil,
|
1581
|
+
lparen_t, args, rparen_t)
|
1582
|
+
}
|
1583
|
+
| primary_value tCOLON2 paren_args
|
1584
|
+
{
|
1585
|
+
lparen_t, args, rparen_t = val[2]
|
1586
|
+
result = @builder.call_method(val[0], val[1], nil,
|
1587
|
+
lparen_t, args, rparen_t)
|
1588
|
+
}
|
1589
|
+
| kSUPER paren_args
|
1590
|
+
{
|
1591
|
+
lparen_t, args, rparen_t = val[1]
|
1592
|
+
result = @builder.keyword_cmd(:super, val[0],
|
1593
|
+
lparen_t, args, rparen_t)
|
1594
|
+
}
|
1595
|
+
| kSUPER
|
1596
|
+
{
|
1597
|
+
result = @builder.keyword_cmd(:zsuper, val[0])
|
1598
|
+
}
|
1599
|
+
| primary_value tLBRACK2 opt_call_args rbracket
|
1600
|
+
{
|
1601
|
+
result = @builder.index(val[0], val[1], val[2], val[3])
|
1602
|
+
}
|
1603
|
+
|
1604
|
+
brace_block: tLCURLY
|
1605
|
+
{
|
1606
|
+
@context.push(:block)
|
1607
|
+
}
|
1608
|
+
brace_body tRCURLY
|
1609
|
+
{
|
1610
|
+
result = [ val[0], *val[2], val[3] ]
|
1611
|
+
@context.pop
|
1612
|
+
}
|
1613
|
+
| kDO
|
1614
|
+
{
|
1615
|
+
@context.push(:block)
|
1616
|
+
}
|
1617
|
+
do_body kEND
|
1618
|
+
{
|
1619
|
+
result = [ val[0], *val[2], val[3] ]
|
1620
|
+
@context.pop
|
1621
|
+
}
|
1622
|
+
|
1623
|
+
brace_body: {
|
1624
|
+
@static_env.extend_dynamic
|
1625
|
+
}
|
1626
|
+
opt_block_param compstmt
|
1627
|
+
{
|
1628
|
+
result = [ val[1], val[2] ]
|
1629
|
+
|
1630
|
+
@static_env.unextend
|
1631
|
+
}
|
1632
|
+
|
1633
|
+
do_body: {
|
1634
|
+
@static_env.extend_dynamic
|
1635
|
+
}
|
1636
|
+
{
|
1637
|
+
@lexer.cmdarg.push(false)
|
1638
|
+
}
|
1639
|
+
opt_block_param bodystmt
|
1640
|
+
{
|
1641
|
+
result = [ val[2], val[3] ]
|
1642
|
+
|
1643
|
+
@static_env.unextend
|
1644
|
+
@lexer.cmdarg.pop
|
1645
|
+
}
|
1646
|
+
|
1647
|
+
case_body: kWHEN args then compstmt cases
|
1648
|
+
{
|
1649
|
+
result = [ @builder.when(val[0], val[1], val[2], val[3]),
|
1650
|
+
*val[4] ]
|
1651
|
+
}
|
1652
|
+
|
1653
|
+
cases: opt_else
|
1654
|
+
{
|
1655
|
+
result = [ val[0] ]
|
1656
|
+
}
|
1657
|
+
| case_body
|
1658
|
+
|
1659
|
+
opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
|
1660
|
+
{
|
1661
|
+
assoc_t, exc_var = val[2]
|
1662
|
+
|
1663
|
+
if val[1]
|
1664
|
+
exc_list = @builder.array(nil, val[1], nil)
|
1665
|
+
end
|
1666
|
+
|
1667
|
+
result = [ @builder.rescue_body(val[0],
|
1668
|
+
exc_list, assoc_t, exc_var,
|
1669
|
+
val[3], val[4]),
|
1670
|
+
*val[5] ]
|
1671
|
+
}
|
1672
|
+
|
|
1673
|
+
{
|
1674
|
+
result = []
|
1675
|
+
}
|
1676
|
+
|
1677
|
+
exc_list: arg_value
|
1678
|
+
{
|
1679
|
+
result = [ val[0] ]
|
1680
|
+
}
|
1681
|
+
| mrhs
|
1682
|
+
| none
|
1683
|
+
|
1684
|
+
exc_var: tASSOC lhs
|
1685
|
+
{
|
1686
|
+
result = [ val[0], val[1] ]
|
1687
|
+
}
|
1688
|
+
| none
|
1689
|
+
|
1690
|
+
opt_ensure: kENSURE compstmt
|
1691
|
+
{
|
1692
|
+
result = [ val[0], val[1] ]
|
1693
|
+
}
|
1694
|
+
| none
|
1695
|
+
|
1696
|
+
literal: numeric
|
1697
|
+
| symbol
|
1698
|
+
| dsym
|
1699
|
+
|
1700
|
+
strings: string
|
1701
|
+
{
|
1702
|
+
result = @builder.string_compose(nil, val[0], nil)
|
1703
|
+
}
|
1704
|
+
|
1705
|
+
string: string1
|
1706
|
+
{
|
1707
|
+
result = [ val[0] ]
|
1708
|
+
}
|
1709
|
+
| string string1
|
1710
|
+
{
|
1711
|
+
result = val[0] << val[1]
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
string1: tSTRING_BEG string_contents tSTRING_END
|
1715
|
+
{
|
1716
|
+
string = @builder.string_compose(val[0], val[1], val[2])
|
1717
|
+
result = @builder.dedent_string(string, @lexer.dedent_level)
|
1718
|
+
}
|
1719
|
+
| tSTRING
|
1720
|
+
{
|
1721
|
+
string = @builder.string(val[0])
|
1722
|
+
result = @builder.dedent_string(string, @lexer.dedent_level)
|
1723
|
+
}
|
1724
|
+
| tCHARACTER
|
1725
|
+
{
|
1726
|
+
result = @builder.character(val[0])
|
1727
|
+
}
|
1728
|
+
|
1729
|
+
xstring: tXSTRING_BEG xstring_contents tSTRING_END
|
1730
|
+
{
|
1731
|
+
string = @builder.xstring_compose(val[0], val[1], val[2])
|
1732
|
+
result = @builder.dedent_string(string, @lexer.dedent_level)
|
1733
|
+
}
|
1734
|
+
|
1735
|
+
regexp: tREGEXP_BEG regexp_contents tSTRING_END tREGEXP_OPT
|
1736
|
+
{
|
1737
|
+
opts = @builder.regexp_options(val[3])
|
1738
|
+
result = @builder.regexp_compose(val[0], val[1], val[2], opts)
|
1739
|
+
}
|
1740
|
+
|
1741
|
+
words: tWORDS_BEG word_list tSTRING_END
|
1742
|
+
{
|
1743
|
+
result = @builder.words_compose(val[0], val[1], val[2])
|
1744
|
+
}
|
1745
|
+
|
1746
|
+
word_list: # nothing
|
1747
|
+
{
|
1748
|
+
result = []
|
1749
|
+
}
|
1750
|
+
| word_list word tSPACE
|
1751
|
+
{
|
1752
|
+
result = val[0] << @builder.word(val[1])
|
1753
|
+
}
|
1754
|
+
|
1755
|
+
word: string_content
|
1756
|
+
{
|
1757
|
+
result = [ val[0] ]
|
1758
|
+
}
|
1759
|
+
| word string_content
|
1760
|
+
{
|
1761
|
+
result = val[0] << val[1]
|
1762
|
+
}
|
1763
|
+
|
1764
|
+
symbols: tSYMBOLS_BEG symbol_list tSTRING_END
|
1765
|
+
{
|
1766
|
+
result = @builder.symbols_compose(val[0], val[1], val[2])
|
1767
|
+
}
|
1768
|
+
|
1769
|
+
symbol_list: # nothing
|
1770
|
+
{
|
1771
|
+
result = []
|
1772
|
+
}
|
1773
|
+
| symbol_list word tSPACE
|
1774
|
+
{
|
1775
|
+
result = val[0] << @builder.word(val[1])
|
1776
|
+
}
|
1777
|
+
|
1778
|
+
qwords: tQWORDS_BEG qword_list tSTRING_END
|
1779
|
+
{
|
1780
|
+
result = @builder.words_compose(val[0], val[1], val[2])
|
1781
|
+
}
|
1782
|
+
|
1783
|
+
qsymbols: tQSYMBOLS_BEG qsym_list tSTRING_END
|
1784
|
+
{
|
1785
|
+
result = @builder.symbols_compose(val[0], val[1], val[2])
|
1786
|
+
}
|
1787
|
+
|
1788
|
+
qword_list: # nothing
|
1789
|
+
{
|
1790
|
+
result = []
|
1791
|
+
}
|
1792
|
+
| qword_list tSTRING_CONTENT tSPACE
|
1793
|
+
{
|
1794
|
+
result = val[0] << @builder.string_internal(val[1])
|
1795
|
+
}
|
1796
|
+
|
1797
|
+
qsym_list: # nothing
|
1798
|
+
{
|
1799
|
+
result = []
|
1800
|
+
}
|
1801
|
+
| qsym_list tSTRING_CONTENT tSPACE
|
1802
|
+
{
|
1803
|
+
result = val[0] << @builder.symbol_internal(val[1])
|
1804
|
+
}
|
1805
|
+
|
1806
|
+
string_contents: # nothing
|
1807
|
+
{
|
1808
|
+
result = []
|
1809
|
+
}
|
1810
|
+
| string_contents string_content
|
1811
|
+
{
|
1812
|
+
result = val[0] << val[1]
|
1813
|
+
}
|
1814
|
+
|
1815
|
+
xstring_contents: # nothing
|
1816
|
+
{
|
1817
|
+
result = []
|
1818
|
+
}
|
1819
|
+
| xstring_contents string_content
|
1820
|
+
{
|
1821
|
+
result = val[0] << val[1]
|
1822
|
+
}
|
1823
|
+
|
1824
|
+
regexp_contents: # nothing
|
1825
|
+
{
|
1826
|
+
result = []
|
1827
|
+
}
|
1828
|
+
| regexp_contents string_content
|
1829
|
+
{
|
1830
|
+
result = val[0] << val[1]
|
1831
|
+
}
|
1832
|
+
|
1833
|
+
string_content: tSTRING_CONTENT
|
1834
|
+
{
|
1835
|
+
result = @builder.string_internal(val[0])
|
1836
|
+
}
|
1837
|
+
| tSTRING_DVAR string_dvar
|
1838
|
+
{
|
1839
|
+
result = val[1]
|
1840
|
+
}
|
1841
|
+
| tSTRING_DBEG
|
1842
|
+
{
|
1843
|
+
@lexer.cmdarg.push(false)
|
1844
|
+
@lexer.cond.push(false)
|
1845
|
+
}
|
1846
|
+
compstmt tSTRING_DEND
|
1847
|
+
{
|
1848
|
+
@lexer.cmdarg.pop
|
1849
|
+
@lexer.cond.pop
|
1850
|
+
|
1851
|
+
result = @builder.begin(val[0], val[2], val[3])
|
1852
|
+
}
|
1853
|
+
|
1854
|
+
string_dvar: tGVAR
|
1855
|
+
{
|
1856
|
+
result = @builder.gvar(val[0])
|
1857
|
+
}
|
1858
|
+
| tIVAR
|
1859
|
+
{
|
1860
|
+
result = @builder.ivar(val[0])
|
1861
|
+
}
|
1862
|
+
| tCVAR
|
1863
|
+
{
|
1864
|
+
result = @builder.cvar(val[0])
|
1865
|
+
}
|
1866
|
+
| backref
|
1867
|
+
|
1868
|
+
|
1869
|
+
symbol: tSYMBOL
|
1870
|
+
{
|
1871
|
+
@lexer.state = :expr_end
|
1872
|
+
result = @builder.symbol(val[0])
|
1873
|
+
}
|
1874
|
+
|
1875
|
+
dsym: tSYMBEG xstring_contents tSTRING_END
|
1876
|
+
{
|
1877
|
+
@lexer.state = :expr_end
|
1878
|
+
result = @builder.symbol_compose(val[0], val[1], val[2])
|
1879
|
+
}
|
1880
|
+
|
1881
|
+
numeric: simple_numeric
|
1882
|
+
{
|
1883
|
+
result = val[0]
|
1884
|
+
}
|
1885
|
+
| tUNARY_NUM simple_numeric =tLOWEST
|
1886
|
+
{
|
1887
|
+
if @builder.respond_to? :negate
|
1888
|
+
# AST builder interface compatibility
|
1889
|
+
result = @builder.negate(val[0], val[1])
|
1890
|
+
else
|
1891
|
+
result = @builder.unary_num(val[0], val[1])
|
1892
|
+
end
|
1893
|
+
}
|
1894
|
+
|
1895
|
+
simple_numeric: tINTEGER
|
1896
|
+
{
|
1897
|
+
@lexer.state = :expr_end
|
1898
|
+
result = @builder.integer(val[0])
|
1899
|
+
}
|
1900
|
+
| tFLOAT
|
1901
|
+
{
|
1902
|
+
@lexer.state = :expr_end
|
1903
|
+
result = @builder.float(val[0])
|
1904
|
+
}
|
1905
|
+
| tRATIONAL
|
1906
|
+
{
|
1907
|
+
@lexer.state = :expr_end
|
1908
|
+
result = @builder.rational(val[0])
|
1909
|
+
}
|
1910
|
+
| tIMAGINARY
|
1911
|
+
{
|
1912
|
+
@lexer.state = :expr_end
|
1913
|
+
result = @builder.complex(val[0])
|
1914
|
+
}
|
1915
|
+
|
1916
|
+
user_variable: tIDENTIFIER
|
1917
|
+
{
|
1918
|
+
result = @builder.ident(val[0])
|
1919
|
+
}
|
1920
|
+
| tIVAR
|
1921
|
+
{
|
1922
|
+
result = @builder.ivar(val[0])
|
1923
|
+
}
|
1924
|
+
| tGVAR
|
1925
|
+
{
|
1926
|
+
result = @builder.gvar(val[0])
|
1927
|
+
}
|
1928
|
+
| tCONSTANT
|
1929
|
+
{
|
1930
|
+
result = @builder.const(val[0])
|
1931
|
+
}
|
1932
|
+
| tCVAR
|
1933
|
+
{
|
1934
|
+
result = @builder.cvar(val[0])
|
1935
|
+
}
|
1936
|
+
|
1937
|
+
keyword_variable: kNIL
|
1938
|
+
{
|
1939
|
+
result = @builder.nil(val[0])
|
1940
|
+
}
|
1941
|
+
| kSELF
|
1942
|
+
{
|
1943
|
+
result = @builder.self(val[0])
|
1944
|
+
}
|
1945
|
+
| kTRUE
|
1946
|
+
{
|
1947
|
+
result = @builder.true(val[0])
|
1948
|
+
}
|
1949
|
+
| kFALSE
|
1950
|
+
{
|
1951
|
+
result = @builder.false(val[0])
|
1952
|
+
}
|
1953
|
+
| k__FILE__
|
1954
|
+
{
|
1955
|
+
result = @builder.__FILE__(val[0])
|
1956
|
+
}
|
1957
|
+
| k__LINE__
|
1958
|
+
{
|
1959
|
+
result = @builder.__LINE__(val[0])
|
1960
|
+
}
|
1961
|
+
| k__ENCODING__
|
1962
|
+
{
|
1963
|
+
result = @builder.__ENCODING__(val[0])
|
1964
|
+
}
|
1965
|
+
|
1966
|
+
var_ref: user_variable
|
1967
|
+
{
|
1968
|
+
result = @builder.accessible(val[0])
|
1969
|
+
}
|
1970
|
+
| keyword_variable
|
1971
|
+
{
|
1972
|
+
result = @builder.accessible(val[0])
|
1973
|
+
}
|
1974
|
+
|
1975
|
+
var_lhs: user_variable
|
1976
|
+
{
|
1977
|
+
result = @builder.assignable(val[0])
|
1978
|
+
}
|
1979
|
+
| keyword_variable
|
1980
|
+
{
|
1981
|
+
result = @builder.assignable(val[0])
|
1982
|
+
}
|
1983
|
+
|
1984
|
+
backref: tNTH_REF
|
1985
|
+
{
|
1986
|
+
result = @builder.nth_ref(val[0])
|
1987
|
+
}
|
1988
|
+
| tBACK_REF
|
1989
|
+
{
|
1990
|
+
result = @builder.back_ref(val[0])
|
1991
|
+
}
|
1992
|
+
|
1993
|
+
superclass: tLT
|
1994
|
+
{
|
1995
|
+
@lexer.state = :expr_value
|
1996
|
+
}
|
1997
|
+
expr_value term
|
1998
|
+
{
|
1999
|
+
result = [ val[0], val[2] ]
|
2000
|
+
}
|
2001
|
+
| # nothing
|
2002
|
+
{
|
2003
|
+
result = nil
|
2004
|
+
}
|
2005
|
+
|
2006
|
+
f_arglist: tLPAREN2 f_args rparen
|
2007
|
+
{
|
2008
|
+
result = @builder.args(val[0], val[1], val[2])
|
2009
|
+
|
2010
|
+
@lexer.state = :expr_value
|
2011
|
+
}
|
2012
|
+
| {
|
2013
|
+
result = @lexer.in_kwarg
|
2014
|
+
@lexer.in_kwarg = true
|
2015
|
+
}
|
2016
|
+
f_args term
|
2017
|
+
{
|
2018
|
+
@lexer.in_kwarg = val[0]
|
2019
|
+
result = @builder.args(nil, val[1], nil)
|
2020
|
+
}
|
2021
|
+
|
2022
|
+
args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
|
2023
|
+
{
|
2024
|
+
result = val[0].concat(val[2]).concat(val[3])
|
2025
|
+
}
|
2026
|
+
| f_kwarg opt_f_block_arg
|
2027
|
+
{
|
2028
|
+
result = val[0].concat(val[1])
|
2029
|
+
}
|
2030
|
+
| f_kwrest opt_f_block_arg
|
2031
|
+
{
|
2032
|
+
result = val[0].concat(val[1])
|
2033
|
+
}
|
2034
|
+
| f_block_arg
|
2035
|
+
{
|
2036
|
+
result = [ val[0] ]
|
2037
|
+
}
|
2038
|
+
|
2039
|
+
opt_args_tail: tCOMMA args_tail
|
2040
|
+
{
|
2041
|
+
result = val[1]
|
2042
|
+
}
|
2043
|
+
| # nothing
|
2044
|
+
{
|
2045
|
+
result = []
|
2046
|
+
}
|
2047
|
+
|
2048
|
+
f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
|
2049
|
+
{
|
2050
|
+
result = val[0].
|
2051
|
+
concat(val[2]).
|
2052
|
+
concat(val[4]).
|
2053
|
+
concat(val[5])
|
2054
|
+
}
|
2055
|
+
| f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
|
2056
|
+
{
|
2057
|
+
result = val[0].
|
2058
|
+
concat(val[2]).
|
2059
|
+
concat(val[4]).
|
2060
|
+
concat(val[6]).
|
2061
|
+
concat(val[7])
|
2062
|
+
}
|
2063
|
+
| f_arg tCOMMA f_optarg opt_args_tail
|
2064
|
+
{
|
2065
|
+
result = val[0].
|
2066
|
+
concat(val[2]).
|
2067
|
+
concat(val[3])
|
2068
|
+
}
|
2069
|
+
| f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
|
2070
|
+
{
|
2071
|
+
result = val[0].
|
2072
|
+
concat(val[2]).
|
2073
|
+
concat(val[4]).
|
2074
|
+
concat(val[5])
|
2075
|
+
}
|
2076
|
+
| f_arg tCOMMA f_rest_arg opt_args_tail
|
2077
|
+
{
|
2078
|
+
result = val[0].
|
2079
|
+
concat(val[2]).
|
2080
|
+
concat(val[3])
|
2081
|
+
}
|
2082
|
+
| f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
|
2083
|
+
{
|
2084
|
+
result = val[0].
|
2085
|
+
concat(val[2]).
|
2086
|
+
concat(val[4]).
|
2087
|
+
concat(val[5])
|
2088
|
+
}
|
2089
|
+
| f_arg opt_args_tail
|
2090
|
+
{
|
2091
|
+
result = val[0].
|
2092
|
+
concat(val[1])
|
2093
|
+
}
|
2094
|
+
| f_optarg tCOMMA f_rest_arg opt_args_tail
|
2095
|
+
{
|
2096
|
+
result = val[0].
|
2097
|
+
concat(val[2]).
|
2098
|
+
concat(val[3])
|
2099
|
+
}
|
2100
|
+
| f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
|
2101
|
+
{
|
2102
|
+
result = val[0].
|
2103
|
+
concat(val[2]).
|
2104
|
+
concat(val[4]).
|
2105
|
+
concat(val[5])
|
2106
|
+
}
|
2107
|
+
| f_optarg opt_args_tail
|
2108
|
+
{
|
2109
|
+
result = val[0].
|
2110
|
+
concat(val[1])
|
2111
|
+
}
|
2112
|
+
| f_optarg tCOMMA f_arg opt_args_tail
|
2113
|
+
{
|
2114
|
+
result = val[0].
|
2115
|
+
concat(val[2]).
|
2116
|
+
concat(val[3])
|
2117
|
+
}
|
2118
|
+
| f_rest_arg opt_args_tail
|
2119
|
+
{
|
2120
|
+
result = val[0].
|
2121
|
+
concat(val[1])
|
2122
|
+
}
|
2123
|
+
| f_rest_arg tCOMMA f_arg opt_args_tail
|
2124
|
+
{
|
2125
|
+
result = val[0].
|
2126
|
+
concat(val[2]).
|
2127
|
+
concat(val[3])
|
2128
|
+
}
|
2129
|
+
| args_tail
|
2130
|
+
{
|
2131
|
+
result = val[0]
|
2132
|
+
}
|
2133
|
+
| # nothing
|
2134
|
+
{
|
2135
|
+
result = []
|
2136
|
+
}
|
2137
|
+
|
2138
|
+
f_bad_arg: tCONSTANT
|
2139
|
+
{
|
2140
|
+
diagnostic :error, :argument_const, nil, val[0]
|
2141
|
+
}
|
2142
|
+
| tIVAR
|
2143
|
+
{
|
2144
|
+
diagnostic :error, :argument_ivar, nil, val[0]
|
2145
|
+
}
|
2146
|
+
| tGVAR
|
2147
|
+
{
|
2148
|
+
diagnostic :error, :argument_gvar, nil, val[0]
|
2149
|
+
}
|
2150
|
+
| tCVAR
|
2151
|
+
{
|
2152
|
+
diagnostic :error, :argument_cvar, nil, val[0]
|
2153
|
+
}
|
2154
|
+
|
2155
|
+
f_norm_arg: f_bad_arg
|
2156
|
+
| tIDENTIFIER
|
2157
|
+
{
|
2158
|
+
@static_env.declare val[0][0]
|
2159
|
+
|
2160
|
+
result = val[0]
|
2161
|
+
}
|
2162
|
+
|
2163
|
+
f_arg_asgn: f_norm_arg
|
2164
|
+
{
|
2165
|
+
result = val[0]
|
2166
|
+
}
|
2167
|
+
|
2168
|
+
f_arg_item: f_arg_asgn
|
2169
|
+
{
|
2170
|
+
result = @builder.arg(val[0])
|
2171
|
+
}
|
2172
|
+
| tLPAREN f_margs rparen
|
2173
|
+
{
|
2174
|
+
result = @builder.multi_lhs(val[0], val[1], val[2])
|
2175
|
+
}
|
2176
|
+
|
2177
|
+
f_arg: f_arg_item
|
2178
|
+
{
|
2179
|
+
result = [ val[0] ]
|
2180
|
+
}
|
2181
|
+
| f_arg tCOMMA f_arg_item
|
2182
|
+
{
|
2183
|
+
result = val[0] << val[2]
|
2184
|
+
}
|
2185
|
+
|
2186
|
+
f_label: tLABEL
|
2187
|
+
{
|
2188
|
+
check_kwarg_name(val[0])
|
2189
|
+
|
2190
|
+
@static_env.declare val[0][0]
|
2191
|
+
|
2192
|
+
result = val[0]
|
2193
|
+
}
|
2194
|
+
|
2195
|
+
f_kw: f_label arg_value
|
2196
|
+
{
|
2197
|
+
result = @builder.kwoptarg(val[0], val[1])
|
2198
|
+
}
|
2199
|
+
| f_label
|
2200
|
+
{
|
2201
|
+
result = @builder.kwarg(val[0])
|
2202
|
+
}
|
2203
|
+
|
2204
|
+
f_block_kw: f_label primary_value
|
2205
|
+
{
|
2206
|
+
result = @builder.kwoptarg(val[0], val[1])
|
2207
|
+
}
|
2208
|
+
| f_label
|
2209
|
+
{
|
2210
|
+
result = @builder.kwarg(val[0])
|
2211
|
+
}
|
2212
|
+
|
2213
|
+
f_block_kwarg: f_block_kw
|
2214
|
+
{
|
2215
|
+
result = [ val[0] ]
|
2216
|
+
}
|
2217
|
+
| f_block_kwarg tCOMMA f_block_kw
|
2218
|
+
{
|
2219
|
+
result = val[0] << val[2]
|
2220
|
+
}
|
2221
|
+
|
2222
|
+
f_kwarg: f_kw
|
2223
|
+
{
|
2224
|
+
result = [ val[0] ]
|
2225
|
+
}
|
2226
|
+
| f_kwarg tCOMMA f_kw
|
2227
|
+
{
|
2228
|
+
result = val[0] << val[2]
|
2229
|
+
}
|
2230
|
+
|
2231
|
+
kwrest_mark: tPOW | tDSTAR
|
2232
|
+
|
2233
|
+
f_kwrest: kwrest_mark tIDENTIFIER
|
2234
|
+
{
|
2235
|
+
@static_env.declare val[1][0]
|
2236
|
+
|
2237
|
+
result = [ @builder.kwrestarg(val[0], val[1]) ]
|
2238
|
+
}
|
2239
|
+
| kwrest_mark
|
2240
|
+
{
|
2241
|
+
result = [ @builder.kwrestarg(val[0]) ]
|
2242
|
+
}
|
2243
|
+
|
2244
|
+
f_opt: f_arg_asgn tEQL arg_value
|
2245
|
+
{
|
2246
|
+
result = @builder.optarg(val[0], val[1], val[2])
|
2247
|
+
}
|
2248
|
+
|
2249
|
+
f_block_opt: f_arg_asgn tEQL primary_value
|
2250
|
+
{
|
2251
|
+
result = @builder.optarg(val[0], val[1], val[2])
|
2252
|
+
}
|
2253
|
+
|
2254
|
+
f_block_optarg: f_block_opt
|
2255
|
+
{
|
2256
|
+
result = [ val[0] ]
|
2257
|
+
}
|
2258
|
+
| f_block_optarg tCOMMA f_block_opt
|
2259
|
+
{
|
2260
|
+
result = val[0] << val[2]
|
2261
|
+
}
|
2262
|
+
|
2263
|
+
f_optarg: f_opt
|
2264
|
+
{
|
2265
|
+
result = [ val[0] ]
|
2266
|
+
}
|
2267
|
+
| f_optarg tCOMMA f_opt
|
2268
|
+
{
|
2269
|
+
result = val[0] << val[2]
|
2270
|
+
}
|
2271
|
+
|
2272
|
+
restarg_mark: tSTAR2 | tSTAR
|
2273
|
+
|
2274
|
+
f_rest_arg: restarg_mark tIDENTIFIER
|
2275
|
+
{
|
2276
|
+
@static_env.declare val[1][0]
|
2277
|
+
|
2278
|
+
result = [ @builder.restarg(val[0], val[1]) ]
|
2279
|
+
}
|
2280
|
+
| restarg_mark
|
2281
|
+
{
|
2282
|
+
result = [ @builder.restarg(val[0]) ]
|
2283
|
+
}
|
2284
|
+
|
2285
|
+
blkarg_mark: tAMPER2 | tAMPER
|
2286
|
+
|
2287
|
+
f_block_arg: blkarg_mark tIDENTIFIER
|
2288
|
+
{
|
2289
|
+
@static_env.declare val[1][0]
|
2290
|
+
|
2291
|
+
result = @builder.blockarg(val[0], val[1])
|
2292
|
+
}
|
2293
|
+
|
2294
|
+
opt_f_block_arg: tCOMMA f_block_arg
|
2295
|
+
{
|
2296
|
+
result = [ val[1] ]
|
2297
|
+
}
|
2298
|
+
|
|
2299
|
+
{
|
2300
|
+
result = []
|
2301
|
+
}
|
2302
|
+
|
2303
|
+
singleton: var_ref
|
2304
|
+
| tLPAREN2 expr rparen
|
2305
|
+
{
|
2306
|
+
result = val[1]
|
2307
|
+
}
|
2308
|
+
|
2309
|
+
assoc_list: # nothing
|
2310
|
+
{
|
2311
|
+
result = []
|
2312
|
+
}
|
2313
|
+
| assocs trailer
|
2314
|
+
|
2315
|
+
assocs: assoc
|
2316
|
+
{
|
2317
|
+
result = [ val[0] ]
|
2318
|
+
}
|
2319
|
+
| assocs tCOMMA assoc
|
2320
|
+
{
|
2321
|
+
result = val[0] << val[2]
|
2322
|
+
}
|
2323
|
+
|
2324
|
+
assoc: arg_value tASSOC arg_value
|
2325
|
+
{
|
2326
|
+
result = @builder.pair(val[0], val[1], val[2])
|
2327
|
+
}
|
2328
|
+
| tLABEL arg_value
|
2329
|
+
{
|
2330
|
+
result = @builder.pair_keyword(val[0], val[1])
|
2331
|
+
}
|
2332
|
+
| tSTRING_BEG string_contents tLABEL_END arg_value
|
2333
|
+
{
|
2334
|
+
result = @builder.pair_quoted(val[0], val[1], val[2], val[3])
|
2335
|
+
}
|
2336
|
+
| tDSTAR arg_value
|
2337
|
+
{
|
2338
|
+
result = @builder.kwsplat(val[0], val[1])
|
2339
|
+
}
|
2340
|
+
|
2341
|
+
operation: tIDENTIFIER | tCONSTANT | tFID
|
2342
|
+
operation2: tIDENTIFIER | tCONSTANT | tFID | op
|
2343
|
+
operation3: tIDENTIFIER | tFID | op
|
2344
|
+
dot_or_colon: call_op | tCOLON2
|
2345
|
+
call_op: tDOT
|
2346
|
+
{
|
2347
|
+
result = [:dot, val[0][1]]
|
2348
|
+
}
|
2349
|
+
| tANDDOT
|
2350
|
+
{
|
2351
|
+
result = [:anddot, val[0][1]]
|
2352
|
+
}
|
2353
|
+
opt_terms: | terms
|
2354
|
+
opt_nl: | tNL
|
2355
|
+
rparen: opt_nl tRPAREN
|
2356
|
+
{
|
2357
|
+
result = val[1]
|
2358
|
+
}
|
2359
|
+
rbracket: opt_nl tRBRACK
|
2360
|
+
{
|
2361
|
+
result = val[1]
|
2362
|
+
}
|
2363
|
+
trailer: | tNL | tCOMMA
|
2364
|
+
|
2365
|
+
term: tSEMI
|
2366
|
+
{
|
2367
|
+
yyerrok
|
2368
|
+
}
|
2369
|
+
| tNL
|
2370
|
+
|
2371
|
+
terms: term
|
2372
|
+
| terms tSEMI
|
2373
|
+
|
2374
|
+
none: # nothing
|
2375
|
+
{
|
2376
|
+
result = nil
|
2377
|
+
}
|
2378
|
+
end
|
2379
|
+
|
2380
|
+
---- header
|
2381
|
+
|
2382
|
+
require 'parser'
|
2383
|
+
|
2384
|
+
---- inner
|
2385
|
+
|
2386
|
+
def version
|
2387
|
+
26
|
2388
|
+
end
|
2389
|
+
|
2390
|
+
def default_encoding
|
2391
|
+
Encoding::UTF_8
|
2392
|
+
end
|