parser 0.9.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
12
12
  tASET tLSHFT tRSHFT tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN
13
13
  tLPAREN2 tRPAREN tLPAREN_ARG tLBRACK tLBRACK2 tRBRACK tLBRACE
14
14
  tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2 tTILDE tPERCENT tDIVIDE
15
- tPLUS tMINUS tLT tGT tPIPE tBANG tCARET tLCURLY tRCURLY
15
+ tDSTAR tPLUS tMINUS tLT tGT tPIPE tBANG tCARET tLCURLY tRCURLY
16
16
  tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tREGEXP_OPT
17
17
  tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DBEG
18
18
  tSTRING_DVAR tSTRING_END tSTRING_DEND tSTRING tSYMBOL
@@ -605,7 +605,7 @@ rule
605
605
  | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
606
606
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
607
607
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tBANG | tTILDE
608
- | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
608
+ | tUPLUS | tUMINUS | tAREF | tASET | tDSTAR | tBACK_REF2
609
609
 
610
610
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
611
611
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -1285,58 +1285,85 @@ rule
1285
1285
  @static_env.declare val[3][0]
1286
1286
 
1287
1287
  result = val[0].
1288
- push(@builder.splatarg(val[2], val[3]))
1288
+ push(@builder.restarg(val[2], val[3]))
1289
1289
  }
1290
1290
  | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1291
1291
  {
1292
1292
  @static_env.declare val[3][0]
1293
1293
 
1294
1294
  result = val[0].
1295
- push(@builder.splatarg(val[2], val[3])).
1295
+ push(@builder.restarg(val[2], val[3])).
1296
1296
  concat(val[5])
1297
1297
  }
1298
1298
  | f_marg_list tCOMMA tSTAR
1299
1299
  {
1300
1300
  result = val[0].
1301
- push(@builder.splatarg(val[2]))
1301
+ push(@builder.restarg(val[2]))
1302
1302
  }
1303
1303
  | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1304
1304
  {
1305
1305
  result = val[0].
1306
- push(@builder.splatarg(val[2])).
1306
+ push(@builder.restarg(val[2])).
1307
1307
  concat(val[4])
1308
1308
  }
1309
1309
  | tSTAR f_norm_arg
1310
1310
  {
1311
1311
  @static_env.declare val[1][0]
1312
1312
 
1313
- result = [ @builder.splatarg(val[0], val[1]) ]
1313
+ result = [ @builder.restarg(val[0], val[1]) ]
1314
1314
  }
1315
1315
  | tSTAR f_norm_arg tCOMMA f_marg_list
1316
1316
  {
1317
1317
  @static_env.declare val[1][0]
1318
1318
 
1319
- result = [ @builder.splatarg(val[0], val[1]),
1319
+ result = [ @builder.restarg(val[0], val[1]),
1320
1320
  *val[3] ]
1321
1321
  }
1322
1322
  | tSTAR
1323
1323
  {
1324
- result = [ @builder.splatarg(val[0]) ]
1324
+ result = [ @builder.restarg(val[0]) ]
1325
1325
  }
1326
1326
  | tSTAR tCOMMA f_marg_list
1327
1327
  {
1328
- result = [ @builder.splatarg(val[0]),
1328
+ result = [ @builder.restarg(val[0]),
1329
1329
  *val[2] ]
1330
1330
  }
1331
1331
 
1332
- block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_f_block_arg
1332
+ block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1333
+ {
1334
+ result = val[0].concat(val[2]).concat(val[3])
1335
+ }
1336
+ | f_block_kwarg opt_f_block_arg
1337
+ {
1338
+ result = val[0].concat(val[1])
1339
+ }
1340
+ | f_kwrest opt_f_block_arg
1341
+ {
1342
+ result = val[0].concat(val[1])
1343
+ }
1344
+ | f_block_arg
1345
+ {
1346
+ result = [ val[0] ]
1347
+ }
1348
+
1349
+ opt_block_args_tail:
1350
+ tCOMMA block_args_tail
1351
+ {
1352
+ result = val[1]
1353
+ }
1354
+ | # nothing
1355
+ {
1356
+ result = []
1357
+ }
1358
+
1359
+ block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1333
1360
  {
1334
1361
  result = val[0].
1335
1362
  concat(val[2]).
1336
1363
  concat(val[4]).
1337
1364
  concat(val[5])
1338
1365
  }
1339
- | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
1366
+ | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1340
1367
  {
1341
1368
  result = val[0].
1342
1369
  concat(val[2]).
@@ -1344,76 +1371,73 @@ rule
1344
1371
  concat(val[6]).
1345
1372
  concat(val[7])
1346
1373
  }
1347
- | f_arg tCOMMA f_block_optarg opt_f_block_arg
1374
+ | f_arg tCOMMA f_block_optarg opt_block_args_tail
1348
1375
  {
1349
1376
  result = val[0].
1350
1377
  concat(val[2]).
1351
1378
  concat(val[3])
1352
1379
  }
1353
- | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_f_block_arg
1380
+ | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
1354
1381
  {
1355
1382
  result = val[0].
1356
1383
  concat(val[2]).
1357
1384
  concat(val[4]).
1358
1385
  concat(val[5])
1359
1386
  }
1360
- | f_arg tCOMMA f_rest_arg opt_f_block_arg
1387
+ | f_arg tCOMMA f_rest_arg opt_block_args_tail
1361
1388
  {
1362
1389
  result = val[0].
1363
1390
  concat(val[2]).
1364
1391
  concat(val[3])
1365
1392
  }
1366
1393
  | f_arg tCOMMA
1367
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
1394
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1368
1395
  {
1369
1396
  result = val[0].
1370
1397
  concat(val[2]).
1371
1398
  concat(val[4]).
1372
1399
  concat(val[5])
1373
1400
  }
1374
- | f_arg opt_f_block_arg
1401
+ | f_arg opt_block_args_tail
1375
1402
  {
1376
1403
  result = val[0].concat(val[1])
1377
1404
  }
1378
- | f_block_optarg tCOMMA f_rest_arg opt_f_block_arg
1405
+ | f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1379
1406
  {
1380
1407
  result = val[0].
1381
1408
  concat(val[2]).
1382
1409
  concat(val[3])
1383
1410
  }
1384
- | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
1411
+ | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1385
1412
  {
1386
1413
  result = val[0].
1387
1414
  concat(val[2]).
1388
1415
  concat(val[4]).
1389
1416
  concat(val[5])
1390
1417
  }
1391
- | f_block_optarg opt_f_block_arg
1418
+ | f_block_optarg opt_block_args_tail
1392
1419
  {
1393
1420
  result = val[0].
1394
1421
  concat(val[1])
1395
1422
  }
1396
- | f_block_optarg tCOMMA f_arg opt_f_block_arg
1423
+ | f_block_optarg tCOMMA f_arg opt_block_args_tail
1397
1424
  {
1398
1425
  result = val[0].
1399
1426
  concat(val[2]).
1400
1427
  concat(val[3])
1401
1428
  }
1402
- | f_rest_arg opt_f_block_arg
1429
+ | f_rest_arg opt_block_args_tail
1403
1430
  {
1404
1431
  result = val[0].
1405
1432
  concat(val[1])
1406
1433
  }
1407
- | f_rest_arg tCOMMA f_arg opt_f_block_arg
1434
+ | f_rest_arg tCOMMA f_arg opt_block_args_tail
1408
1435
  {
1409
1436
  result = val[0].
1410
1437
  concat(val[2]).
1411
1438
  concat(val[3])
1412
1439
  }
1413
- | f_block_arg
1414
- {
1415
- result = [ val[0] ]
1416
- }
1440
+ | block_args_tail
1417
1441
 
1418
1442
  opt_block_param: # nothing
1419
1443
  {
@@ -1507,6 +1531,25 @@ rule
1507
1531
  result = @builder.call_method(val[0], val[1], val[2],
1508
1532
  lparen_t, args, rparen_t)
1509
1533
  }
1534
+ | block_call dot_or_colon operation2 opt_paren_args brace_block
1535
+ {
1536
+ lparen_t, args, rparen_t = val[3]
1537
+ method_call = @builder.call_method(val[0], val[1], val[2],
1538
+ lparen_t, args, rparen_t)
1539
+
1540
+ begin_t, args, body, end_t = val[4]
1541
+ result = @builder.block(method_call,
1542
+ begin_t, args, body, end_t)
1543
+ }
1544
+ | block_call dot_or_colon operation2 command_args do_block
1545
+ {
1546
+ method_call = @builder.call_method(val[0], val[1], val[2],
1547
+ nil, val[3], nil)
1548
+
1549
+ begin_t, args, body, end_t = val[4]
1550
+ result = @builder.block(method_call,
1551
+ begin_t, args, body, end_t)
1552
+ }
1510
1553
 
1511
1554
  method_call: fcall paren_args
1512
1555
  {
@@ -1929,14 +1972,40 @@ keyword_variable: kNIL
1929
1972
  @lexer.state = :expr_value
1930
1973
  }
1931
1974
 
1932
- f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_f_block_arg
1975
+ args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
1976
+ {
1977
+ result = val[0].concat(val[2]).concat(val[3])
1978
+ }
1979
+ | f_kwarg opt_f_block_arg
1980
+ {
1981
+ result = val[0].concat(val[1])
1982
+ }
1983
+ | f_kwrest opt_f_block_arg
1984
+ {
1985
+ result = val[0].concat(val[1])
1986
+ }
1987
+ | f_block_arg
1988
+ {
1989
+ result = [ val[0] ]
1990
+ }
1991
+
1992
+ opt_args_tail: tCOMMA args_tail
1993
+ {
1994
+ result = val[1]
1995
+ }
1996
+ | # nothing
1997
+ {
1998
+ result = []
1999
+ }
2000
+
2001
+ f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
1933
2002
  {
1934
2003
  result = val[0].
1935
2004
  concat(val[2]).
1936
2005
  concat(val[4]).
1937
2006
  concat(val[5])
1938
2007
  }
1939
- | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
2008
+ | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
1940
2009
  {
1941
2010
  result = val[0].
1942
2011
  concat(val[2]).
@@ -1944,75 +2013,75 @@ keyword_variable: kNIL
1944
2013
  concat(val[6]).
1945
2014
  concat(val[7])
1946
2015
  }
1947
- | f_arg tCOMMA f_optarg opt_f_block_arg
2016
+ | f_arg tCOMMA f_optarg opt_args_tail
1948
2017
  {
1949
2018
  result = val[0].
1950
2019
  concat(val[2]).
1951
2020
  concat(val[3])
1952
2021
  }
1953
- | f_arg tCOMMA f_optarg tCOMMA f_arg opt_f_block_arg
2022
+ | f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
1954
2023
  {
1955
2024
  result = val[0].
1956
2025
  concat(val[2]).
1957
2026
  concat(val[4]).
1958
2027
  concat(val[5])
1959
2028
  }
1960
- | f_arg tCOMMA f_rest_arg opt_f_block_arg
2029
+ | f_arg tCOMMA f_rest_arg opt_args_tail
1961
2030
  {
1962
2031
  result = val[0].
1963
2032
  concat(val[2]).
1964
2033
  concat(val[3])
1965
2034
  }
1966
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
2035
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
1967
2036
  {
1968
2037
  result = val[0].
1969
2038
  concat(val[2]).
1970
2039
  concat(val[4]).
1971
2040
  concat(val[5])
1972
2041
  }
1973
- | f_arg opt_f_block_arg
2042
+ | f_arg opt_args_tail
1974
2043
  {
1975
2044
  result = val[0].
1976
2045
  concat(val[1])
1977
2046
  }
1978
- | f_optarg tCOMMA f_rest_arg opt_f_block_arg
2047
+ | f_optarg tCOMMA f_rest_arg opt_args_tail
1979
2048
  {
1980
2049
  result = val[0].
1981
2050
  concat(val[2]).
1982
2051
  concat(val[3])
1983
2052
  }
1984
- | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
2053
+ | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
1985
2054
  {
1986
2055
  result = val[0].
1987
2056
  concat(val[2]).
1988
2057
  concat(val[4]).
1989
2058
  concat(val[5])
1990
2059
  }
1991
- | f_optarg opt_f_block_arg
2060
+ | f_optarg opt_args_tail
1992
2061
  {
1993
2062
  result = val[0].
1994
2063
  concat(val[1])
1995
2064
  }
1996
- | f_optarg tCOMMA f_arg opt_f_block_arg
2065
+ | f_optarg tCOMMA f_arg opt_args_tail
1997
2066
  {
1998
2067
  result = val[0].
1999
2068
  concat(val[2]).
2000
2069
  concat(val[3])
2001
2070
  }
2002
- | f_rest_arg opt_f_block_arg
2071
+ | f_rest_arg opt_args_tail
2003
2072
  {
2004
2073
  result = val[0].
2005
2074
  concat(val[1])
2006
2075
  }
2007
- | f_rest_arg tCOMMA f_arg opt_f_block_arg
2076
+ | f_rest_arg tCOMMA f_arg opt_args_tail
2008
2077
  {
2009
2078
  result = val[0].
2010
2079
  concat(val[2]).
2011
2080
  concat(val[3])
2012
2081
  }
2013
- | f_block_arg
2082
+ | args_tail
2014
2083
  {
2015
- result = [ val[0] ]
2084
+ result = val[0]
2016
2085
  }
2017
2086
  | # nothing
2018
2087
  {
@@ -2059,6 +2128,55 @@ keyword_variable: kNIL
2059
2128
  result = val[0] << val[2]
2060
2129
  }
2061
2130
 
2131
+ f_kw: tLABEL arg_value
2132
+ {
2133
+ check_kwarg_name(val[0])
2134
+
2135
+ @static_env.declare val[0][0]
2136
+
2137
+ result = @builder.kwoptarg(val[0], val[1])
2138
+ }
2139
+
2140
+ f_block_kw: tLABEL primary_value
2141
+ {
2142
+ check_kwarg_name(val[0])
2143
+
2144
+ @static_env.declare val[0][0]
2145
+
2146
+ result = @builder.kwoptarg(val[0], val[1])
2147
+ }
2148
+
2149
+ f_block_kwarg: f_block_kw
2150
+ {
2151
+ result = [ val[0] ]
2152
+ }
2153
+ | f_block_kwarg tCOMMA f_block_kw
2154
+ {
2155
+ result = val[0] << val[2]
2156
+ }
2157
+
2158
+ f_kwarg: f_kw
2159
+ {
2160
+ result = [ val[0] ]
2161
+ }
2162
+ | f_kwarg tCOMMA f_kw
2163
+ {
2164
+ result = val[0] << val[2]
2165
+ }
2166
+
2167
+ kwrest_mark: tPOW | tDSTAR
2168
+
2169
+ f_kwrest: kwrest_mark tIDENTIFIER
2170
+ {
2171
+ @static_env.declare val[1][0]
2172
+
2173
+ result = [ @builder.kwrestarg(val[0], val[1]) ]
2174
+ }
2175
+ | kwrest_mark
2176
+ {
2177
+ result = [ @builder.kwrestarg(val[0]) ]
2178
+ }
2179
+
2062
2180
  f_opt: tIDENTIFIER tEQL arg_value
2063
2181
  {
2064
2182
  @static_env.declare val[0][0]
@@ -2097,11 +2215,11 @@ keyword_variable: kNIL
2097
2215
  {
2098
2216
  @static_env.declare val[1][0]
2099
2217
 
2100
- result = [ @builder.splatarg(val[0], val[1]) ]
2218
+ result = [ @builder.restarg(val[0], val[1]) ]
2101
2219
  }
2102
2220
  | restarg_mark
2103
2221
  {
2104
- result = [ @builder.splatarg(val[0]) ]
2222
+ result = [ @builder.restarg(val[0]) ]
2105
2223
  }
2106
2224
 
2107
2225
  blkarg_mark: tAMPER2 | tAMPER
@@ -2153,6 +2271,10 @@ keyword_variable: kNIL
2153
2271
  key = @builder.symbol(val[0])
2154
2272
  result = @builder.pair(key, nil, val[1])
2155
2273
  }
2274
+ | tDSTAR arg_value
2275
+ {
2276
+ result = @builder.kwsplat(val[0], val[1])
2277
+ }
2156
2278
 
2157
2279
  operation: tIDENTIFIER | tCONSTANT | tFID
2158
2280
  operation2: tIDENTIFIER | tCONSTANT | tFID | op
@@ -2161,7 +2283,13 @@ keyword_variable: kNIL
2161
2283
  opt_terms: | terms
2162
2284
  opt_nl: | tNL
2163
2285
  rparen: opt_nl tRPAREN
2286
+ {
2287
+ result = val[1]
2288
+ }
2164
2289
  rbracket: opt_nl tRBRACK
2290
+ {
2291
+ result = val[1]
2292
+ }
2165
2293
  trailer: | tNL | tCOMMA
2166
2294
 
2167
2295
  term: tSEMI
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'parser'
5
- spec.version = '0.9.2'
5
+ spec.version = '1.0.0'
6
6
  spec.authors = ['Peter Zotov']
7
7
  spec.email = ['whitequark@whitequark.org']
8
8
  spec.description = %q{A Ruby parser written in pure Ruby.}