brakeman 5.0.2 → 5.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +46 -1
  3. data/README.md +1 -1
  4. data/bundle/load.rb +5 -5
  5. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/CHANGELOG.md +8 -0
  6. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/FAQ.md +0 -0
  7. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/Gemfile +0 -0
  8. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/MIT-LICENSE +0 -0
  9. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/README.md +19 -13
  10. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/REFERENCE.md +10 -3
  11. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/TODO +0 -0
  12. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/haml.gemspec +0 -0
  13. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/attribute_builder.rb +55 -0
  14. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/attribute_compiler.rb +4 -2
  15. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/attribute_parser.rb +0 -0
  16. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/buffer.rb +0 -56
  17. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/compiler.rb +0 -0
  18. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/engine.rb +0 -0
  19. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/error.rb +0 -0
  20. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/escapable.rb +0 -0
  21. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/exec.rb +0 -0
  22. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/filters.rb +0 -0
  23. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/generator.rb +0 -0
  24. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/action_view_extensions.rb +0 -0
  25. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/action_view_mods.rb +0 -0
  26. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/action_view_xss_mods.rb +0 -0
  27. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/safe_erubi_template.rb +0 -0
  28. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/safe_erubis_template.rb +0 -0
  29. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/xss_mods.rb +0 -0
  30. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers.rb +0 -0
  31. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/options.rb +0 -0
  32. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/parser.rb +0 -0
  33. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/plugin.rb +18 -1
  34. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/railtie.rb +5 -0
  35. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/sass_rails_filter.rb +0 -0
  36. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/template/options.rb +0 -0
  37. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/template.rb +0 -0
  38. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/temple_engine.rb +2 -1
  39. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/temple_line_counter.rb +0 -0
  40. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/util.rb +0 -0
  41. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/version.rb +1 -1
  42. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml.rb +0 -0
  43. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/yard/default/fulldoc/html/css/common.sass +0 -0
  44. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/yard/default/layout/html/footer.erb +0 -0
  45. data/bundle/ruby/2.7.0/gems/{parallel-1.20.1 → parallel-1.21.0}/MIT-LICENSE.txt +0 -0
  46. data/bundle/ruby/2.7.0/gems/parallel-1.21.0/lib/parallel/processor_count.rb +45 -0
  47. data/bundle/ruby/2.7.0/gems/parallel-1.21.0/lib/parallel/version.rb +4 -0
  48. data/bundle/ruby/2.7.0/gems/{parallel-1.20.1 → parallel-1.21.0}/lib/parallel.rb +52 -43
  49. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/History.rdoc +76 -0
  50. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/Manifest.txt +3 -0
  51. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/README.rdoc +1 -0
  52. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/compare/normalize.rb +6 -1
  53. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/debugging.md +0 -0
  54. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/gauntlet.md +106 -0
  55. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/rp_extensions.rb +15 -36
  56. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/rp_stringscanner.rb +33 -0
  57. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby20_parser.rb +7122 -0
  58. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/ruby20_parser.y +327 -247
  59. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby21_parser.rb +7176 -0
  60. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/ruby21_parser.y +322 -244
  61. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby22_parser.rb +7222 -0
  62. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby22_parser.y +2718 -0
  63. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby23_parser.rb +7231 -0
  64. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0/lib/ruby26_parser.y → ruby_parser-3.18.0/lib/ruby23_parser.y} +328 -271
  65. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby24_parser.rb +7262 -0
  66. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/ruby24_parser.y +326 -246
  67. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby25_parser.rb +7262 -0
  68. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0/lib/ruby30_parser.y → ruby_parser-3.18.0/lib/ruby25_parser.y} +327 -276
  69. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby26_parser.rb +7281 -0
  70. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0/lib/ruby27_parser.y → ruby_parser-3.18.0/lib/ruby26_parser.y} +326 -260
  71. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby27_parser.rb +8511 -0
  72. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0/lib/ruby_parser.yy → ruby_parser-3.18.0/lib/ruby27_parser.y} +905 -355
  73. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby30_parser.rb +8741 -0
  74. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby30_parser.y +3463 -0
  75. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby3_parser.yy +3467 -0
  76. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/ruby_lexer.rb +261 -609
  77. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/ruby_lexer.rex +27 -20
  78. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/ruby_lexer.rex.rb +59 -23
  79. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby_lexer_strings.rb +638 -0
  80. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/ruby_parser.rb +0 -0
  81. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.0/lib/ruby_parser.yy +3481 -0
  82. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/lib/ruby_parser_extras.rb +296 -115
  83. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/tools/munge.rb +34 -6
  84. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.0}/tools/ripper.rb +15 -10
  85. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/History.rdoc +15 -0
  86. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/Manifest.txt +0 -0
  87. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/README.rdoc +0 -0
  88. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/composite_sexp_processor.rb +0 -0
  89. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/pt_testcase.rb +7 -2
  90. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/sexp.rb +19 -9
  91. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/sexp_matcher.rb +0 -0
  92. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/sexp_processor.rb +1 -1
  93. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/strict_sexp.rb +25 -3
  94. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/unique.rb +0 -0
  95. data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/CHANGELOG.md +4 -0
  96. data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/MIT-LICENSE.txt +0 -0
  97. data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/README.md +1 -1
  98. data/bundle/ruby/2.7.0/gems/unicode-display_width-1.8.0/data/display_width.marshal.gz +0 -0
  99. data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/lib/unicode/display_width/constants.rb +2 -2
  100. data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/lib/unicode/display_width/index.rb +0 -0
  101. data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/lib/unicode/display_width/no_string_ext.rb +0 -0
  102. data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/lib/unicode/display_width/string_ext.rb +0 -0
  103. data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/lib/unicode/display_width.rb +0 -0
  104. data/lib/brakeman/app_tree.rb +1 -1
  105. data/lib/brakeman/checks/check_execute.rb +10 -0
  106. data/lib/brakeman/checks/check_json_parsing.rb +1 -1
  107. data/lib/brakeman/checks/check_render.rb +15 -1
  108. data/lib/brakeman/checks/check_sql.rb +45 -8
  109. data/lib/brakeman/file_parser.rb +10 -2
  110. data/lib/brakeman/options.rb +6 -1
  111. data/lib/brakeman/processors/alias_processor.rb +41 -4
  112. data/lib/brakeman/processors/haml_template_processor.rb +9 -0
  113. data/lib/brakeman/processors/lib/call_conversion_helper.rb +2 -6
  114. data/lib/brakeman/processors/model_processor.rb +32 -0
  115. data/lib/brakeman/report/ignore/config.rb +1 -1
  116. data/lib/brakeman/report/report_csv.rb +1 -1
  117. data/lib/brakeman/report/report_sarif.rb +22 -3
  118. data/lib/brakeman/report/report_text.rb +1 -1
  119. data/lib/brakeman/rescanner.rb +1 -1
  120. data/lib/brakeman/scanner.rb +13 -13
  121. data/lib/brakeman/tracker/collection.rb +30 -2
  122. data/lib/brakeman/tracker/method_info.rb +41 -0
  123. data/lib/brakeman/util.rb +26 -18
  124. data/lib/brakeman/version.rb +1 -1
  125. data/lib/brakeman.rb +4 -2
  126. data/lib/ruby_parser/bm_sexp.rb +24 -0
  127. metadata +101 -98
  128. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/processor_count.rb +0 -42
  129. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/version.rb +0 -3
  130. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/rp_stringscanner.rb +0 -64
  131. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby20_parser.rb +0 -7070
  132. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby21_parser.rb +0 -7143
  133. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby22_parser.rb +0 -7180
  134. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby22_parser.y +0 -2638
  135. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.rb +0 -7194
  136. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.y +0 -2640
  137. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby24_parser.rb +0 -7214
  138. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.rb +0 -7213
  139. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.y +0 -2648
  140. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby26_parser.rb +0 -7235
  141. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby27_parser.rb +0 -7310
  142. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.rb +0 -7310
  143. data/bundle/ruby/2.7.0/gems/unicode-display_width-1.7.0/data/display_width.marshal.gz +0 -0
@@ -1,6 +1,6 @@
1
1
  # -*- racc -*-
2
2
 
3
- class Ruby26Parser
3
+ class Ruby23Parser
4
4
 
5
5
  token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
6
6
  kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
@@ -18,11 +18,10 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
18
18
  tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
19
19
  tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END
20
20
  tSTRING tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA
21
- tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND tUBANG
21
+ tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND
22
22
  tRATIONAL tIMAGINARY
23
23
  tLABEL_END
24
24
  tLONELY
25
- tBDOT2 tBDOT3
26
25
 
27
26
  preclow
28
27
  nonassoc tLOWEST
@@ -80,7 +79,7 @@ rule
80
79
  | klBEGIN
81
80
  {
82
81
  if (self.in_def || self.in_single > 0) then
83
- debug20 1
82
+ debug 11
84
83
  yyerror "BEGIN in method"
85
84
  end
86
85
  self.env.extend
@@ -105,7 +104,9 @@ rule
105
104
  bodystmt: compstmt opt_rescue k_else
106
105
  {
107
106
  res = _values[-2]
108
- yyerror "else without rescue is useless" unless res
107
+ # TODO: move down to main match so I can just use val
108
+
109
+ warn "else without rescue is useless" unless res
109
110
  }
110
111
  compstmt
111
112
  opt_ensure
@@ -135,7 +136,7 @@ rule
135
136
  | error stmt
136
137
  {
137
138
  result = val[1]
138
- debug20 2, val, result
139
+ debug 12
139
140
  }
140
141
 
141
142
  stmt_or_begin: stmt
@@ -143,6 +144,10 @@ rule
143
144
  {
144
145
  yyerror "BEGIN is permitted only at toplevel"
145
146
  }
147
+ begin_block
148
+ {
149
+ result = val[2] # wtf?
150
+ }
146
151
 
147
152
  stmt: kALIAS fitem
148
153
  {
@@ -155,12 +160,12 @@ rule
155
160
  }
156
161
  | kALIAS tGVAR tGVAR
157
162
  {
158
- (_, line), lhs, rhs = val
163
+ (_, line), (lhs, _), (rhs, _) = val
159
164
  result = s(:valias, lhs.to_sym, rhs.to_sym).line line
160
165
  }
161
166
  | kALIAS tGVAR tBACK_REF
162
167
  {
163
- (_, line), lhs, rhs = val
168
+ (_, line), (lhs, _), (rhs, _) = val
164
169
  result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
165
170
  }
166
171
  | kALIAS tGVAR tNTH_REF
@@ -203,7 +208,7 @@ rule
203
208
  (_, line), _, stmt, _ = val
204
209
 
205
210
  if (self.in_def || self.in_single > 0) then
206
- debug20 3
211
+ debug 13
207
212
  yyerror "END in method; use at_exit"
208
213
  end
209
214
 
@@ -243,32 +248,31 @@ rule
243
248
  }
244
249
  | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
245
250
  {
246
- prim, _, id, opasgn, rhs = val
247
- result = s(:op_asgn, prim, rhs, id.to_sym, opasgn.to_sym)
248
- if val[1] == '&.'
249
- result.sexp_type = :safe_op_asgn
250
- end
251
- result.line = val[0].line
251
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
252
+
253
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
254
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
255
+ result.line prim.line
252
256
  }
253
257
  | primary_value call_op tCONSTANT tOP_ASGN command_rhs
254
258
  {
255
- result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
256
- if val[1] == '&.'
257
- result.sexp_type = :safe_op_asgn
258
- end
259
- result.line = val[0].line
259
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
260
+
261
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
262
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
263
+ result.line prim.line
260
264
  }
261
265
  | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
262
266
  {
263
- lhs1, _, lhs2, op, rhs = val
267
+ lhs1, _, (lhs2, line), (id, _), rhs = val
264
268
 
265
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
269
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
266
270
  }
267
271
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
268
272
  {
269
- lhs1, _, lhs2, op, rhs = val
273
+ lhs1, _, (lhs2, line), (id, _), rhs = val
270
274
 
271
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
275
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
272
276
  }
273
277
  | backref tOP_ASGN command_rhs
274
278
  {
@@ -280,14 +284,6 @@ rule
280
284
  expr, = val
281
285
  result = value_expr expr
282
286
  }
283
- | command_call kRESCUE_MOD stmt
284
- {
285
- expr, (_, line), resbody = val
286
-
287
- expr = value_expr expr
288
- ary = s(:array).line line
289
- result = new_rescue(expr, new_resbody(ary, resbody))
290
- }
291
287
  | command_asgn
292
288
 
293
289
  expr: command_call
@@ -314,7 +310,7 @@ rule
314
310
  # TODO: fix line number to tBANG... but causes BAD shift/reduce conflict
315
311
  # REFACTOR: call_uni_op -- see parse26.y
316
312
  }
317
- | arg
313
+ | arg =tLBRACE_ARG
318
314
 
319
315
  expr_value: expr
320
316
  {
@@ -339,7 +335,7 @@ rule
339
335
  block_command: block_call
340
336
  | block_call call_op2 operation2 command_args
341
337
  {
342
- blk, _, msg, args = val
338
+ blk, _, (msg, _line), args = val
343
339
  result = new_call(blk, msg.to_sym, args).line blk.line
344
340
  }
345
341
 
@@ -353,15 +349,15 @@ rule
353
349
  _, line, body, _ = val
354
350
 
355
351
  result = body
356
- result.line = line
352
+ result.line line
357
353
 
358
354
  # self.env.unextend
359
355
  }
360
356
 
361
357
  fcall: operation
362
358
  {
363
- msg, = val
364
- result = new_call(nil, msg.to_sym).line lexer.lineno
359
+ (msg, line), = val
360
+ result = new_call(nil, msg.to_sym).line line
365
361
  }
366
362
 
367
363
  command: fcall command_args =tLOWEST
@@ -384,12 +380,14 @@ rule
384
380
  }
385
381
  | primary_value call_op operation2 command_args =tLOWEST
386
382
  {
387
- lhs, callop, op, args = val
383
+ lhs, callop, (op, _), args = val
384
+
388
385
  result = new_call lhs, op.to_sym, args, callop
386
+ result.line lhs.line
389
387
  }
390
388
  | primary_value call_op operation2 command_args cmd_brace_block
391
389
  {
392
- recv, _, msg, args, block = val
390
+ recv, _, (msg, _line), args, block = val
393
391
  call = new_call recv, msg.to_sym, args, val[1]
394
392
 
395
393
  block_dup_check call, block
@@ -399,11 +397,14 @@ rule
399
397
  }
400
398
  | primary_value tCOLON2 operation2 command_args =tLOWEST
401
399
  {
402
- result = new_call val[0], val[2].to_sym, val[3]
400
+ lhs, _, (id, line), args = val
401
+
402
+ result = new_call lhs, id.to_sym, args
403
+ result.line line
403
404
  }
404
405
  | primary_value tCOLON2 operation2 command_args cmd_brace_block
405
406
  {
406
- recv, _, msg, args, block = val
407
+ recv, _, (msg, _line), args, block = val
407
408
  call = new_call recv, msg.to_sym, args
408
409
 
409
410
  block_dup_check call, block
@@ -561,25 +562,29 @@ rule
561
562
  }
562
563
  | primary_value call_op tIDENTIFIER
563
564
  {
564
- result = new_attrasgn val[0], val[2], val[1]
565
+ lhs, call_op, (id, _line) = val
566
+
567
+ result = new_attrasgn lhs, id, call_op
565
568
  }
566
569
  | primary_value tCOLON2 tIDENTIFIER
567
570
  {
568
- recv, _, id = val
571
+ recv, _, (id, _line) = val
569
572
  result = new_attrasgn recv, id
570
573
  }
571
574
  | primary_value call_op tCONSTANT
572
575
  {
573
- result = new_attrasgn val[0], val[2], val[1]
576
+ lhs, call_op, (id, _line) = val
577
+
578
+ result = new_attrasgn lhs, id, call_op
574
579
  }
575
580
  | primary_value tCOLON2 tCONSTANT
576
581
  {
577
582
  if (self.in_def || self.in_single > 0) then
578
- debug20 7
583
+ debug 14
579
584
  yyerror "dynamic constant assignment"
580
585
  end
581
586
 
582
- expr, _, id = val
587
+ expr, _, (id, _line) = val
583
588
  l = expr.line
584
589
 
585
590
  result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
@@ -587,58 +592,65 @@ rule
587
592
  | tCOLON3 tCONSTANT
588
593
  {
589
594
  if (self.in_def || self.in_single > 0) then
590
- debug20 8
595
+ debug 15
591
596
  yyerror "dynamic constant assignment"
592
597
  end
593
598
 
594
- _, id = val
595
- l = lexer.lineno
599
+ _, (id, l) = val
596
600
 
597
601
  result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
598
602
  }
599
603
  | backref
600
604
  {
601
- self.backref_assign_error val[0]
605
+ ref, = val
606
+
607
+ self.backref_assign_error ref
602
608
  }
603
609
 
604
610
  lhs: user_variable
605
611
  {
606
- line = lexer.lineno
607
- result = self.assignable val[0]
608
- result.line = line
612
+ var, = val
613
+
614
+ result = self.assignable var
609
615
  }
610
616
  | keyword_variable
611
617
  {
612
- line = lexer.lineno
613
- result = self.assignable val[0]
614
- result.line = line
615
- debug20 9, val, result
618
+ var, = val
619
+
620
+ result = self.assignable var
621
+
622
+ debug 16
616
623
  }
617
624
  | primary_value tLBRACK2 opt_call_args rbracket
618
625
  {
619
626
  lhs, _, args, _ = val
627
+
620
628
  result = self.aryset lhs, args
621
629
  }
622
630
  | primary_value call_op tIDENTIFIER # REFACTOR
623
631
  {
624
- lhs, op, id = val
632
+ lhs, op, (id, _line) = val
633
+
625
634
  result = new_attrasgn lhs, id, op
626
635
  }
627
636
  | primary_value tCOLON2 tIDENTIFIER
628
637
  {
629
- lhs, _, id = val
638
+ lhs, _, (id, _line) = val
639
+
630
640
  result = new_attrasgn lhs, id
631
641
  }
632
642
  | primary_value call_op tCONSTANT # REFACTOR?
633
643
  {
634
- result = new_attrasgn val[0], val[2], val[1]
644
+ lhs, call_op, (id, _line) = val
645
+
646
+ result = new_attrasgn lhs, id, call_op
635
647
  }
636
648
  | primary_value tCOLON2 tCONSTANT
637
649
  {
638
- expr, _, id = val
650
+ expr, _, (id, _line) = val
639
651
 
640
652
  if (self.in_def || self.in_single > 0) then
641
- debug20 10
653
+ debug 17
642
654
  yyerror "dynamic constant assignment"
643
655
  end
644
656
 
@@ -647,14 +659,13 @@ rule
647
659
  }
648
660
  | tCOLON3 tCONSTANT
649
661
  {
650
- _, id = val
662
+ _, (id, l) = val
651
663
 
652
664
  if (self.in_def || self.in_single > 0) then
653
- debug20 11
665
+ debug 18
654
666
  yyerror "dynamic constant assignment"
655
667
  end
656
668
 
657
- l = lexer.lineno
658
669
  result = s(:const, s(:colon3, id.to_sym).line(l)).line l
659
670
  }
660
671
  | backref
@@ -670,16 +681,17 @@ rule
670
681
 
671
682
  cpath: tCOLON3 cname
672
683
  {
673
- _, name = val
674
- result = s(:colon3, name.to_sym).line lexer.lineno
684
+ _, (name, line) = val
685
+ result = s(:colon3, name.to_sym).line line
675
686
  }
676
687
  | cname
677
688
  {
678
- result = val[0].to_sym
689
+ (id, line), = val
690
+ result = [id.to_sym, line] # TODO: sexp?
679
691
  }
680
692
  | primary_value tCOLON2 cname
681
693
  {
682
- pval, _, name = val
694
+ pval, _, (name, _line) = val
683
695
 
684
696
  result = s(:colon2, pval, name.to_sym)
685
697
  result.line pval.line
@@ -689,24 +701,17 @@ rule
689
701
  | op
690
702
  {
691
703
  lexer.lex_state = EXPR_END
692
- result = val[0]
693
704
  }
694
705
 
695
706
  | reswords
696
- {
697
- (sym, _line), = val
698
- lexer.lex_state = EXPR_END
699
- result = sym
700
- }
701
-
702
- fsym: fname | symbol
703
707
 
704
- fitem: fsym
708
+ fitem: fname
705
709
  {
706
- id, = val
707
- result = s(:lit, id.to_sym).line lexer.lineno
710
+ (id, line), = val
711
+
712
+ result = s(:lit, id.to_sym).line line
708
713
  }
709
- | dsym
714
+ | symbol
710
715
 
711
716
  undef_list: fitem
712
717
  {
@@ -727,8 +732,6 @@ rule
727
732
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
728
733
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
729
734
  | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
730
- # TODO: tUBANG dead?
731
- | tUBANG
732
735
 
733
736
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
734
737
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -762,24 +765,20 @@ rule
762
765
  }
763
766
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
764
767
  {
765
- lhs, _, id, op, rhs = val
768
+ lhs, _, (id, _line), (op, _), rhs = val
766
769
 
767
770
  result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
768
771
  }
769
772
  | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
770
773
  {
771
- lhs1, _, lhs2, op, rhs = val
774
+ lhs1, _, (lhs2, _line), op, rhs = val
772
775
 
773
776
  lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
774
777
  result = new_const_op_asgn [lhs, op, rhs]
775
778
  }
776
- | tCOLON3 tCONSTANT
779
+ | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
777
780
  {
778
- result = self.lexer.lineno
779
- }
780
- tOP_ASGN arg_rhs
781
- {
782
- _, lhs, line, op, rhs = val
781
+ _, (lhs, line), op, rhs = val
783
782
 
784
783
  lhs = s(:colon3, lhs.to_sym).line line
785
784
  result = new_const_op_asgn [lhs, op, rhs]
@@ -793,7 +792,7 @@ rule
793
792
  | arg tDOT2 arg
794
793
  {
795
794
  v1, v2 = val[0], val[2]
796
- if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
795
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
797
796
  result = s(:lit, (v1.last)..(v2.last)).line v1.line
798
797
  else
799
798
  result = s(:dot2, v1, v2).line v1.line
@@ -802,26 +801,12 @@ rule
802
801
  | arg tDOT3 arg
803
802
  {
804
803
  v1, v2 = val[0], val[2]
805
- if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
804
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
806
805
  result = s(:lit, (v1.last)...(v2.last)).line v1.line
807
806
  else
808
807
  result = s(:dot3, v1, v2).line v1.line
809
808
  end
810
809
  }
811
- | arg tDOT2
812
- {
813
- v1, _ = val
814
- v2 = nil
815
-
816
- result = s(:dot2, v1, v2).line v1.line
817
- }
818
- | arg tDOT3
819
- {
820
- v1, _ = val
821
- v2 = nil
822
-
823
- result = s(:dot3, v1, v2).line v1.line
824
- }
825
810
 
826
811
 
827
812
  | arg tPLUS arg
@@ -850,8 +835,9 @@ rule
850
835
  }
851
836
  | tUMINUS_NUM simple_numeric tPOW arg
852
837
  {
853
- lit = s(:lit, val[1]).line lexer.lineno
854
- result = new_call(new_call(lit, :"**", argl(val[3])), :"-@")
838
+ _, (num, line), _, arg = val
839
+ lit = s(:lit, num).line line
840
+ result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
855
841
 
856
842
  }
857
843
  | tUPLUS arg
@@ -950,12 +936,12 @@ rule
950
936
 
951
937
  rel_expr: arg relop arg =tGT
952
938
  {
953
- lhs, op, rhs = val
939
+ lhs, (op, _), rhs = val
954
940
  result = new_call lhs, op.to_sym, argl(rhs)
955
941
  }
956
942
  | rel_expr relop arg =tGT
957
943
  {
958
- lhs, op, rhs = val
944
+ lhs, (op, _), rhs = val
959
945
  warn "comparison '%s' after comparison", op
960
946
  result = new_call lhs, op.to_sym, argl(rhs)
961
947
  }
@@ -1146,8 +1132,9 @@ rule
1146
1132
  | backref
1147
1133
  | tFID
1148
1134
  {
1149
- msg, = val
1135
+ (msg, line), = val
1150
1136
  result = new_call nil, msg.to_sym
1137
+ result.line line
1151
1138
  }
1152
1139
  | k_begin
1153
1140
  {
@@ -1189,15 +1176,15 @@ rule
1189
1176
  }
1190
1177
  | primary_value tCOLON2 tCONSTANT
1191
1178
  {
1192
- expr, _, id = val
1179
+ expr, _, (id, _line) = val
1193
1180
 
1194
1181
  result = s(:colon2, expr, id.to_sym).line expr.line
1195
1182
  }
1196
1183
  | tCOLON3 tCONSTANT
1197
1184
  {
1198
- _, id = val
1185
+ _, (id, line) = val
1199
1186
 
1200
- result = s(:colon3, id.to_sym).line lexer.lineno
1187
+ result = s(:colon3, id.to_sym).line line
1201
1188
  }
1202
1189
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1203
1190
  {
@@ -1244,7 +1231,7 @@ rule
1244
1231
  }
1245
1232
  | kNOT tLPAREN2 rparen
1246
1233
  {
1247
- debug20 14, val, result
1234
+ debug 20
1248
1235
  }
1249
1236
  | fcall brace_block
1250
1237
  {
@@ -1262,9 +1249,10 @@ rule
1262
1249
  iter.insert 1, call # FIX
1263
1250
  result = iter
1264
1251
  }
1265
- | tLAMBDA lambda
1252
+ | lambda
1266
1253
  {
1267
- result = val[1] # TODO: fix lineno
1254
+ expr, = val
1255
+ result = expr
1268
1256
  }
1269
1257
  | k_if expr_value then compstmt if_tail k_end
1270
1258
  {
@@ -1307,7 +1295,6 @@ rule
1307
1295
  }
1308
1296
  cpath superclass
1309
1297
  {
1310
- self.comments.push self.lexer.comments
1311
1298
  if (self.in_def || self.in_single > 0) then
1312
1299
  yyerror "class definition in method body"
1313
1300
  end
@@ -1317,7 +1304,7 @@ rule
1317
1304
  {
1318
1305
  result = new_class val
1319
1306
  self.env.unextend
1320
- self.lexer.comments # we don't care about comments in the body
1307
+ self.lexer.ignore_body_comments
1321
1308
  }
1322
1309
  | k_class tLSHFT
1323
1310
  {
@@ -1338,7 +1325,7 @@ rule
1338
1325
  {
1339
1326
  result = new_sclass val
1340
1327
  self.env.unextend
1341
- self.lexer.comments # we don't care about comments in the body
1328
+ self.lexer.ignore_body_comments
1342
1329
  }
1343
1330
  | k_module
1344
1331
  {
@@ -1346,7 +1333,6 @@ rule
1346
1333
  }
1347
1334
  cpath
1348
1335
  {
1349
- self.comments.push self.lexer.comments
1350
1336
  yyerror "module definition in method body" if
1351
1337
  self.in_def or self.in_single > 0
1352
1338
 
@@ -1356,7 +1342,7 @@ rule
1356
1342
  {
1357
1343
  result = new_module val
1358
1344
  self.env.unextend
1359
- self.lexer.comments # we don't care about comments in the body
1345
+ self.lexer.ignore_body_comments
1360
1346
  }
1361
1347
  | k_def fname
1362
1348
  {
@@ -1366,21 +1352,17 @@ rule
1366
1352
  self.env.extend
1367
1353
  lexer.cmdarg.push false
1368
1354
  lexer.cond.push false
1369
-
1370
- self.comments.push self.lexer.comments
1371
1355
  }
1372
- f_arglist bodystmt { result = lexer.lineno } k_end
1356
+ f_arglist bodystmt k_end
1373
1357
  {
1374
- in_def = val[2]
1375
-
1376
- result = new_defn val
1358
+ result, in_def = new_defn val
1377
1359
 
1378
1360
  lexer.cond.pop # group = local_pop
1379
1361
  lexer.cmdarg.pop
1380
1362
  self.env.unextend
1381
1363
  self.in_def = in_def
1382
1364
 
1383
- self.lexer.comments # we don't care about comments in the body
1365
+ self.lexer.ignore_body_comments
1384
1366
  }
1385
1367
  | k_def singleton dot_or_colon
1386
1368
  {
@@ -1388,7 +1370,7 @@ rule
1388
1370
  }
1389
1371
  fname
1390
1372
  {
1391
- result = [self.in_def, lexer.lineno]
1373
+ result = self.in_def
1392
1374
 
1393
1375
  self.in_single += 1 # TODO: remove?
1394
1376
 
@@ -1398,13 +1380,18 @@ rule
1398
1380
  lexer.cond.push false
1399
1381
 
1400
1382
  lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
1401
- self.comments.push self.lexer.comments
1402
1383
  }
1403
1384
  f_arglist bodystmt k_end
1404
1385
  {
1405
- _, _recv, _, _, _name, (in_def, _lineno), _args, _body, _ = val
1406
1386
 
1407
- result = new_defs val
1387
+ # [kdef, recv, _, _, (name, line), in_def, args, body, kend]
1388
+ # =>
1389
+ # [kdef, recv, (name, line), in_def, args, body, kend]
1390
+
1391
+ val.delete_at 3
1392
+ val.delete_at 2
1393
+
1394
+ result, in_def = new_defs val
1408
1395
 
1409
1396
  lexer.cond.pop # group = local_pop
1410
1397
  lexer.cmdarg.pop
@@ -1415,7 +1402,7 @@ rule
1415
1402
 
1416
1403
  # TODO: restore cur_arg ? what's cur_arg?
1417
1404
 
1418
- self.lexer.comments # we don't care about comments in the body
1405
+ self.lexer.ignore_body_comments
1419
1406
  }
1420
1407
  | kBREAK
1421
1408
  {
@@ -1452,8 +1439,17 @@ rule
1452
1439
  k_case: kCASE
1453
1440
  k_for: kFOR
1454
1441
  k_class: kCLASS
1442
+ {
1443
+ self.comments.push self.lexer.comments
1444
+ }
1455
1445
  k_module: kMODULE
1446
+ {
1447
+ self.comments.push self.lexer.comments
1448
+ }
1456
1449
  k_def: kDEF
1450
+ {
1451
+ self.comments.push self.lexer.comments
1452
+ }
1457
1453
  k_do: kDO
1458
1454
  k_do_block: kDO_BLOCK
1459
1455
  k_rescue: kRESCUE
@@ -1514,51 +1510,42 @@ rule
1514
1510
 
1515
1511
  result = block_var args
1516
1512
  }
1517
- | f_marg_list tCOMMA tSTAR f_norm_arg
1513
+ | f_marg_list tCOMMA f_rest_marg
1518
1514
  {
1519
- args, _, _, splat = val
1515
+ args, _, rest = val
1520
1516
 
1521
- result = block_var args, "*#{splat}".to_sym
1517
+ result = block_var args, rest
1522
1518
  }
1523
- | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1519
+ | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1524
1520
  {
1525
- args, _, _, splat, _, args2 = val
1521
+ lhs, _, splat, _, rhs = val
1526
1522
 
1527
- result = block_var args, "*#{splat}".to_sym, args2
1523
+ result = block_var lhs, splat, rhs
1528
1524
  }
1529
- | f_marg_list tCOMMA tSTAR
1525
+ | f_rest_marg
1530
1526
  {
1531
- args, _, _ = val
1527
+ rest, = val
1532
1528
 
1533
- result = block_var args, :*
1529
+ result = block_var rest
1534
1530
  }
1535
- | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1531
+ | f_rest_marg tCOMMA f_marg_list
1536
1532
  {
1537
- args, _, _, _, args2 = val
1533
+ splat, _, rest = val
1538
1534
 
1539
- result = block_var args, :*, args2
1535
+ result = block_var splat, rest
1540
1536
  }
1541
- | tSTAR f_norm_arg
1542
- {
1543
- _, splat = val
1544
1537
 
1545
- result = block_var :"*#{splat}"
1546
- }
1547
- | tSTAR f_norm_arg tCOMMA f_marg_list
1538
+ f_rest_marg: tSTAR f_norm_arg
1548
1539
  {
1549
- _, splat, _, args = val
1540
+ _, (id, line) = val
1550
1541
 
1551
- result = block_var :"*#{splat}", args
1542
+ result = args ["*#{id}".to_sym]
1543
+ result.line line
1552
1544
  }
1553
1545
  | tSTAR
1554
1546
  {
1555
- result = block_var :*
1556
- }
1557
- | tSTAR tCOMMA f_marg_list
1558
- {
1559
- _, _, args = val
1560
-
1561
- result = block_var :*, args
1547
+ result = args [:*]
1548
+ result.line lexer.lineno # FIX: tSTAR -> line
1562
1549
  }
1563
1550
 
1564
1551
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -1575,8 +1562,8 @@ rule
1575
1562
  }
1576
1563
  | f_block_arg
1577
1564
  {
1578
- line = lexer.lineno
1579
- result = call_args val # TODO: push line down
1565
+ (id, line), = val
1566
+ result = call_args [id]
1580
1567
  result.line line
1581
1568
  }
1582
1569
 
@@ -1685,13 +1672,13 @@ opt_block_args_tail: tCOMMA block_args_tail
1685
1672
 
1686
1673
  bvar: tIDENTIFIER
1687
1674
  {
1688
- id, = val
1689
- line = lexer.lineno
1675
+ (id, line), = val
1690
1676
  result = s(:shadow, id.to_sym).line line
1691
1677
  }
1692
1678
  | f_bad_arg
1693
1679
 
1694
- lambda: {
1680
+ lambda: tLAMBDA
1681
+ {
1695
1682
  self.env.extend :dynamic
1696
1683
  result = [lexer.lineno, lexer.lpar_beg]
1697
1684
  lexer.paren_nest += 1
@@ -1703,14 +1690,14 @@ opt_block_args_tail: tCOMMA block_args_tail
1703
1690
  }
1704
1691
  lambda_body
1705
1692
  {
1706
- (line, lpar), args, _cmdarg, body = val
1693
+ _, (line, lpar), args, _cmdarg, body = val
1707
1694
  lexer.lpar_beg = lpar
1708
1695
 
1709
1696
  lexer.cmdarg.pop
1710
1697
 
1711
1698
  call = s(:lambda).line line
1712
1699
  result = new_iter call, args, body
1713
- result.line = line
1700
+ result.line line
1714
1701
  self.env.unextend # TODO: dynapush & dynapop
1715
1702
  }
1716
1703
 
@@ -1745,23 +1732,28 @@ opt_block_args_tail: tCOMMA block_args_tail
1745
1732
  ## if (nd_type($1) == NODE_YIELD) {
1746
1733
  ## compile_error(PARSER_ARG "block given to yield");
1747
1734
 
1748
- syntax_error "Both block arg and actual block given." if
1749
- val[0].block_pass?
1735
+ cmd, blk = val
1750
1736
 
1751
- val = invert_block_call val if inverted? val
1737
+ syntax_error "Both block arg and actual block given." if
1738
+ cmd.block_pass?
1752
1739
 
1753
- cmd, blk = val
1740
+ if inverted? val then
1741
+ val = invert_block_call val
1742
+ cmd, blk = val
1743
+ end
1754
1744
 
1755
1745
  result = blk
1756
1746
  result.insert 1, cmd
1757
1747
  }
1758
1748
  | block_call call_op2 operation2 opt_paren_args
1759
1749
  {
1760
- result = new_call val[0], val[2].to_sym, val[3]
1750
+ lhs, _, (id, _line), args = val
1751
+
1752
+ result = new_call lhs, id.to_sym, args
1761
1753
  }
1762
1754
  | block_call call_op2 operation2 opt_paren_args brace_block
1763
1755
  {
1764
- iter1, _, name, args, iter2 = val
1756
+ iter1, _, (name, _line), args, iter2 = val
1765
1757
 
1766
1758
  call = new_call iter1, name.to_sym, args
1767
1759
  iter2.insert 1, call
@@ -1770,7 +1762,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1770
1762
  }
1771
1763
  | block_call call_op2 operation2 command_args do_block
1772
1764
  {
1773
- iter1, _, name, args, iter2 = val
1765
+ iter1, _, (name, _line), args, iter2 = val
1774
1766
 
1775
1767
  call = new_call iter1, name.to_sym, args
1776
1768
  iter2.insert 1, call
@@ -1778,28 +1770,29 @@ opt_block_args_tail: tCOMMA block_args_tail
1778
1770
  result = iter2
1779
1771
  }
1780
1772
 
1781
- method_call: fcall
1782
- {
1783
- result = self.lexer.lineno
1784
- }
1785
- paren_args
1773
+ method_call: fcall paren_args
1786
1774
  {
1787
- call, lineno, args = val
1775
+ call, args = val
1788
1776
 
1789
1777
  result = call.concat args.sexp_body if args
1790
- result.line lineno
1791
1778
  }
1792
1779
  | primary_value call_op operation2 opt_paren_args
1793
1780
  {
1794
- result = new_call val[0], val[2].to_sym, val[3], val[1]
1781
+ recv, call_op, (op, _line), args = val
1782
+
1783
+ result = new_call recv, op.to_sym, args, call_op
1795
1784
  }
1796
1785
  | primary_value tCOLON2 operation2 paren_args
1797
1786
  {
1798
- result = new_call val[0], val[2].to_sym, val[3]
1787
+ recv, _, (op, _line), args = val
1788
+
1789
+ result = new_call recv, op.to_sym, args
1799
1790
  }
1800
1791
  | primary_value tCOLON2 operation3
1801
1792
  {
1802
- result = new_call val[0], val[2].to_sym
1793
+ lhs, _, (id, _line) = val
1794
+
1795
+ result = new_call lhs, id.to_sym
1803
1796
  }
1804
1797
  | primary_value call_op paren_args
1805
1798
  {
@@ -1832,7 +1825,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1832
1825
  _, line, body, _ = val
1833
1826
 
1834
1827
  result = body
1835
- result.line = line
1828
+ result.line line
1836
1829
 
1837
1830
  self.env.unextend
1838
1831
  }
@@ -1846,7 +1839,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1846
1839
  _, line, body, _ = val
1847
1840
 
1848
1841
  result = body
1849
- result.line = line
1842
+ result.line line
1850
1843
 
1851
1844
  self.env.unextend
1852
1845
  }
@@ -1866,7 +1859,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1866
1859
  do_body: { self.env.extend :dynamic; result = self.lexer.lineno }
1867
1860
  { lexer.cmdarg.push false }
1868
1861
  opt_block_param
1869
- bodystmt
1862
+ compstmt
1870
1863
  {
1871
1864
  line, _cmdarg, param, cmpstmt = val
1872
1865
 
@@ -1875,14 +1868,39 @@ opt_block_args_tail: tCOMMA block_args_tail
1875
1868
  self.env.unextend
1876
1869
  }
1877
1870
 
1871
+ case_args: arg_value
1872
+ {
1873
+ arg, = val
1874
+
1875
+ result = s(:array, arg).line arg.line
1876
+ }
1877
+ | tSTAR arg_value
1878
+ {
1879
+ _, arg = val
1880
+
1881
+ result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1882
+ }
1883
+ | case_args tCOMMA arg_value
1884
+ {
1885
+ args, _, id = val
1886
+
1887
+ result = self.list_append args, id
1888
+ }
1889
+ | case_args tCOMMA tSTAR arg_value
1890
+ {
1891
+ args, _, _, id = val
1892
+
1893
+ result = self.list_append args, s(:splat, id).line(id.line)
1894
+ }
1895
+
1878
1896
  case_body: k_when
1879
1897
  {
1880
1898
  result = self.lexer.lineno
1881
1899
  }
1882
- args then compstmt cases
1900
+ case_args then compstmt cases
1883
1901
  {
1884
1902
  result = new_when(val[2], val[4])
1885
- result.line = val[1]
1903
+ result.line val[1]
1886
1904
  result << val[5] if val[5]
1887
1905
  }
1888
1906
 
@@ -1928,17 +1946,10 @@ opt_block_args_tail: tCOMMA block_args_tail
1928
1946
 
1929
1947
  literal: numeric
1930
1948
  {
1931
- line = lexer.lineno
1932
- result = s(:lit, val[0])
1933
- result.line = line
1949
+ (lit, line), = val
1950
+ result = s(:lit, lit).line line
1934
1951
  }
1935
1952
  | symbol
1936
- {
1937
- line = lexer.lineno
1938
- result = s(:lit, val[0])
1939
- result.line = line
1940
- }
1941
- | dsym
1942
1953
 
1943
1954
  strings: string
1944
1955
  {
@@ -1949,7 +1960,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1949
1960
 
1950
1961
  string: tCHAR
1951
1962
  {
1952
- debug20 23, val, result
1963
+ debug 37
1953
1964
  }
1954
1965
  | string1
1955
1966
  | string string1
@@ -1959,11 +1970,11 @@ opt_block_args_tail: tCOMMA block_args_tail
1959
1970
 
1960
1971
  string1: tSTRING_BEG string_contents tSTRING_END
1961
1972
  {
1962
- _, str, (_, func) = val
1973
+ (_, line), str, (_, func) = val
1963
1974
 
1964
- str = dedent str if func =~ RubyLexer::STR_FUNC_ICNTNT
1975
+ str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
1965
1976
 
1966
- result = str
1977
+ result = str.line line
1967
1978
  }
1968
1979
  | tSTRING
1969
1980
  {
@@ -1983,11 +1994,15 @@ opt_block_args_tail: tCOMMA block_args_tail
1983
1994
 
1984
1995
  words: tWORDS_BEG tSPACE tSTRING_END
1985
1996
  {
1986
- result = s(:array).line lexer.lineno
1997
+ (_, line), _, _ = val
1998
+
1999
+ result = s(:array).line line
1987
2000
  }
1988
2001
  | tWORDS_BEG word_list tSTRING_END
1989
2002
  {
1990
- result = val[1]
2003
+ (_, line), list, _ = val
2004
+
2005
+ result = list.line line
1991
2006
  }
1992
2007
 
1993
2008
  word_list: none
@@ -2007,18 +2022,20 @@ opt_block_args_tail: tCOMMA block_args_tail
2007
2022
 
2008
2023
  symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2009
2024
  {
2010
- result = s(:array).line lexer.lineno
2025
+ (_, line), _, _ = val
2026
+
2027
+ result = s(:array).line line
2011
2028
  }
2012
- | tSYMBOLS_BEG { result = lexer.lineno } symbol_list tSTRING_END
2029
+ | tSYMBOLS_BEG symbol_list tSTRING_END
2013
2030
  {
2014
- _, line, list, _, = val
2015
- list.line = line
2031
+ (_, line), list, _, = val
2032
+ list.line line
2016
2033
  result = list
2017
2034
  }
2018
2035
 
2019
2036
  symbol_list: none
2020
2037
  {
2021
- result = new_symbol_list.line lexer.lineno
2038
+ result = new_symbol_list
2022
2039
  }
2023
2040
  | symbol_list word tSPACE
2024
2041
  {
@@ -2028,20 +2045,28 @@ opt_block_args_tail: tCOMMA block_args_tail
2028
2045
 
2029
2046
  qwords: tQWORDS_BEG tSPACE tSTRING_END
2030
2047
  {
2031
- result = s(:array).line lexer.lineno
2048
+ (_, line), _, _ = val
2049
+
2050
+ result = s(:array).line line
2032
2051
  }
2033
2052
  | tQWORDS_BEG qword_list tSTRING_END
2034
2053
  {
2035
- result = val[1]
2054
+ (_, line), list, _ = val
2055
+
2056
+ result = list.line line
2036
2057
  }
2037
2058
 
2038
2059
  qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2039
2060
  {
2040
- result = s(:array).line lexer.lineno # FIX
2061
+ (_, line), _, _ = val
2062
+
2063
+ result = s(:array).line line
2041
2064
  }
2042
2065
  | tQSYMBOLS_BEG qsym_list tSTRING_END
2043
2066
  {
2044
- result = val[1]
2067
+ (_, line), list, _ = val
2068
+
2069
+ result = list.line line
2045
2070
  }
2046
2071
 
2047
2072
  qword_list: none
@@ -2064,7 +2089,8 @@ opt_block_args_tail: tCOMMA block_args_tail
2064
2089
 
2065
2090
  string_contents: none
2066
2091
  {
2067
- result = s(:str, "").line lexer.lineno
2092
+ line = prev_value_to_lineno _values.last
2093
+ result = s(:str, +"").line line
2068
2094
  }
2069
2095
  | string_contents string_content
2070
2096
  {
@@ -2139,8 +2165,8 @@ regexp_contents: none
2139
2165
  lexer.brace_nest = brace_nest
2140
2166
  lexer.string_nest = string_nest
2141
2167
 
2142
- lexer.cmdarg.pop
2143
2168
  lexer.cond.pop
2169
+ lexer.cmdarg.pop
2144
2170
 
2145
2171
  lexer.lex_state = oldlex_state
2146
2172
 
@@ -2155,29 +2181,49 @@ regexp_contents: none
2155
2181
  when nil then
2156
2182
  result = s(:evstr).line line
2157
2183
  else
2158
- debug20 25
2184
+ debug 38
2159
2185
  raise "unknown string body: #{stmt.inspect}"
2160
2186
  end
2161
2187
  }
2162
2188
 
2163
- string_dvar: tGVAR { result = s(:gvar, val[0].to_sym).line lexer.lineno }
2164
- | tIVAR { result = s(:ivar, val[0].to_sym).line lexer.lineno }
2165
- | tCVAR { result = s(:cvar, val[0].to_sym).line lexer.lineno }
2189
+ string_dvar: tGVAR
2190
+ {
2191
+ (id, line), = val
2192
+ result = s(:gvar, id.to_sym).line line
2193
+ }
2194
+ | tIVAR
2195
+ {
2196
+ (id, line), = val
2197
+ result = s(:ivar, id.to_sym).line line
2198
+ }
2199
+ | tCVAR
2200
+ {
2201
+ (id, line), = val
2202
+ result = s(:cvar, id.to_sym).line line
2203
+ }
2166
2204
  | backref
2167
2205
 
2168
- symbol: tSYMBEG sym
2206
+ symbol: ssym
2207
+ | dsym
2208
+
2209
+ ssym: tSYMBEG sym
2169
2210
  {
2211
+ _, (id, line) = val
2212
+
2170
2213
  lexer.lex_state = EXPR_END
2171
- result = val[1].to_sym
2214
+ result = s(:lit, id.to_sym).line line
2172
2215
  }
2173
2216
  | tSYMBOL
2174
2217
  {
2175
- result = val[0].to_sym
2218
+ (id, line), = val
2219
+
2220
+ lexer.lex_state = EXPR_END
2221
+ result = s(:lit, id.to_sym).line line
2176
2222
  }
2177
2223
 
2178
2224
  sym: fname | tIVAR | tGVAR | tCVAR
2179
2225
 
2180
- dsym: tSYMBEG xstring_contents tSTRING_END
2226
+ dsym: tSYMBEG string_contents tSTRING_END
2181
2227
  {
2182
2228
  _, result, _ = val
2183
2229
 
@@ -2193,14 +2239,15 @@ regexp_contents: none
2193
2239
  when :evstr then
2194
2240
  result = s(:dsym, "", result).line result.line
2195
2241
  else
2196
- debug20 26, val, result
2242
+ debug 39
2197
2243
  end
2198
2244
  }
2199
2245
 
2200
2246
  numeric: simple_numeric
2201
- | tUMINUS_NUM simple_numeric
2247
+ | tUMINUS_NUM simple_numeric =tLOWEST
2202
2248
  {
2203
- result = -val[1] # TODO: pt_testcase
2249
+ _, (num, line) = val
2250
+ result = [-num, line]
2204
2251
  }
2205
2252
 
2206
2253
  simple_numeric: tINTEGER
@@ -2233,8 +2280,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2233
2280
 
2234
2281
  var_ref: user_variable
2235
2282
  {
2236
- var = val[0]
2283
+ raise "NO: #{val.inspect}" if Sexp === val.first
2284
+ (var, line), = val
2237
2285
  result = Sexp === var ? var : self.gettable(var)
2286
+ result.line line
2238
2287
  }
2239
2288
  | keyword_variable
2240
2289
  {
@@ -2249,11 +2298,19 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2249
2298
  | keyword_variable
2250
2299
  {
2251
2300
  result = self.assignable val[0]
2252
- debug20 29, val, result
2301
+ debug 40
2253
2302
  }
2254
2303
 
2255
- backref: tNTH_REF { result = s(:nth_ref, val[0]).line lexer.lineno }
2256
- | tBACK_REF { result = s(:back_ref, val[0]).line lexer.lineno }
2304
+ backref: tNTH_REF
2305
+ {
2306
+ (ref, line), = val
2307
+ result = s(:nth_ref, ref).line line
2308
+ }
2309
+ | tBACK_REF
2310
+ {
2311
+ (ref, line), = val
2312
+ result = s(:back_ref, ref).line line
2313
+ }
2257
2314
 
2258
2315
  superclass: tLT
2259
2316
  {
@@ -2271,9 +2328,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2271
2328
 
2272
2329
  f_arglist: tLPAREN2 f_args rparen
2273
2330
  {
2274
- result = val[1]
2275
- self.lexer.lex_state = EXPR_BEG
2276
- self.lexer.command_start = true
2331
+ result = end_args val
2277
2332
  }
2278
2333
  | {
2279
2334
  result = self.in_kwarg
@@ -2282,12 +2337,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2282
2337
  }
2283
2338
  f_args term
2284
2339
  {
2285
- kwarg, args, _ = val
2286
-
2287
- self.in_kwarg = kwarg
2288
- result = args
2289
- lexer.lex_state = EXPR_BEG
2290
- lexer.command_start = true
2340
+ result = end_args val
2291
2341
  }
2292
2342
 
2293
2343
  args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -2372,8 +2422,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2372
2422
  |
2373
2423
  {
2374
2424
  result = args val
2425
+ # result.line lexer.lineno
2375
2426
  }
2376
2427
 
2428
+
2377
2429
  f_bad_arg: tCONSTANT
2378
2430
  {
2379
2431
  yyerror "formal argument cannot be a constant"
@@ -2394,10 +2446,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2394
2446
  f_norm_arg: f_bad_arg
2395
2447
  | tIDENTIFIER
2396
2448
  {
2397
- identifier = val[0].to_sym
2449
+ (id, line), = val
2450
+ identifier = id.to_sym
2398
2451
  self.env[identifier] = :lvar
2399
2452
 
2400
- result = identifier
2453
+ result = [identifier, line]
2401
2454
  }
2402
2455
 
2403
2456
  f_arg_asgn: f_norm_arg
@@ -2405,22 +2458,14 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2405
2458
  f_arg_item: f_arg_asgn
2406
2459
  | tLPAREN f_margs rparen
2407
2460
  {
2408
- result = val[1]
2461
+ _, margs, _ = val
2462
+
2463
+ result = margs
2409
2464
  }
2410
2465
 
2411
2466
  f_arg: f_arg_item
2412
2467
  {
2413
- arg, = val
2414
-
2415
- case arg
2416
- when Symbol then
2417
- result = s(:args, arg).line lexer.lineno
2418
- when Sexp then
2419
- result = arg
2420
- else
2421
- debug20 32
2422
- raise "Unknown f_arg type: #{val.inspect}"
2423
- end
2468
+ result = new_arg val
2424
2469
  }
2425
2470
  | f_arg tCOMMA f_arg_item
2426
2471
  {
@@ -2432,7 +2477,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2432
2477
  result = s(:args, list).line list.line
2433
2478
  end
2434
2479
 
2435
- result << item
2480
+ result << (Sexp === item ? item : item.first)
2436
2481
  }
2437
2482
 
2438
2483
  f_label: tLABEL
@@ -2493,26 +2538,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2493
2538
  kwrest_mark: tPOW
2494
2539
  | tDSTAR
2495
2540
 
2541
+
2496
2542
  f_kwrest: kwrest_mark tIDENTIFIER
2497
2543
  {
2498
- name = val[1].to_sym
2499
- self.assignable name
2500
- result = :"**#{name}"
2544
+ _, (id, line) = val
2545
+
2546
+ name = id.to_sym
2547
+ self.assignable [name, line]
2548
+ result = [:"**#{name}", line]
2501
2549
  }
2502
2550
  | kwrest_mark
2503
2551
  {
2504
- result = :"**"
2552
+ id = :"**"
2553
+ self.env[id] = :lvar # TODO: needed?!?
2554
+ result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
2505
2555
  }
2506
2556
 
2507
2557
  f_opt: f_arg_asgn tEQL arg_value
2508
2558
  {
2509
- result = self.assignable val[0], val[2]
2559
+ lhs, _, rhs = val
2560
+ result = self.assignable lhs, rhs
2510
2561
  # TODO: detect duplicate names
2511
2562
  }
2512
2563
 
2513
2564
  f_block_opt: f_arg_asgn tEQL primary_value
2514
2565
  {
2515
- result = self.assignable val[0], val[2]
2566
+ lhs, _, rhs = val
2567
+ result = self.assignable lhs, rhs
2516
2568
  }
2517
2569
 
2518
2570
  f_block_optarg: f_block_opt
@@ -2542,30 +2594,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2542
2594
  f_rest_arg: restarg_mark tIDENTIFIER
2543
2595
  {
2544
2596
  # TODO: differs from parse.y - needs tests
2545
- name = val[1].to_sym
2546
- self.assignable name
2547
- result = :"*#{name}"
2597
+ _, (id, line) = val
2598
+ name = id.to_sym
2599
+ self.assignable [name, line]
2600
+ result = [:"*#{name}", line]
2548
2601
  }
2549
2602
  | restarg_mark
2550
2603
  {
2551
2604
  name = :"*"
2552
2605
  self.env[name] = :lvar
2553
- result = name
2606
+ result = [name, lexer.lineno] # FIX: tSTAR to include lineno
2554
2607
  }
2555
2608
 
2556
2609
  blkarg_mark: tAMPER2 | tAMPER
2557
2610
 
2558
2611
  f_block_arg: blkarg_mark tIDENTIFIER
2559
2612
  {
2560
- identifier = val[1].to_sym
2613
+ _, (id, line) = val
2614
+ identifier = id.to_sym
2561
2615
 
2562
2616
  self.env[identifier] = :lvar
2563
- result = "&#{identifier}".to_sym
2617
+ result = ["&#{identifier}".to_sym, line]
2564
2618
  }
2565
2619
 
2566
2620
  opt_f_block_arg: tCOMMA f_block_arg
2567
2621
  {
2568
- result = val[1]
2622
+ _, arg = val
2623
+ result = arg
2569
2624
  }
2570
2625
  |
2571
2626
  {
@@ -2614,9 +2669,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2614
2669
  }
2615
2670
  | tSTRING_BEG string_contents tLABEL_END arg_value
2616
2671
  {
2617
- _, sym, _, value = val
2672
+ (_, line), sym, _, value = val
2673
+
2618
2674
  sym.sexp_type = :dsym
2619
- result = s(:array, sym, value).line sym.line
2675
+
2676
+ result = s(:array, sym, value).line line
2620
2677
  }
2621
2678
  | tDSTAR arg_value
2622
2679
  {