parser 2.7.1.3 → 2.7.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1029,11 +1029,15 @@ rule
1029
1029
  result = @builder.block(val[0],
1030
1030
  begin_t, args, body, end_t)
1031
1031
  }
1032
- | tLAMBDA lambda
1032
+ | tLAMBDA
1033
+ {
1034
+ @context.push(:lambda)
1035
+ }
1036
+ lambda
1033
1037
  {
1034
1038
  lambda_call = @builder.call_lambda(val[0])
1035
1039
 
1036
- args, (begin_t, body, end_t) = val[1]
1040
+ args, (begin_t, body, end_t) = val[2]
1037
1041
  result = @builder.block(lambda_call,
1038
1042
  begin_t, args, body, end_t)
1039
1043
  }
@@ -1147,6 +1151,7 @@ rule
1147
1151
  {
1148
1152
  @static_env.extend_static
1149
1153
  @lexer.push_cmdarg
1154
+ @context.push(:module)
1150
1155
  }
1151
1156
  bodystmt kEND
1152
1157
  {
@@ -1159,6 +1164,7 @@ rule
1159
1164
 
1160
1165
  @lexer.pop_cmdarg
1161
1166
  @static_env.unextend
1167
+ @context.pop
1162
1168
  }
1163
1169
  | kDEF fname
1164
1170
  {
@@ -1471,6 +1477,7 @@ opt_block_args_tail:
1471
1477
  {
1472
1478
  result = @lexer.cmdarg.dup
1473
1479
  @lexer.cmdarg.clear
1480
+ @context.pop
1474
1481
  }
1475
1482
  lambda_body
1476
1483
  {
@@ -1028,11 +1028,15 @@ rule
1028
1028
  result = @builder.block(val[0],
1029
1029
  begin_t, args, body, end_t)
1030
1030
  }
1031
- | tLAMBDA lambda
1031
+ | tLAMBDA
1032
+ {
1033
+ @context.push(:lambda)
1034
+ }
1035
+ lambda
1032
1036
  {
1033
1037
  lambda_call = @builder.call_lambda(val[0])
1034
1038
 
1035
- args, (begin_t, body, end_t) = val[1]
1039
+ args, (begin_t, body, end_t) = val[2]
1036
1040
  result = @builder.block(lambda_call,
1037
1041
  begin_t, args, body, end_t)
1038
1042
  }
@@ -1146,6 +1150,7 @@ rule
1146
1150
  {
1147
1151
  @static_env.extend_static
1148
1152
  @lexer.push_cmdarg
1153
+ @context.push(:module)
1149
1154
  }
1150
1155
  bodystmt kEND
1151
1156
  {
@@ -1158,6 +1163,7 @@ rule
1158
1163
 
1159
1164
  @lexer.pop_cmdarg
1160
1165
  @static_env.unextend
1166
+ @context.pop
1161
1167
  }
1162
1168
  | kDEF fname
1163
1169
  {
@@ -1470,6 +1476,7 @@ opt_block_args_tail:
1470
1476
  {
1471
1477
  result = @lexer.cmdarg.dup
1472
1478
  @lexer.cmdarg.clear
1479
+ @context.pop
1473
1480
  }
1474
1481
  lambda_body
1475
1482
  {
@@ -1028,11 +1028,15 @@ rule
1028
1028
  result = @builder.block(val[0],
1029
1029
  begin_t, args, body, end_t)
1030
1030
  }
1031
- | tLAMBDA lambda
1031
+ | tLAMBDA
1032
+ {
1033
+ @context.push(:lambda)
1034
+ }
1035
+ lambda
1032
1036
  {
1033
1037
  lambda_call = @builder.call_lambda(val[0])
1034
1038
 
1035
- args, (begin_t, body, end_t) = val[1]
1039
+ args, (begin_t, body, end_t) = val[2]
1036
1040
  result = @builder.block(lambda_call,
1037
1041
  begin_t, args, body, end_t)
1038
1042
  }
@@ -1146,6 +1150,7 @@ rule
1146
1150
  {
1147
1151
  @static_env.extend_static
1148
1152
  @lexer.push_cmdarg
1153
+ @context.push(:module)
1149
1154
  }
1150
1155
  bodystmt kEND
1151
1156
  {
@@ -1158,6 +1163,7 @@ rule
1158
1163
 
1159
1164
  @lexer.pop_cmdarg
1160
1165
  @static_env.unextend
1166
+ @context.pop
1161
1167
  }
1162
1168
  | kDEF fname
1163
1169
  {
@@ -1470,6 +1476,7 @@ opt_block_args_tail:
1470
1476
  {
1471
1477
  result = @lexer.cmdarg.dup
1472
1478
  @lexer.cmdarg.clear
1479
+ @context.pop
1473
1480
  }
1474
1481
  lambda_body
1475
1482
  {
@@ -1047,11 +1047,15 @@ rule
1047
1047
  result = @builder.block(val[0],
1048
1048
  begin_t, args, body, end_t)
1049
1049
  }
1050
- | tLAMBDA lambda
1050
+ | tLAMBDA
1051
+ {
1052
+ @context.push(:lambda)
1053
+ }
1054
+ lambda
1051
1055
  {
1052
1056
  lambda_call = @builder.call_lambda(val[0])
1053
1057
 
1054
- args, (begin_t, body, end_t) = val[1]
1058
+ args, (begin_t, body, end_t) = val[2]
1055
1059
  result = @builder.block(lambda_call,
1056
1060
  begin_t, args, body, end_t)
1057
1061
  }
@@ -1165,6 +1169,7 @@ rule
1165
1169
  {
1166
1170
  @static_env.extend_static
1167
1171
  @lexer.cmdarg.push(false)
1172
+ @context.push(:module)
1168
1173
  }
1169
1174
  bodystmt kEND
1170
1175
  {
@@ -1177,6 +1182,7 @@ rule
1177
1182
 
1178
1183
  @lexer.cmdarg.pop
1179
1184
  @static_env.unextend
1185
+ @context.pop
1180
1186
  }
1181
1187
  | kDEF fname
1182
1188
  {
@@ -1487,6 +1493,7 @@ opt_block_args_tail:
1487
1493
  }
1488
1494
  f_larglist
1489
1495
  {
1496
+ @context.pop
1490
1497
  @lexer.cmdarg.push(false)
1491
1498
  }
1492
1499
  lambda_body
@@ -1057,11 +1057,15 @@ rule
1057
1057
  result = @builder.block(val[0],
1058
1058
  begin_t, args, body, end_t)
1059
1059
  }
1060
- | tLAMBDA lambda
1060
+ | tLAMBDA
1061
+ {
1062
+ @context.push(:lambda)
1063
+ }
1064
+ lambda
1061
1065
  {
1062
1066
  lambda_call = @builder.call_lambda(val[0])
1063
1067
 
1064
- args, (begin_t, body, end_t) = val[1]
1068
+ args, (begin_t, body, end_t) = val[2]
1065
1069
  result = @builder.block(lambda_call,
1066
1070
  begin_t, args, body, end_t)
1067
1071
  }
@@ -1151,6 +1155,7 @@ rule
1151
1155
  {
1152
1156
  @static_env.extend_static
1153
1157
  @lexer.cmdarg.push(false)
1158
+ @context.push(:module)
1154
1159
  }
1155
1160
  bodystmt kEND
1156
1161
  {
@@ -1163,6 +1168,7 @@ rule
1163
1168
 
1164
1169
  @lexer.cmdarg.pop
1165
1170
  @static_env.unextend
1171
+ @context.pop
1166
1172
  }
1167
1173
  | kDEF fname
1168
1174
  {
@@ -1484,6 +1490,7 @@ opt_block_args_tail:
1484
1490
  }
1485
1491
  f_larglist
1486
1492
  {
1493
+ @context.pop
1487
1494
  @lexer.cmdarg.push(false)
1488
1495
  }
1489
1496
  lambda_body
@@ -1065,11 +1065,15 @@ rule
1065
1065
  result = @builder.block(val[0],
1066
1066
  begin_t, args, body, end_t)
1067
1067
  }
1068
- | tLAMBDA lambda
1068
+ | tLAMBDA
1069
+ {
1070
+ @context.push(:lambda)
1071
+ }
1072
+ lambda
1069
1073
  {
1070
1074
  lambda_call = @builder.call_lambda(val[0])
1071
1075
 
1072
- args, (begin_t, body, end_t) = val[1]
1076
+ args, (begin_t, body, end_t) = val[2]
1073
1077
  result = @builder.block(lambda_call,
1074
1078
  begin_t, args, body, end_t)
1075
1079
  }
@@ -1159,6 +1163,7 @@ rule
1159
1163
  {
1160
1164
  @static_env.extend_static
1161
1165
  @lexer.cmdarg.push(false)
1166
+ @context.push(:module)
1162
1167
  }
1163
1168
  bodystmt kEND
1164
1169
  {
@@ -1171,6 +1176,7 @@ rule
1171
1176
 
1172
1177
  @lexer.cmdarg.pop
1173
1178
  @static_env.unextend
1179
+ @context.pop
1174
1180
  }
1175
1181
  | kDEF fname
1176
1182
  {
@@ -1492,6 +1498,7 @@ opt_block_args_tail:
1492
1498
  }
1493
1499
  f_larglist
1494
1500
  {
1501
+ @context.pop
1495
1502
  @lexer.cmdarg.push(false)
1496
1503
  }
1497
1504
  lambda_body
@@ -1109,11 +1109,15 @@ rule
1109
1109
  result = @builder.block(val[0],
1110
1110
  begin_t, args, body, end_t)
1111
1111
  }
1112
- | tLAMBDA lambda
1112
+ | tLAMBDA
1113
+ {
1114
+ @context.push(:lambda)
1115
+ }
1116
+ lambda
1113
1117
  {
1114
1118
  lambda_call = @builder.call_lambda(val[0])
1115
1119
 
1116
- args, (begin_t, body, end_t) = val[1]
1120
+ args, (begin_t, body, end_t) = val[2]
1117
1121
  result = @builder.block(lambda_call,
1118
1122
  begin_t, args, body, end_t)
1119
1123
  }
@@ -1211,6 +1215,7 @@ rule
1211
1215
  {
1212
1216
  @static_env.extend_static
1213
1217
  @lexer.cmdarg.push(false)
1218
+ @context.push(:module)
1214
1219
  }
1215
1220
  bodystmt kEND
1216
1221
  {
@@ -1223,6 +1228,7 @@ rule
1223
1228
 
1224
1229
  @lexer.cmdarg.pop
1225
1230
  @static_env.unextend
1231
+ @context.pop
1226
1232
  }
1227
1233
  | kDEF fname
1228
1234
  {
@@ -1538,7 +1544,6 @@ opt_block_args_tail:
1538
1544
  lambda: {
1539
1545
  @static_env.extend_dynamic
1540
1546
  @max_numparam_stack.push
1541
- @context.push(:lambda)
1542
1547
  }
1543
1548
  f_larglist
1544
1549
  {
@@ -2089,11 +2094,15 @@ opt_block_args_tail:
2089
2094
  {
2090
2095
  result = @builder.accessible(val[0])
2091
2096
  }
2092
- | tLAMBDA lambda
2097
+ | tLAMBDA
2098
+ {
2099
+ @context.push(:lambda)
2100
+ }
2101
+ lambda
2093
2102
  {
2094
2103
  lambda_call = @builder.call_lambda(val[0])
2095
2104
 
2096
- args, (begin_t, body, end_t) = val[1]
2105
+ args, (begin_t, body, end_t) = val[2]
2097
2106
  result = @builder.block(lambda_call,
2098
2107
  begin_t, args, body, end_t)
2099
2108
  }
@@ -2523,7 +2532,7 @@ keyword_variable: kNIL
2523
2532
  }
2524
2533
  | tLPAREN2 args_forward rparen
2525
2534
  {
2526
- result = @builder.forward_args(val[0], val[1], val[2])
2535
+ result = @builder.forward_only_args(val[0], val[1], val[2])
2527
2536
  @static_env.declare_forward_args
2528
2537
 
2529
2538
  @lexer.state = :expr_value
@@ -960,6 +960,14 @@ rule
960
960
  {
961
961
  result = val
962
962
  }
963
+ | tLPAREN2 args tCOMMA args_forward rparen
964
+ {
965
+ unless @static_env.declared_forward_args?
966
+ diagnostic :error, :unexpected_token, { :token => 'tBDOT3' } , val[3]
967
+ end
968
+
969
+ result = [val[0], [*val[1], @builder.forwarded_args(val[3])], val[4]]
970
+ }
963
971
  | tLPAREN2 args_forward rparen
964
972
  {
965
973
  unless @static_env.declared_forward_args?
@@ -1212,14 +1220,7 @@ rule
1212
1220
  result = @builder.block(val[0],
1213
1221
  begin_t, args, body, end_t)
1214
1222
  }
1215
- | tLAMBDA lambda
1216
- {
1217
- lambda_call = @builder.call_lambda(val[0])
1218
-
1219
- args, (begin_t, body, end_t) = val[1]
1220
- result = @builder.block(lambda_call,
1221
- begin_t, args, body, end_t)
1222
- }
1223
+ | lambda
1223
1224
  | kIF expr_value then compstmt if_tail kEND
1224
1225
  {
1225
1226
  else_t, else_ = val[4]
@@ -1314,6 +1315,7 @@ rule
1314
1315
  {
1315
1316
  @static_env.extend_static
1316
1317
  @lexer.cmdarg.push(false)
1318
+ @context.push(:module)
1317
1319
  }
1318
1320
  bodystmt kEND
1319
1321
  {
@@ -1326,6 +1328,7 @@ rule
1326
1328
 
1327
1329
  @lexer.cmdarg.pop
1328
1330
  @static_env.unextend
1331
+ @context.pop
1329
1332
  }
1330
1333
  | defn_head f_arglist bodystmt kEND
1331
1334
  {
@@ -1483,6 +1486,8 @@ opt_block_args_tail:
1483
1486
  result = []
1484
1487
  }
1485
1488
 
1489
+ excessed_comma: tCOMMA
1490
+
1486
1491
  block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1487
1492
  {
1488
1493
  result = val[0].
@@ -1517,7 +1522,7 @@ opt_block_args_tail:
1517
1522
  concat(val[2]).
1518
1523
  concat(val[3])
1519
1524
  }
1520
- | f_arg tCOMMA
1525
+ | f_arg excessed_comma
1521
1526
  | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1522
1527
  {
1523
1528
  result = val[0].
@@ -1617,7 +1622,8 @@ opt_block_args_tail:
1617
1622
  }
1618
1623
  | f_bad_arg
1619
1624
 
1620
- lambda: {
1625
+ lambda: tLAMBDA
1626
+ {
1621
1627
  @static_env.extend_dynamic
1622
1628
  @max_numparam_stack.push
1623
1629
  @context.push(:lambda)
@@ -1629,12 +1635,16 @@ opt_block_args_tail:
1629
1635
  }
1630
1636
  lambda_body
1631
1637
  {
1632
- args = @max_numparam_stack.has_numparams? ? @builder.numargs(@max_numparam_stack.top) : val[1]
1633
- result = [ args, val[3] ]
1638
+ lambda_call = @builder.call_lambda(val[0])
1639
+ args = @max_numparam_stack.has_numparams? ? @builder.numargs(@max_numparam_stack.top) : val[2]
1640
+ begin_t, body, end_t = val[4]
1634
1641
 
1635
1642
  @max_numparam_stack.pop
1636
1643
  @static_env.unextend
1637
1644
  @lexer.cmdarg.pop
1645
+
1646
+ result = @builder.block(lambda_call,
1647
+ begin_t, args, body, end_t)
1638
1648
  }
1639
1649
 
1640
1650
  f_larglist: tLPAREN2 f_args opt_bv_decl tRPAREN
@@ -1873,6 +1883,10 @@ opt_block_args_tail:
1873
1883
  {
1874
1884
  result = @builder.array_pattern(nil, [val[0]].concat(val[2]), nil)
1875
1885
  }
1886
+ | p_find
1887
+ {
1888
+ result = @builder.find_pattern(nil, val[0], nil)
1889
+ }
1876
1890
  | p_args_tail
1877
1891
  {
1878
1892
  result = @builder.array_pattern(nil, val[0], nil)
@@ -1915,6 +1929,12 @@ opt_block_args_tail:
1915
1929
  pattern = @builder.array_pattern(nil, val[2], nil)
1916
1930
  result = @builder.const_pattern(val[0], val[1], pattern, val[3])
1917
1931
  }
1932
+ | p_const p_lparen p_find rparen
1933
+ {
1934
+ @pattern_hash_keys.pop
1935
+ pattern = @builder.find_pattern(nil, val[2], nil)
1936
+ result = @builder.const_pattern(val[0], val[1], pattern, val[3])
1937
+ }
1918
1938
  | p_const p_lparen p_kwargs rparen
1919
1939
  {
1920
1940
  @pattern_hash_keys.pop
@@ -1932,6 +1952,12 @@ opt_block_args_tail:
1932
1952
  pattern = @builder.array_pattern(nil, val[2], nil)
1933
1953
  result = @builder.const_pattern(val[0], val[1], pattern, val[3])
1934
1954
  }
1955
+ | p_const p_lbracket p_find rbracket
1956
+ {
1957
+ @pattern_hash_keys.pop
1958
+ pattern = @builder.find_pattern(nil, val[2], nil)
1959
+ result = @builder.const_pattern(val[0], val[1], pattern, val[3])
1960
+ }
1935
1961
  | p_const p_lbracket p_kwargs rbracket
1936
1962
  {
1937
1963
  @pattern_hash_keys.pop
@@ -1943,14 +1969,13 @@ opt_block_args_tail:
1943
1969
  pattern = @builder.array_pattern(val[1], nil, val[2])
1944
1970
  result = @builder.const_pattern(val[0], val[1], pattern, val[2])
1945
1971
  }
1946
- | tLBRACK
1972
+ | tLBRACK p_args rbracket
1947
1973
  {
1948
- @pattern_hash_keys.push
1974
+ result = @builder.array_pattern(val[0], val[1], val[2])
1949
1975
  }
1950
- p_args rbracket
1976
+ | tLBRACK p_find rbracket
1951
1977
  {
1952
- @pattern_hash_keys.pop
1953
- result = @builder.array_pattern(val[0], val[2], val[3])
1978
+ result = @builder.find_pattern(val[0], val[1], val[2])
1954
1979
  }
1955
1980
  | tLBRACK rbracket
1956
1981
  {
@@ -2031,25 +2056,27 @@ opt_block_args_tail:
2031
2056
  result = [ *val[0], last_item ]
2032
2057
  }
2033
2058
 
2034
- p_args_tail: tSTAR tIDENTIFIER
2059
+ p_args_tail: p_rest
2035
2060
  {
2036
- match_rest = @builder.match_rest(val[0], val[1])
2037
- result = [ match_rest ]
2061
+ result = [ val[0] ]
2038
2062
  }
2039
- | tSTAR tIDENTIFIER tCOMMA p_args_post
2063
+ | p_rest tCOMMA p_args_post
2040
2064
  {
2041
- match_rest = @builder.match_rest(val[0], val[1])
2042
- result = [ match_rest, *val[3] ]
2065
+ result = [ val[0], *val[2] ]
2043
2066
  }
2044
- | tSTAR
2067
+
2068
+ p_find: p_rest tCOMMA p_args_post tCOMMA p_rest
2045
2069
  {
2046
- match_rest = @builder.match_rest(val[0])
2047
- result = [ match_rest ]
2070
+ result = [ val[0], *val[2], val[4] ]
2048
2071
  }
2049
- | tSTAR tCOMMA p_args_post
2072
+
2073
+ p_rest: tSTAR tIDENTIFIER
2050
2074
  {
2051
- match_rest = @builder.match_rest(val[0])
2052
- result = [ match_rest, *val[2] ]
2075
+ result = @builder.match_rest(val[0], val[1])
2076
+ }
2077
+ | tSTAR
2078
+ {
2079
+ result = @builder.match_rest(val[0])
2053
2080
  }
2054
2081
 
2055
2082
  p_args_post: p_arg
@@ -2166,14 +2193,7 @@ opt_block_args_tail:
2166
2193
  {
2167
2194
  result = @builder.accessible(val[0])
2168
2195
  }
2169
- | tLAMBDA lambda
2170
- {
2171
- lambda_call = @builder.call_lambda(val[0])
2172
-
2173
- args, (begin_t, body, end_t) = val[1]
2174
- result = @builder.block(lambda_call,
2175
- begin_t, args, body, end_t)
2176
- }
2196
+ | lambda
2177
2197
 
2178
2198
  p_variable: tIDENTIFIER
2179
2199
  {
@@ -2598,9 +2618,16 @@ keyword_variable: kNIL
2598
2618
 
2599
2619
  @lexer.state = :expr_value
2600
2620
  }
2621
+ | tLPAREN2 f_arg tCOMMA args_forward rparen
2622
+ {
2623
+ args = [ *val[1], @builder.forward_arg(val[3]) ]
2624
+ result = @builder.args(val[0], args, val[4])
2625
+
2626
+ @static_env.declare_forward_args
2627
+ }
2601
2628
  | tLPAREN2 args_forward rparen
2602
2629
  {
2603
- result = @builder.forward_args(val[0], val[1], val[2])
2630
+ result = @builder.forward_only_args(val[0], val[1], val[2])
2604
2631
  @static_env.declare_forward_args
2605
2632
 
2606
2633
  @lexer.state = :expr_value