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 Ruby27Parser
3
+ class Ruby26Parser
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,7 +18,7 @@ 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
@@ -80,7 +80,7 @@ rule
80
80
  | klBEGIN
81
81
  {
82
82
  if (self.in_def || self.in_single > 0) then
83
- debug20 1
83
+ debug 11
84
84
  yyerror "BEGIN in method"
85
85
  end
86
86
  self.env.extend
@@ -105,6 +105,8 @@ rule
105
105
  bodystmt: compstmt opt_rescue k_else
106
106
  {
107
107
  res = _values[-2]
108
+ # TODO: move down to main match so I can just use val
109
+
108
110
  yyerror "else without rescue is useless" unless res
109
111
  }
110
112
  compstmt
@@ -135,7 +137,7 @@ rule
135
137
  | error stmt
136
138
  {
137
139
  result = val[1]
138
- debug20 2, val, result
140
+ debug 12
139
141
  }
140
142
 
141
143
  stmt_or_begin: stmt
@@ -143,6 +145,10 @@ rule
143
145
  {
144
146
  yyerror "BEGIN is permitted only at toplevel"
145
147
  }
148
+ begin_block
149
+ {
150
+ result = val[2] # wtf?
151
+ }
146
152
 
147
153
  stmt: kALIAS fitem
148
154
  {
@@ -155,12 +161,12 @@ rule
155
161
  }
156
162
  | kALIAS tGVAR tGVAR
157
163
  {
158
- (_, line), lhs, rhs = val
164
+ (_, line), (lhs, _), (rhs, _) = val
159
165
  result = s(:valias, lhs.to_sym, rhs.to_sym).line line
160
166
  }
161
167
  | kALIAS tGVAR tBACK_REF
162
168
  {
163
- (_, line), lhs, rhs = val
169
+ (_, line), (lhs, _), (rhs, _) = val
164
170
  result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
165
171
  }
166
172
  | kALIAS tGVAR tNTH_REF
@@ -203,7 +209,7 @@ rule
203
209
  (_, line), _, stmt, _ = val
204
210
 
205
211
  if (self.in_def || self.in_single > 0) then
206
- debug20 3
212
+ debug 13
207
213
  yyerror "END in method; use at_exit"
208
214
  end
209
215
 
@@ -243,32 +249,31 @@ rule
243
249
  }
244
250
  | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
245
251
  {
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
252
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
253
+
254
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
255
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
256
+ result.line prim.line
252
257
  }
253
258
  | primary_value call_op tCONSTANT tOP_ASGN command_rhs
254
259
  {
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
260
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
261
+
262
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
263
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
264
+ result.line prim.line
260
265
  }
261
266
  | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
262
267
  {
263
- lhs1, _, lhs2, op, rhs = val
268
+ lhs1, _, (lhs2, line), (id, _), rhs = val
264
269
 
265
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
270
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
266
271
  }
267
272
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
268
273
  {
269
- lhs1, _, lhs2, op, rhs = val
274
+ lhs1, _, (lhs2, line), (id, _), rhs = val
270
275
 
271
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
276
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
272
277
  }
273
278
  | backref tOP_ASGN command_rhs
274
279
  {
@@ -314,7 +319,7 @@ rule
314
319
  # TODO: fix line number to tBANG... but causes BAD shift/reduce conflict
315
320
  # REFACTOR: call_uni_op -- see parse26.y
316
321
  }
317
- | arg
322
+ | arg =tLBRACE_ARG
318
323
 
319
324
  expr_value: expr
320
325
  {
@@ -339,7 +344,7 @@ rule
339
344
  block_command: block_call
340
345
  | block_call call_op2 operation2 command_args
341
346
  {
342
- blk, _, msg, args = val
347
+ blk, _, (msg, _line), args = val
343
348
  result = new_call(blk, msg.to_sym, args).line blk.line
344
349
  }
345
350
 
@@ -353,15 +358,15 @@ rule
353
358
  _, line, body, _ = val
354
359
 
355
360
  result = body
356
- result.line = line
361
+ result.line line
357
362
 
358
363
  # self.env.unextend
359
364
  }
360
365
 
361
366
  fcall: operation
362
367
  {
363
- msg, = val
364
- result = new_call(nil, msg.to_sym).line lexer.lineno
368
+ (msg, line), = val
369
+ result = new_call(nil, msg.to_sym).line line
365
370
  }
366
371
 
367
372
  command: fcall command_args =tLOWEST
@@ -384,12 +389,14 @@ rule
384
389
  }
385
390
  | primary_value call_op operation2 command_args =tLOWEST
386
391
  {
387
- lhs, callop, op, args = val
392
+ lhs, callop, (op, _), args = val
393
+
388
394
  result = new_call lhs, op.to_sym, args, callop
395
+ result.line lhs.line
389
396
  }
390
397
  | primary_value call_op operation2 command_args cmd_brace_block
391
398
  {
392
- recv, _, msg, args, block = val
399
+ recv, _, (msg, _line), args, block = val
393
400
  call = new_call recv, msg.to_sym, args, val[1]
394
401
 
395
402
  block_dup_check call, block
@@ -399,11 +406,14 @@ rule
399
406
  }
400
407
  | primary_value tCOLON2 operation2 command_args =tLOWEST
401
408
  {
402
- result = new_call val[0], val[2].to_sym, val[3]
409
+ lhs, _, (id, line), args = val
410
+
411
+ result = new_call lhs, id.to_sym, args
412
+ result.line line
403
413
  }
404
414
  | primary_value tCOLON2 operation2 command_args cmd_brace_block
405
415
  {
406
- recv, _, msg, args, block = val
416
+ recv, _, (msg, _line), args, block = val
407
417
  call = new_call recv, msg.to_sym, args
408
418
 
409
419
  block_dup_check call, block
@@ -561,25 +571,29 @@ rule
561
571
  }
562
572
  | primary_value call_op tIDENTIFIER
563
573
  {
564
- result = new_attrasgn val[0], val[2], val[1]
574
+ lhs, call_op, (id, _line) = val
575
+
576
+ result = new_attrasgn lhs, id, call_op
565
577
  }
566
578
  | primary_value tCOLON2 tIDENTIFIER
567
579
  {
568
- recv, _, id = val
580
+ recv, _, (id, _line) = val
569
581
  result = new_attrasgn recv, id
570
582
  }
571
583
  | primary_value call_op tCONSTANT
572
584
  {
573
- result = new_attrasgn val[0], val[2], val[1]
585
+ lhs, call_op, (id, _line) = val
586
+
587
+ result = new_attrasgn lhs, id, call_op
574
588
  }
575
589
  | primary_value tCOLON2 tCONSTANT
576
590
  {
577
591
  if (self.in_def || self.in_single > 0) then
578
- debug20 7
592
+ debug 14
579
593
  yyerror "dynamic constant assignment"
580
594
  end
581
595
 
582
- expr, _, id = val
596
+ expr, _, (id, _line) = val
583
597
  l = expr.line
584
598
 
585
599
  result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
@@ -587,58 +601,65 @@ rule
587
601
  | tCOLON3 tCONSTANT
588
602
  {
589
603
  if (self.in_def || self.in_single > 0) then
590
- debug20 8
604
+ debug 15
591
605
  yyerror "dynamic constant assignment"
592
606
  end
593
607
 
594
- _, id = val
595
- l = lexer.lineno
608
+ _, (id, l) = val
596
609
 
597
610
  result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
598
611
  }
599
612
  | backref
600
613
  {
601
- self.backref_assign_error val[0]
614
+ ref, = val
615
+
616
+ self.backref_assign_error ref
602
617
  }
603
618
 
604
619
  lhs: user_variable
605
620
  {
606
- line = lexer.lineno
607
- result = self.assignable val[0]
608
- result.line = line
621
+ var, = val
622
+
623
+ result = self.assignable var
609
624
  }
610
625
  | keyword_variable
611
626
  {
612
- line = lexer.lineno
613
- result = self.assignable val[0]
614
- result.line = line
615
- debug20 9, val, result
627
+ var, = val
628
+
629
+ result = self.assignable var
630
+
631
+ debug 16
616
632
  }
617
633
  | primary_value tLBRACK2 opt_call_args rbracket
618
634
  {
619
635
  lhs, _, args, _ = val
636
+
620
637
  result = self.aryset lhs, args
621
638
  }
622
639
  | primary_value call_op tIDENTIFIER # REFACTOR
623
640
  {
624
- lhs, op, id = val
641
+ lhs, op, (id, _line) = val
642
+
625
643
  result = new_attrasgn lhs, id, op
626
644
  }
627
645
  | primary_value tCOLON2 tIDENTIFIER
628
646
  {
629
- lhs, _, id = val
647
+ lhs, _, (id, _line) = val
648
+
630
649
  result = new_attrasgn lhs, id
631
650
  }
632
651
  | primary_value call_op tCONSTANT # REFACTOR?
633
652
  {
634
- result = new_attrasgn val[0], val[2], val[1]
653
+ lhs, call_op, (id, _line) = val
654
+
655
+ result = new_attrasgn lhs, id, call_op
635
656
  }
636
657
  | primary_value tCOLON2 tCONSTANT
637
658
  {
638
- expr, _, id = val
659
+ expr, _, (id, _line) = val
639
660
 
640
661
  if (self.in_def || self.in_single > 0) then
641
- debug20 10
662
+ debug 17
642
663
  yyerror "dynamic constant assignment"
643
664
  end
644
665
 
@@ -647,14 +668,13 @@ rule
647
668
  }
648
669
  | tCOLON3 tCONSTANT
649
670
  {
650
- _, id = val
671
+ _, (id, l) = val
651
672
 
652
673
  if (self.in_def || self.in_single > 0) then
653
- debug20 11
674
+ debug 18
654
675
  yyerror "dynamic constant assignment"
655
676
  end
656
677
 
657
- l = lexer.lineno
658
678
  result = s(:const, s(:colon3, id.to_sym).line(l)).line l
659
679
  }
660
680
  | backref
@@ -670,16 +690,17 @@ rule
670
690
 
671
691
  cpath: tCOLON3 cname
672
692
  {
673
- _, name = val
674
- result = s(:colon3, name.to_sym).line lexer.lineno
693
+ _, (name, line) = val
694
+ result = s(:colon3, name.to_sym).line line
675
695
  }
676
696
  | cname
677
697
  {
678
- result = val[0].to_sym
698
+ (id, line), = val
699
+ result = [id.to_sym, line] # TODO: sexp?
679
700
  }
680
701
  | primary_value tCOLON2 cname
681
702
  {
682
- pval, _, name = val
703
+ pval, _, (name, _line) = val
683
704
 
684
705
  result = s(:colon2, pval, name.to_sym)
685
706
  result.line pval.line
@@ -689,24 +710,17 @@ rule
689
710
  | op
690
711
  {
691
712
  lexer.lex_state = EXPR_END
692
- result = val[0]
693
713
  }
694
714
 
695
715
  | reswords
696
- {
697
- (sym, _line), = val
698
- lexer.lex_state = EXPR_END
699
- result = sym
700
- }
701
-
702
- fsym: fname | symbol
703
716
 
704
- fitem: fsym
717
+ fitem: fname
705
718
  {
706
- id, = val
707
- result = s(:lit, id.to_sym).line lexer.lineno
719
+ (id, line), = val
720
+
721
+ result = s(:lit, id.to_sym).line line
708
722
  }
709
- | dsym
723
+ | symbol
710
724
 
711
725
  undef_list: fitem
712
726
  {
@@ -727,8 +741,6 @@ rule
727
741
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
728
742
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
729
743
  | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
730
- # TODO: tUBANG dead?
731
- | tUBANG
732
744
 
733
745
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
734
746
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -762,24 +774,20 @@ rule
762
774
  }
763
775
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
764
776
  {
765
- lhs, _, id, op, rhs = val
777
+ lhs, _, (id, _line), (op, _), rhs = val
766
778
 
767
779
  result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
768
780
  }
769
781
  | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
770
782
  {
771
- lhs1, _, lhs2, op, rhs = val
783
+ lhs1, _, (lhs2, _line), op, rhs = val
772
784
 
773
785
  lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
774
786
  result = new_const_op_asgn [lhs, op, rhs]
775
787
  }
776
- | tCOLON3 tCONSTANT
788
+ | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
777
789
  {
778
- result = self.lexer.lineno
779
- }
780
- tOP_ASGN arg_rhs
781
- {
782
- _, lhs, line, op, rhs = val
790
+ _, (lhs, line), op, rhs = val
783
791
 
784
792
  lhs = s(:colon3, lhs.to_sym).line line
785
793
  result = new_const_op_asgn [lhs, op, rhs]
@@ -793,7 +801,7 @@ rule
793
801
  | arg tDOT2 arg
794
802
  {
795
803
  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
804
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
797
805
  result = s(:lit, (v1.last)..(v2.last)).line v1.line
798
806
  else
799
807
  result = s(:dot2, v1, v2).line v1.line
@@ -802,7 +810,7 @@ rule
802
810
  | arg tDOT3 arg
803
811
  {
804
812
  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
813
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
806
814
  result = s(:lit, (v1.last)...(v2.last)).line v1.line
807
815
  else
808
816
  result = s(:dot3, v1, v2).line v1.line
@@ -823,20 +831,6 @@ rule
823
831
  result = s(:dot3, v1, v2).line v1.line
824
832
  }
825
833
 
826
- | tBDOT2 arg
827
- {
828
- _, v2, = val
829
- v1 = nil
830
-
831
- result = s(:dot2, v1, v2).line v2.line
832
- }
833
- | tBDOT3 arg
834
- {
835
- _, v2 = val
836
- v1 = nil
837
-
838
- result = s(:dot3, v1, v2).line v2.line
839
- }
840
834
 
841
835
  | arg tPLUS arg
842
836
  {
@@ -864,8 +858,9 @@ rule
864
858
  }
865
859
  | tUMINUS_NUM simple_numeric tPOW arg
866
860
  {
867
- lit = s(:lit, val[1]).line lexer.lineno
868
- result = new_call(new_call(lit, :"**", argl(val[3])), :"-@")
861
+ _, (num, line), _, arg = val
862
+ lit = s(:lit, num).line line
863
+ result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
869
864
 
870
865
  }
871
866
  | tUPLUS arg
@@ -964,12 +959,12 @@ rule
964
959
 
965
960
  rel_expr: arg relop arg =tGT
966
961
  {
967
- lhs, op, rhs = val
962
+ lhs, (op, _), rhs = val
968
963
  result = new_call lhs, op.to_sym, argl(rhs)
969
964
  }
970
965
  | rel_expr relop arg =tGT
971
966
  {
972
- lhs, op, rhs = val
967
+ lhs, (op, _), rhs = val
973
968
  warn "comparison '%s' after comparison", op
974
969
  result = new_call lhs, op.to_sym, argl(rhs)
975
970
  }
@@ -1160,8 +1155,9 @@ rule
1160
1155
  | backref
1161
1156
  | tFID
1162
1157
  {
1163
- msg, = val
1158
+ (msg, line), = val
1164
1159
  result = new_call nil, msg.to_sym
1160
+ result.line line
1165
1161
  }
1166
1162
  | k_begin
1167
1163
  {
@@ -1203,15 +1199,15 @@ rule
1203
1199
  }
1204
1200
  | primary_value tCOLON2 tCONSTANT
1205
1201
  {
1206
- expr, _, id = val
1202
+ expr, _, (id, _line) = val
1207
1203
 
1208
1204
  result = s(:colon2, expr, id.to_sym).line expr.line
1209
1205
  }
1210
1206
  | tCOLON3 tCONSTANT
1211
1207
  {
1212
- _, id = val
1208
+ _, (id, line) = val
1213
1209
 
1214
- result = s(:colon3, id.to_sym).line lexer.lineno
1210
+ result = s(:colon3, id.to_sym).line line
1215
1211
  }
1216
1212
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1217
1213
  {
@@ -1258,7 +1254,7 @@ rule
1258
1254
  }
1259
1255
  | kNOT tLPAREN2 rparen
1260
1256
  {
1261
- debug20 14, val, result
1257
+ debug 20
1262
1258
  }
1263
1259
  | fcall brace_block
1264
1260
  {
@@ -1276,9 +1272,10 @@ rule
1276
1272
  iter.insert 1, call # FIX
1277
1273
  result = iter
1278
1274
  }
1279
- | tLAMBDA lambda
1275
+ | lambda
1280
1276
  {
1281
- result = val[1] # TODO: fix lineno
1277
+ expr, = val
1278
+ result = expr
1282
1279
  }
1283
1280
  | k_if expr_value then compstmt if_tail k_end
1284
1281
  {
@@ -1321,7 +1318,6 @@ rule
1321
1318
  }
1322
1319
  cpath superclass
1323
1320
  {
1324
- self.comments.push self.lexer.comments
1325
1321
  if (self.in_def || self.in_single > 0) then
1326
1322
  yyerror "class definition in method body"
1327
1323
  end
@@ -1331,7 +1327,7 @@ rule
1331
1327
  {
1332
1328
  result = new_class val
1333
1329
  self.env.unextend
1334
- self.lexer.comments # we don't care about comments in the body
1330
+ self.lexer.ignore_body_comments
1335
1331
  }
1336
1332
  | k_class tLSHFT
1337
1333
  {
@@ -1352,7 +1348,7 @@ rule
1352
1348
  {
1353
1349
  result = new_sclass val
1354
1350
  self.env.unextend
1355
- self.lexer.comments # we don't care about comments in the body
1351
+ self.lexer.ignore_body_comments
1356
1352
  }
1357
1353
  | k_module
1358
1354
  {
@@ -1360,7 +1356,6 @@ rule
1360
1356
  }
1361
1357
  cpath
1362
1358
  {
1363
- self.comments.push self.lexer.comments
1364
1359
  yyerror "module definition in method body" if
1365
1360
  self.in_def or self.in_single > 0
1366
1361
 
@@ -1370,7 +1365,7 @@ rule
1370
1365
  {
1371
1366
  result = new_module val
1372
1367
  self.env.unextend
1373
- self.lexer.comments # we don't care about comments in the body
1368
+ self.lexer.ignore_body_comments
1374
1369
  }
1375
1370
  | k_def fname
1376
1371
  {
@@ -1380,21 +1375,17 @@ rule
1380
1375
  self.env.extend
1381
1376
  lexer.cmdarg.push false
1382
1377
  lexer.cond.push false
1383
-
1384
- self.comments.push self.lexer.comments
1385
1378
  }
1386
- f_arglist bodystmt { result = lexer.lineno } k_end
1379
+ f_arglist bodystmt k_end
1387
1380
  {
1388
- in_def = val[2]
1389
-
1390
- result = new_defn val
1381
+ result, in_def = new_defn val
1391
1382
 
1392
1383
  lexer.cond.pop # group = local_pop
1393
1384
  lexer.cmdarg.pop
1394
1385
  self.env.unextend
1395
1386
  self.in_def = in_def
1396
1387
 
1397
- self.lexer.comments # we don't care about comments in the body
1388
+ self.lexer.ignore_body_comments
1398
1389
  }
1399
1390
  | k_def singleton dot_or_colon
1400
1391
  {
@@ -1402,7 +1393,7 @@ rule
1402
1393
  }
1403
1394
  fname
1404
1395
  {
1405
- result = [self.in_def, lexer.lineno]
1396
+ result = self.in_def
1406
1397
 
1407
1398
  self.in_single += 1 # TODO: remove?
1408
1399
 
@@ -1412,13 +1403,18 @@ rule
1412
1403
  lexer.cond.push false
1413
1404
 
1414
1405
  lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
1415
- self.comments.push self.lexer.comments
1416
1406
  }
1417
1407
  f_arglist bodystmt k_end
1418
1408
  {
1419
- _, _recv, _, _, _name, (in_def, _lineno), _args, _body, _ = val
1420
1409
 
1421
- result = new_defs val
1410
+ # [kdef, recv, _, _, (name, line), in_def, args, body, kend]
1411
+ # =>
1412
+ # [kdef, recv, (name, line), in_def, args, body, kend]
1413
+
1414
+ val.delete_at 3
1415
+ val.delete_at 2
1416
+
1417
+ result, in_def = new_defs val
1422
1418
 
1423
1419
  lexer.cond.pop # group = local_pop
1424
1420
  lexer.cmdarg.pop
@@ -1429,7 +1425,7 @@ rule
1429
1425
 
1430
1426
  # TODO: restore cur_arg ? what's cur_arg?
1431
1427
 
1432
- self.lexer.comments # we don't care about comments in the body
1428
+ self.lexer.ignore_body_comments
1433
1429
  }
1434
1430
  | kBREAK
1435
1431
  {
@@ -1466,8 +1462,17 @@ rule
1466
1462
  k_case: kCASE
1467
1463
  k_for: kFOR
1468
1464
  k_class: kCLASS
1465
+ {
1466
+ self.comments.push self.lexer.comments
1467
+ }
1469
1468
  k_module: kMODULE
1469
+ {
1470
+ self.comments.push self.lexer.comments
1471
+ }
1470
1472
  k_def: kDEF
1473
+ {
1474
+ self.comments.push self.lexer.comments
1475
+ }
1471
1476
  k_do: kDO
1472
1477
  k_do_block: kDO_BLOCK
1473
1478
  k_rescue: kRESCUE
@@ -1528,51 +1533,42 @@ rule
1528
1533
 
1529
1534
  result = block_var args
1530
1535
  }
1531
- | f_marg_list tCOMMA tSTAR f_norm_arg
1536
+ | f_marg_list tCOMMA f_rest_marg
1532
1537
  {
1533
- args, _, _, splat = val
1538
+ args, _, rest = val
1534
1539
 
1535
- result = block_var args, "*#{splat}".to_sym
1540
+ result = block_var args, rest
1536
1541
  }
1537
- | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1542
+ | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1538
1543
  {
1539
- args, _, _, splat, _, args2 = val
1544
+ lhs, _, splat, _, rhs = val
1540
1545
 
1541
- result = block_var args, "*#{splat}".to_sym, args2
1546
+ result = block_var lhs, splat, rhs
1542
1547
  }
1543
- | f_marg_list tCOMMA tSTAR
1548
+ | f_rest_marg
1544
1549
  {
1545
- args, _, _ = val
1550
+ rest, = val
1546
1551
 
1547
- result = block_var args, :*
1552
+ result = block_var rest
1548
1553
  }
1549
- | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1554
+ | f_rest_marg tCOMMA f_marg_list
1550
1555
  {
1551
- args, _, _, _, args2 = val
1556
+ splat, _, rest = val
1552
1557
 
1553
- result = block_var args, :*, args2
1558
+ result = block_var splat, rest
1554
1559
  }
1555
- | tSTAR f_norm_arg
1556
- {
1557
- _, splat = val
1558
1560
 
1559
- result = block_var :"*#{splat}"
1560
- }
1561
- | tSTAR f_norm_arg tCOMMA f_marg_list
1561
+ f_rest_marg: tSTAR f_norm_arg
1562
1562
  {
1563
- _, splat, _, args = val
1563
+ _, (id, line) = val
1564
1564
 
1565
- result = block_var :"*#{splat}", args
1565
+ result = args ["*#{id}".to_sym]
1566
+ result.line line
1566
1567
  }
1567
1568
  | tSTAR
1568
1569
  {
1569
- result = block_var :*
1570
- }
1571
- | tSTAR tCOMMA f_marg_list
1572
- {
1573
- _, _, args = val
1574
-
1575
- result = block_var :*, args
1570
+ result = args [:*]
1571
+ result.line lexer.lineno # FIX: tSTAR -> line
1576
1572
  }
1577
1573
 
1578
1574
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -1589,8 +1585,8 @@ rule
1589
1585
  }
1590
1586
  | f_block_arg
1591
1587
  {
1592
- line = lexer.lineno
1593
- result = call_args val # TODO: push line down
1588
+ (id, line), = val
1589
+ result = call_args [id]
1594
1590
  result.line line
1595
1591
  }
1596
1592
 
@@ -1699,13 +1695,13 @@ opt_block_args_tail: tCOMMA block_args_tail
1699
1695
 
1700
1696
  bvar: tIDENTIFIER
1701
1697
  {
1702
- id, = val
1703
- line = lexer.lineno
1698
+ (id, line), = val
1704
1699
  result = s(:shadow, id.to_sym).line line
1705
1700
  }
1706
1701
  | f_bad_arg
1707
1702
 
1708
- lambda: {
1703
+ lambda: tLAMBDA
1704
+ {
1709
1705
  self.env.extend :dynamic
1710
1706
  result = [lexer.lineno, lexer.lpar_beg]
1711
1707
  lexer.paren_nest += 1
@@ -1717,14 +1713,14 @@ opt_block_args_tail: tCOMMA block_args_tail
1717
1713
  }
1718
1714
  lambda_body
1719
1715
  {
1720
- (line, lpar), args, _cmdarg, body = val
1716
+ _, (line, lpar), args, _cmdarg, body = val
1721
1717
  lexer.lpar_beg = lpar
1722
1718
 
1723
1719
  lexer.cmdarg.pop
1724
1720
 
1725
1721
  call = s(:lambda).line line
1726
1722
  result = new_iter call, args, body
1727
- result.line = line
1723
+ result.line line
1728
1724
  self.env.unextend # TODO: dynapush & dynapop
1729
1725
  }
1730
1726
 
@@ -1759,23 +1755,28 @@ opt_block_args_tail: tCOMMA block_args_tail
1759
1755
  ## if (nd_type($1) == NODE_YIELD) {
1760
1756
  ## compile_error(PARSER_ARG "block given to yield");
1761
1757
 
1762
- syntax_error "Both block arg and actual block given." if
1763
- val[0].block_pass?
1758
+ cmd, blk = val
1764
1759
 
1765
- val = invert_block_call val if inverted? val
1760
+ syntax_error "Both block arg and actual block given." if
1761
+ cmd.block_pass?
1766
1762
 
1767
- cmd, blk = val
1763
+ if inverted? val then
1764
+ val = invert_block_call val
1765
+ cmd, blk = val
1766
+ end
1768
1767
 
1769
1768
  result = blk
1770
1769
  result.insert 1, cmd
1771
1770
  }
1772
1771
  | block_call call_op2 operation2 opt_paren_args
1773
1772
  {
1774
- result = new_call val[0], val[2].to_sym, val[3]
1773
+ lhs, _, (id, _line), args = val
1774
+
1775
+ result = new_call lhs, id.to_sym, args
1775
1776
  }
1776
1777
  | block_call call_op2 operation2 opt_paren_args brace_block
1777
1778
  {
1778
- iter1, _, name, args, iter2 = val
1779
+ iter1, _, (name, _line), args, iter2 = val
1779
1780
 
1780
1781
  call = new_call iter1, name.to_sym, args
1781
1782
  iter2.insert 1, call
@@ -1784,7 +1785,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1784
1785
  }
1785
1786
  | block_call call_op2 operation2 command_args do_block
1786
1787
  {
1787
- iter1, _, name, args, iter2 = val
1788
+ iter1, _, (name, _line), args, iter2 = val
1788
1789
 
1789
1790
  call = new_call iter1, name.to_sym, args
1790
1791
  iter2.insert 1, call
@@ -1792,28 +1793,29 @@ opt_block_args_tail: tCOMMA block_args_tail
1792
1793
  result = iter2
1793
1794
  }
1794
1795
 
1795
- method_call: fcall
1796
+ method_call: fcall paren_args
1796
1797
  {
1797
- result = self.lexer.lineno
1798
- }
1799
- paren_args
1800
- {
1801
- call, lineno, args = val
1798
+ call, args = val
1802
1799
 
1803
1800
  result = call.concat args.sexp_body if args
1804
- result.line lineno
1805
1801
  }
1806
1802
  | primary_value call_op operation2 opt_paren_args
1807
1803
  {
1808
- result = new_call val[0], val[2].to_sym, val[3], val[1]
1804
+ recv, call_op, (op, _line), args = val
1805
+
1806
+ result = new_call recv, op.to_sym, args, call_op
1809
1807
  }
1810
1808
  | primary_value tCOLON2 operation2 paren_args
1811
1809
  {
1812
- result = new_call val[0], val[2].to_sym, val[3]
1810
+ recv, _, (op, _line), args = val
1811
+
1812
+ result = new_call recv, op.to_sym, args
1813
1813
  }
1814
1814
  | primary_value tCOLON2 operation3
1815
1815
  {
1816
- result = new_call val[0], val[2].to_sym
1816
+ lhs, _, (id, _line) = val
1817
+
1818
+ result = new_call lhs, id.to_sym
1817
1819
  }
1818
1820
  | primary_value call_op paren_args
1819
1821
  {
@@ -1846,7 +1848,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1846
1848
  _, line, body, _ = val
1847
1849
 
1848
1850
  result = body
1849
- result.line = line
1851
+ result.line line
1850
1852
 
1851
1853
  self.env.unextend
1852
1854
  }
@@ -1860,7 +1862,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1860
1862
  _, line, body, _ = val
1861
1863
 
1862
1864
  result = body
1863
- result.line = line
1865
+ result.line line
1864
1866
 
1865
1867
  self.env.unextend
1866
1868
  }
@@ -1889,14 +1891,39 @@ opt_block_args_tail: tCOMMA block_args_tail
1889
1891
  self.env.unextend
1890
1892
  }
1891
1893
 
1894
+ case_args: arg_value
1895
+ {
1896
+ arg, = val
1897
+
1898
+ result = s(:array, arg).line arg.line
1899
+ }
1900
+ | tSTAR arg_value
1901
+ {
1902
+ _, arg = val
1903
+
1904
+ result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1905
+ }
1906
+ | case_args tCOMMA arg_value
1907
+ {
1908
+ args, _, id = val
1909
+
1910
+ result = self.list_append args, id
1911
+ }
1912
+ | case_args tCOMMA tSTAR arg_value
1913
+ {
1914
+ args, _, _, id = val
1915
+
1916
+ result = self.list_append args, s(:splat, id).line(id.line)
1917
+ }
1918
+
1892
1919
  case_body: k_when
1893
1920
  {
1894
1921
  result = self.lexer.lineno
1895
1922
  }
1896
- args then compstmt cases
1923
+ case_args then compstmt cases
1897
1924
  {
1898
1925
  result = new_when(val[2], val[4])
1899
- result.line = val[1]
1926
+ result.line val[1]
1900
1927
  result << val[5] if val[5]
1901
1928
  }
1902
1929
 
@@ -1942,17 +1969,10 @@ opt_block_args_tail: tCOMMA block_args_tail
1942
1969
 
1943
1970
  literal: numeric
1944
1971
  {
1945
- line = lexer.lineno
1946
- result = s(:lit, val[0])
1947
- result.line = line
1972
+ (lit, line), = val
1973
+ result = s(:lit, lit).line line
1948
1974
  }
1949
1975
  | symbol
1950
- {
1951
- line = lexer.lineno
1952
- result = s(:lit, val[0])
1953
- result.line = line
1954
- }
1955
- | dsym
1956
1976
 
1957
1977
  strings: string
1958
1978
  {
@@ -1963,7 +1983,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1963
1983
 
1964
1984
  string: tCHAR
1965
1985
  {
1966
- debug20 23, val, result
1986
+ debug 37
1967
1987
  }
1968
1988
  | string1
1969
1989
  | string string1
@@ -1973,11 +1993,11 @@ opt_block_args_tail: tCOMMA block_args_tail
1973
1993
 
1974
1994
  string1: tSTRING_BEG string_contents tSTRING_END
1975
1995
  {
1976
- _, str, (_, func) = val
1996
+ (_, line), str, (_, func) = val
1977
1997
 
1978
- str = dedent str if func =~ RubyLexer::STR_FUNC_ICNTNT
1998
+ str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
1979
1999
 
1980
- result = str
2000
+ result = str.line line
1981
2001
  }
1982
2002
  | tSTRING
1983
2003
  {
@@ -1997,11 +2017,15 @@ opt_block_args_tail: tCOMMA block_args_tail
1997
2017
 
1998
2018
  words: tWORDS_BEG tSPACE tSTRING_END
1999
2019
  {
2000
- result = s(:array).line lexer.lineno
2020
+ (_, line), _, _ = val
2021
+
2022
+ result = s(:array).line line
2001
2023
  }
2002
2024
  | tWORDS_BEG word_list tSTRING_END
2003
2025
  {
2004
- result = val[1]
2026
+ (_, line), list, _ = val
2027
+
2028
+ result = list.line line
2005
2029
  }
2006
2030
 
2007
2031
  word_list: none
@@ -2021,18 +2045,20 @@ opt_block_args_tail: tCOMMA block_args_tail
2021
2045
 
2022
2046
  symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2023
2047
  {
2024
- result = s(:array).line lexer.lineno
2048
+ (_, line), _, _ = val
2049
+
2050
+ result = s(:array).line line
2025
2051
  }
2026
- | tSYMBOLS_BEG { result = lexer.lineno } symbol_list tSTRING_END
2052
+ | tSYMBOLS_BEG symbol_list tSTRING_END
2027
2053
  {
2028
- _, line, list, _, = val
2029
- list.line = line
2054
+ (_, line), list, _, = val
2055
+ list.line line
2030
2056
  result = list
2031
2057
  }
2032
2058
 
2033
2059
  symbol_list: none
2034
2060
  {
2035
- result = new_symbol_list.line lexer.lineno
2061
+ result = new_symbol_list
2036
2062
  }
2037
2063
  | symbol_list word tSPACE
2038
2064
  {
@@ -2042,20 +2068,28 @@ opt_block_args_tail: tCOMMA block_args_tail
2042
2068
 
2043
2069
  qwords: tQWORDS_BEG tSPACE tSTRING_END
2044
2070
  {
2045
- result = s(:array).line lexer.lineno
2071
+ (_, line), _, _ = val
2072
+
2073
+ result = s(:array).line line
2046
2074
  }
2047
2075
  | tQWORDS_BEG qword_list tSTRING_END
2048
2076
  {
2049
- result = val[1]
2077
+ (_, line), list, _ = val
2078
+
2079
+ result = list.line line
2050
2080
  }
2051
2081
 
2052
2082
  qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2053
2083
  {
2054
- result = s(:array).line lexer.lineno # FIX
2084
+ (_, line), _, _ = val
2085
+
2086
+ result = s(:array).line line
2055
2087
  }
2056
2088
  | tQSYMBOLS_BEG qsym_list tSTRING_END
2057
2089
  {
2058
- result = val[1]
2090
+ (_, line), list, _ = val
2091
+
2092
+ result = list.line line
2059
2093
  }
2060
2094
 
2061
2095
  qword_list: none
@@ -2078,7 +2112,8 @@ opt_block_args_tail: tCOMMA block_args_tail
2078
2112
 
2079
2113
  string_contents: none
2080
2114
  {
2081
- result = s(:str, "").line lexer.lineno
2115
+ line = prev_value_to_lineno _values.last
2116
+ result = s(:str, +"").line line
2082
2117
  }
2083
2118
  | string_contents string_content
2084
2119
  {
@@ -2153,8 +2188,8 @@ regexp_contents: none
2153
2188
  lexer.brace_nest = brace_nest
2154
2189
  lexer.string_nest = string_nest
2155
2190
 
2156
- lexer.cmdarg.pop
2157
2191
  lexer.cond.pop
2192
+ lexer.cmdarg.pop
2158
2193
 
2159
2194
  lexer.lex_state = oldlex_state
2160
2195
 
@@ -2169,29 +2204,49 @@ regexp_contents: none
2169
2204
  when nil then
2170
2205
  result = s(:evstr).line line
2171
2206
  else
2172
- debug20 25
2207
+ debug 38
2173
2208
  raise "unknown string body: #{stmt.inspect}"
2174
2209
  end
2175
2210
  }
2176
2211
 
2177
- string_dvar: tGVAR { result = s(:gvar, val[0].to_sym).line lexer.lineno }
2178
- | tIVAR { result = s(:ivar, val[0].to_sym).line lexer.lineno }
2179
- | tCVAR { result = s(:cvar, val[0].to_sym).line lexer.lineno }
2212
+ string_dvar: tGVAR
2213
+ {
2214
+ (id, line), = val
2215
+ result = s(:gvar, id.to_sym).line line
2216
+ }
2217
+ | tIVAR
2218
+ {
2219
+ (id, line), = val
2220
+ result = s(:ivar, id.to_sym).line line
2221
+ }
2222
+ | tCVAR
2223
+ {
2224
+ (id, line), = val
2225
+ result = s(:cvar, id.to_sym).line line
2226
+ }
2180
2227
  | backref
2181
2228
 
2182
- symbol: tSYMBEG sym
2229
+ symbol: ssym
2230
+ | dsym
2231
+
2232
+ ssym: tSYMBEG sym
2183
2233
  {
2234
+ _, (id, line) = val
2235
+
2184
2236
  lexer.lex_state = EXPR_END
2185
- result = val[1].to_sym
2237
+ result = s(:lit, id.to_sym).line line
2186
2238
  }
2187
2239
  | tSYMBOL
2188
2240
  {
2189
- result = val[0].to_sym
2241
+ (id, line), = val
2242
+
2243
+ lexer.lex_state = EXPR_END
2244
+ result = s(:lit, id.to_sym).line line
2190
2245
  }
2191
2246
 
2192
2247
  sym: fname | tIVAR | tGVAR | tCVAR
2193
2248
 
2194
- dsym: tSYMBEG xstring_contents tSTRING_END
2249
+ dsym: tSYMBEG string_contents tSTRING_END
2195
2250
  {
2196
2251
  _, result, _ = val
2197
2252
 
@@ -2207,14 +2262,15 @@ regexp_contents: none
2207
2262
  when :evstr then
2208
2263
  result = s(:dsym, "", result).line result.line
2209
2264
  else
2210
- debug20 26, val, result
2265
+ debug 39
2211
2266
  end
2212
2267
  }
2213
2268
 
2214
2269
  numeric: simple_numeric
2215
- | tUMINUS_NUM simple_numeric
2270
+ | tUMINUS_NUM simple_numeric =tLOWEST
2216
2271
  {
2217
- result = -val[1] # TODO: pt_testcase
2272
+ _, (num, line) = val
2273
+ result = [-num, line]
2218
2274
  }
2219
2275
 
2220
2276
  simple_numeric: tINTEGER
@@ -2247,8 +2303,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2247
2303
 
2248
2304
  var_ref: user_variable
2249
2305
  {
2250
- var = val[0]
2306
+ raise "NO: #{val.inspect}" if Sexp === val.first
2307
+ (var, line), = val
2251
2308
  result = Sexp === var ? var : self.gettable(var)
2309
+ result.line line
2252
2310
  }
2253
2311
  | keyword_variable
2254
2312
  {
@@ -2263,11 +2321,19 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2263
2321
  | keyword_variable
2264
2322
  {
2265
2323
  result = self.assignable val[0]
2266
- debug20 29, val, result
2324
+ debug 40
2267
2325
  }
2268
2326
 
2269
- backref: tNTH_REF { result = s(:nth_ref, val[0]).line lexer.lineno }
2270
- | tBACK_REF { result = s(:back_ref, val[0]).line lexer.lineno }
2327
+ backref: tNTH_REF
2328
+ {
2329
+ (ref, line), = val
2330
+ result = s(:nth_ref, ref).line line
2331
+ }
2332
+ | tBACK_REF
2333
+ {
2334
+ (ref, line), = val
2335
+ result = s(:back_ref, ref).line line
2336
+ }
2271
2337
 
2272
2338
  superclass: tLT
2273
2339
  {
@@ -2285,9 +2351,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2285
2351
 
2286
2352
  f_arglist: tLPAREN2 f_args rparen
2287
2353
  {
2288
- result = val[1]
2289
- self.lexer.lex_state = EXPR_BEG
2290
- self.lexer.command_start = true
2354
+ result = end_args val
2291
2355
  }
2292
2356
  | {
2293
2357
  result = self.in_kwarg
@@ -2296,12 +2360,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2296
2360
  }
2297
2361
  f_args term
2298
2362
  {
2299
- kwarg, args, _ = val
2300
-
2301
- self.in_kwarg = kwarg
2302
- result = args
2303
- lexer.lex_state = EXPR_BEG
2304
- lexer.command_start = true
2363
+ result = end_args val
2305
2364
  }
2306
2365
 
2307
2366
  args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -2386,8 +2445,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2386
2445
  |
2387
2446
  {
2388
2447
  result = args val
2448
+ # result.line lexer.lineno
2389
2449
  }
2390
2450
 
2451
+
2391
2452
  f_bad_arg: tCONSTANT
2392
2453
  {
2393
2454
  yyerror "formal argument cannot be a constant"
@@ -2408,10 +2469,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2408
2469
  f_norm_arg: f_bad_arg
2409
2470
  | tIDENTIFIER
2410
2471
  {
2411
- identifier = val[0].to_sym
2472
+ (id, line), = val
2473
+ identifier = id.to_sym
2412
2474
  self.env[identifier] = :lvar
2413
2475
 
2414
- result = identifier
2476
+ result = [identifier, line]
2415
2477
  }
2416
2478
 
2417
2479
  f_arg_asgn: f_norm_arg
@@ -2419,22 +2481,14 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2419
2481
  f_arg_item: f_arg_asgn
2420
2482
  | tLPAREN f_margs rparen
2421
2483
  {
2422
- result = val[1]
2484
+ _, margs, _ = val
2485
+
2486
+ result = margs
2423
2487
  }
2424
2488
 
2425
2489
  f_arg: f_arg_item
2426
2490
  {
2427
- arg, = val
2428
-
2429
- case arg
2430
- when Symbol then
2431
- result = s(:args, arg).line lexer.lineno
2432
- when Sexp then
2433
- result = arg
2434
- else
2435
- debug20 32
2436
- raise "Unknown f_arg type: #{val.inspect}"
2437
- end
2491
+ result = new_arg val
2438
2492
  }
2439
2493
  | f_arg tCOMMA f_arg_item
2440
2494
  {
@@ -2446,7 +2500,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2446
2500
  result = s(:args, list).line list.line
2447
2501
  end
2448
2502
 
2449
- result << item
2503
+ result << (Sexp === item ? item : item.first)
2450
2504
  }
2451
2505
 
2452
2506
  f_label: tLABEL
@@ -2507,26 +2561,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2507
2561
  kwrest_mark: tPOW
2508
2562
  | tDSTAR
2509
2563
 
2564
+
2510
2565
  f_kwrest: kwrest_mark tIDENTIFIER
2511
2566
  {
2512
- name = val[1].to_sym
2513
- self.assignable name
2514
- result = :"**#{name}"
2567
+ _, (id, line) = val
2568
+
2569
+ name = id.to_sym
2570
+ self.assignable [name, line]
2571
+ result = [:"**#{name}", line]
2515
2572
  }
2516
2573
  | kwrest_mark
2517
2574
  {
2518
- result = :"**"
2575
+ id = :"**"
2576
+ self.env[id] = :lvar # TODO: needed?!?
2577
+ result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
2519
2578
  }
2520
2579
 
2521
2580
  f_opt: f_arg_asgn tEQL arg_value
2522
2581
  {
2523
- result = self.assignable val[0], val[2]
2582
+ lhs, _, rhs = val
2583
+ result = self.assignable lhs, rhs
2524
2584
  # TODO: detect duplicate names
2525
2585
  }
2526
2586
 
2527
2587
  f_block_opt: f_arg_asgn tEQL primary_value
2528
2588
  {
2529
- result = self.assignable val[0], val[2]
2589
+ lhs, _, rhs = val
2590
+ result = self.assignable lhs, rhs
2530
2591
  }
2531
2592
 
2532
2593
  f_block_optarg: f_block_opt
@@ -2556,30 +2617,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2556
2617
  f_rest_arg: restarg_mark tIDENTIFIER
2557
2618
  {
2558
2619
  # TODO: differs from parse.y - needs tests
2559
- name = val[1].to_sym
2560
- self.assignable name
2561
- result = :"*#{name}"
2620
+ _, (id, line) = val
2621
+ name = id.to_sym
2622
+ self.assignable [name, line]
2623
+ result = [:"*#{name}", line]
2562
2624
  }
2563
2625
  | restarg_mark
2564
2626
  {
2565
2627
  name = :"*"
2566
2628
  self.env[name] = :lvar
2567
- result = name
2629
+ result = [name, lexer.lineno] # FIX: tSTAR to include lineno
2568
2630
  }
2569
2631
 
2570
2632
  blkarg_mark: tAMPER2 | tAMPER
2571
2633
 
2572
2634
  f_block_arg: blkarg_mark tIDENTIFIER
2573
2635
  {
2574
- identifier = val[1].to_sym
2636
+ _, (id, line) = val
2637
+ identifier = id.to_sym
2575
2638
 
2576
2639
  self.env[identifier] = :lvar
2577
- result = "&#{identifier}".to_sym
2640
+ result = ["&#{identifier}".to_sym, line]
2578
2641
  }
2579
2642
 
2580
2643
  opt_f_block_arg: tCOMMA f_block_arg
2581
2644
  {
2582
- result = val[1]
2645
+ _, arg = val
2646
+ result = arg
2583
2647
  }
2584
2648
  |
2585
2649
  {
@@ -2628,9 +2692,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2628
2692
  }
2629
2693
  | tSTRING_BEG string_contents tLABEL_END arg_value
2630
2694
  {
2631
- _, sym, _, value = val
2695
+ (_, line), sym, _, value = val
2696
+
2632
2697
  sym.sexp_type = :dsym
2633
- result = s(:array, sym, value).line sym.line
2698
+
2699
+ result = s(:array, sym, value).line line
2634
2700
  }
2635
2701
  | tDSTAR arg_value
2636
2702
  {