brakeman 5.1.1 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +18 -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.1}/History.rdoc +88 -0
  50. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/Manifest.txt +3 -0
  51. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/README.rdoc +1 -0
  52. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/compare/normalize.rb +6 -1
  53. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/debugging.md +0 -0
  54. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/gauntlet.md +106 -0
  55. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/rp_extensions.rb +15 -36
  56. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/rp_stringscanner.rb +33 -0
  57. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby20_parser.rb +7128 -0
  58. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby20_parser.y +335 -252
  59. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby21_parser.rb +7182 -0
  60. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby21_parser.y +330 -249
  61. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby22_parser.rb +7228 -0
  62. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby22_parser.y +334 -251
  63. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby23_parser.rb +7237 -0
  64. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0/lib/ruby26_parser.y → ruby_parser-3.18.1/lib/ruby23_parser.y} +336 -276
  65. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby24_parser.rb +7268 -0
  66. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby24_parser.y +334 -251
  67. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby25_parser.rb +7268 -0
  68. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0/lib/ruby30_parser.y → ruby_parser-3.18.1/lib/ruby25_parser.y} +335 -304
  69. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby26_parser.rb +7287 -0
  70. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0/lib/ruby27_parser.y → ruby_parser-3.18.1/lib/ruby26_parser.y} +334 -288
  71. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby27_parser.rb +8517 -0
  72. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0/lib/ruby_parser.yy → ruby_parser-3.18.1/lib/ruby27_parser.y} +906 -380
  73. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby30_parser.rb +8751 -0
  74. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby30_parser.y +3472 -0
  75. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby3_parser.yy +3476 -0
  76. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_lexer.rb +261 -609
  77. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_lexer.rex +27 -20
  78. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_lexer.rex.rb +59 -23
  79. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby_lexer_strings.rb +638 -0
  80. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_parser.rb +0 -0
  81. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby_parser.yy +3487 -0
  82. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_parser_extras.rb +296 -115
  83. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/tools/munge.rb +34 -6
  84. data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/tools/ripper.rb +44 -0
  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/base_check.rb +10 -0
  106. data/lib/brakeman/checks/check_eol_rails.rb +23 -0
  107. data/lib/brakeman/checks/check_eol_ruby.rb +26 -0
  108. data/lib/brakeman/checks/check_json_parsing.rb +1 -1
  109. data/lib/brakeman/checks/check_sql.rb +3 -2
  110. data/lib/brakeman/checks/check_symbol_dos.rb +1 -1
  111. data/lib/brakeman/checks/eol_check.rb +47 -0
  112. data/lib/brakeman/options.rb +8 -0
  113. data/lib/brakeman/processors/alias_processor.rb +7 -1
  114. data/lib/brakeman/processors/gem_processor.rb +3 -0
  115. data/lib/brakeman/processors/haml_template_processor.rb +9 -0
  116. data/lib/brakeman/processors/lib/call_conversion_helper.rb +2 -0
  117. data/lib/brakeman/processors/lib/rails3_route_processor.rb +2 -0
  118. data/lib/brakeman/processors/model_processor.rb +1 -0
  119. data/lib/brakeman/report/ignore/config.rb +1 -1
  120. data/lib/brakeman/report/report_csv.rb +1 -1
  121. data/lib/brakeman/report/report_sarif.rb +1 -1
  122. data/lib/brakeman/report/report_text.rb +1 -1
  123. data/lib/brakeman/scanner.rb +15 -13
  124. data/lib/brakeman/tracker/config.rb +8 -1
  125. data/lib/brakeman/version.rb +1 -1
  126. data/lib/brakeman/warning_codes.rb +2 -0
  127. data/lib/brakeman.rb +2 -2
  128. data/lib/ruby_parser/bm_sexp.rb +11 -1
  129. metadata +105 -99
  130. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/processor_count.rb +0 -42
  131. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/version.rb +0 -3
  132. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/rp_stringscanner.rb +0 -64
  133. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby20_parser.rb +0 -7075
  134. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby21_parser.rb +0 -7148
  135. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby22_parser.rb +0 -7185
  136. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.rb +0 -7199
  137. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.y +0 -2643
  138. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby24_parser.rb +0 -7219
  139. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.rb +0 -7218
  140. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.y +0 -2651
  141. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby26_parser.rb +0 -7240
  142. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby27_parser.rb +0 -7358
  143. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.rb +0 -7358
  144. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/tools/ripper.rb +0 -39
  145. data/bundle/ruby/2.7.0/gems/unicode-display_width-1.7.0/data/display_width.marshal.gz +0 -0
@@ -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
 
24
24
  preclow
@@ -77,7 +77,7 @@ rule
77
77
  | klBEGIN
78
78
  {
79
79
  if (self.in_def || self.in_single > 0) then
80
- debug20 1
80
+ debug 11
81
81
  yyerror "BEGIN in method"
82
82
  end
83
83
  self.env.extend
@@ -102,7 +102,9 @@ rule
102
102
  bodystmt: compstmt opt_rescue k_else
103
103
  {
104
104
  res = _values[-2]
105
- yyerror "else without rescue is useless" unless res
105
+ # TODO: move down to main match so I can just use val
106
+
107
+ warn "else without rescue is useless" unless res
106
108
  }
107
109
  compstmt
108
110
  opt_ensure
@@ -132,7 +134,7 @@ rule
132
134
  | error stmt
133
135
  {
134
136
  result = val[1]
135
- debug20 2, val, result
137
+ debug 12
136
138
  }
137
139
 
138
140
  stmt_or_begin: stmt
@@ -140,6 +142,10 @@ rule
140
142
  {
141
143
  yyerror "BEGIN is permitted only at toplevel"
142
144
  }
145
+ begin_block
146
+ {
147
+ result = val[2] # wtf?
148
+ }
143
149
 
144
150
  stmt: kALIAS fitem
145
151
  {
@@ -152,12 +158,12 @@ rule
152
158
  }
153
159
  | kALIAS tGVAR tGVAR
154
160
  {
155
- (_, line), lhs, rhs = val
161
+ (_, line), (lhs, _), (rhs, _) = val
156
162
  result = s(:valias, lhs.to_sym, rhs.to_sym).line line
157
163
  }
158
164
  | kALIAS tGVAR tBACK_REF
159
165
  {
160
- (_, line), lhs, rhs = val
166
+ (_, line), (lhs, _), (rhs, _) = val
161
167
  result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
162
168
  }
163
169
  | kALIAS tGVAR tNTH_REF
@@ -200,7 +206,7 @@ rule
200
206
  (_, line), _, stmt, _ = val
201
207
 
202
208
  if (self.in_def || self.in_single > 0) then
203
- debug20 3
209
+ debug 13
204
210
  yyerror "END in method; use at_exit"
205
211
  end
206
212
 
@@ -240,32 +246,31 @@ rule
240
246
  }
241
247
  | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
242
248
  {
243
- prim, _, id, opasgn, rhs = val
244
- result = s(:op_asgn, prim, rhs, id.to_sym, opasgn.to_sym)
245
- if val[1] == '&.'
246
- result.sexp_type = :safe_op_asgn
247
- end
248
- result.line = val[0].line
249
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
250
+
251
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
252
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
253
+ result.line prim.line
249
254
  }
250
255
  | primary_value call_op tCONSTANT tOP_ASGN command_rhs
251
256
  {
252
- result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
253
- if val[1] == '&.'
254
- result.sexp_type = :safe_op_asgn
255
- end
256
- result.line = val[0].line
257
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
258
+
259
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
260
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
261
+ result.line prim.line
257
262
  }
258
263
  | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
259
264
  {
260
- lhs1, _, lhs2, op, rhs = val
265
+ lhs1, _, (lhs2, line), (id, _), rhs = val
261
266
 
262
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
267
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
263
268
  }
264
269
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
265
270
  {
266
- lhs1, _, lhs2, op, rhs = val
271
+ lhs1, _, (lhs2, line), (id, _), rhs = val
267
272
 
268
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
273
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
269
274
  }
270
275
  | backref tOP_ASGN command_rhs
271
276
  {
@@ -303,7 +308,7 @@ rule
303
308
  # TODO: fix line number to tBANG... but causes BAD shift/reduce conflict
304
309
  # REFACTOR: call_uni_op -- see parse26.y
305
310
  }
306
- | arg
311
+ | arg =tLBRACE_ARG
307
312
 
308
313
  expr_value: expr
309
314
  {
@@ -328,7 +333,7 @@ rule
328
333
  block_command: block_call
329
334
  | block_call call_op2 operation2 command_args
330
335
  {
331
- blk, _, msg, args = val
336
+ blk, _, (msg, _line), args = val
332
337
  result = new_call(blk, msg.to_sym, args).line blk.line
333
338
  }
334
339
 
@@ -342,15 +347,15 @@ rule
342
347
  _, line, body, _ = val
343
348
 
344
349
  result = body
345
- result.line = line
350
+ result.line line
346
351
 
347
352
  # self.env.unextend
348
353
  }
349
354
 
350
355
  fcall: operation
351
356
  {
352
- msg, = val
353
- result = new_call(nil, msg.to_sym).line lexer.lineno
357
+ (msg, line), = val
358
+ result = new_call(nil, msg.to_sym).line line
354
359
  }
355
360
 
356
361
  command: fcall command_args =tLOWEST
@@ -373,12 +378,14 @@ rule
373
378
  }
374
379
  | primary_value call_op operation2 command_args =tLOWEST
375
380
  {
376
- lhs, callop, op, args = val
381
+ lhs, callop, (op, _), args = val
382
+
377
383
  result = new_call lhs, op.to_sym, args, callop
384
+ result.line lhs.line
378
385
  }
379
386
  | primary_value call_op operation2 command_args cmd_brace_block
380
387
  {
381
- recv, _, msg, args, block = val
388
+ recv, _, (msg, _line), args, block = val
382
389
  call = new_call recv, msg.to_sym, args, val[1]
383
390
 
384
391
  block_dup_check call, block
@@ -388,11 +395,14 @@ rule
388
395
  }
389
396
  | primary_value tCOLON2 operation2 command_args =tLOWEST
390
397
  {
391
- result = new_call val[0], val[2].to_sym, val[3]
398
+ lhs, _, (id, line), args = val
399
+
400
+ result = new_call lhs, id.to_sym, args
401
+ result.line line
392
402
  }
393
403
  | primary_value tCOLON2 operation2 command_args cmd_brace_block
394
404
  {
395
- recv, _, msg, args, block = val
405
+ recv, _, (msg, _line), args, block = val
396
406
  call = new_call recv, msg.to_sym, args
397
407
 
398
408
  block_dup_check call, block
@@ -550,25 +560,29 @@ rule
550
560
  }
551
561
  | primary_value call_op tIDENTIFIER
552
562
  {
553
- result = new_attrasgn val[0], val[2], val[1]
563
+ lhs, call_op, (id, _line) = val
564
+
565
+ result = new_attrasgn lhs, id, call_op
554
566
  }
555
567
  | primary_value tCOLON2 tIDENTIFIER
556
568
  {
557
- recv, _, id = val
569
+ recv, _, (id, _line) = val
558
570
  result = new_attrasgn recv, id
559
571
  }
560
572
  | primary_value call_op tCONSTANT
561
573
  {
562
- 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
563
577
  }
564
578
  | primary_value tCOLON2 tCONSTANT
565
579
  {
566
580
  if (self.in_def || self.in_single > 0) then
567
- debug20 7
581
+ debug 14
568
582
  yyerror "dynamic constant assignment"
569
583
  end
570
584
 
571
- expr, _, id = val
585
+ expr, _, (id, _line) = val
572
586
  l = expr.line
573
587
 
574
588
  result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
@@ -576,58 +590,65 @@ rule
576
590
  | tCOLON3 tCONSTANT
577
591
  {
578
592
  if (self.in_def || self.in_single > 0) then
579
- debug20 8
593
+ debug 15
580
594
  yyerror "dynamic constant assignment"
581
595
  end
582
596
 
583
- _, id = val
584
- l = lexer.lineno
597
+ _, (id, l) = val
585
598
 
586
599
  result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
587
600
  }
588
601
  | backref
589
602
  {
590
- self.backref_assign_error val[0]
603
+ ref, = val
604
+
605
+ self.backref_assign_error ref
591
606
  }
592
607
 
593
608
  lhs: user_variable
594
609
  {
595
- line = lexer.lineno
596
- result = self.assignable val[0]
597
- result.line = line
610
+ var, = val
611
+
612
+ result = self.assignable var
598
613
  }
599
614
  | keyword_variable
600
615
  {
601
- line = lexer.lineno
602
- result = self.assignable val[0]
603
- result.line = line
604
- debug20 9, val, result
616
+ var, = val
617
+
618
+ result = self.assignable var
619
+
620
+ debug 16
605
621
  }
606
622
  | primary_value tLBRACK2 opt_call_args rbracket
607
623
  {
608
624
  lhs, _, args, _ = val
625
+
609
626
  result = self.aryset lhs, args
610
627
  }
611
628
  | primary_value call_op tIDENTIFIER # REFACTOR
612
629
  {
613
- lhs, op, id = val
630
+ lhs, op, (id, _line) = val
631
+
614
632
  result = new_attrasgn lhs, id, op
615
633
  }
616
634
  | primary_value tCOLON2 tIDENTIFIER
617
635
  {
618
- lhs, _, id = val
636
+ lhs, _, (id, _line) = val
637
+
619
638
  result = new_attrasgn lhs, id
620
639
  }
621
640
  | primary_value call_op tCONSTANT # REFACTOR?
622
641
  {
623
- result = new_attrasgn val[0], val[2], val[1]
642
+ lhs, call_op, (id, _line) = val
643
+
644
+ result = new_attrasgn lhs, id, call_op
624
645
  }
625
646
  | primary_value tCOLON2 tCONSTANT
626
647
  {
627
- expr, _, id = val
648
+ expr, _, (id, _line) = val
628
649
 
629
650
  if (self.in_def || self.in_single > 0) then
630
- debug20 10
651
+ debug 17
631
652
  yyerror "dynamic constant assignment"
632
653
  end
633
654
 
@@ -636,14 +657,13 @@ rule
636
657
  }
637
658
  | tCOLON3 tCONSTANT
638
659
  {
639
- _, id = val
660
+ _, (id, l) = val
640
661
 
641
662
  if (self.in_def || self.in_single > 0) then
642
- debug20 11
663
+ debug 18
643
664
  yyerror "dynamic constant assignment"
644
665
  end
645
666
 
646
- l = lexer.lineno
647
667
  result = s(:const, s(:colon3, id.to_sym).line(l)).line l
648
668
  }
649
669
  | backref
@@ -659,16 +679,17 @@ rule
659
679
 
660
680
  cpath: tCOLON3 cname
661
681
  {
662
- _, name = val
663
- result = s(:colon3, name.to_sym).line lexer.lineno
682
+ _, (name, line) = val
683
+ result = s(:colon3, name.to_sym).line line
664
684
  }
665
685
  | cname
666
686
  {
667
- result = val[0].to_sym
687
+ (id, line), = val
688
+ result = [id.to_sym, line] # TODO: sexp?
668
689
  }
669
690
  | primary_value tCOLON2 cname
670
691
  {
671
- pval, _, name = val
692
+ pval, _, (name, _line) = val
672
693
 
673
694
  result = s(:colon2, pval, name.to_sym)
674
695
  result.line pval.line
@@ -678,24 +699,17 @@ rule
678
699
  | op
679
700
  {
680
701
  lexer.lex_state = EXPR_END
681
- result = val[0]
682
702
  }
683
703
 
684
704
  | reswords
685
- {
686
- (sym, _line), = val
687
- lexer.lex_state = EXPR_END
688
- result = sym
689
- }
690
-
691
- fsym: fname | symbol
692
705
 
693
- fitem: fsym
706
+ fitem: fname
694
707
  {
695
- id, = val
696
- result = s(:lit, id.to_sym).line lexer.lineno
708
+ (id, line), = val
709
+
710
+ result = s(:lit, id.to_sym).line line
697
711
  }
698
- | dsym
712
+ | symbol
699
713
 
700
714
  undef_list: fitem
701
715
  {
@@ -716,8 +730,6 @@ rule
716
730
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
717
731
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
718
732
  | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
719
- # TODO: tUBANG dead?
720
- | tUBANG
721
733
 
722
734
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
723
735
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -751,24 +763,20 @@ rule
751
763
  }
752
764
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
753
765
  {
754
- lhs, _, id, op, rhs = val
766
+ lhs, _, (id, _line), (op, _), rhs = val
755
767
 
756
768
  result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
757
769
  }
758
770
  | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
759
771
  {
760
- lhs1, _, lhs2, op, rhs = val
772
+ lhs1, _, (lhs2, _line), op, rhs = val
761
773
 
762
774
  lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
763
775
  result = new_const_op_asgn [lhs, op, rhs]
764
776
  }
765
- | tCOLON3 tCONSTANT
766
- {
767
- result = self.lexer.lineno
768
- }
769
- tOP_ASGN arg_rhs
777
+ | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
770
778
  {
771
- _, lhs, line, op, rhs = val
779
+ _, (lhs, line), op, rhs = val
772
780
 
773
781
  lhs = s(:colon3, lhs.to_sym).line line
774
782
  result = new_const_op_asgn [lhs, op, rhs]
@@ -782,7 +790,7 @@ rule
782
790
  | arg tDOT2 arg
783
791
  {
784
792
  v1, v2 = val[0], val[2]
785
- if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
793
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
786
794
  result = s(:lit, (v1.last)..(v2.last)).line v1.line
787
795
  else
788
796
  result = s(:dot2, v1, v2).line v1.line
@@ -791,7 +799,7 @@ rule
791
799
  | arg tDOT3 arg
792
800
  {
793
801
  v1, v2 = val[0], val[2]
794
- if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
802
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
795
803
  result = s(:lit, (v1.last)...(v2.last)).line v1.line
796
804
  else
797
805
  result = s(:dot3, v1, v2).line v1.line
@@ -825,8 +833,9 @@ rule
825
833
  }
826
834
  | tUMINUS_NUM simple_numeric tPOW arg
827
835
  {
828
- lit = s(:lit, val[1]).line lexer.lineno
829
- result = new_call(new_call(lit, :"**", argl(val[3])), :"-@")
836
+ _, (num, line), _, arg = val
837
+ lit = s(:lit, num).line line
838
+ result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
830
839
 
831
840
  }
832
841
  | tUPLUS arg
@@ -925,12 +934,12 @@ rule
925
934
 
926
935
  rel_expr: arg relop arg =tGT
927
936
  {
928
- lhs, op, rhs = val
937
+ lhs, (op, _), rhs = val
929
938
  result = new_call lhs, op.to_sym, argl(rhs)
930
939
  }
931
940
  | rel_expr relop arg =tGT
932
941
  {
933
- lhs, op, rhs = val
942
+ lhs, (op, _), rhs = val
934
943
  warn "comparison '%s' after comparison", op
935
944
  result = new_call lhs, op.to_sym, argl(rhs)
936
945
  }
@@ -1121,8 +1130,9 @@ rule
1121
1130
  | backref
1122
1131
  | tFID
1123
1132
  {
1124
- msg, = val
1133
+ (msg, line), = val
1125
1134
  result = new_call nil, msg.to_sym
1135
+ result.line line
1126
1136
  }
1127
1137
  | k_begin
1128
1138
  {
@@ -1164,15 +1174,15 @@ rule
1164
1174
  }
1165
1175
  | primary_value tCOLON2 tCONSTANT
1166
1176
  {
1167
- expr, _, id = val
1177
+ expr, _, (id, _line) = val
1168
1178
 
1169
1179
  result = s(:colon2, expr, id.to_sym).line expr.line
1170
1180
  }
1171
1181
  | tCOLON3 tCONSTANT
1172
1182
  {
1173
- _, id = val
1183
+ _, (id, line) = val
1174
1184
 
1175
- result = s(:colon3, id.to_sym).line lexer.lineno
1185
+ result = s(:colon3, id.to_sym).line line
1176
1186
  }
1177
1187
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1178
1188
  {
@@ -1196,15 +1206,21 @@ rule
1196
1206
  }
1197
1207
  | kYIELD tLPAREN2 call_args rparen
1198
1208
  {
1199
- result = new_yield val[2]
1209
+ (_, line), _, args, _ = val
1210
+
1211
+ result = new_yield(args).line line
1200
1212
  }
1201
1213
  | kYIELD tLPAREN2 rparen
1202
1214
  {
1203
- result = new_yield
1215
+ (_, line), _, _ = val
1216
+
1217
+ result = new_yield.line line
1204
1218
  }
1205
1219
  | kYIELD
1206
1220
  {
1207
- result = new_yield
1221
+ (_, line), = val
1222
+
1223
+ result = new_yield.line line
1208
1224
  }
1209
1225
  | kDEFINED opt_nl tLPAREN2 expr rparen
1210
1226
  {
@@ -1219,7 +1235,7 @@ rule
1219
1235
  }
1220
1236
  | kNOT tLPAREN2 rparen
1221
1237
  {
1222
- debug20 14, val, result
1238
+ debug 20
1223
1239
  }
1224
1240
  | fcall brace_block
1225
1241
  {
@@ -1237,9 +1253,10 @@ rule
1237
1253
  iter.insert 1, call # FIX
1238
1254
  result = iter
1239
1255
  }
1240
- | tLAMBDA lambda
1256
+ | lambda
1241
1257
  {
1242
- result = val[1] # TODO: fix lineno
1258
+ expr, = val
1259
+ result = expr
1243
1260
  }
1244
1261
  | k_if expr_value then compstmt if_tail k_end
1245
1262
  {
@@ -1282,7 +1299,6 @@ rule
1282
1299
  }
1283
1300
  cpath superclass
1284
1301
  {
1285
- self.comments.push self.lexer.comments
1286
1302
  if (self.in_def || self.in_single > 0) then
1287
1303
  yyerror "class definition in method body"
1288
1304
  end
@@ -1292,7 +1308,7 @@ rule
1292
1308
  {
1293
1309
  result = new_class val
1294
1310
  self.env.unextend
1295
- self.lexer.comments # we don't care about comments in the body
1311
+ self.lexer.ignore_body_comments
1296
1312
  }
1297
1313
  | k_class tLSHFT
1298
1314
  {
@@ -1313,7 +1329,7 @@ rule
1313
1329
  {
1314
1330
  result = new_sclass val
1315
1331
  self.env.unextend
1316
- self.lexer.comments # we don't care about comments in the body
1332
+ self.lexer.ignore_body_comments
1317
1333
  }
1318
1334
  | k_module
1319
1335
  {
@@ -1321,7 +1337,6 @@ rule
1321
1337
  }
1322
1338
  cpath
1323
1339
  {
1324
- self.comments.push self.lexer.comments
1325
1340
  yyerror "module definition in method body" if
1326
1341
  self.in_def or self.in_single > 0
1327
1342
 
@@ -1331,7 +1346,7 @@ rule
1331
1346
  {
1332
1347
  result = new_module val
1333
1348
  self.env.unextend
1334
- self.lexer.comments # we don't care about comments in the body
1349
+ self.lexer.ignore_body_comments
1335
1350
  }
1336
1351
  | k_def fname
1337
1352
  {
@@ -1341,21 +1356,17 @@ rule
1341
1356
  self.env.extend
1342
1357
  lexer.cmdarg.push false
1343
1358
  lexer.cond.push false
1344
-
1345
- self.comments.push self.lexer.comments
1346
1359
  }
1347
- f_arglist bodystmt { result = lexer.lineno } k_end
1360
+ f_arglist bodystmt k_end
1348
1361
  {
1349
- in_def = val[2]
1350
-
1351
- result = new_defn val
1362
+ result, in_def = new_defn val
1352
1363
 
1353
1364
  lexer.cond.pop # group = local_pop
1354
1365
  lexer.cmdarg.pop
1355
1366
  self.env.unextend
1356
1367
  self.in_def = in_def
1357
1368
 
1358
- self.lexer.comments # we don't care about comments in the body
1369
+ self.lexer.ignore_body_comments
1359
1370
  }
1360
1371
  | k_def singleton dot_or_colon
1361
1372
  {
@@ -1363,7 +1374,7 @@ rule
1363
1374
  }
1364
1375
  fname
1365
1376
  {
1366
- result = [self.in_def, lexer.lineno]
1377
+ result = self.in_def
1367
1378
 
1368
1379
  self.in_single += 1 # TODO: remove?
1369
1380
 
@@ -1373,13 +1384,18 @@ rule
1373
1384
  lexer.cond.push false
1374
1385
 
1375
1386
  lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
1376
- self.comments.push self.lexer.comments
1377
1387
  }
1378
1388
  f_arglist bodystmt k_end
1379
1389
  {
1380
- _, _recv, _, _, _name, (in_def, _lineno), _args, _body, _ = val
1381
1390
 
1382
- result = new_defs val
1391
+ # [kdef, recv, _, _, (name, line), in_def, args, body, kend]
1392
+ # =>
1393
+ # [kdef, recv, (name, line), in_def, args, body, kend]
1394
+
1395
+ val.delete_at 3
1396
+ val.delete_at 2
1397
+
1398
+ result, in_def = new_defs val
1383
1399
 
1384
1400
  lexer.cond.pop # group = local_pop
1385
1401
  lexer.cmdarg.pop
@@ -1390,7 +1406,7 @@ rule
1390
1406
 
1391
1407
  # TODO: restore cur_arg ? what's cur_arg?
1392
1408
 
1393
- self.lexer.comments # we don't care about comments in the body
1409
+ self.lexer.ignore_body_comments
1394
1410
  }
1395
1411
  | kBREAK
1396
1412
  {
@@ -1427,8 +1443,17 @@ rule
1427
1443
  k_case: kCASE
1428
1444
  k_for: kFOR
1429
1445
  k_class: kCLASS
1446
+ {
1447
+ self.comments.push self.lexer.comments
1448
+ }
1430
1449
  k_module: kMODULE
1450
+ {
1451
+ self.comments.push self.lexer.comments
1452
+ }
1431
1453
  k_def: kDEF
1454
+ {
1455
+ self.comments.push self.lexer.comments
1456
+ }
1432
1457
  k_do: kDO
1433
1458
  k_do_block: kDO_BLOCK
1434
1459
  k_rescue: kRESCUE
@@ -1489,51 +1514,42 @@ rule
1489
1514
 
1490
1515
  result = block_var args
1491
1516
  }
1492
- | f_marg_list tCOMMA tSTAR f_norm_arg
1517
+ | f_marg_list tCOMMA f_rest_marg
1493
1518
  {
1494
- args, _, _, splat = val
1519
+ args, _, rest = val
1495
1520
 
1496
- result = block_var args, "*#{splat}".to_sym
1521
+ result = block_var args, rest
1497
1522
  }
1498
- | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1523
+ | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1499
1524
  {
1500
- args, _, _, splat, _, args2 = val
1525
+ lhs, _, splat, _, rhs = val
1501
1526
 
1502
- result = block_var args, "*#{splat}".to_sym, args2
1527
+ result = block_var lhs, splat, rhs
1503
1528
  }
1504
- | f_marg_list tCOMMA tSTAR
1529
+ | f_rest_marg
1505
1530
  {
1506
- args, _, _ = val
1531
+ rest, = val
1507
1532
 
1508
- result = block_var args, :*
1533
+ result = block_var rest
1509
1534
  }
1510
- | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1535
+ | f_rest_marg tCOMMA f_marg_list
1511
1536
  {
1512
- args, _, _, _, args2 = val
1537
+ splat, _, rest = val
1513
1538
 
1514
- result = block_var args, :*, args2
1539
+ result = block_var splat, rest
1515
1540
  }
1516
- | tSTAR f_norm_arg
1517
- {
1518
- _, splat = val
1519
1541
 
1520
- result = block_var :"*#{splat}"
1521
- }
1522
- | tSTAR f_norm_arg tCOMMA f_marg_list
1542
+ f_rest_marg: tSTAR f_norm_arg
1523
1543
  {
1524
- _, splat, _, args = val
1544
+ _, (id, line) = val
1525
1545
 
1526
- result = block_var :"*#{splat}", args
1546
+ result = args ["*#{id}".to_sym]
1547
+ result.line line
1527
1548
  }
1528
1549
  | tSTAR
1529
1550
  {
1530
- result = block_var :*
1531
- }
1532
- | tSTAR tCOMMA f_marg_list
1533
- {
1534
- _, _, args = val
1535
-
1536
- result = block_var :*, args
1551
+ result = args [:*]
1552
+ result.line lexer.lineno # FIX: tSTAR -> line
1537
1553
  }
1538
1554
 
1539
1555
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -1550,8 +1566,8 @@ rule
1550
1566
  }
1551
1567
  | f_block_arg
1552
1568
  {
1553
- line = lexer.lineno
1554
- result = call_args val # TODO: push line down
1569
+ (id, line), = val
1570
+ result = call_args [id]
1555
1571
  result.line line
1556
1572
  }
1557
1573
 
@@ -1660,13 +1676,13 @@ opt_block_args_tail: tCOMMA block_args_tail
1660
1676
 
1661
1677
  bvar: tIDENTIFIER
1662
1678
  {
1663
- id, = val
1664
- line = lexer.lineno
1679
+ (id, line), = val
1665
1680
  result = s(:shadow, id.to_sym).line line
1666
1681
  }
1667
1682
  | f_bad_arg
1668
1683
 
1669
- lambda: {
1684
+ lambda: tLAMBDA
1685
+ {
1670
1686
  self.env.extend :dynamic
1671
1687
  result = [lexer.lineno, lexer.lpar_beg]
1672
1688
  lexer.paren_nest += 1
@@ -1678,14 +1694,14 @@ opt_block_args_tail: tCOMMA block_args_tail
1678
1694
  }
1679
1695
  lambda_body
1680
1696
  {
1681
- (line, lpar), args, _cmdarg, body = val
1697
+ _, (line, lpar), args, _cmdarg, body = val
1682
1698
  lexer.lpar_beg = lpar
1683
1699
 
1684
1700
  lexer.cmdarg.pop
1685
1701
 
1686
1702
  call = s(:lambda).line line
1687
1703
  result = new_iter call, args, body
1688
- result.line = line
1704
+ result.line line
1689
1705
  self.env.unextend # TODO: dynapush & dynapop
1690
1706
  }
1691
1707
 
@@ -1720,23 +1736,28 @@ opt_block_args_tail: tCOMMA block_args_tail
1720
1736
  ## if (nd_type($1) == NODE_YIELD) {
1721
1737
  ## compile_error(PARSER_ARG "block given to yield");
1722
1738
 
1723
- syntax_error "Both block arg and actual block given." if
1724
- val[0].block_pass?
1739
+ cmd, blk = val
1725
1740
 
1726
- val = invert_block_call val if inverted? val
1741
+ syntax_error "Both block arg and actual block given." if
1742
+ cmd.block_pass?
1727
1743
 
1728
- cmd, blk = val
1744
+ if inverted? val then
1745
+ val = invert_block_call val
1746
+ cmd, blk = val
1747
+ end
1729
1748
 
1730
1749
  result = blk
1731
1750
  result.insert 1, cmd
1732
1751
  }
1733
1752
  | block_call call_op2 operation2 opt_paren_args
1734
1753
  {
1735
- result = new_call val[0], val[2].to_sym, val[3]
1754
+ lhs, _, (id, _line), args = val
1755
+
1756
+ result = new_call lhs, id.to_sym, args
1736
1757
  }
1737
1758
  | block_call call_op2 operation2 opt_paren_args brace_block
1738
1759
  {
1739
- iter1, _, name, args, iter2 = val
1760
+ iter1, _, (name, _line), args, iter2 = val
1740
1761
 
1741
1762
  call = new_call iter1, name.to_sym, args
1742
1763
  iter2.insert 1, call
@@ -1745,7 +1766,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1745
1766
  }
1746
1767
  | block_call call_op2 operation2 command_args do_block
1747
1768
  {
1748
- iter1, _, name, args, iter2 = val
1769
+ iter1, _, (name, _line), args, iter2 = val
1749
1770
 
1750
1771
  call = new_call iter1, name.to_sym, args
1751
1772
  iter2.insert 1, call
@@ -1753,28 +1774,29 @@ opt_block_args_tail: tCOMMA block_args_tail
1753
1774
  result = iter2
1754
1775
  }
1755
1776
 
1756
- method_call: fcall
1777
+ method_call: fcall paren_args
1757
1778
  {
1758
- result = self.lexer.lineno
1759
- }
1760
- paren_args
1761
- {
1762
- call, lineno, args = val
1779
+ call, args = val
1763
1780
 
1764
1781
  result = call.concat args.sexp_body if args
1765
- result.line lineno
1766
1782
  }
1767
1783
  | primary_value call_op operation2 opt_paren_args
1768
1784
  {
1769
- result = new_call val[0], val[2].to_sym, val[3], val[1]
1785
+ recv, call_op, (op, _line), args = val
1786
+
1787
+ result = new_call recv, op.to_sym, args, call_op
1770
1788
  }
1771
1789
  | primary_value tCOLON2 operation2 paren_args
1772
1790
  {
1773
- result = new_call val[0], val[2].to_sym, val[3]
1791
+ recv, _, (op, _line), args = val
1792
+
1793
+ result = new_call recv, op.to_sym, args
1774
1794
  }
1775
1795
  | primary_value tCOLON2 operation3
1776
1796
  {
1777
- result = new_call val[0], val[2].to_sym
1797
+ lhs, _, (id, _line) = val
1798
+
1799
+ result = new_call lhs, id.to_sym
1778
1800
  }
1779
1801
  | primary_value call_op paren_args
1780
1802
  {
@@ -1807,7 +1829,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1807
1829
  _, line, body, _ = val
1808
1830
 
1809
1831
  result = body
1810
- result.line = line
1832
+ result.line line
1811
1833
 
1812
1834
  self.env.unextend
1813
1835
  }
@@ -1821,7 +1843,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1821
1843
  _, line, body, _ = val
1822
1844
 
1823
1845
  result = body
1824
- result.line = line
1846
+ result.line line
1825
1847
 
1826
1848
  self.env.unextend
1827
1849
  }
@@ -1850,14 +1872,39 @@ opt_block_args_tail: tCOMMA block_args_tail
1850
1872
  self.env.unextend
1851
1873
  }
1852
1874
 
1875
+ case_args: arg_value
1876
+ {
1877
+ arg, = val
1878
+
1879
+ result = s(:array, arg).line arg.line
1880
+ }
1881
+ | tSTAR arg_value
1882
+ {
1883
+ _, arg = val
1884
+
1885
+ result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1886
+ }
1887
+ | case_args tCOMMA arg_value
1888
+ {
1889
+ args, _, id = val
1890
+
1891
+ result = self.list_append args, id
1892
+ }
1893
+ | case_args tCOMMA tSTAR arg_value
1894
+ {
1895
+ args, _, _, id = val
1896
+
1897
+ result = self.list_append args, s(:splat, id).line(id.line)
1898
+ }
1899
+
1853
1900
  case_body: k_when
1854
1901
  {
1855
1902
  result = self.lexer.lineno
1856
1903
  }
1857
- args then compstmt cases
1904
+ case_args then compstmt cases
1858
1905
  {
1859
1906
  result = new_when(val[2], val[4])
1860
- result.line = val[1]
1907
+ result.line val[1]
1861
1908
  result << val[5] if val[5]
1862
1909
  }
1863
1910
 
@@ -1903,17 +1950,10 @@ opt_block_args_tail: tCOMMA block_args_tail
1903
1950
 
1904
1951
  literal: numeric
1905
1952
  {
1906
- line = lexer.lineno
1907
- result = s(:lit, val[0])
1908
- result.line = line
1953
+ (lit, line), = val
1954
+ result = s(:lit, lit).line line
1909
1955
  }
1910
1956
  | symbol
1911
- {
1912
- line = lexer.lineno
1913
- result = s(:lit, val[0])
1914
- result.line = line
1915
- }
1916
- | dsym
1917
1957
 
1918
1958
  strings: string
1919
1959
  {
@@ -1924,7 +1964,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1924
1964
 
1925
1965
  string: tCHAR
1926
1966
  {
1927
- debug20 23, val, result
1967
+ debug 37
1928
1968
  }
1929
1969
  | string1
1930
1970
  | string string1
@@ -1934,11 +1974,11 @@ opt_block_args_tail: tCOMMA block_args_tail
1934
1974
 
1935
1975
  string1: tSTRING_BEG string_contents tSTRING_END
1936
1976
  {
1937
- _, str, (_, func) = val
1977
+ (_, line), str, (_, func) = val
1938
1978
 
1939
- str = dedent str if func =~ RubyLexer::STR_FUNC_ICNTNT
1979
+ str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
1940
1980
 
1941
- result = str
1981
+ result = str.line line
1942
1982
  }
1943
1983
  | tSTRING
1944
1984
  {
@@ -1958,11 +1998,15 @@ opt_block_args_tail: tCOMMA block_args_tail
1958
1998
 
1959
1999
  words: tWORDS_BEG tSPACE tSTRING_END
1960
2000
  {
1961
- result = s(:array).line lexer.lineno
2001
+ (_, line), _, _ = val
2002
+
2003
+ result = s(:array).line line
1962
2004
  }
1963
2005
  | tWORDS_BEG word_list tSTRING_END
1964
2006
  {
1965
- result = val[1]
2007
+ (_, line), list, _ = val
2008
+
2009
+ result = list.line line
1966
2010
  }
1967
2011
 
1968
2012
  word_list: none
@@ -1982,18 +2026,20 @@ opt_block_args_tail: tCOMMA block_args_tail
1982
2026
 
1983
2027
  symbols: tSYMBOLS_BEG tSPACE tSTRING_END
1984
2028
  {
1985
- result = s(:array).line lexer.lineno
2029
+ (_, line), _, _ = val
2030
+
2031
+ result = s(:array).line line
1986
2032
  }
1987
- | tSYMBOLS_BEG { result = lexer.lineno } symbol_list tSTRING_END
2033
+ | tSYMBOLS_BEG symbol_list tSTRING_END
1988
2034
  {
1989
- _, line, list, _, = val
1990
- list.line = line
2035
+ (_, line), list, _, = val
2036
+ list.line line
1991
2037
  result = list
1992
2038
  }
1993
2039
 
1994
2040
  symbol_list: none
1995
2041
  {
1996
- result = new_symbol_list.line lexer.lineno
2042
+ result = new_symbol_list
1997
2043
  }
1998
2044
  | symbol_list word tSPACE
1999
2045
  {
@@ -2003,20 +2049,28 @@ opt_block_args_tail: tCOMMA block_args_tail
2003
2049
 
2004
2050
  qwords: tQWORDS_BEG tSPACE tSTRING_END
2005
2051
  {
2006
- result = s(:array).line lexer.lineno
2052
+ (_, line), _, _ = val
2053
+
2054
+ result = s(:array).line line
2007
2055
  }
2008
2056
  | tQWORDS_BEG qword_list tSTRING_END
2009
2057
  {
2010
- result = val[1]
2058
+ (_, line), list, _ = val
2059
+
2060
+ result = list.line line
2011
2061
  }
2012
2062
 
2013
2063
  qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2014
2064
  {
2015
- result = s(:array).line lexer.lineno # FIX
2065
+ (_, line), _, _ = val
2066
+
2067
+ result = s(:array).line line
2016
2068
  }
2017
2069
  | tQSYMBOLS_BEG qsym_list tSTRING_END
2018
2070
  {
2019
- result = val[1]
2071
+ (_, line), list, _ = val
2072
+
2073
+ result = list.line line
2020
2074
  }
2021
2075
 
2022
2076
  qword_list: none
@@ -2039,7 +2093,8 @@ opt_block_args_tail: tCOMMA block_args_tail
2039
2093
 
2040
2094
  string_contents: none
2041
2095
  {
2042
- result = s(:str, "").line lexer.lineno
2096
+ line = prev_value_to_lineno _values.last
2097
+ result = s(:str, +"").line line
2043
2098
  }
2044
2099
  | string_contents string_content
2045
2100
  {
@@ -2114,8 +2169,8 @@ regexp_contents: none
2114
2169
  lexer.brace_nest = brace_nest
2115
2170
  lexer.string_nest = string_nest
2116
2171
 
2117
- lexer.cmdarg.pop
2118
2172
  lexer.cond.pop
2173
+ lexer.cmdarg.pop
2119
2174
 
2120
2175
  lexer.lex_state = oldlex_state
2121
2176
 
@@ -2130,29 +2185,49 @@ regexp_contents: none
2130
2185
  when nil then
2131
2186
  result = s(:evstr).line line
2132
2187
  else
2133
- debug20 25
2188
+ debug 38
2134
2189
  raise "unknown string body: #{stmt.inspect}"
2135
2190
  end
2136
2191
  }
2137
2192
 
2138
- string_dvar: tGVAR { result = s(:gvar, val[0].to_sym).line lexer.lineno }
2139
- | tIVAR { result = s(:ivar, val[0].to_sym).line lexer.lineno }
2140
- | tCVAR { result = s(:cvar, val[0].to_sym).line lexer.lineno }
2193
+ string_dvar: tGVAR
2194
+ {
2195
+ (id, line), = val
2196
+ result = s(:gvar, id.to_sym).line line
2197
+ }
2198
+ | tIVAR
2199
+ {
2200
+ (id, line), = val
2201
+ result = s(:ivar, id.to_sym).line line
2202
+ }
2203
+ | tCVAR
2204
+ {
2205
+ (id, line), = val
2206
+ result = s(:cvar, id.to_sym).line line
2207
+ }
2141
2208
  | backref
2142
2209
 
2143
- symbol: tSYMBEG sym
2210
+ symbol: ssym
2211
+ | dsym
2212
+
2213
+ ssym: tSYMBEG sym
2144
2214
  {
2215
+ _, (id, line) = val
2216
+
2145
2217
  lexer.lex_state = EXPR_END
2146
- result = val[1].to_sym
2218
+ result = s(:lit, id.to_sym).line line
2147
2219
  }
2148
2220
  | tSYMBOL
2149
2221
  {
2150
- result = val[0].to_sym
2222
+ (id, line), = val
2223
+
2224
+ lexer.lex_state = EXPR_END
2225
+ result = s(:lit, id.to_sym).line line
2151
2226
  }
2152
2227
 
2153
2228
  sym: fname | tIVAR | tGVAR | tCVAR
2154
2229
 
2155
- dsym: tSYMBEG xstring_contents tSTRING_END
2230
+ dsym: tSYMBEG string_contents tSTRING_END
2156
2231
  {
2157
2232
  _, result, _ = val
2158
2233
 
@@ -2168,14 +2243,15 @@ regexp_contents: none
2168
2243
  when :evstr then
2169
2244
  result = s(:dsym, "", result).line result.line
2170
2245
  else
2171
- debug20 26, val, result
2246
+ debug 39
2172
2247
  end
2173
2248
  }
2174
2249
 
2175
2250
  numeric: simple_numeric
2176
- | tUMINUS_NUM simple_numeric
2251
+ | tUMINUS_NUM simple_numeric =tLOWEST
2177
2252
  {
2178
- result = -val[1] # TODO: pt_testcase
2253
+ _, (num, line) = val
2254
+ result = [-num, line]
2179
2255
  }
2180
2256
 
2181
2257
  simple_numeric: tINTEGER
@@ -2208,8 +2284,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2208
2284
 
2209
2285
  var_ref: user_variable
2210
2286
  {
2211
- var = val[0]
2287
+ raise "NO: #{val.inspect}" if Sexp === val.first
2288
+ (var, line), = val
2212
2289
  result = Sexp === var ? var : self.gettable(var)
2290
+ result.line line
2213
2291
  }
2214
2292
  | keyword_variable
2215
2293
  {
@@ -2224,11 +2302,19 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2224
2302
  | keyword_variable
2225
2303
  {
2226
2304
  result = self.assignable val[0]
2227
- debug20 29, val, result
2305
+ debug 40
2228
2306
  }
2229
2307
 
2230
- backref: tNTH_REF { result = s(:nth_ref, val[0]).line lexer.lineno }
2231
- | tBACK_REF { result = s(:back_ref, val[0]).line lexer.lineno }
2308
+ backref: tNTH_REF
2309
+ {
2310
+ (ref, line), = val
2311
+ result = s(:nth_ref, ref).line line
2312
+ }
2313
+ | tBACK_REF
2314
+ {
2315
+ (ref, line), = val
2316
+ result = s(:back_ref, ref).line line
2317
+ }
2232
2318
 
2233
2319
  superclass: tLT
2234
2320
  {
@@ -2246,9 +2332,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2246
2332
 
2247
2333
  f_arglist: tLPAREN2 f_args rparen
2248
2334
  {
2249
- result = val[1]
2250
- self.lexer.lex_state = EXPR_BEG
2251
- self.lexer.command_start = true
2335
+ result = end_args val
2252
2336
  }
2253
2337
  | {
2254
2338
  result = self.in_kwarg
@@ -2257,12 +2341,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2257
2341
  }
2258
2342
  f_args term
2259
2343
  {
2260
- kwarg, args, _ = val
2261
-
2262
- self.in_kwarg = kwarg
2263
- result = args
2264
- lexer.lex_state = EXPR_BEG
2265
- lexer.command_start = true
2344
+ result = end_args val
2266
2345
  }
2267
2346
 
2268
2347
  args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -2347,9 +2426,9 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2347
2426
  |
2348
2427
  {
2349
2428
  result = args val
2429
+ # result.line lexer.lineno
2350
2430
  }
2351
2431
 
2352
- args_forward: tBDOT3
2353
2432
 
2354
2433
  f_bad_arg: tCONSTANT
2355
2434
  {
@@ -2371,31 +2450,24 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2371
2450
  f_norm_arg: f_bad_arg
2372
2451
  | tIDENTIFIER
2373
2452
  {
2374
- identifier = val[0].to_sym
2453
+ (id, line), = val
2454
+ identifier = id.to_sym
2375
2455
  self.env[identifier] = :lvar
2376
2456
 
2377
- result = identifier
2457
+ result = [identifier, line]
2378
2458
  }
2379
2459
 
2380
2460
  f_arg_item: f_norm_arg
2381
2461
  | tLPAREN f_margs rparen
2382
2462
  {
2383
- result = val[1]
2463
+ _, margs, _ = val
2464
+
2465
+ result = margs
2384
2466
  }
2385
2467
 
2386
2468
  f_arg: f_arg_item
2387
2469
  {
2388
- arg, = val
2389
-
2390
- case arg
2391
- when Symbol then
2392
- result = s(:args, arg).line lexer.lineno
2393
- when Sexp then
2394
- result = arg
2395
- else
2396
- debug20 32
2397
- raise "Unknown f_arg type: #{val.inspect}"
2398
- end
2470
+ result = new_arg val
2399
2471
  }
2400
2472
  | f_arg tCOMMA f_arg_item
2401
2473
  {
@@ -2407,7 +2479,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2407
2479
  result = s(:args, list).line list.line
2408
2480
  end
2409
2481
 
2410
- result << item
2482
+ result << (Sexp === item ? item : item.first)
2411
2483
  }
2412
2484
 
2413
2485
  f_label: tLABEL
@@ -2468,27 +2540,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2468
2540
  kwrest_mark: tPOW
2469
2541
  | tDSTAR
2470
2542
 
2543
+
2471
2544
  f_kwrest: kwrest_mark tIDENTIFIER
2472
2545
  {
2473
- name = val[1].to_sym
2474
- self.assignable name
2475
- result = :"**#{name}"
2546
+ _, (id, line) = val
2547
+
2548
+ name = id.to_sym
2549
+ self.assignable [name, line]
2550
+ result = [:"**#{name}", line]
2476
2551
  }
2477
2552
  | kwrest_mark
2478
2553
  {
2479
- result = :"**"
2480
- self.env[result] = :lvar
2554
+ id = :"**"
2555
+ self.env[id] = :lvar # TODO: needed?!?
2556
+ result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
2481
2557
  }
2482
2558
 
2483
2559
  f_opt: f_norm_arg tEQL arg_value
2484
2560
  {
2485
- result = self.assignable val[0], val[2]
2561
+ lhs, _, rhs = val
2562
+ result = self.assignable lhs, rhs
2486
2563
  # TODO: detect duplicate names
2487
2564
  }
2488
2565
 
2489
2566
  f_block_opt: f_norm_arg tEQL primary_value
2490
2567
  {
2491
- result = self.assignable val[0], val[2]
2568
+ lhs, _, rhs = val
2569
+ result = self.assignable lhs, rhs
2492
2570
  }
2493
2571
 
2494
2572
  f_block_optarg: f_block_opt
@@ -2518,30 +2596,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2518
2596
  f_rest_arg: restarg_mark tIDENTIFIER
2519
2597
  {
2520
2598
  # TODO: differs from parse.y - needs tests
2521
- name = val[1].to_sym
2522
- self.assignable name
2523
- result = :"*#{name}"
2599
+ _, (id, line) = val
2600
+ name = id.to_sym
2601
+ self.assignable [name, line]
2602
+ result = [:"*#{name}", line]
2524
2603
  }
2525
2604
  | restarg_mark
2526
2605
  {
2527
2606
  name = :"*"
2528
2607
  self.env[name] = :lvar
2529
- result = name
2608
+ result = [name, lexer.lineno] # FIX: tSTAR to include lineno
2530
2609
  }
2531
2610
 
2532
2611
  blkarg_mark: tAMPER2 | tAMPER
2533
2612
 
2534
2613
  f_block_arg: blkarg_mark tIDENTIFIER
2535
2614
  {
2536
- identifier = val[1].to_sym
2615
+ _, (id, line) = val
2616
+ identifier = id.to_sym
2537
2617
 
2538
2618
  self.env[identifier] = :lvar
2539
- result = "&#{identifier}".to_sym
2619
+ result = ["&#{identifier}".to_sym, line]
2540
2620
  }
2541
2621
 
2542
2622
  opt_f_block_arg: tCOMMA f_block_arg
2543
2623
  {
2544
- result = val[1]
2624
+ _, arg = val
2625
+ result = arg
2545
2626
  }
2546
2627
  |
2547
2628
  {