ruby_parser 3.16.0 → 3.17.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ruby30_parser.y CHANGED
@@ -1009,6 +1009,24 @@ rule
1009
1009
  _, args, _ = val
1010
1010
  result = args
1011
1011
  }
1012
+ | tLPAREN2 args tCOMMA args_forward rparen
1013
+ {
1014
+ yyerror "Unexpected ..." unless
1015
+ self.lexer.is_local_id(:"*") &&
1016
+ self.lexer.is_local_id(:"**") &&
1017
+ self.lexer.is_local_id(:"&")
1018
+
1019
+ result = call_args val
1020
+ }
1021
+ | tLPAREN2 args_forward rparen
1022
+ {
1023
+ yyerror "Unexpected ..." unless
1024
+ self.lexer.is_local_id(:"*") &&
1025
+ self.lexer.is_local_id(:"**") &&
1026
+ self.lexer.is_local_id(:"&")
1027
+
1028
+ result = call_args val
1029
+ }
1012
1030
 
1013
1031
  opt_paren_args: none
1014
1032
  | paren_args
@@ -2286,6 +2304,20 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2286
2304
  f_arglist: tLPAREN2 f_args rparen
2287
2305
  {
2288
2306
  result = val[1]
2307
+ self.lexer.lex_state = EXPR_BEG
2308
+ self.lexer.command_start = true
2309
+ }
2310
+ | tLPAREN2 f_arg tCOMMA args_forward rparen
2311
+ {
2312
+ result = args val
2313
+
2314
+ self.lexer.lex_state = EXPR_BEG
2315
+ self.lexer.command_start = true
2316
+ }
2317
+ | tLPAREN2 args_forward rparen
2318
+ {
2319
+ result = args val
2320
+
2289
2321
  self.lexer.lex_state = EXPR_BEG
2290
2322
  self.lexer.command_start = true
2291
2323
  }
@@ -2388,6 +2420,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2388
2420
  result = args val
2389
2421
  }
2390
2422
 
2423
+ args_forward: tBDOT3
2424
+ {
2425
+ result = s(:forward_args).line lexer.lineno
2426
+ }
2427
+
2391
2428
  f_bad_arg: tCONSTANT
2392
2429
  {
2393
2430
  yyerror "formal argument cannot be a constant"
@@ -2516,6 +2553,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2516
2553
  | kwrest_mark
2517
2554
  {
2518
2555
  result = :"**"
2556
+ self.env[result] = :lvar
2519
2557
  }
2520
2558
 
2521
2559
  f_opt: f_arg_asgn tEQL arg_value
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  #--
3
3
  # This file is automatically generated. Do not modify it.
4
- # Generated by: oedipus_lex version 2.5.2.
4
+ # Generated by: oedipus_lex version 2.5.3.
5
5
  # Source: lib/ruby_lexer.rex
6
6
  #++
7
7
 
data/lib/ruby_parser.yy CHANGED
@@ -1066,6 +1066,26 @@ rule
1066
1066
  _, args, _ = val
1067
1067
  result = args
1068
1068
  }
1069
+ #if V >= 27
1070
+ | tLPAREN2 args tCOMMA args_forward rparen
1071
+ {
1072
+ yyerror "Unexpected ..." unless
1073
+ self.lexer.is_local_id(:"*") &&
1074
+ self.lexer.is_local_id(:"**") &&
1075
+ self.lexer.is_local_id(:"&")
1076
+
1077
+ result = call_args val
1078
+ }
1079
+ | tLPAREN2 args_forward rparen
1080
+ {
1081
+ yyerror "Unexpected ..." unless
1082
+ self.lexer.is_local_id(:"*") &&
1083
+ self.lexer.is_local_id(:"**") &&
1084
+ self.lexer.is_local_id(:"&")
1085
+
1086
+ result = call_args val
1087
+ }
1088
+ #endif
1069
1089
 
1070
1090
  opt_paren_args: none
1071
1091
  | paren_args
@@ -2366,6 +2386,22 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2366
2386
  self.lexer.lex_state = EXPR_BEG
2367
2387
  self.lexer.command_start = true
2368
2388
  }
2389
+ #if V >= 27
2390
+ | tLPAREN2 f_arg tCOMMA args_forward rparen
2391
+ {
2392
+ result = args val
2393
+
2394
+ self.lexer.lex_state = EXPR_BEG
2395
+ self.lexer.command_start = true
2396
+ }
2397
+ | tLPAREN2 args_forward rparen
2398
+ {
2399
+ result = args val
2400
+
2401
+ self.lexer.lex_state = EXPR_BEG
2402
+ self.lexer.command_start = true
2403
+ }
2404
+ #endif
2369
2405
  | {
2370
2406
  result = self.in_kwarg
2371
2407
  self.in_kwarg = true
@@ -2465,6 +2501,13 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2465
2501
  result = args val
2466
2502
  }
2467
2503
 
2504
+ #if V >= 27
2505
+ args_forward: tBDOT3
2506
+ {
2507
+ result = s(:forward_args).line lexer.lineno
2508
+ }
2509
+ #endif
2510
+
2468
2511
  f_bad_arg: tCONSTANT
2469
2512
  {
2470
2513
  yyerror "formal argument cannot be a constant"
@@ -2613,6 +2656,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2613
2656
  | kwrest_mark
2614
2657
  {
2615
2658
  result = :"**"
2659
+ self.env[result] = :lvar
2616
2660
  }
2617
2661
 
2618
2662
  #if V == 20
@@ -160,6 +160,12 @@ module RubyParserStuff
160
160
  case arg.sexp_type
161
161
  when :args, :block, :array, :call_args then # HACK call_args mismatch
162
162
  result.concat arg.sexp_body
163
+ when :forward_args then
164
+ self.env[:*] = :lvar # TODO: arg_var(p, idFWD_REST) ?
165
+ self.env[:**] = :lvar
166
+ self.env[:&] = :lvar
167
+
168
+ result << arg
163
169
  when :block_arg then
164
170
  result << :"&#{arg.last}"
165
171
  when :shadow then
@@ -311,7 +317,7 @@ module RubyParserStuff
311
317
  end
312
318
  when Symbol then
313
319
  result << arg
314
- when ",", nil then
320
+ when ",", nil, "(" then
315
321
  # ignore
316
322
  else
317
323
  raise "unhandled: #{arg.inspect} in #{args.inspect}"
@@ -4138,6 +4138,43 @@ end
4138
4138
 
4139
4139
  module TestRubyParserShared27Plus
4140
4140
  include TestRubyParserShared26Plus
4141
+
4142
+ def test_defn_forward_args
4143
+ rb = "def a(...); b(...); end"
4144
+ pt = s(:defn, :a, s(:args, s(:forward_args)),
4145
+ s(:call, nil, :b, s(:forward_args)))
4146
+
4147
+ assert_parse_line rb, pt, 1
4148
+ end
4149
+
4150
+ def test_defn_arg_forward_args
4151
+ rb = "def a(x, ...); b(x, ...); end"
4152
+ pt = s(:defn, :a, s(:args, :x, s(:forward_args)),
4153
+ s(:call, nil, :b, s(:lvar, :x), s(:forward_args)))
4154
+
4155
+ assert_parse_line rb, pt, 1
4156
+ end
4157
+
4158
+ def test_defn_args_forward_args
4159
+ rb = "def a(x, y, z, ...); b(:get, z, ...); end"
4160
+ pt = s(:defn, :a, s(:args, :x, :y, :z, s(:forward_args)),
4161
+ s(:call, nil, :b, s(:lit, :get), s(:lvar, :z),
4162
+ s(:forward_args)))
4163
+
4164
+ assert_parse_line rb, pt, 1
4165
+ end
4166
+
4167
+ def test_call_forward_args_outside_method_definition
4168
+ rb = "b(...)"
4169
+
4170
+ assert_syntax_error rb, "Unexpected ..."
4171
+ end
4172
+
4173
+ def test_call_arg_forward_args_outside_method_definition
4174
+ rb = "b(x, ...)"
4175
+
4176
+ assert_syntax_error rb, "Unexpected ..."
4177
+ end
4141
4178
  end
4142
4179
 
4143
4180
  module TestRubyParserShared30Plus
@@ -4437,7 +4474,6 @@ class TestRubyParserV26 < RubyParserTestCase
4437
4474
 
4438
4475
  assert_parse_line rb, pt, 1
4439
4476
  end
4440
-
4441
4477
  end
4442
4478
 
4443
4479
  class TestRubyParserV27 < RubyParserTestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.16.0
4
+ version: 3.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  d/AHw/kcnU6iuMUoJEcGiJd4gVCTn1l3cDcIvxakGslCA88Jubw0Sqatan0TnC9g
30
30
  KToW560QIey7SPfHWduzFJnV
31
31
  -----END CERTIFICATE-----
32
- date: 2021-05-15 00:00:00.000000000 Z
32
+ date: 2021-08-04 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
metadata.gz.sig CHANGED
Binary file