brakeman 5.0.4 → 5.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +40 -1
  3. data/README.md +1 -1
  4. data/bundle/load.rb +5 -4
  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.21.0/MIT-LICENSE.txt +20 -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.21.0/lib/parallel.rb +532 -0
  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 +326 -249
  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 +321 -246
  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.16.0 → ruby_parser-3.18.0}/lib/ruby22_parser.y +325 -248
  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/ruby24_parser.y → ruby_parser-3.18.0/lib/ruby23_parser.y} +326 -257
  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/lib/ruby30_parser.y → ruby_parser-3.18.0/lib/ruby24_parser.y} +327 -302
  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/ruby26_parser.y → ruby_parser-3.18.0/lib/ruby25_parser.y} +326 -264
  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} +325 -285
  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} +897 -377
  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.18.0/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/check_detailed_exceptions.rb +1 -1
  106. data/lib/brakeman/checks/check_evaluation.rb +1 -1
  107. data/lib/brakeman/checks/check_execute.rb +10 -0
  108. data/lib/brakeman/checks/check_json_parsing.rb +1 -1
  109. data/lib/brakeman/checks/check_render.rb +15 -1
  110. data/lib/brakeman/checks/check_sql.rb +58 -8
  111. data/lib/brakeman/checks/check_verb_confusion.rb +1 -1
  112. data/lib/brakeman/file_parser.rb +45 -15
  113. data/lib/brakeman/options.rb +7 -2
  114. data/lib/brakeman/processors/alias_processor.rb +91 -9
  115. data/lib/brakeman/processors/controller_alias_processor.rb +6 -43
  116. data/lib/brakeman/processors/haml_template_processor.rb +9 -0
  117. data/lib/brakeman/processors/lib/call_conversion_helper.rb +12 -6
  118. data/lib/brakeman/processors/library_processor.rb +9 -0
  119. data/lib/brakeman/processors/model_processor.rb +32 -0
  120. data/lib/brakeman/report/ignore/config.rb +1 -1
  121. data/lib/brakeman/report/ignore/interactive.rb +1 -1
  122. data/lib/brakeman/report/report_csv.rb +1 -1
  123. data/lib/brakeman/report/report_github.rb +31 -0
  124. data/lib/brakeman/report/report_sarif.rb +22 -3
  125. data/lib/brakeman/report/report_text.rb +1 -1
  126. data/lib/brakeman/report.rb +4 -1
  127. data/lib/brakeman/rescanner.rb +1 -1
  128. data/lib/brakeman/scanner.rb +16 -13
  129. data/lib/brakeman/tracker/collection.rb +57 -7
  130. data/lib/brakeman/tracker/method_info.rb +70 -0
  131. data/lib/brakeman/tracker.rb +33 -4
  132. data/lib/brakeman/util.rb +34 -18
  133. data/lib/brakeman/version.rb +1 -1
  134. data/lib/brakeman.rb +8 -2
  135. data/lib/ruby_parser/bm_sexp.rb +24 -0
  136. metadata +103 -94
  137. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/rp_stringscanner.rb +0 -64
  138. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby20_parser.rb +0 -7075
  139. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby21_parser.rb +0 -7148
  140. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby22_parser.rb +0 -7185
  141. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.rb +0 -7199
  142. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.y +0 -2643
  143. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby24_parser.rb +0 -7219
  144. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.rb +0 -7218
  145. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.y +0 -2651
  146. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby26_parser.rb +0 -7240
  147. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby27_parser.rb +0 -7358
  148. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.rb +0 -7358
  149. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/tools/ripper.rb +0 -39
  150. 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 Ruby30Parser
3
+ class Ruby24Parser
4
4
 
5
5
  token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
6
6
  kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
@@ -18,11 +18,10 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
18
18
  tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
19
19
  tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END
20
20
  tSTRING tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA
21
- tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND tUBANG
21
+ tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND
22
22
  tRATIONAL tIMAGINARY
23
23
  tLABEL_END
24
24
  tLONELY
25
- tBDOT2 tBDOT3
26
25
 
27
26
  preclow
28
27
  nonassoc tLOWEST
@@ -80,7 +79,7 @@ rule
80
79
  | klBEGIN
81
80
  {
82
81
  if (self.in_def || self.in_single > 0) then
83
- debug20 1
82
+ debug 11
84
83
  yyerror "BEGIN in method"
85
84
  end
86
85
  self.env.extend
@@ -105,7 +104,9 @@ rule
105
104
  bodystmt: compstmt opt_rescue k_else
106
105
  {
107
106
  res = _values[-2]
108
- yyerror "else without rescue is useless" unless res
107
+ # TODO: move down to main match so I can just use val
108
+
109
+ warn "else without rescue is useless" unless res
109
110
  }
110
111
  compstmt
111
112
  opt_ensure
@@ -135,7 +136,7 @@ rule
135
136
  | error stmt
136
137
  {
137
138
  result = val[1]
138
- debug20 2, val, result
139
+ debug 12
139
140
  }
140
141
 
141
142
  stmt_or_begin: stmt
@@ -143,6 +144,10 @@ rule
143
144
  {
144
145
  yyerror "BEGIN is permitted only at toplevel"
145
146
  }
147
+ begin_block
148
+ {
149
+ result = val[2] # wtf?
150
+ }
146
151
 
147
152
  stmt: kALIAS fitem
148
153
  {
@@ -155,12 +160,12 @@ rule
155
160
  }
156
161
  | kALIAS tGVAR tGVAR
157
162
  {
158
- (_, line), lhs, rhs = val
163
+ (_, line), (lhs, _), (rhs, _) = val
159
164
  result = s(:valias, lhs.to_sym, rhs.to_sym).line line
160
165
  }
161
166
  | kALIAS tGVAR tBACK_REF
162
167
  {
163
- (_, line), lhs, rhs = val
168
+ (_, line), (lhs, _), (rhs, _) = val
164
169
  result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
165
170
  }
166
171
  | kALIAS tGVAR tNTH_REF
@@ -203,7 +208,7 @@ rule
203
208
  (_, line), _, stmt, _ = val
204
209
 
205
210
  if (self.in_def || self.in_single > 0) then
206
- debug20 3
211
+ debug 13
207
212
  yyerror "END in method; use at_exit"
208
213
  end
209
214
 
@@ -243,32 +248,31 @@ rule
243
248
  }
244
249
  | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
245
250
  {
246
- prim, _, id, opasgn, rhs = val
247
- result = s(:op_asgn, prim, rhs, id.to_sym, opasgn.to_sym)
248
- if val[1] == '&.'
249
- result.sexp_type = :safe_op_asgn
250
- end
251
- result.line = val[0].line
251
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
252
+
253
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
254
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
255
+ result.line prim.line
252
256
  }
253
257
  | primary_value call_op tCONSTANT tOP_ASGN command_rhs
254
258
  {
255
- result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
256
- if val[1] == '&.'
257
- result.sexp_type = :safe_op_asgn
258
- end
259
- result.line = val[0].line
259
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
260
+
261
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
262
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
263
+ result.line prim.line
260
264
  }
261
265
  | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
262
266
  {
263
- lhs1, _, lhs2, op, rhs = val
267
+ lhs1, _, (lhs2, line), (id, _), rhs = val
264
268
 
265
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
269
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
266
270
  }
267
271
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
268
272
  {
269
- lhs1, _, lhs2, op, rhs = val
273
+ lhs1, _, (lhs2, line), (id, _), rhs = val
270
274
 
271
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
275
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
272
276
  }
273
277
  | backref tOP_ASGN command_rhs
274
278
  {
@@ -314,7 +318,7 @@ rule
314
318
  # TODO: fix line number to tBANG... but causes BAD shift/reduce conflict
315
319
  # REFACTOR: call_uni_op -- see parse26.y
316
320
  }
317
- | arg
321
+ | arg =tLBRACE_ARG
318
322
 
319
323
  expr_value: expr
320
324
  {
@@ -339,7 +343,7 @@ rule
339
343
  block_command: block_call
340
344
  | block_call call_op2 operation2 command_args
341
345
  {
342
- blk, _, msg, args = val
346
+ blk, _, (msg, _line), args = val
343
347
  result = new_call(blk, msg.to_sym, args).line blk.line
344
348
  }
345
349
 
@@ -353,15 +357,15 @@ rule
353
357
  _, line, body, _ = val
354
358
 
355
359
  result = body
356
- result.line = line
360
+ result.line line
357
361
 
358
362
  # self.env.unextend
359
363
  }
360
364
 
361
365
  fcall: operation
362
366
  {
363
- msg, = val
364
- result = new_call(nil, msg.to_sym).line lexer.lineno
367
+ (msg, line), = val
368
+ result = new_call(nil, msg.to_sym).line line
365
369
  }
366
370
 
367
371
  command: fcall command_args =tLOWEST
@@ -384,12 +388,14 @@ rule
384
388
  }
385
389
  | primary_value call_op operation2 command_args =tLOWEST
386
390
  {
387
- lhs, callop, op, args = val
391
+ lhs, callop, (op, _), args = val
392
+
388
393
  result = new_call lhs, op.to_sym, args, callop
394
+ result.line lhs.line
389
395
  }
390
396
  | primary_value call_op operation2 command_args cmd_brace_block
391
397
  {
392
- recv, _, msg, args, block = val
398
+ recv, _, (msg, _line), args, block = val
393
399
  call = new_call recv, msg.to_sym, args, val[1]
394
400
 
395
401
  block_dup_check call, block
@@ -399,11 +405,14 @@ rule
399
405
  }
400
406
  | primary_value tCOLON2 operation2 command_args =tLOWEST
401
407
  {
402
- result = new_call val[0], val[2].to_sym, val[3]
408
+ lhs, _, (id, line), args = val
409
+
410
+ result = new_call lhs, id.to_sym, args
411
+ result.line line
403
412
  }
404
413
  | primary_value tCOLON2 operation2 command_args cmd_brace_block
405
414
  {
406
- recv, _, msg, args, block = val
415
+ recv, _, (msg, _line), args, block = val
407
416
  call = new_call recv, msg.to_sym, args
408
417
 
409
418
  block_dup_check call, block
@@ -561,25 +570,29 @@ rule
561
570
  }
562
571
  | primary_value call_op tIDENTIFIER
563
572
  {
564
- result = new_attrasgn val[0], val[2], val[1]
573
+ lhs, call_op, (id, _line) = val
574
+
575
+ result = new_attrasgn lhs, id, call_op
565
576
  }
566
577
  | primary_value tCOLON2 tIDENTIFIER
567
578
  {
568
- recv, _, id = val
579
+ recv, _, (id, _line) = val
569
580
  result = new_attrasgn recv, id
570
581
  }
571
582
  | primary_value call_op tCONSTANT
572
583
  {
573
- result = new_attrasgn val[0], val[2], val[1]
584
+ lhs, call_op, (id, _line) = val
585
+
586
+ result = new_attrasgn lhs, id, call_op
574
587
  }
575
588
  | primary_value tCOLON2 tCONSTANT
576
589
  {
577
590
  if (self.in_def || self.in_single > 0) then
578
- debug20 7
591
+ debug 14
579
592
  yyerror "dynamic constant assignment"
580
593
  end
581
594
 
582
- expr, _, id = val
595
+ expr, _, (id, _line) = val
583
596
  l = expr.line
584
597
 
585
598
  result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
@@ -587,58 +600,65 @@ rule
587
600
  | tCOLON3 tCONSTANT
588
601
  {
589
602
  if (self.in_def || self.in_single > 0) then
590
- debug20 8
603
+ debug 15
591
604
  yyerror "dynamic constant assignment"
592
605
  end
593
606
 
594
- _, id = val
595
- l = lexer.lineno
607
+ _, (id, l) = val
596
608
 
597
609
  result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
598
610
  }
599
611
  | backref
600
612
  {
601
- self.backref_assign_error val[0]
613
+ ref, = val
614
+
615
+ self.backref_assign_error ref
602
616
  }
603
617
 
604
618
  lhs: user_variable
605
619
  {
606
- line = lexer.lineno
607
- result = self.assignable val[0]
608
- result.line = line
620
+ var, = val
621
+
622
+ result = self.assignable var
609
623
  }
610
624
  | keyword_variable
611
625
  {
612
- line = lexer.lineno
613
- result = self.assignable val[0]
614
- result.line = line
615
- debug20 9, val, result
626
+ var, = val
627
+
628
+ result = self.assignable var
629
+
630
+ debug 16
616
631
  }
617
632
  | primary_value tLBRACK2 opt_call_args rbracket
618
633
  {
619
634
  lhs, _, args, _ = val
635
+
620
636
  result = self.aryset lhs, args
621
637
  }
622
638
  | primary_value call_op tIDENTIFIER # REFACTOR
623
639
  {
624
- lhs, op, id = val
640
+ lhs, op, (id, _line) = val
641
+
625
642
  result = new_attrasgn lhs, id, op
626
643
  }
627
644
  | primary_value tCOLON2 tIDENTIFIER
628
645
  {
629
- lhs, _, id = val
646
+ lhs, _, (id, _line) = val
647
+
630
648
  result = new_attrasgn lhs, id
631
649
  }
632
650
  | primary_value call_op tCONSTANT # REFACTOR?
633
651
  {
634
- result = new_attrasgn val[0], val[2], val[1]
652
+ lhs, call_op, (id, _line) = val
653
+
654
+ result = new_attrasgn lhs, id, call_op
635
655
  }
636
656
  | primary_value tCOLON2 tCONSTANT
637
657
  {
638
- expr, _, id = val
658
+ expr, _, (id, _line) = val
639
659
 
640
660
  if (self.in_def || self.in_single > 0) then
641
- debug20 10
661
+ debug 17
642
662
  yyerror "dynamic constant assignment"
643
663
  end
644
664
 
@@ -647,14 +667,13 @@ rule
647
667
  }
648
668
  | tCOLON3 tCONSTANT
649
669
  {
650
- _, id = val
670
+ _, (id, l) = val
651
671
 
652
672
  if (self.in_def || self.in_single > 0) then
653
- debug20 11
673
+ debug 18
654
674
  yyerror "dynamic constant assignment"
655
675
  end
656
676
 
657
- l = lexer.lineno
658
677
  result = s(:const, s(:colon3, id.to_sym).line(l)).line l
659
678
  }
660
679
  | backref
@@ -670,16 +689,17 @@ rule
670
689
 
671
690
  cpath: tCOLON3 cname
672
691
  {
673
- _, name = val
674
- result = s(:colon3, name.to_sym).line lexer.lineno
692
+ _, (name, line) = val
693
+ result = s(:colon3, name.to_sym).line line
675
694
  }
676
695
  | cname
677
696
  {
678
- result = val[0].to_sym
697
+ (id, line), = val
698
+ result = [id.to_sym, line] # TODO: sexp?
679
699
  }
680
700
  | primary_value tCOLON2 cname
681
701
  {
682
- pval, _, name = val
702
+ pval, _, (name, _line) = val
683
703
 
684
704
  result = s(:colon2, pval, name.to_sym)
685
705
  result.line pval.line
@@ -689,24 +709,17 @@ rule
689
709
  | op
690
710
  {
691
711
  lexer.lex_state = EXPR_END
692
- result = val[0]
693
712
  }
694
713
 
695
714
  | reswords
696
- {
697
- (sym, _line), = val
698
- lexer.lex_state = EXPR_END
699
- result = sym
700
- }
701
-
702
- fsym: fname | symbol
703
715
 
704
- fitem: fsym
716
+ fitem: fname
705
717
  {
706
- id, = val
707
- result = s(:lit, id.to_sym).line lexer.lineno
718
+ (id, line), = val
719
+
720
+ result = s(:lit, id.to_sym).line line
708
721
  }
709
- | dsym
722
+ | symbol
710
723
 
711
724
  undef_list: fitem
712
725
  {
@@ -727,8 +740,6 @@ rule
727
740
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
728
741
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
729
742
  | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
730
- # TODO: tUBANG dead?
731
- | tUBANG
732
743
 
733
744
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
734
745
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -762,24 +773,20 @@ rule
762
773
  }
763
774
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
764
775
  {
765
- lhs, _, id, op, rhs = val
776
+ lhs, _, (id, _line), (op, _), rhs = val
766
777
 
767
778
  result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
768
779
  }
769
780
  | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
770
781
  {
771
- lhs1, _, lhs2, op, rhs = val
782
+ lhs1, _, (lhs2, _line), op, rhs = val
772
783
 
773
784
  lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
774
785
  result = new_const_op_asgn [lhs, op, rhs]
775
786
  }
776
- | tCOLON3 tCONSTANT
777
- {
778
- result = self.lexer.lineno
779
- }
780
- tOP_ASGN arg_rhs
787
+ | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
781
788
  {
782
- _, lhs, line, op, rhs = val
789
+ _, (lhs, line), op, rhs = val
783
790
 
784
791
  lhs = s(:colon3, lhs.to_sym).line line
785
792
  result = new_const_op_asgn [lhs, op, rhs]
@@ -793,7 +800,7 @@ rule
793
800
  | arg tDOT2 arg
794
801
  {
795
802
  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
803
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
797
804
  result = s(:lit, (v1.last)..(v2.last)).line v1.line
798
805
  else
799
806
  result = s(:dot2, v1, v2).line v1.line
@@ -802,41 +809,13 @@ rule
802
809
  | arg tDOT3 arg
803
810
  {
804
811
  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
812
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
806
813
  result = s(:lit, (v1.last)...(v2.last)).line v1.line
807
814
  else
808
815
  result = s(:dot3, v1, v2).line v1.line
809
816
  end
810
817
  }
811
- | arg tDOT2
812
- {
813
- v1, _ = val
814
- v2 = nil
815
-
816
- result = s(:dot2, v1, v2).line v1.line
817
- }
818
- | arg tDOT3
819
- {
820
- v1, _ = val
821
- v2 = nil
822
-
823
- result = s(:dot3, v1, v2).line v1.line
824
- }
825
-
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
818
 
838
- result = s(:dot3, v1, v2).line v2.line
839
- }
840
819
 
841
820
  | arg tPLUS arg
842
821
  {
@@ -864,8 +843,9 @@ rule
864
843
  }
865
844
  | tUMINUS_NUM simple_numeric tPOW arg
866
845
  {
867
- lit = s(:lit, val[1]).line lexer.lineno
868
- result = new_call(new_call(lit, :"**", argl(val[3])), :"-@")
846
+ _, (num, line), _, arg = val
847
+ lit = s(:lit, num).line line
848
+ result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
869
849
 
870
850
  }
871
851
  | tUPLUS arg
@@ -964,12 +944,12 @@ rule
964
944
 
965
945
  rel_expr: arg relop arg =tGT
966
946
  {
967
- lhs, op, rhs = val
947
+ lhs, (op, _), rhs = val
968
948
  result = new_call lhs, op.to_sym, argl(rhs)
969
949
  }
970
950
  | rel_expr relop arg =tGT
971
951
  {
972
- lhs, op, rhs = val
952
+ lhs, (op, _), rhs = val
973
953
  warn "comparison '%s' after comparison", op
974
954
  result = new_call lhs, op.to_sym, argl(rhs)
975
955
  }
@@ -1009,16 +989,6 @@ rule
1009
989
  _, args, _ = val
1010
990
  result = args
1011
991
  }
1012
- | tLPAREN2 args_forward rparen
1013
- {
1014
- if (!self.lexer.is_local_id(:"*") ||
1015
- !self.lexer.is_local_id(:"**") ||
1016
- !self.lexer.is_local_id(:"&")) then
1017
-
1018
- yyerror("Invalid argument forwarding")
1019
- end
1020
- result = call_args [s(:forward_args).line(lexer.lineno)]
1021
- }
1022
992
 
1023
993
  opt_paren_args: none
1024
994
  | paren_args
@@ -1170,8 +1140,9 @@ rule
1170
1140
  | backref
1171
1141
  | tFID
1172
1142
  {
1173
- msg, = val
1143
+ (msg, line), = val
1174
1144
  result = new_call nil, msg.to_sym
1145
+ result.line line
1175
1146
  }
1176
1147
  | k_begin
1177
1148
  {
@@ -1213,15 +1184,15 @@ rule
1213
1184
  }
1214
1185
  | primary_value tCOLON2 tCONSTANT
1215
1186
  {
1216
- expr, _, id = val
1187
+ expr, _, (id, _line) = val
1217
1188
 
1218
1189
  result = s(:colon2, expr, id.to_sym).line expr.line
1219
1190
  }
1220
1191
  | tCOLON3 tCONSTANT
1221
1192
  {
1222
- _, id = val
1193
+ _, (id, line) = val
1223
1194
 
1224
- result = s(:colon3, id.to_sym).line lexer.lineno
1195
+ result = s(:colon3, id.to_sym).line line
1225
1196
  }
1226
1197
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1227
1198
  {
@@ -1268,7 +1239,7 @@ rule
1268
1239
  }
1269
1240
  | kNOT tLPAREN2 rparen
1270
1241
  {
1271
- debug20 14, val, result
1242
+ debug 20
1272
1243
  }
1273
1244
  | fcall brace_block
1274
1245
  {
@@ -1286,9 +1257,10 @@ rule
1286
1257
  iter.insert 1, call # FIX
1287
1258
  result = iter
1288
1259
  }
1289
- | tLAMBDA lambda
1260
+ | lambda
1290
1261
  {
1291
- result = val[1] # TODO: fix lineno
1262
+ expr, = val
1263
+ result = expr
1292
1264
  }
1293
1265
  | k_if expr_value then compstmt if_tail k_end
1294
1266
  {
@@ -1331,7 +1303,6 @@ rule
1331
1303
  }
1332
1304
  cpath superclass
1333
1305
  {
1334
- self.comments.push self.lexer.comments
1335
1306
  if (self.in_def || self.in_single > 0) then
1336
1307
  yyerror "class definition in method body"
1337
1308
  end
@@ -1341,7 +1312,7 @@ rule
1341
1312
  {
1342
1313
  result = new_class val
1343
1314
  self.env.unextend
1344
- self.lexer.comments # we don't care about comments in the body
1315
+ self.lexer.ignore_body_comments
1345
1316
  }
1346
1317
  | k_class tLSHFT
1347
1318
  {
@@ -1362,7 +1333,7 @@ rule
1362
1333
  {
1363
1334
  result = new_sclass val
1364
1335
  self.env.unextend
1365
- self.lexer.comments # we don't care about comments in the body
1336
+ self.lexer.ignore_body_comments
1366
1337
  }
1367
1338
  | k_module
1368
1339
  {
@@ -1370,7 +1341,6 @@ rule
1370
1341
  }
1371
1342
  cpath
1372
1343
  {
1373
- self.comments.push self.lexer.comments
1374
1344
  yyerror "module definition in method body" if
1375
1345
  self.in_def or self.in_single > 0
1376
1346
 
@@ -1380,7 +1350,7 @@ rule
1380
1350
  {
1381
1351
  result = new_module val
1382
1352
  self.env.unextend
1383
- self.lexer.comments # we don't care about comments in the body
1353
+ self.lexer.ignore_body_comments
1384
1354
  }
1385
1355
  | k_def fname
1386
1356
  {
@@ -1390,21 +1360,17 @@ rule
1390
1360
  self.env.extend
1391
1361
  lexer.cmdarg.push false
1392
1362
  lexer.cond.push false
1393
-
1394
- self.comments.push self.lexer.comments
1395
1363
  }
1396
- f_arglist bodystmt { result = lexer.lineno } k_end
1364
+ f_arglist bodystmt k_end
1397
1365
  {
1398
- in_def = val[2]
1399
-
1400
- result = new_defn val
1366
+ result, in_def = new_defn val
1401
1367
 
1402
1368
  lexer.cond.pop # group = local_pop
1403
1369
  lexer.cmdarg.pop
1404
1370
  self.env.unextend
1405
1371
  self.in_def = in_def
1406
1372
 
1407
- self.lexer.comments # we don't care about comments in the body
1373
+ self.lexer.ignore_body_comments
1408
1374
  }
1409
1375
  | k_def singleton dot_or_colon
1410
1376
  {
@@ -1412,7 +1378,7 @@ rule
1412
1378
  }
1413
1379
  fname
1414
1380
  {
1415
- result = [self.in_def, lexer.lineno]
1381
+ result = self.in_def
1416
1382
 
1417
1383
  self.in_single += 1 # TODO: remove?
1418
1384
 
@@ -1422,13 +1388,18 @@ rule
1422
1388
  lexer.cond.push false
1423
1389
 
1424
1390
  lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
1425
- self.comments.push self.lexer.comments
1426
1391
  }
1427
1392
  f_arglist bodystmt k_end
1428
1393
  {
1429
- _, _recv, _, _, _name, (in_def, _lineno), _args, _body, _ = val
1430
1394
 
1431
- result = new_defs val
1395
+ # [kdef, recv, _, _, (name, line), in_def, args, body, kend]
1396
+ # =>
1397
+ # [kdef, recv, (name, line), in_def, args, body, kend]
1398
+
1399
+ val.delete_at 3
1400
+ val.delete_at 2
1401
+
1402
+ result, in_def = new_defs val
1432
1403
 
1433
1404
  lexer.cond.pop # group = local_pop
1434
1405
  lexer.cmdarg.pop
@@ -1439,7 +1410,7 @@ rule
1439
1410
 
1440
1411
  # TODO: restore cur_arg ? what's cur_arg?
1441
1412
 
1442
- self.lexer.comments # we don't care about comments in the body
1413
+ self.lexer.ignore_body_comments
1443
1414
  }
1444
1415
  | kBREAK
1445
1416
  {
@@ -1476,8 +1447,17 @@ rule
1476
1447
  k_case: kCASE
1477
1448
  k_for: kFOR
1478
1449
  k_class: kCLASS
1450
+ {
1451
+ self.comments.push self.lexer.comments
1452
+ }
1479
1453
  k_module: kMODULE
1454
+ {
1455
+ self.comments.push self.lexer.comments
1456
+ }
1480
1457
  k_def: kDEF
1458
+ {
1459
+ self.comments.push self.lexer.comments
1460
+ }
1481
1461
  k_do: kDO
1482
1462
  k_do_block: kDO_BLOCK
1483
1463
  k_rescue: kRESCUE
@@ -1538,51 +1518,42 @@ rule
1538
1518
 
1539
1519
  result = block_var args
1540
1520
  }
1541
- | f_marg_list tCOMMA tSTAR f_norm_arg
1521
+ | f_marg_list tCOMMA f_rest_marg
1542
1522
  {
1543
- args, _, _, splat = val
1523
+ args, _, rest = val
1544
1524
 
1545
- result = block_var args, "*#{splat}".to_sym
1525
+ result = block_var args, rest
1546
1526
  }
1547
- | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1527
+ | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1548
1528
  {
1549
- args, _, _, splat, _, args2 = val
1529
+ lhs, _, splat, _, rhs = val
1550
1530
 
1551
- result = block_var args, "*#{splat}".to_sym, args2
1531
+ result = block_var lhs, splat, rhs
1552
1532
  }
1553
- | f_marg_list tCOMMA tSTAR
1533
+ | f_rest_marg
1554
1534
  {
1555
- args, _, _ = val
1535
+ rest, = val
1556
1536
 
1557
- result = block_var args, :*
1537
+ result = block_var rest
1558
1538
  }
1559
- | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1539
+ | f_rest_marg tCOMMA f_marg_list
1560
1540
  {
1561
- args, _, _, _, args2 = val
1541
+ splat, _, rest = val
1562
1542
 
1563
- result = block_var args, :*, args2
1543
+ result = block_var splat, rest
1564
1544
  }
1565
- | tSTAR f_norm_arg
1566
- {
1567
- _, splat = val
1568
1545
 
1569
- result = block_var :"*#{splat}"
1570
- }
1571
- | tSTAR f_norm_arg tCOMMA f_marg_list
1546
+ f_rest_marg: tSTAR f_norm_arg
1572
1547
  {
1573
- _, splat, _, args = val
1548
+ _, (id, line) = val
1574
1549
 
1575
- result = block_var :"*#{splat}", args
1550
+ result = args ["*#{id}".to_sym]
1551
+ result.line line
1576
1552
  }
1577
1553
  | tSTAR
1578
1554
  {
1579
- result = block_var :*
1580
- }
1581
- | tSTAR tCOMMA f_marg_list
1582
- {
1583
- _, _, args = val
1584
-
1585
- result = block_var :*, args
1555
+ result = args [:*]
1556
+ result.line lexer.lineno # FIX: tSTAR -> line
1586
1557
  }
1587
1558
 
1588
1559
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -1599,8 +1570,8 @@ rule
1599
1570
  }
1600
1571
  | f_block_arg
1601
1572
  {
1602
- line = lexer.lineno
1603
- result = call_args val # TODO: push line down
1573
+ (id, line), = val
1574
+ result = call_args [id]
1604
1575
  result.line line
1605
1576
  }
1606
1577
 
@@ -1709,13 +1680,13 @@ opt_block_args_tail: tCOMMA block_args_tail
1709
1680
 
1710
1681
  bvar: tIDENTIFIER
1711
1682
  {
1712
- id, = val
1713
- line = lexer.lineno
1683
+ (id, line), = val
1714
1684
  result = s(:shadow, id.to_sym).line line
1715
1685
  }
1716
1686
  | f_bad_arg
1717
1687
 
1718
- lambda: {
1688
+ lambda: tLAMBDA
1689
+ {
1719
1690
  self.env.extend :dynamic
1720
1691
  result = [lexer.lineno, lexer.lpar_beg]
1721
1692
  lexer.paren_nest += 1
@@ -1727,14 +1698,14 @@ opt_block_args_tail: tCOMMA block_args_tail
1727
1698
  }
1728
1699
  lambda_body
1729
1700
  {
1730
- (line, lpar), args, _cmdarg, body = val
1701
+ _, (line, lpar), args, _cmdarg, body = val
1731
1702
  lexer.lpar_beg = lpar
1732
1703
 
1733
1704
  lexer.cmdarg.pop
1734
1705
 
1735
1706
  call = s(:lambda).line line
1736
1707
  result = new_iter call, args, body
1737
- result.line = line
1708
+ result.line line
1738
1709
  self.env.unextend # TODO: dynapush & dynapop
1739
1710
  }
1740
1711
 
@@ -1769,23 +1740,28 @@ opt_block_args_tail: tCOMMA block_args_tail
1769
1740
  ## if (nd_type($1) == NODE_YIELD) {
1770
1741
  ## compile_error(PARSER_ARG "block given to yield");
1771
1742
 
1772
- syntax_error "Both block arg and actual block given." if
1773
- val[0].block_pass?
1743
+ cmd, blk = val
1774
1744
 
1775
- val = invert_block_call val if inverted? val
1745
+ syntax_error "Both block arg and actual block given." if
1746
+ cmd.block_pass?
1776
1747
 
1777
- cmd, blk = val
1748
+ if inverted? val then
1749
+ val = invert_block_call val
1750
+ cmd, blk = val
1751
+ end
1778
1752
 
1779
1753
  result = blk
1780
1754
  result.insert 1, cmd
1781
1755
  }
1782
1756
  | block_call call_op2 operation2 opt_paren_args
1783
1757
  {
1784
- result = new_call val[0], val[2].to_sym, val[3]
1758
+ lhs, _, (id, _line), args = val
1759
+
1760
+ result = new_call lhs, id.to_sym, args
1785
1761
  }
1786
1762
  | block_call call_op2 operation2 opt_paren_args brace_block
1787
1763
  {
1788
- iter1, _, name, args, iter2 = val
1764
+ iter1, _, (name, _line), args, iter2 = val
1789
1765
 
1790
1766
  call = new_call iter1, name.to_sym, args
1791
1767
  iter2.insert 1, call
@@ -1794,7 +1770,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1794
1770
  }
1795
1771
  | block_call call_op2 operation2 command_args do_block
1796
1772
  {
1797
- iter1, _, name, args, iter2 = val
1773
+ iter1, _, (name, _line), args, iter2 = val
1798
1774
 
1799
1775
  call = new_call iter1, name.to_sym, args
1800
1776
  iter2.insert 1, call
@@ -1802,28 +1778,29 @@ opt_block_args_tail: tCOMMA block_args_tail
1802
1778
  result = iter2
1803
1779
  }
1804
1780
 
1805
- method_call: fcall
1781
+ method_call: fcall paren_args
1806
1782
  {
1807
- result = self.lexer.lineno
1808
- }
1809
- paren_args
1810
- {
1811
- call, lineno, args = val
1783
+ call, args = val
1812
1784
 
1813
1785
  result = call.concat args.sexp_body if args
1814
- result.line lineno
1815
1786
  }
1816
1787
  | primary_value call_op operation2 opt_paren_args
1817
1788
  {
1818
- result = new_call val[0], val[2].to_sym, val[3], val[1]
1789
+ recv, call_op, (op, _line), args = val
1790
+
1791
+ result = new_call recv, op.to_sym, args, call_op
1819
1792
  }
1820
1793
  | primary_value tCOLON2 operation2 paren_args
1821
1794
  {
1822
- result = new_call val[0], val[2].to_sym, val[3]
1795
+ recv, _, (op, _line), args = val
1796
+
1797
+ result = new_call recv, op.to_sym, args
1823
1798
  }
1824
1799
  | primary_value tCOLON2 operation3
1825
1800
  {
1826
- result = new_call val[0], val[2].to_sym
1801
+ lhs, _, (id, _line) = val
1802
+
1803
+ result = new_call lhs, id.to_sym
1827
1804
  }
1828
1805
  | primary_value call_op paren_args
1829
1806
  {
@@ -1856,7 +1833,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1856
1833
  _, line, body, _ = val
1857
1834
 
1858
1835
  result = body
1859
- result.line = line
1836
+ result.line line
1860
1837
 
1861
1838
  self.env.unextend
1862
1839
  }
@@ -1870,7 +1847,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1870
1847
  _, line, body, _ = val
1871
1848
 
1872
1849
  result = body
1873
- result.line = line
1850
+ result.line line
1874
1851
 
1875
1852
  self.env.unextend
1876
1853
  }
@@ -1890,7 +1867,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1890
1867
  do_body: { self.env.extend :dynamic; result = self.lexer.lineno }
1891
1868
  { lexer.cmdarg.push false }
1892
1869
  opt_block_param
1893
- bodystmt
1870
+ compstmt
1894
1871
  {
1895
1872
  line, _cmdarg, param, cmpstmt = val
1896
1873
 
@@ -1899,14 +1876,39 @@ opt_block_args_tail: tCOMMA block_args_tail
1899
1876
  self.env.unextend
1900
1877
  }
1901
1878
 
1879
+ case_args: arg_value
1880
+ {
1881
+ arg, = val
1882
+
1883
+ result = s(:array, arg).line arg.line
1884
+ }
1885
+ | tSTAR arg_value
1886
+ {
1887
+ _, arg = val
1888
+
1889
+ result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1890
+ }
1891
+ | case_args tCOMMA arg_value
1892
+ {
1893
+ args, _, id = val
1894
+
1895
+ result = self.list_append args, id
1896
+ }
1897
+ | case_args tCOMMA tSTAR arg_value
1898
+ {
1899
+ args, _, _, id = val
1900
+
1901
+ result = self.list_append args, s(:splat, id).line(id.line)
1902
+ }
1903
+
1902
1904
  case_body: k_when
1903
1905
  {
1904
1906
  result = self.lexer.lineno
1905
1907
  }
1906
- args then compstmt cases
1908
+ case_args then compstmt cases
1907
1909
  {
1908
1910
  result = new_when(val[2], val[4])
1909
- result.line = val[1]
1911
+ result.line val[1]
1910
1912
  result << val[5] if val[5]
1911
1913
  }
1912
1914
 
@@ -1952,17 +1954,10 @@ opt_block_args_tail: tCOMMA block_args_tail
1952
1954
 
1953
1955
  literal: numeric
1954
1956
  {
1955
- line = lexer.lineno
1956
- result = s(:lit, val[0])
1957
- result.line = line
1957
+ (lit, line), = val
1958
+ result = s(:lit, lit).line line
1958
1959
  }
1959
1960
  | symbol
1960
- {
1961
- line = lexer.lineno
1962
- result = s(:lit, val[0])
1963
- result.line = line
1964
- }
1965
- | dsym
1966
1961
 
1967
1962
  strings: string
1968
1963
  {
@@ -1973,7 +1968,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1973
1968
 
1974
1969
  string: tCHAR
1975
1970
  {
1976
- debug20 23, val, result
1971
+ debug 37
1977
1972
  }
1978
1973
  | string1
1979
1974
  | string string1
@@ -1983,11 +1978,11 @@ opt_block_args_tail: tCOMMA block_args_tail
1983
1978
 
1984
1979
  string1: tSTRING_BEG string_contents tSTRING_END
1985
1980
  {
1986
- _, str, (_, func) = val
1981
+ (_, line), str, (_, func) = val
1987
1982
 
1988
- str = dedent str if func =~ RubyLexer::STR_FUNC_ICNTNT
1983
+ str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
1989
1984
 
1990
- result = str
1985
+ result = str.line line
1991
1986
  }
1992
1987
  | tSTRING
1993
1988
  {
@@ -2007,11 +2002,15 @@ opt_block_args_tail: tCOMMA block_args_tail
2007
2002
 
2008
2003
  words: tWORDS_BEG tSPACE tSTRING_END
2009
2004
  {
2010
- result = s(:array).line lexer.lineno
2005
+ (_, line), _, _ = val
2006
+
2007
+ result = s(:array).line line
2011
2008
  }
2012
2009
  | tWORDS_BEG word_list tSTRING_END
2013
2010
  {
2014
- result = val[1]
2011
+ (_, line), list, _ = val
2012
+
2013
+ result = list.line line
2015
2014
  }
2016
2015
 
2017
2016
  word_list: none
@@ -2031,18 +2030,20 @@ opt_block_args_tail: tCOMMA block_args_tail
2031
2030
 
2032
2031
  symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2033
2032
  {
2034
- result = s(:array).line lexer.lineno
2033
+ (_, line), _, _ = val
2034
+
2035
+ result = s(:array).line line
2035
2036
  }
2036
- | tSYMBOLS_BEG { result = lexer.lineno } symbol_list tSTRING_END
2037
+ | tSYMBOLS_BEG symbol_list tSTRING_END
2037
2038
  {
2038
- _, line, list, _, = val
2039
- list.line = line
2039
+ (_, line), list, _, = val
2040
+ list.line line
2040
2041
  result = list
2041
2042
  }
2042
2043
 
2043
2044
  symbol_list: none
2044
2045
  {
2045
- result = new_symbol_list.line lexer.lineno
2046
+ result = new_symbol_list
2046
2047
  }
2047
2048
  | symbol_list word tSPACE
2048
2049
  {
@@ -2052,20 +2053,28 @@ opt_block_args_tail: tCOMMA block_args_tail
2052
2053
 
2053
2054
  qwords: tQWORDS_BEG tSPACE tSTRING_END
2054
2055
  {
2055
- result = s(:array).line lexer.lineno
2056
+ (_, line), _, _ = val
2057
+
2058
+ result = s(:array).line line
2056
2059
  }
2057
2060
  | tQWORDS_BEG qword_list tSTRING_END
2058
2061
  {
2059
- result = val[1]
2062
+ (_, line), list, _ = val
2063
+
2064
+ result = list.line line
2060
2065
  }
2061
2066
 
2062
2067
  qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2063
2068
  {
2064
- result = s(:array).line lexer.lineno # FIX
2069
+ (_, line), _, _ = val
2070
+
2071
+ result = s(:array).line line
2065
2072
  }
2066
2073
  | tQSYMBOLS_BEG qsym_list tSTRING_END
2067
2074
  {
2068
- result = val[1]
2075
+ (_, line), list, _ = val
2076
+
2077
+ result = list.line line
2069
2078
  }
2070
2079
 
2071
2080
  qword_list: none
@@ -2088,7 +2097,8 @@ opt_block_args_tail: tCOMMA block_args_tail
2088
2097
 
2089
2098
  string_contents: none
2090
2099
  {
2091
- result = s(:str, "").line lexer.lineno
2100
+ line = prev_value_to_lineno _values.last
2101
+ result = s(:str, +"").line line
2092
2102
  }
2093
2103
  | string_contents string_content
2094
2104
  {
@@ -2163,8 +2173,8 @@ regexp_contents: none
2163
2173
  lexer.brace_nest = brace_nest
2164
2174
  lexer.string_nest = string_nest
2165
2175
 
2166
- lexer.cmdarg.pop
2167
2176
  lexer.cond.pop
2177
+ lexer.cmdarg.pop
2168
2178
 
2169
2179
  lexer.lex_state = oldlex_state
2170
2180
 
@@ -2179,29 +2189,49 @@ regexp_contents: none
2179
2189
  when nil then
2180
2190
  result = s(:evstr).line line
2181
2191
  else
2182
- debug20 25
2192
+ debug 38
2183
2193
  raise "unknown string body: #{stmt.inspect}"
2184
2194
  end
2185
2195
  }
2186
2196
 
2187
- string_dvar: tGVAR { result = s(:gvar, val[0].to_sym).line lexer.lineno }
2188
- | tIVAR { result = s(:ivar, val[0].to_sym).line lexer.lineno }
2189
- | tCVAR { result = s(:cvar, val[0].to_sym).line lexer.lineno }
2197
+ string_dvar: tGVAR
2198
+ {
2199
+ (id, line), = val
2200
+ result = s(:gvar, id.to_sym).line line
2201
+ }
2202
+ | tIVAR
2203
+ {
2204
+ (id, line), = val
2205
+ result = s(:ivar, id.to_sym).line line
2206
+ }
2207
+ | tCVAR
2208
+ {
2209
+ (id, line), = val
2210
+ result = s(:cvar, id.to_sym).line line
2211
+ }
2190
2212
  | backref
2191
2213
 
2192
- symbol: tSYMBEG sym
2214
+ symbol: ssym
2215
+ | dsym
2216
+
2217
+ ssym: tSYMBEG sym
2193
2218
  {
2219
+ _, (id, line) = val
2220
+
2194
2221
  lexer.lex_state = EXPR_END
2195
- result = val[1].to_sym
2222
+ result = s(:lit, id.to_sym).line line
2196
2223
  }
2197
2224
  | tSYMBOL
2198
2225
  {
2199
- result = val[0].to_sym
2226
+ (id, line), = val
2227
+
2228
+ lexer.lex_state = EXPR_END
2229
+ result = s(:lit, id.to_sym).line line
2200
2230
  }
2201
2231
 
2202
2232
  sym: fname | tIVAR | tGVAR | tCVAR
2203
2233
 
2204
- dsym: tSYMBEG xstring_contents tSTRING_END
2234
+ dsym: tSYMBEG string_contents tSTRING_END
2205
2235
  {
2206
2236
  _, result, _ = val
2207
2237
 
@@ -2217,14 +2247,15 @@ regexp_contents: none
2217
2247
  when :evstr then
2218
2248
  result = s(:dsym, "", result).line result.line
2219
2249
  else
2220
- debug20 26, val, result
2250
+ debug 39
2221
2251
  end
2222
2252
  }
2223
2253
 
2224
2254
  numeric: simple_numeric
2225
- | tUMINUS_NUM simple_numeric
2255
+ | tUMINUS_NUM simple_numeric =tLOWEST
2226
2256
  {
2227
- result = -val[1] # TODO: pt_testcase
2257
+ _, (num, line) = val
2258
+ result = [-num, line]
2228
2259
  }
2229
2260
 
2230
2261
  simple_numeric: tINTEGER
@@ -2257,8 +2288,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2257
2288
 
2258
2289
  var_ref: user_variable
2259
2290
  {
2260
- var = val[0]
2291
+ raise "NO: #{val.inspect}" if Sexp === val.first
2292
+ (var, line), = val
2261
2293
  result = Sexp === var ? var : self.gettable(var)
2294
+ result.line line
2262
2295
  }
2263
2296
  | keyword_variable
2264
2297
  {
@@ -2273,11 +2306,19 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2273
2306
  | keyword_variable
2274
2307
  {
2275
2308
  result = self.assignable val[0]
2276
- debug20 29, val, result
2309
+ debug 40
2277
2310
  }
2278
2311
 
2279
- backref: tNTH_REF { result = s(:nth_ref, val[0]).line lexer.lineno }
2280
- | tBACK_REF { result = s(:back_ref, val[0]).line lexer.lineno }
2312
+ backref: tNTH_REF
2313
+ {
2314
+ (ref, line), = val
2315
+ result = s(:nth_ref, ref).line line
2316
+ }
2317
+ | tBACK_REF
2318
+ {
2319
+ (ref, line), = val
2320
+ result = s(:back_ref, ref).line line
2321
+ }
2281
2322
 
2282
2323
  superclass: tLT
2283
2324
  {
@@ -2295,22 +2336,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2295
2336
 
2296
2337
  f_arglist: tLPAREN2 f_args rparen
2297
2338
  {
2298
- result = val[1]
2299
- self.lexer.lex_state = EXPR_BEG
2300
- self.lexer.command_start = true
2301
- }
2302
- | tLPAREN2 args_forward rparen
2303
- {
2304
- args_rest = :"*"
2305
- kwargs_rest = :"**"
2306
- block_fwd = :"&"
2307
- self.env[args_rest] = :lvar
2308
- self.env[kwargs_rest] = :lvar
2309
- self.env[block_fwd] = :lvar
2310
-
2311
- result = s(:args, s(:forward_args)).line lexer.lineno
2312
- self.lexer.lex_state = EXPR_BEG
2313
- self.lexer.command_start = true
2339
+ result = end_args val
2314
2340
  }
2315
2341
  | {
2316
2342
  result = self.in_kwarg
@@ -2319,12 +2345,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2319
2345
  }
2320
2346
  f_args term
2321
2347
  {
2322
- kwarg, args, _ = val
2323
-
2324
- self.in_kwarg = kwarg
2325
- result = args
2326
- lexer.lex_state = EXPR_BEG
2327
- lexer.command_start = true
2348
+ result = end_args val
2328
2349
  }
2329
2350
 
2330
2351
  args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -2409,9 +2430,9 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2409
2430
  |
2410
2431
  {
2411
2432
  result = args val
2433
+ # result.line lexer.lineno
2412
2434
  }
2413
2435
 
2414
- args_forward: tBDOT3
2415
2436
 
2416
2437
  f_bad_arg: tCONSTANT
2417
2438
  {
@@ -2433,10 +2454,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2433
2454
  f_norm_arg: f_bad_arg
2434
2455
  | tIDENTIFIER
2435
2456
  {
2436
- identifier = val[0].to_sym
2457
+ (id, line), = val
2458
+ identifier = id.to_sym
2437
2459
  self.env[identifier] = :lvar
2438
2460
 
2439
- result = identifier
2461
+ result = [identifier, line]
2440
2462
  }
2441
2463
 
2442
2464
  f_arg_asgn: f_norm_arg
@@ -2444,22 +2466,14 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2444
2466
  f_arg_item: f_arg_asgn
2445
2467
  | tLPAREN f_margs rparen
2446
2468
  {
2447
- result = val[1]
2469
+ _, margs, _ = val
2470
+
2471
+ result = margs
2448
2472
  }
2449
2473
 
2450
2474
  f_arg: f_arg_item
2451
2475
  {
2452
- arg, = val
2453
-
2454
- case arg
2455
- when Symbol then
2456
- result = s(:args, arg).line lexer.lineno
2457
- when Sexp then
2458
- result = arg
2459
- else
2460
- debug20 32
2461
- raise "Unknown f_arg type: #{val.inspect}"
2462
- end
2476
+ result = new_arg val
2463
2477
  }
2464
2478
  | f_arg tCOMMA f_arg_item
2465
2479
  {
@@ -2471,7 +2485,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2471
2485
  result = s(:args, list).line list.line
2472
2486
  end
2473
2487
 
2474
- result << item
2488
+ result << (Sexp === item ? item : item.first)
2475
2489
  }
2476
2490
 
2477
2491
  f_label: tLABEL
@@ -2532,27 +2546,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2532
2546
  kwrest_mark: tPOW
2533
2547
  | tDSTAR
2534
2548
 
2549
+
2535
2550
  f_kwrest: kwrest_mark tIDENTIFIER
2536
2551
  {
2537
- name = val[1].to_sym
2538
- self.assignable name
2539
- result = :"**#{name}"
2552
+ _, (id, line) = val
2553
+
2554
+ name = id.to_sym
2555
+ self.assignable [name, line]
2556
+ result = [:"**#{name}", line]
2540
2557
  }
2541
2558
  | kwrest_mark
2542
2559
  {
2543
- result = :"**"
2544
- self.env[result] = :lvar
2560
+ id = :"**"
2561
+ self.env[id] = :lvar # TODO: needed?!?
2562
+ result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
2545
2563
  }
2546
2564
 
2547
2565
  f_opt: f_arg_asgn tEQL arg_value
2548
2566
  {
2549
- result = self.assignable val[0], val[2]
2567
+ lhs, _, rhs = val
2568
+ result = self.assignable lhs, rhs
2550
2569
  # TODO: detect duplicate names
2551
2570
  }
2552
2571
 
2553
2572
  f_block_opt: f_arg_asgn tEQL primary_value
2554
2573
  {
2555
- result = self.assignable val[0], val[2]
2574
+ lhs, _, rhs = val
2575
+ result = self.assignable lhs, rhs
2556
2576
  }
2557
2577
 
2558
2578
  f_block_optarg: f_block_opt
@@ -2582,30 +2602,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2582
2602
  f_rest_arg: restarg_mark tIDENTIFIER
2583
2603
  {
2584
2604
  # TODO: differs from parse.y - needs tests
2585
- name = val[1].to_sym
2586
- self.assignable name
2587
- result = :"*#{name}"
2605
+ _, (id, line) = val
2606
+ name = id.to_sym
2607
+ self.assignable [name, line]
2608
+ result = [:"*#{name}", line]
2588
2609
  }
2589
2610
  | restarg_mark
2590
2611
  {
2591
2612
  name = :"*"
2592
2613
  self.env[name] = :lvar
2593
- result = name
2614
+ result = [name, lexer.lineno] # FIX: tSTAR to include lineno
2594
2615
  }
2595
2616
 
2596
2617
  blkarg_mark: tAMPER2 | tAMPER
2597
2618
 
2598
2619
  f_block_arg: blkarg_mark tIDENTIFIER
2599
2620
  {
2600
- identifier = val[1].to_sym
2621
+ _, (id, line) = val
2622
+ identifier = id.to_sym
2601
2623
 
2602
2624
  self.env[identifier] = :lvar
2603
- result = "&#{identifier}".to_sym
2625
+ result = ["&#{identifier}".to_sym, line]
2604
2626
  }
2605
2627
 
2606
2628
  opt_f_block_arg: tCOMMA f_block_arg
2607
2629
  {
2608
- result = val[1]
2630
+ _, arg = val
2631
+ result = arg
2609
2632
  }
2610
2633
  |
2611
2634
  {
@@ -2654,9 +2677,11 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2654
2677
  }
2655
2678
  | tSTRING_BEG string_contents tLABEL_END arg_value
2656
2679
  {
2657
- _, sym, _, value = val
2680
+ (_, line), sym, _, value = val
2681
+
2658
2682
  sym.sexp_type = :dsym
2659
- result = s(:array, sym, value).line sym.line
2683
+
2684
+ result = s(:array, sym, value).line line
2660
2685
  }
2661
2686
  | tDSTAR arg_value
2662
2687
  {