ruby_parser 3.20.0 → 3.20.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ruby20_parser.y CHANGED
@@ -219,6 +219,7 @@ rule
219
219
  | lhs tEQL mrhs
220
220
  {
221
221
  lhs, _, rhs = val
222
+
222
223
  result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
223
224
  }
224
225
  | mlhs tEQL arg_value
@@ -984,8 +985,10 @@ rule
984
985
 
985
986
  paren_args: tLPAREN2 opt_call_args rparen
986
987
  {
987
- _, args, _ = val
988
+ _, args, (_, line_max) = val
989
+
988
990
  result = args
991
+ result.line_max = line_max if args
989
992
  }
990
993
 
991
994
  opt_paren_args: none
@@ -1136,7 +1139,6 @@ rule
1136
1139
  | k_begin
1137
1140
  {
1138
1141
  lexer.cmdarg.push false
1139
- result = self.lexer.lineno
1140
1142
  }
1141
1143
  bodystmt k_end
1142
1144
  {
@@ -1181,12 +1183,14 @@ rule
1181
1183
  {
1182
1184
  result = wrap :colon3, val[1]
1183
1185
  }
1184
- | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1186
+ | tLBRACK { result = lexer.lineno } aref_args rbracket
1185
1187
  {
1186
- _, line, args, _ = val
1188
+ _, line, args, (_, line_max) = val
1189
+
1187
1190
  result = args || s(:array)
1188
1191
  result.sexp_type = :array # aref_args is :args
1189
1192
  result.line line
1193
+ result.line_max = line_max
1190
1194
  }
1191
1195
  | tLBRACE
1192
1196
  {
@@ -1291,9 +1295,6 @@ rule
1291
1295
  result = new_for iter, var, body
1292
1296
  }
1293
1297
  | k_class
1294
- {
1295
- result = self.lexer.lineno
1296
- }
1297
1298
  cpath superclass
1298
1299
  {
1299
1300
  if (self.in_def || self.in_single > 0) then
@@ -1308,9 +1309,6 @@ rule
1308
1309
  self.lexer.ignore_body_comments
1309
1310
  }
1310
1311
  | k_class tLSHFT
1311
- {
1312
- result = self.lexer.lineno
1313
- }
1314
1312
  expr
1315
1313
  {
1316
1314
  result = self.in_def
@@ -1329,9 +1327,6 @@ rule
1329
1327
  self.lexer.ignore_body_comments
1330
1328
  }
1331
1329
  | k_module
1332
- {
1333
- result = self.lexer.lineno
1334
- }
1335
1330
  cpath
1336
1331
  {
1337
1332
  yyerror "module definition in method body" if
@@ -1774,13 +1769,19 @@ opt_block_args_tail: tCOMMA block_args_tail
1774
1769
  {
1775
1770
  call, args = val
1776
1771
 
1777
- result = call.concat args.sexp_body if args
1772
+ result = call
1773
+
1774
+ if args then
1775
+ call.concat args.sexp_body
1776
+ result.line_max = args.line_max
1777
+ end
1778
1778
  }
1779
1779
  | primary_value call_op operation2 opt_paren_args
1780
1780
  {
1781
- recv, call_op, (op, _line), args = val
1781
+ recv, call_op, (op, op_line), args = val
1782
1782
 
1783
1783
  result = new_call recv, op.to_sym, args, call_op
1784
+ result.line_max = op_line unless args
1784
1785
  }
1785
1786
  | primary_value tCOLON2 operation2 paren_args
1786
1787
  {
@@ -1994,15 +1995,17 @@ opt_block_args_tail: tCOMMA block_args_tail
1994
1995
 
1995
1996
  words: tWORDS_BEG tSPACE tSTRING_END
1996
1997
  {
1997
- (_, line), _, _ = val
1998
+ (_, line), _, (_, line_max) = val
1998
1999
 
1999
2000
  result = s(:array).line line
2001
+ result.line_max = line_max
2000
2002
  }
2001
2003
  | tWORDS_BEG word_list tSTRING_END
2002
2004
  {
2003
- (_, line), list, _ = val
2005
+ (_, line), list, (_, line_max) = val
2004
2006
 
2005
2007
  result = list.line line
2008
+ result.line_max = line_max
2006
2009
  }
2007
2010
 
2008
2011
  word_list: none
@@ -2022,15 +2025,17 @@ opt_block_args_tail: tCOMMA block_args_tail
2022
2025
 
2023
2026
  symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2024
2027
  {
2025
- (_, line), _, _ = val
2028
+ (_, line), _, (_, line_max) = val
2026
2029
 
2027
2030
  result = s(:array).line line
2031
+ result.line_max = line_max
2028
2032
  }
2029
2033
  | tSYMBOLS_BEG symbol_list tSTRING_END
2030
2034
  {
2031
- (_, line), list, _, = val
2032
- list.line line
2033
- result = list
2035
+ (_, line), list, (_, line_max), = val
2036
+
2037
+ result = list.line line
2038
+ result.line_max = line_max
2034
2039
  }
2035
2040
 
2036
2041
  symbol_list: none
@@ -2045,28 +2050,32 @@ opt_block_args_tail: tCOMMA block_args_tail
2045
2050
 
2046
2051
  qwords: tQWORDS_BEG tSPACE tSTRING_END
2047
2052
  {
2048
- (_, line), _, _ = val
2053
+ (_, line), _, (_, line_max) = val
2049
2054
 
2050
2055
  result = s(:array).line line
2056
+ result.line_max = line_max
2051
2057
  }
2052
2058
  | tQWORDS_BEG qword_list tSTRING_END
2053
2059
  {
2054
- (_, line), list, _ = val
2060
+ (_, line), list, (_, line_max) = val
2055
2061
 
2056
2062
  result = list.line line
2063
+ result.line_max = line_max
2057
2064
  }
2058
2065
 
2059
2066
  qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2060
2067
  {
2061
- (_, line), _, _ = val
2068
+ (_, line), _, (_, line_max) = val
2062
2069
 
2063
2070
  result = s(:array).line line
2071
+ result.line_max = line_max
2064
2072
  }
2065
2073
  | tQSYMBOLS_BEG qsym_list tSTRING_END
2066
2074
  {
2067
- (_, line), list, _ = val
2075
+ (_, line), list, (_, line_max) = val
2068
2076
 
2069
2077
  result = list.line line
2078
+ result.line_max = line_max
2070
2079
  }
2071
2080
 
2072
2081
  qword_list: none
@@ -2469,7 +2478,14 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2469
2478
  result = s(:args, list).line list.line
2470
2479
  end
2471
2480
 
2472
- result << (Sexp === item ? item : item.first)
2481
+ if Sexp === item then
2482
+ line_max = item.line_max
2483
+ else
2484
+ item, line_max = item
2485
+ end
2486
+
2487
+ result << item
2488
+ result.line_max = line_max
2473
2489
  }
2474
2490
 
2475
2491
  f_kw: tLABEL arg_value
@@ -2658,7 +2674,15 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2658
2674
  opt_terms: | terms
2659
2675
  opt_nl: | tNL
2660
2676
  rparen: opt_nl tRPAREN
2677
+ {
2678
+ _, close = val
2679
+ result = [close, lexer.lineno]
2680
+ }
2661
2681
  rbracket: opt_nl tRBRACK
2682
+ {
2683
+ _, close = val
2684
+ result = [close, lexer.lineno]
2685
+ }
2662
2686
  trailer: | tNL | tCOMMA
2663
2687
 
2664
2688
  term: tSEMI { yyerrok }