ruby_parser 3.6.6 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ruby20_parser.y CHANGED
@@ -163,7 +163,7 @@ rule
163
163
  debug20 3
164
164
  yyerror "END in method; use at_exit"
165
165
  end
166
- result = new_iter s(:postexe), nil, val[2]
166
+ result = new_iter s(:postexe), 0, val[2]
167
167
  }
168
168
  | command_asgn
169
169
  | mlhs tEQL command_call
@@ -582,7 +582,8 @@ rule
582
582
  | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
583
583
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
584
584
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
585
- | tUPLUS | tUMINUS | tUBANG | tAREF | tASET | tBACK_REF2
585
+ | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
586
+ | tUBANG
586
587
 
587
588
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
588
589
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -689,9 +690,10 @@ rule
689
690
  | tUMINUS_NUM tFLOAT tPOW arg
690
691
  {
691
692
  result = new_call(new_call(s(:lit, val[1]), :"**", argl(val[3])), :"-@")
693
+ ## TODO: why is this 2.0 only?
692
694
  debug20 12, val, result
693
695
  }
694
- | tUPLUS arg
696
+ | tUPLUS arg
695
697
  {
696
698
  result = new_call val[1], :"+@"
697
699
  }
@@ -1137,18 +1139,22 @@ rule
1137
1139
  }
1138
1140
  | kDEF fname
1139
1141
  {
1140
- result = self.in_def
1142
+ result = [self.in_def, self.lexer.cmdarg.stack.dup]
1141
1143
 
1142
1144
  self.comments.push self.lexer.comments
1143
1145
  self.in_def = true
1144
1146
  self.env.extend
1147
+ # TODO: local->cmdargs = cmdarg_stack;
1148
+ # TODO: port local_push_gen and local_pop_gen
1149
+ lexer.cmdarg.stack.replace [false]
1145
1150
  }
1146
1151
  f_arglist bodystmt kEND
1147
1152
  {
1148
- in_def = val[2]
1153
+ in_def, cmdarg = val[2]
1149
1154
 
1150
1155
  result = new_defn val
1151
1156
 
1157
+ lexer.cmdarg.stack.replace cmdarg
1152
1158
  self.env.unextend
1153
1159
  self.in_def = in_def
1154
1160
  self.lexer.comments # we don't care about comments in the body
@@ -1389,18 +1395,17 @@ opt_block_args_tail: tCOMMA block_args_tail
1389
1395
  result = args val
1390
1396
  }
1391
1397
 
1392
- opt_block_param: none
1398
+ opt_block_param: none { result = 0 }
1393
1399
  | block_param_def
1394
1400
 
1395
1401
  block_param_def: tPIPE opt_bv_decl tPIPE
1396
1402
  {
1397
1403
  result = args val
1398
- result = 0 if result == s(:args)
1399
1404
  }
1400
1405
  | tOROP
1401
1406
  {
1402
- result = 0
1403
1407
  self.lexer.command_start = true
1408
+ result = s(:args)
1404
1409
  }
1405
1410
  | tPIPE block_param opt_bv_decl tPIPE
1406
1411
  {
@@ -1441,8 +1446,6 @@ opt_block_args_tail: tCOMMA block_args_tail
1441
1446
  lpar, args, body = val
1442
1447
  lexer.lpar_beg = lpar
1443
1448
 
1444
- args = 0 if args == s(:args)
1445
-
1446
1449
  call = new_call nil, :lambda
1447
1450
  result = new_iter call, args, body
1448
1451
  self.env.unextend
@@ -1455,6 +1458,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1455
1458
  | f_args
1456
1459
  {
1457
1460
  result = val[0]
1461
+ result = 0 if result == s(:args)
1458
1462
  }
1459
1463
 
1460
1464
  lambda_body: tLAMBEG compstmt tRCURLY
@@ -1488,8 +1492,8 @@ opt_block_args_tail: tCOMMA block_args_tail
1488
1492
  block_call: command do_block
1489
1493
  {
1490
1494
  # TODO:
1491
- # if (nd_type($1) == NODE_YIELD) {
1492
- # compile_error(PARSER_ARG "block given to yield");
1495
+ ## if (nd_type($1) == NODE_YIELD) {
1496
+ ## compile_error(PARSER_ARG "block given to yield");
1493
1497
 
1494
1498
  syntax_error "Both block arg and actual block given." if
1495
1499
  val[0].block_pass?
@@ -1587,7 +1591,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1587
1591
  self.env.extend :dynamic
1588
1592
  result = self.lexer.lineno
1589
1593
  }
1590
- opt_block_param
1594
+ opt_block_param
1591
1595
  {
1592
1596
  result = nil # self.env.dynamic.keys
1593
1597
  }
@@ -1835,7 +1839,9 @@ regexp_contents: none
1835
1839
  lexer.brace_nest,
1836
1840
  lexer.string_nest, # TODO: remove
1837
1841
  lexer.cond.store,
1838
- lexer.cmdarg.store]
1842
+ lexer.cmdarg.store,
1843
+ lexer.lex_state,
1844
+ ]
1839
1845
 
1840
1846
  lexer.lex_strterm = nil
1841
1847
  lexer.brace_nest = 0
@@ -1848,7 +1854,7 @@ regexp_contents: none
1848
1854
  # TODO: tRCURLY -> tSTRING_DEND
1849
1855
  _, memo, stmt, _ = val
1850
1856
 
1851
- lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg = memo
1857
+ lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg, oldlex_state = memo
1852
1858
 
1853
1859
  lexer.lex_strterm = lex_strterm
1854
1860
  lexer.brace_nest = brace_nest
@@ -1857,6 +1863,8 @@ regexp_contents: none
1857
1863
  lexer.cond.restore oldcond
1858
1864
  lexer.cmdarg.restore oldcmdarg
1859
1865
 
1866
+ lexer.lex_state = oldlex_state
1867
+
1860
1868
  case stmt
1861
1869
  when Sexp then
1862
1870
  case stmt[0]
@@ -1990,9 +1998,13 @@ keyword_variable: kNIL { result = s(:nil) }
1990
1998
  result = val[1]
1991
1999
  self.lexer.lex_state = :expr_beg
1992
2000
  self.lexer.command_start = true
2001
+ # TODO:
2002
+ # $<num>$ = parser->parser_in_kwarg;
2003
+ # parser->parser_in_kwarg = 1;
1993
2004
  }
1994
2005
  | f_args term
1995
2006
  {
2007
+ # TODO: parser->parser_in_kwarg = $<num>1;
1996
2008
  result = val[0]
1997
2009
  self.lexer.lex_state = :expr_beg
1998
2010
  self.lexer.command_start = true
data/lib/ruby21_parser.rb CHANGED
@@ -2681,7 +2681,7 @@ racc_reduce_table = [
2681
2681
  2, 283, :_reduce_389,
2682
2682
  4, 283, :_reduce_390,
2683
2683
  1, 283, :_reduce_391,
2684
- 1, 186, :_reduce_none,
2684
+ 1, 186, :_reduce_392,
2685
2685
  1, 186, :_reduce_none,
2686
2686
  3, 287, :_reduce_394,
2687
2687
  1, 287, :_reduce_395,
@@ -3588,7 +3588,7 @@ def _reduce_28(val, _values, result)
3588
3588
  debug20 3
3589
3589
  yyerror "END in method; use at_exit"
3590
3590
  end
3591
- result = new_iter s(:postexe), nil, val[2]
3591
+ result = new_iter s(:postexe), 0, val[2]
3592
3592
 
3593
3593
  result
3594
3594
  end
@@ -5075,20 +5075,24 @@ def _reduce_325(val, _values, result)
5075
5075
  end
5076
5076
 
5077
5077
  def _reduce_326(val, _values, result)
5078
- result = self.in_def
5078
+ result = [self.in_def, self.lexer.cmdarg.stack.dup]
5079
5079
 
5080
5080
  self.comments.push self.lexer.comments
5081
5081
  self.in_def = true
5082
5082
  self.env.extend
5083
+ # TODO: local->cmdargs = cmdarg_stack;
5084
+ # TODO: port local_push_gen and local_pop_gen
5085
+ lexer.cmdarg.stack.replace [false]
5083
5086
 
5084
5087
  result
5085
5088
  end
5086
5089
 
5087
5090
  def _reduce_327(val, _values, result)
5088
- in_def = val[2]
5091
+ in_def, cmdarg = val[2]
5089
5092
 
5090
5093
  result = new_defn val
5091
5094
 
5095
+ lexer.cmdarg.stack.replace cmdarg
5092
5096
  self.env.unextend
5093
5097
  self.in_def = in_def
5094
5098
  self.lexer.comments # we don't care about comments in the body
@@ -5424,20 +5428,22 @@ def _reduce_391(val, _values, result)
5424
5428
  result
5425
5429
  end
5426
5430
 
5427
- # reduce 392 omitted
5431
+ def _reduce_392(val, _values, result)
5432
+ result = 0
5433
+ result
5434
+ end
5428
5435
 
5429
5436
  # reduce 393 omitted
5430
5437
 
5431
5438
  def _reduce_394(val, _values, result)
5432
5439
  result = args val
5433
- result = 0 if result == s(:args)
5434
5440
 
5435
5441
  result
5436
5442
  end
5437
5443
 
5438
5444
  def _reduce_395(val, _values, result)
5439
- result = 0
5440
5445
  self.lexer.command_start = true
5446
+ result = s(:args)
5441
5447
 
5442
5448
  result
5443
5449
  end
@@ -5491,8 +5497,6 @@ def _reduce_404(val, _values, result)
5491
5497
  lpar, args, body = val
5492
5498
  lexer.lpar_beg = lpar
5493
5499
 
5494
- args = 0 if args == s(:args)
5495
-
5496
5500
  call = new_call nil, :lambda
5497
5501
  result = new_iter call, args, body
5498
5502
  self.env.unextend
@@ -5508,6 +5512,7 @@ end
5508
5512
 
5509
5513
  def _reduce_406(val, _values, result)
5510
5514
  result = val[0]
5515
+ result = 0 if result == s(:args)
5511
5516
 
5512
5517
  result
5513
5518
  end
@@ -5550,8 +5555,8 @@ end
5550
5555
 
5551
5556
  def _reduce_412(val, _values, result)
5552
5557
  # TODO:
5553
- # if (nd_type($1) == NODE_YIELD) {
5554
- # compile_error(PARSER_ARG "block given to yield");
5558
+ ## if (nd_type($1) == NODE_YIELD) {
5559
+ ## compile_error(PARSER_ARG "block given to yield");
5555
5560
 
5556
5561
  syntax_error "Both block arg and actual block given." if
5557
5562
  val[0].block_pass?
@@ -6004,7 +6009,9 @@ def _reduce_483(val, _values, result)
6004
6009
  lexer.brace_nest,
6005
6010
  lexer.string_nest, # TODO: remove
6006
6011
  lexer.cond.store,
6007
- lexer.cmdarg.store]
6012
+ lexer.cmdarg.store,
6013
+ lexer.lex_state,
6014
+ ]
6008
6015
 
6009
6016
  lexer.lex_strterm = nil
6010
6017
  lexer.brace_nest = 0
@@ -6019,7 +6026,7 @@ def _reduce_484(val, _values, result)
6019
6026
  # TODO: tRCURLY -> tSTRING_END
6020
6027
  _, memo, stmt, _ = val
6021
6028
 
6022
- lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg = memo
6029
+ lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg, oldlex_state = memo
6023
6030
 
6024
6031
  lexer.lex_strterm = lex_strterm
6025
6032
  lexer.brace_nest = brace_nest
@@ -6028,6 +6035,8 @@ def _reduce_484(val, _values, result)
6028
6035
  lexer.cond.restore oldcond
6029
6036
  lexer.cmdarg.restore oldcmdarg
6030
6037
 
6038
+ lexer.lex_state = oldlex_state
6039
+
6031
6040
  case stmt
6032
6041
  when Sexp then
6033
6042
  case stmt[0]
@@ -6107,7 +6116,7 @@ end
6107
6116
  # reduce 496 omitted
6108
6117
 
6109
6118
  def _reduce_497(val, _values, result)
6110
- result = -val[1]
6119
+ result = -val[1] # TODO: pt_testcase
6111
6120
 
6112
6121
  result
6113
6122
  end
@@ -6238,11 +6247,15 @@ def _reduce_524(val, _values, result)
6238
6247
  result = val[1]
6239
6248
  self.lexer.lex_state = :expr_beg
6240
6249
  self.lexer.command_start = true
6250
+ # TODO:
6251
+ # $<num>$ = parser->parser_in_kwarg;
6252
+ # parser->parser_in_kwarg = 1;
6241
6253
 
6242
6254
  result
6243
6255
  end
6244
6256
 
6245
6257
  def _reduce_525(val, _values, result)
6258
+ # TODO: parser->parser_in_kwarg = $<num>1;
6246
6259
  result = val[0]
6247
6260
  self.lexer.lex_state = :expr_beg
6248
6261
  self.lexer.command_start = true
data/lib/ruby21_parser.y CHANGED
@@ -164,7 +164,7 @@ rule
164
164
  debug20 3
165
165
  yyerror "END in method; use at_exit"
166
166
  end
167
- result = new_iter s(:postexe), nil, val[2]
167
+ result = new_iter s(:postexe), 0, val[2]
168
168
  }
169
169
  | command_asgn
170
170
  | mlhs tEQL command_call
@@ -579,7 +579,7 @@ rule
579
579
  | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
580
580
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
581
581
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
582
- | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
582
+ | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
583
583
 
584
584
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
585
585
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -683,7 +683,7 @@ rule
683
683
  {
684
684
  result = new_call(new_call(s(:lit, val[1]), :"**", argl(val[3])), :"-@")
685
685
  }
686
- | tUPLUS arg
686
+ | tUPLUS arg
687
687
  {
688
688
  result = new_call val[1], :"+@"
689
689
  }
@@ -1138,18 +1138,22 @@ rule
1138
1138
  }
1139
1139
  | kDEF fname
1140
1140
  {
1141
- result = self.in_def
1141
+ result = [self.in_def, self.lexer.cmdarg.stack.dup]
1142
1142
 
1143
1143
  self.comments.push self.lexer.comments
1144
1144
  self.in_def = true
1145
1145
  self.env.extend
1146
+ # TODO: local->cmdargs = cmdarg_stack;
1147
+ # TODO: port local_push_gen and local_pop_gen
1148
+ lexer.cmdarg.stack.replace [false]
1146
1149
  }
1147
1150
  f_arglist bodystmt kEND
1148
1151
  {
1149
- in_def = val[2]
1152
+ in_def, cmdarg = val[2]
1150
1153
 
1151
1154
  result = new_defn val
1152
1155
 
1156
+ lexer.cmdarg.stack.replace cmdarg
1153
1157
  self.env.unextend
1154
1158
  self.in_def = in_def
1155
1159
  self.lexer.comments # we don't care about comments in the body
@@ -1390,18 +1394,17 @@ opt_block_args_tail: tCOMMA block_args_tail
1390
1394
  result = args val
1391
1395
  }
1392
1396
 
1393
- opt_block_param: none
1397
+ opt_block_param: none { result = 0 }
1394
1398
  | block_param_def
1395
1399
 
1396
1400
  block_param_def: tPIPE opt_bv_decl tPIPE
1397
1401
  {
1398
1402
  result = args val
1399
- result = 0 if result == s(:args)
1400
1403
  }
1401
1404
  | tOROP
1402
1405
  {
1403
- result = 0
1404
1406
  self.lexer.command_start = true
1407
+ result = s(:args)
1405
1408
  }
1406
1409
  | tPIPE block_param opt_bv_decl tPIPE
1407
1410
  {
@@ -1442,8 +1445,6 @@ opt_block_args_tail: tCOMMA block_args_tail
1442
1445
  lpar, args, body = val
1443
1446
  lexer.lpar_beg = lpar
1444
1447
 
1445
- args = 0 if args == s(:args)
1446
-
1447
1448
  call = new_call nil, :lambda
1448
1449
  result = new_iter call, args, body
1449
1450
  self.env.unextend
@@ -1456,6 +1457,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1456
1457
  | f_args
1457
1458
  {
1458
1459
  result = val[0]
1460
+ result = 0 if result == s(:args)
1459
1461
  }
1460
1462
 
1461
1463
  lambda_body: tLAMBEG compstmt tRCURLY
@@ -1489,8 +1491,8 @@ opt_block_args_tail: tCOMMA block_args_tail
1489
1491
  block_call: command do_block
1490
1492
  {
1491
1493
  # TODO:
1492
- # if (nd_type($1) == NODE_YIELD) {
1493
- # compile_error(PARSER_ARG "block given to yield");
1494
+ ## if (nd_type($1) == NODE_YIELD) {
1495
+ ## compile_error(PARSER_ARG "block given to yield");
1494
1496
 
1495
1497
  syntax_error "Both block arg and actual block given." if
1496
1498
  val[0].block_pass?
@@ -1588,7 +1590,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1588
1590
  self.env.extend :dynamic
1589
1591
  result = self.lexer.lineno
1590
1592
  }
1591
- opt_block_param
1593
+ opt_block_param
1592
1594
  {
1593
1595
  result = nil # self.env.dynamic.keys
1594
1596
  }
@@ -1836,7 +1838,9 @@ regexp_contents: none
1836
1838
  lexer.brace_nest,
1837
1839
  lexer.string_nest, # TODO: remove
1838
1840
  lexer.cond.store,
1839
- lexer.cmdarg.store]
1841
+ lexer.cmdarg.store,
1842
+ lexer.lex_state,
1843
+ ]
1840
1844
 
1841
1845
  lexer.lex_strterm = nil
1842
1846
  lexer.brace_nest = 0
@@ -1849,7 +1853,7 @@ regexp_contents: none
1849
1853
  # TODO: tRCURLY -> tSTRING_END
1850
1854
  _, memo, stmt, _ = val
1851
1855
 
1852
- lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg = memo
1856
+ lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg, oldlex_state = memo
1853
1857
 
1854
1858
  lexer.lex_strterm = lex_strterm
1855
1859
  lexer.brace_nest = brace_nest
@@ -1858,6 +1862,8 @@ regexp_contents: none
1858
1862
  lexer.cond.restore oldcond
1859
1863
  lexer.cmdarg.restore oldcmdarg
1860
1864
 
1865
+ lexer.lex_state = oldlex_state
1866
+
1861
1867
  case stmt
1862
1868
  when Sexp then
1863
1869
  case stmt[0]
@@ -1913,7 +1919,7 @@ regexp_contents: none
1913
1919
  numeric: simple_numeric
1914
1920
  | tUMINUS_NUM simple_numeric
1915
1921
  {
1916
- result = -val[1]
1922
+ result = -val[1] # TODO: pt_testcase
1917
1923
  }
1918
1924
 
1919
1925
  simple_numeric: tINTEGER
@@ -1991,9 +1997,13 @@ keyword_variable: kNIL { result = s(:nil) }
1991
1997
  result = val[1]
1992
1998
  self.lexer.lex_state = :expr_beg
1993
1999
  self.lexer.command_start = true
2000
+ # TODO:
2001
+ # $<num>$ = parser->parser_in_kwarg;
2002
+ # parser->parser_in_kwarg = 1;
1994
2003
  }
1995
2004
  | f_args term
1996
2005
  {
2006
+ # TODO: parser->parser_in_kwarg = $<num>1;
1997
2007
  result = val[0]
1998
2008
  self.lexer.lex_state = :expr_beg
1999
2009
  self.lexer.command_start = true