brakeman 5.0.4 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +49 -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.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_detailed_exceptions.rb +1 -1
  107. data/lib/brakeman/checks/check_eol_rails.rb +23 -0
  108. data/lib/brakeman/checks/check_eol_ruby.rb +26 -0
  109. data/lib/brakeman/checks/check_evaluation.rb +1 -1
  110. data/lib/brakeman/checks/check_execute.rb +10 -0
  111. data/lib/brakeman/checks/check_json_parsing.rb +1 -1
  112. data/lib/brakeman/checks/check_render.rb +15 -1
  113. data/lib/brakeman/checks/check_sql.rb +58 -7
  114. data/lib/brakeman/checks/check_symbol_dos.rb +1 -1
  115. data/lib/brakeman/checks/check_verb_confusion.rb +1 -1
  116. data/lib/brakeman/checks/eol_check.rb +47 -0
  117. data/lib/brakeman/file_parser.rb +45 -15
  118. data/lib/brakeman/options.rb +15 -2
  119. data/lib/brakeman/processors/alias_processor.rb +91 -9
  120. data/lib/brakeman/processors/controller_alias_processor.rb +6 -43
  121. data/lib/brakeman/processors/gem_processor.rb +3 -0
  122. data/lib/brakeman/processors/haml_template_processor.rb +9 -0
  123. data/lib/brakeman/processors/lib/call_conversion_helper.rb +12 -6
  124. data/lib/brakeman/processors/lib/rails3_route_processor.rb +2 -0
  125. data/lib/brakeman/processors/library_processor.rb +9 -0
  126. data/lib/brakeman/processors/model_processor.rb +32 -0
  127. data/lib/brakeman/report/ignore/config.rb +1 -1
  128. data/lib/brakeman/report/ignore/interactive.rb +1 -1
  129. data/lib/brakeman/report/report_csv.rb +1 -1
  130. data/lib/brakeman/report/report_github.rb +31 -0
  131. data/lib/brakeman/report/report_sarif.rb +22 -3
  132. data/lib/brakeman/report/report_text.rb +1 -1
  133. data/lib/brakeman/report.rb +4 -1
  134. data/lib/brakeman/rescanner.rb +1 -1
  135. data/lib/brakeman/scanner.rb +19 -14
  136. data/lib/brakeman/tracker/collection.rb +57 -7
  137. data/lib/brakeman/tracker/config.rb +8 -1
  138. data/lib/brakeman/tracker/method_info.rb +70 -0
  139. data/lib/brakeman/tracker.rb +33 -4
  140. data/lib/brakeman/util.rb +34 -18
  141. data/lib/brakeman/version.rb +1 -1
  142. data/lib/brakeman/warning_codes.rb +2 -0
  143. data/lib/brakeman.rb +8 -2
  144. data/lib/ruby_parser/bm_sexp.rb +24 -0
  145. metadata +107 -95
  146. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/rp_stringscanner.rb +0 -64
  147. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby20_parser.rb +0 -7075
  148. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby21_parser.rb +0 -7148
  149. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby22_parser.rb +0 -7185
  150. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.rb +0 -7199
  151. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.y +0 -2643
  152. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby24_parser.rb +0 -7219
  153. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.rb +0 -7218
  154. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.y +0 -2651
  155. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby26_parser.rb +0 -7240
  156. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby27_parser.rb +0 -7358
  157. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.rb +0 -7358
  158. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/tools/ripper.rb +0 -39
  159. data/bundle/ruby/2.7.0/gems/unicode-display_width-1.7.0/data/display_width.marshal.gz +0 -0
@@ -1,26 +1,6 @@
1
1
  # -*- racc -*-
2
2
 
3
- #if V==20
4
- class Ruby20Parser
5
- #elif V==21
6
- class Ruby21Parser
7
- #elif V == 22
8
- class Ruby22Parser
9
- #elif V == 23
10
- class Ruby23Parser
11
- #elif V == 24
12
- class Ruby24Parser
13
- #elif V == 25
14
- class Ruby25Parser
15
- #elif V == 26
16
- class Ruby26Parser
17
- #elif V == 27
18
3
  class Ruby27Parser
19
- #elif V == 30
20
- class Ruby30Parser
21
- #else
22
- fail "version not specified or supported on code generation"
23
- #endif
24
4
 
25
5
  token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
26
6
  kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
@@ -38,19 +18,11 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
38
18
  tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
39
19
  tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END
40
20
  tSTRING tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA
41
- tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND tUBANG
42
- #if V >= 21
21
+ tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND
43
22
  tRATIONAL tIMAGINARY
44
- #endif
45
- #if V >= 22
46
23
  tLABEL_END
47
- #endif
48
- #if V >= 23
49
24
  tLONELY
50
- #endif
51
- #if V >= 26
52
25
  tBDOT2 tBDOT3
53
- #endif
54
26
 
55
27
  preclow
56
28
  nonassoc tLOWEST
@@ -108,7 +80,7 @@ rule
108
80
  | klBEGIN
109
81
  {
110
82
  if (self.in_def || self.in_single > 0) then
111
- debug20 1
83
+ debug 11
112
84
  yyerror "BEGIN in method"
113
85
  end
114
86
  self.env.extend
@@ -133,6 +105,8 @@ rule
133
105
  bodystmt: compstmt opt_rescue k_else
134
106
  {
135
107
  res = _values[-2]
108
+ # TODO: move down to main match so I can just use val
109
+
136
110
  yyerror "else without rescue is useless" unless res
137
111
  }
138
112
  compstmt
@@ -163,7 +137,7 @@ rule
163
137
  | error stmt
164
138
  {
165
139
  result = val[1]
166
- debug20 2, val, result
140
+ debug 12
167
141
  }
168
142
 
169
143
  stmt_or_begin: stmt
@@ -171,6 +145,10 @@ rule
171
145
  {
172
146
  yyerror "BEGIN is permitted only at toplevel"
173
147
  }
148
+ begin_block
149
+ {
150
+ result = val[2] # wtf?
151
+ }
174
152
 
175
153
  stmt: kALIAS fitem
176
154
  {
@@ -183,12 +161,12 @@ rule
183
161
  }
184
162
  | kALIAS tGVAR tGVAR
185
163
  {
186
- (_, line), lhs, rhs = val
164
+ (_, line), (lhs, _), (rhs, _) = val
187
165
  result = s(:valias, lhs.to_sym, rhs.to_sym).line line
188
166
  }
189
167
  | kALIAS tGVAR tBACK_REF
190
168
  {
191
- (_, line), lhs, rhs = val
169
+ (_, line), (lhs, _), (rhs, _) = val
192
170
  result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
193
171
  }
194
172
  | kALIAS tGVAR tNTH_REF
@@ -231,7 +209,7 @@ rule
231
209
  (_, line), _, stmt, _ = val
232
210
 
233
211
  if (self.in_def || self.in_single > 0) then
234
- debug20 3
212
+ debug 13
235
213
  yyerror "END in method; use at_exit"
236
214
  end
237
215
 
@@ -247,15 +225,16 @@ rule
247
225
  lhs, _, rhs = val
248
226
  result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
249
227
  }
250
- #if V == 20
251
- | mlhs tEQL arg_value
228
+ | mlhs tEQL mrhs_arg kRESCUE_MOD stmt
252
229
  {
253
- result = new_masgn val[0], val[2], :wrap
230
+ # unwraps s(:to_ary, rhs)
231
+ lhs, _, (_, rhs), _, resbody = val
232
+
233
+ resbody = new_resbody s(:array).line(resbody.line), resbody
234
+
235
+ result = new_masgn lhs, new_rescue(rhs, resbody), :wrap
254
236
  }
255
- | mlhs tEQL mrhs
256
- #else
257
237
  | mlhs tEQL mrhs_arg
258
- #endif
259
238
  {
260
239
  result = new_masgn val[0], val[2]
261
240
  }
@@ -279,32 +258,31 @@ rule
279
258
  }
280
259
  | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
281
260
  {
282
- prim, _, id, opasgn, rhs = val
283
- result = s(:op_asgn, prim, rhs, id.to_sym, opasgn.to_sym)
284
- if val[1] == '&.'
285
- result.sexp_type = :safe_op_asgn
286
- end
287
- result.line = val[0].line
261
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
262
+
263
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
264
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
265
+ result.line prim.line
288
266
  }
289
267
  | primary_value call_op tCONSTANT tOP_ASGN command_rhs
290
268
  {
291
- result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
292
- if val[1] == '&.'
293
- result.sexp_type = :safe_op_asgn
294
- end
295
- result.line = val[0].line
269
+ prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
270
+
271
+ result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
272
+ result.sexp_type = :safe_op_asgn if call_op == '&.'
273
+ result.line prim.line
296
274
  }
297
275
  | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
298
276
  {
299
- lhs1, _, lhs2, op, rhs = val
277
+ lhs1, _, (lhs2, line), (id, _), rhs = val
300
278
 
301
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
279
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
302
280
  }
303
281
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
304
282
  {
305
- lhs1, _, lhs2, op, rhs = val
283
+ lhs1, _, (lhs2, line), (id, _), rhs = val
306
284
 
307
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, op.to_sym)
285
+ result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
308
286
  }
309
287
  | backref tOP_ASGN command_rhs
310
288
  {
@@ -316,7 +294,6 @@ rule
316
294
  expr, = val
317
295
  result = value_expr expr
318
296
  }
319
- #if V >= 24
320
297
  | command_call kRESCUE_MOD stmt
321
298
  {
322
299
  expr, (_, line), resbody = val
@@ -325,7 +302,6 @@ rule
325
302
  ary = s(:array).line line
326
303
  result = new_rescue(expr, new_resbody(ary, resbody))
327
304
  }
328
- #endif
329
305
  | command_asgn
330
306
 
331
307
  expr: command_call
@@ -353,6 +329,28 @@ rule
353
329
  # REFACTOR: call_uni_op -- see parse26.y
354
330
  }
355
331
  | arg
332
+ kIN
333
+ {
334
+ # TODO? value_expr($1);
335
+ self.lexer.lex_state = EXPR_BEG|EXPR_LABEL
336
+ self.lexer.command_start = false
337
+ result = self.in_kwarg
338
+ self.in_kwarg = true
339
+ self.env.extend
340
+ }
341
+ p_expr
342
+ {
343
+ self.env.unextend
344
+
345
+ expr, _, old_kwarg, pat = val
346
+
347
+ expr = value_expr expr
348
+
349
+ self.in_kwarg = old_kwarg
350
+ pat_in = new_in pat, nil, nil, expr.line
351
+ result = new_case expr, pat_in, expr.line
352
+ }
353
+ | arg =tLBRACE_ARG
356
354
 
357
355
  expr_value: expr
358
356
  {
@@ -377,7 +375,7 @@ rule
377
375
  block_command: block_call
378
376
  | block_call call_op2 operation2 command_args
379
377
  {
380
- blk, _, msg, args = val
378
+ blk, _, (msg, _line), args = val
381
379
  result = new_call(blk, msg.to_sym, args).line blk.line
382
380
  }
383
381
 
@@ -391,15 +389,15 @@ rule
391
389
  _, line, body, _ = val
392
390
 
393
391
  result = body
394
- result.line = line
392
+ result.line line
395
393
 
396
394
  # self.env.unextend
397
395
  }
398
396
 
399
397
  fcall: operation
400
398
  {
401
- msg, = val
402
- result = new_call(nil, msg.to_sym).line lexer.lineno
399
+ (msg, line), = val
400
+ result = new_call(nil, msg.to_sym).line line
403
401
  }
404
402
 
405
403
  command: fcall command_args =tLOWEST
@@ -422,12 +420,14 @@ rule
422
420
  }
423
421
  | primary_value call_op operation2 command_args =tLOWEST
424
422
  {
425
- lhs, callop, op, args = val
423
+ lhs, callop, (op, _), args = val
424
+
426
425
  result = new_call lhs, op.to_sym, args, callop
426
+ result.line lhs.line
427
427
  }
428
428
  | primary_value call_op operation2 command_args cmd_brace_block
429
429
  {
430
- recv, _, msg, args, block = val
430
+ recv, _, (msg, _line), args, block = val
431
431
  call = new_call recv, msg.to_sym, args, val[1]
432
432
 
433
433
  block_dup_check call, block
@@ -437,11 +437,14 @@ rule
437
437
  }
438
438
  | primary_value tCOLON2 operation2 command_args =tLOWEST
439
439
  {
440
- result = new_call val[0], val[2].to_sym, val[3]
440
+ lhs, _, (id, line), args = val
441
+
442
+ result = new_call lhs, id.to_sym, args
443
+ result.line line
441
444
  }
442
445
  | primary_value tCOLON2 operation2 command_args cmd_brace_block
443
446
  {
444
- recv, _, msg, args, block = val
447
+ recv, _, (msg, _line), args, block = val
445
448
  call = new_call recv, msg.to_sym, args
446
449
 
447
450
  block_dup_check call, block
@@ -599,25 +602,29 @@ rule
599
602
  }
600
603
  | primary_value call_op tIDENTIFIER
601
604
  {
602
- result = new_attrasgn val[0], val[2], val[1]
605
+ lhs, call_op, (id, _line) = val
606
+
607
+ result = new_attrasgn lhs, id, call_op
603
608
  }
604
609
  | primary_value tCOLON2 tIDENTIFIER
605
610
  {
606
- recv, _, id = val
611
+ recv, _, (id, _line) = val
607
612
  result = new_attrasgn recv, id
608
613
  }
609
614
  | primary_value call_op tCONSTANT
610
615
  {
611
- result = new_attrasgn val[0], val[2], val[1]
616
+ lhs, call_op, (id, _line) = val
617
+
618
+ result = new_attrasgn lhs, id, call_op
612
619
  }
613
620
  | primary_value tCOLON2 tCONSTANT
614
621
  {
615
622
  if (self.in_def || self.in_single > 0) then
616
- debug20 7
623
+ debug 14
617
624
  yyerror "dynamic constant assignment"
618
625
  end
619
626
 
620
- expr, _, id = val
627
+ expr, _, (id, _line) = val
621
628
  l = expr.line
622
629
 
623
630
  result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
@@ -625,58 +632,65 @@ rule
625
632
  | tCOLON3 tCONSTANT
626
633
  {
627
634
  if (self.in_def || self.in_single > 0) then
628
- debug20 8
635
+ debug 15
629
636
  yyerror "dynamic constant assignment"
630
637
  end
631
638
 
632
- _, id = val
633
- l = lexer.lineno
639
+ _, (id, l) = val
634
640
 
635
641
  result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
636
642
  }
637
643
  | backref
638
644
  {
639
- self.backref_assign_error val[0]
645
+ ref, = val
646
+
647
+ self.backref_assign_error ref
640
648
  }
641
649
 
642
650
  lhs: user_variable
643
651
  {
644
- line = lexer.lineno
645
- result = self.assignable val[0]
646
- result.line = line
652
+ var, = val
653
+
654
+ result = self.assignable var
647
655
  }
648
656
  | keyword_variable
649
657
  {
650
- line = lexer.lineno
651
- result = self.assignable val[0]
652
- result.line = line
653
- debug20 9, val, result
658
+ var, = val
659
+
660
+ result = self.assignable var
661
+
662
+ debug 16
654
663
  }
655
664
  | primary_value tLBRACK2 opt_call_args rbracket
656
665
  {
657
666
  lhs, _, args, _ = val
667
+
658
668
  result = self.aryset lhs, args
659
669
  }
660
670
  | primary_value call_op tIDENTIFIER # REFACTOR
661
671
  {
662
- lhs, op, id = val
672
+ lhs, op, (id, _line) = val
673
+
663
674
  result = new_attrasgn lhs, id, op
664
675
  }
665
676
  | primary_value tCOLON2 tIDENTIFIER
666
677
  {
667
- lhs, _, id = val
678
+ lhs, _, (id, _line) = val
679
+
668
680
  result = new_attrasgn lhs, id
669
681
  }
670
682
  | primary_value call_op tCONSTANT # REFACTOR?
671
683
  {
672
- result = new_attrasgn val[0], val[2], val[1]
684
+ lhs, call_op, (id, _line) = val
685
+
686
+ result = new_attrasgn lhs, id, call_op
673
687
  }
674
688
  | primary_value tCOLON2 tCONSTANT
675
689
  {
676
- expr, _, id = val
690
+ expr, _, (id, _line) = val
677
691
 
678
692
  if (self.in_def || self.in_single > 0) then
679
- debug20 10
693
+ debug 17
680
694
  yyerror "dynamic constant assignment"
681
695
  end
682
696
 
@@ -685,14 +699,13 @@ rule
685
699
  }
686
700
  | tCOLON3 tCONSTANT
687
701
  {
688
- _, id = val
702
+ _, (id, l) = val
689
703
 
690
704
  if (self.in_def || self.in_single > 0) then
691
- debug20 11
705
+ debug 18
692
706
  yyerror "dynamic constant assignment"
693
707
  end
694
708
 
695
- l = lexer.lineno
696
709
  result = s(:const, s(:colon3, id.to_sym).line(l)).line l
697
710
  }
698
711
  | backref
@@ -708,16 +721,17 @@ rule
708
721
 
709
722
  cpath: tCOLON3 cname
710
723
  {
711
- _, name = val
712
- result = s(:colon3, name.to_sym).line lexer.lineno
724
+ _, (name, line) = val
725
+ result = s(:colon3, name.to_sym).line line
713
726
  }
714
727
  | cname
715
728
  {
716
- result = val[0].to_sym
729
+ (id, line), = val
730
+ result = [id.to_sym, line] # TODO: sexp?
717
731
  }
718
732
  | primary_value tCOLON2 cname
719
733
  {
720
- pval, _, name = val
734
+ pval, _, (name, _line) = val
721
735
 
722
736
  result = s(:colon2, pval, name.to_sym)
723
737
  result.line pval.line
@@ -727,24 +741,17 @@ rule
727
741
  | op
728
742
  {
729
743
  lexer.lex_state = EXPR_END
730
- result = val[0]
731
744
  }
732
745
 
733
746
  | reswords
734
- {
735
- (sym, _line), = val
736
- lexer.lex_state = EXPR_END
737
- result = sym
738
- }
739
-
740
- fsym: fname | symbol
741
747
 
742
- fitem: fsym
748
+ fitem: fname
743
749
  {
744
- id, = val
745
- result = s(:lit, id.to_sym).line lexer.lineno
750
+ (id, line), = val
751
+
752
+ result = s(:lit, id.to_sym).line line
746
753
  }
747
- | dsym
754
+ | symbol
748
755
 
749
756
  undef_list: fitem
750
757
  {
@@ -765,10 +772,6 @@ rule
765
772
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
766
773
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
767
774
  | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
768
- #if V >= 20
769
- # TODO: tUBANG dead?
770
- | tUBANG
771
- #endif
772
775
 
773
776
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
774
777
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -802,24 +805,20 @@ rule
802
805
  }
803
806
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
804
807
  {
805
- lhs, _, id, op, rhs = val
808
+ lhs, _, (id, _line), (op, _), rhs = val
806
809
 
807
810
  result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
808
811
  }
809
812
  | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
810
813
  {
811
- lhs1, _, lhs2, op, rhs = val
814
+ lhs1, _, (lhs2, _line), op, rhs = val
812
815
 
813
816
  lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
814
817
  result = new_const_op_asgn [lhs, op, rhs]
815
818
  }
816
- | tCOLON3 tCONSTANT
819
+ | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
817
820
  {
818
- result = self.lexer.lineno
819
- }
820
- tOP_ASGN arg_rhs
821
- {
822
- _, lhs, line, op, rhs = val
821
+ _, (lhs, line), op, rhs = val
823
822
 
824
823
  lhs = s(:colon3, lhs.to_sym).line line
825
824
  result = new_const_op_asgn [lhs, op, rhs]
@@ -833,7 +832,7 @@ rule
833
832
  | arg tDOT2 arg
834
833
  {
835
834
  v1, v2 = val[0], val[2]
836
- if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
835
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
837
836
  result = s(:lit, (v1.last)..(v2.last)).line v1.line
838
837
  else
839
838
  result = s(:dot2, v1, v2).line v1.line
@@ -842,13 +841,12 @@ rule
842
841
  | arg tDOT3 arg
843
842
  {
844
843
  v1, v2 = val[0], val[2]
845
- if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
844
+ if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
846
845
  result = s(:lit, (v1.last)...(v2.last)).line v1.line
847
846
  else
848
847
  result = s(:dot3, v1, v2).line v1.line
849
848
  end
850
849
  }
851
- #if V >= 26
852
850
  | arg tDOT2
853
851
  {
854
852
  v1, _ = val
@@ -863,9 +861,7 @@ rule
863
861
 
864
862
  result = s(:dot3, v1, v2).line v1.line
865
863
  }
866
- #endif
867
864
 
868
- #if V >= 27
869
865
  | tBDOT2 arg
870
866
  {
871
867
  _, v2, = val
@@ -880,7 +876,6 @@ rule
880
876
 
881
877
  result = s(:dot3, v1, v2).line v2.line
882
878
  }
883
- #endif
884
879
 
885
880
  | arg tPLUS arg
886
881
  {
@@ -906,24 +901,12 @@ rule
906
901
  {
907
902
  result = new_call val[0], :**, argl(val[2])
908
903
  }
909
- #if V == 20
910
- | tUMINUS_NUM tINTEGER tPOW arg
911
- {
912
- lit = s(:lit, val[1]).line lexer.lineno
913
- result = new_call(new_call(lit, :"**", argl(val[3])), :"-@")
914
- }
915
- | tUMINUS_NUM tFLOAT tPOW arg
916
- #else
917
904
  | tUMINUS_NUM simple_numeric tPOW arg
918
- #endif
919
905
  {
920
- lit = s(:lit, val[1]).line lexer.lineno
921
- result = new_call(new_call(lit, :"**", argl(val[3])), :"-@")
906
+ _, (num, line), _, arg = val
907
+ lit = s(:lit, num).line line
908
+ result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
922
909
 
923
- #if V == 20
924
- ## TODO: why is this 2.0 only?
925
- debug20 12, val, result
926
- #endif
927
910
  }
928
911
  | tUPLUS arg
929
912
  {
@@ -1021,12 +1004,12 @@ rule
1021
1004
 
1022
1005
  rel_expr: arg relop arg =tGT
1023
1006
  {
1024
- lhs, op, rhs = val
1007
+ lhs, (op, _), rhs = val
1025
1008
  result = new_call lhs, op.to_sym, argl(rhs)
1026
1009
  }
1027
1010
  | rel_expr relop arg =tGT
1028
1011
  {
1029
- lhs, op, rhs = val
1012
+ lhs, (op, _), rhs = val
1030
1013
  warn "comparison '%s' after comparison", op
1031
1014
  result = new_call lhs, op.to_sym, argl(rhs)
1032
1015
  }
@@ -1066,18 +1049,24 @@ rule
1066
1049
  _, args, _ = val
1067
1050
  result = args
1068
1051
  }
1069
- #if V >= 27
1052
+ | tLPAREN2 args tCOMMA args_forward rparen
1053
+ {
1054
+ yyerror "Unexpected ..." unless
1055
+ self.lexer.is_local_id(:"*") &&
1056
+ self.lexer.is_local_id(:"**") &&
1057
+ self.lexer.is_local_id(:"&")
1058
+
1059
+ result = call_args val
1060
+ }
1070
1061
  | tLPAREN2 args_forward rparen
1071
1062
  {
1072
- if (!self.lexer.is_local_id(:"*") ||
1073
- !self.lexer.is_local_id(:"**") ||
1074
- !self.lexer.is_local_id(:"&")) then
1063
+ yyerror "Unexpected ..." unless
1064
+ self.lexer.is_local_id(:"*") &&
1065
+ self.lexer.is_local_id(:"**") &&
1066
+ self.lexer.is_local_id(:"&")
1075
1067
 
1076
- yyerror("Invalid argument forwarding")
1077
- end
1078
- result = call_args [s(:forward_args).line(lexer.lineno)]
1068
+ result = call_args val
1079
1069
  }
1080
- #endif
1081
1070
 
1082
1071
  opt_paren_args: none
1083
1072
  | paren_args
@@ -1192,7 +1181,6 @@ rule
1192
1181
  result = self.list_append args, s(:splat, id).line(line)
1193
1182
  }
1194
1183
 
1195
- #if V >= 21
1196
1184
  mrhs_arg: mrhs
1197
1185
  {
1198
1186
  result = new_masgn_arg val[0]
@@ -1202,7 +1190,6 @@ rule
1202
1190
  result = new_masgn_arg val[0], :wrap
1203
1191
  }
1204
1192
 
1205
- #endif
1206
1193
  mrhs: args tCOMMA arg_value
1207
1194
  {
1208
1195
  result = val[0] << val[2]
@@ -1231,8 +1218,9 @@ rule
1231
1218
  | backref
1232
1219
  | tFID
1233
1220
  {
1234
- msg, = val
1221
+ (msg, line), = val
1235
1222
  result = new_call nil, msg.to_sym
1223
+ result.line line
1236
1224
  }
1237
1225
  | k_begin
1238
1226
  {
@@ -1274,15 +1262,15 @@ rule
1274
1262
  }
1275
1263
  | primary_value tCOLON2 tCONSTANT
1276
1264
  {
1277
- expr, _, id = val
1265
+ expr, _, (id, _line) = val
1278
1266
 
1279
1267
  result = s(:colon2, expr, id.to_sym).line expr.line
1280
1268
  }
1281
1269
  | tCOLON3 tCONSTANT
1282
1270
  {
1283
- _, id = val
1271
+ _, (id, line) = val
1284
1272
 
1285
- result = s(:colon3, id.to_sym).line lexer.lineno
1273
+ result = s(:colon3, id.to_sym).line line
1286
1274
  }
1287
1275
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1288
1276
  {
@@ -1306,15 +1294,21 @@ rule
1306
1294
  }
1307
1295
  | kYIELD tLPAREN2 call_args rparen
1308
1296
  {
1309
- result = new_yield val[2]
1297
+ (_, line), _, args, _ = val
1298
+
1299
+ result = new_yield(args).line line
1310
1300
  }
1311
1301
  | kYIELD tLPAREN2 rparen
1312
1302
  {
1313
- result = new_yield
1303
+ (_, line), _, _ = val
1304
+
1305
+ result = new_yield.line line
1314
1306
  }
1315
1307
  | kYIELD
1316
1308
  {
1317
- result = new_yield
1309
+ (_, line), = val
1310
+
1311
+ result = new_yield.line line
1318
1312
  }
1319
1313
  | kDEFINED opt_nl tLPAREN2 expr rparen
1320
1314
  {
@@ -1329,7 +1323,7 @@ rule
1329
1323
  }
1330
1324
  | kNOT tLPAREN2 rparen
1331
1325
  {
1332
- debug20 14, val, result
1326
+ debug 20
1333
1327
  }
1334
1328
  | fcall brace_block
1335
1329
  {
@@ -1347,9 +1341,10 @@ rule
1347
1341
  iter.insert 1, call # FIX
1348
1342
  result = iter
1349
1343
  }
1350
- | tLAMBDA lambda
1344
+ | lambda
1351
1345
  {
1352
- result = val[1] # TODO: fix lineno
1346
+ expr, = val
1347
+ result = expr
1353
1348
  }
1354
1349
  | k_if expr_value then compstmt if_tail k_end
1355
1350
  {
@@ -1381,6 +1376,12 @@ rule
1381
1376
  (_, line), _, body, _ = val
1382
1377
  result = new_case nil, body, line
1383
1378
  }
1379
+ | k_case expr_value opt_terms p_case_body k_end
1380
+ {
1381
+ (_, line), expr, _, body, _ = val
1382
+
1383
+ result = new_case expr, body, line
1384
+ }
1384
1385
  | k_for for_var kIN expr_value_do compstmt k_end
1385
1386
  {
1386
1387
  _, var, _, iter, body, _ = val
@@ -1392,7 +1393,6 @@ rule
1392
1393
  }
1393
1394
  cpath superclass
1394
1395
  {
1395
- self.comments.push self.lexer.comments
1396
1396
  if (self.in_def || self.in_single > 0) then
1397
1397
  yyerror "class definition in method body"
1398
1398
  end
@@ -1402,7 +1402,7 @@ rule
1402
1402
  {
1403
1403
  result = new_class val
1404
1404
  self.env.unextend
1405
- self.lexer.comments # we don't care about comments in the body
1405
+ self.lexer.ignore_body_comments
1406
1406
  }
1407
1407
  | k_class tLSHFT
1408
1408
  {
@@ -1423,7 +1423,7 @@ rule
1423
1423
  {
1424
1424
  result = new_sclass val
1425
1425
  self.env.unextend
1426
- self.lexer.comments # we don't care about comments in the body
1426
+ self.lexer.ignore_body_comments
1427
1427
  }
1428
1428
  | k_module
1429
1429
  {
@@ -1431,7 +1431,6 @@ rule
1431
1431
  }
1432
1432
  cpath
1433
1433
  {
1434
- self.comments.push self.lexer.comments
1435
1434
  yyerror "module definition in method body" if
1436
1435
  self.in_def or self.in_single > 0
1437
1436
 
@@ -1441,7 +1440,7 @@ rule
1441
1440
  {
1442
1441
  result = new_module val
1443
1442
  self.env.unextend
1444
- self.lexer.comments # we don't care about comments in the body
1443
+ self.lexer.ignore_body_comments
1445
1444
  }
1446
1445
  | k_def fname
1447
1446
  {
@@ -1451,21 +1450,17 @@ rule
1451
1450
  self.env.extend
1452
1451
  lexer.cmdarg.push false
1453
1452
  lexer.cond.push false
1454
-
1455
- self.comments.push self.lexer.comments
1456
1453
  }
1457
- f_arglist bodystmt { result = lexer.lineno } k_end
1454
+ f_arglist bodystmt k_end
1458
1455
  {
1459
- in_def = val[2]
1460
-
1461
- result = new_defn val
1456
+ result, in_def = new_defn val
1462
1457
 
1463
1458
  lexer.cond.pop # group = local_pop
1464
1459
  lexer.cmdarg.pop
1465
1460
  self.env.unextend
1466
1461
  self.in_def = in_def
1467
1462
 
1468
- self.lexer.comments # we don't care about comments in the body
1463
+ self.lexer.ignore_body_comments
1469
1464
  }
1470
1465
  | k_def singleton dot_or_colon
1471
1466
  {
@@ -1473,7 +1468,7 @@ rule
1473
1468
  }
1474
1469
  fname
1475
1470
  {
1476
- result = [self.in_def, lexer.lineno]
1471
+ result = self.in_def
1477
1472
 
1478
1473
  self.in_single += 1 # TODO: remove?
1479
1474
 
@@ -1483,13 +1478,18 @@ rule
1483
1478
  lexer.cond.push false
1484
1479
 
1485
1480
  lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
1486
- self.comments.push self.lexer.comments
1487
1481
  }
1488
1482
  f_arglist bodystmt k_end
1489
1483
  {
1490
- _, _recv, _, _, _name, (in_def, _lineno), _args, _body, _ = val
1491
1484
 
1492
- result = new_defs val
1485
+ # [kdef, recv, _, _, (name, line), in_def, args, body, kend]
1486
+ # =>
1487
+ # [kdef, recv, (name, line), in_def, args, body, kend]
1488
+
1489
+ val.delete_at 3
1490
+ val.delete_at 2
1491
+
1492
+ result, in_def = new_defs val
1493
1493
 
1494
1494
  lexer.cond.pop # group = local_pop
1495
1495
  lexer.cmdarg.pop
@@ -1500,7 +1500,7 @@ rule
1500
1500
 
1501
1501
  # TODO: restore cur_arg ? what's cur_arg?
1502
1502
 
1503
- self.lexer.comments # we don't care about comments in the body
1503
+ self.lexer.ignore_body_comments
1504
1504
  }
1505
1505
  | kBREAK
1506
1506
  {
@@ -1537,8 +1537,17 @@ rule
1537
1537
  k_case: kCASE
1538
1538
  k_for: kFOR
1539
1539
  k_class: kCLASS
1540
+ {
1541
+ self.comments.push self.lexer.comments
1542
+ }
1540
1543
  k_module: kMODULE
1544
+ {
1545
+ self.comments.push self.lexer.comments
1546
+ }
1541
1547
  k_def: kDEF
1548
+ {
1549
+ self.comments.push self.lexer.comments
1550
+ }
1542
1551
  k_do: kDO
1543
1552
  k_do_block: kDO_BLOCK
1544
1553
  k_rescue: kRESCUE
@@ -1599,51 +1608,42 @@ rule
1599
1608
 
1600
1609
  result = block_var args
1601
1610
  }
1602
- | f_marg_list tCOMMA tSTAR f_norm_arg
1611
+ | f_marg_list tCOMMA f_rest_marg
1603
1612
  {
1604
- args, _, _, splat = val
1613
+ args, _, rest = val
1605
1614
 
1606
- result = block_var args, "*#{splat}".to_sym
1615
+ result = block_var args, rest
1607
1616
  }
1608
- | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1617
+ | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1609
1618
  {
1610
- args, _, _, splat, _, args2 = val
1619
+ lhs, _, splat, _, rhs = val
1611
1620
 
1612
- result = block_var args, "*#{splat}".to_sym, args2
1621
+ result = block_var lhs, splat, rhs
1613
1622
  }
1614
- | f_marg_list tCOMMA tSTAR
1623
+ | f_rest_marg
1615
1624
  {
1616
- args, _, _ = val
1625
+ rest, = val
1617
1626
 
1618
- result = block_var args, :*
1627
+ result = block_var rest
1619
1628
  }
1620
- | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1629
+ | f_rest_marg tCOMMA f_marg_list
1621
1630
  {
1622
- args, _, _, _, args2 = val
1631
+ splat, _, rest = val
1623
1632
 
1624
- result = block_var args, :*, args2
1633
+ result = block_var splat, rest
1625
1634
  }
1626
- | tSTAR f_norm_arg
1627
- {
1628
- _, splat = val
1629
1635
 
1630
- result = block_var :"*#{splat}"
1631
- }
1632
- | tSTAR f_norm_arg tCOMMA f_marg_list
1636
+ f_rest_marg: tSTAR f_norm_arg
1633
1637
  {
1634
- _, splat, _, args = val
1638
+ _, (id, line) = val
1635
1639
 
1636
- result = block_var :"*#{splat}", args
1640
+ result = args ["*#{id}".to_sym]
1641
+ result.line line
1637
1642
  }
1638
1643
  | tSTAR
1639
1644
  {
1640
- result = block_var :*
1641
- }
1642
- | tSTAR tCOMMA f_marg_list
1643
- {
1644
- _, _, args = val
1645
-
1646
- result = block_var :*, args
1645
+ result = args [:*]
1646
+ result.line lexer.lineno # FIX: tSTAR -> line
1647
1647
  }
1648
1648
 
1649
1649
  block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -1658,10 +1658,14 @@ rule
1658
1658
  {
1659
1659
  result = call_args val
1660
1660
  }
1661
+ | f_no_kwarg opt_f_block_arg
1662
+ {
1663
+ result = args val
1664
+ }
1661
1665
  | f_block_arg
1662
1666
  {
1663
- line = lexer.lineno
1664
- result = call_args val # TODO: push line down
1667
+ (id, line), = val
1668
+ result = call_args [id]
1665
1669
  result.line line
1666
1670
  }
1667
1671
 
@@ -1770,13 +1774,13 @@ opt_block_args_tail: tCOMMA block_args_tail
1770
1774
 
1771
1775
  bvar: tIDENTIFIER
1772
1776
  {
1773
- id, = val
1774
- line = lexer.lineno
1777
+ (id, line), = val
1775
1778
  result = s(:shadow, id.to_sym).line line
1776
1779
  }
1777
1780
  | f_bad_arg
1778
1781
 
1779
- lambda: {
1782
+ lambda: tLAMBDA
1783
+ {
1780
1784
  self.env.extend :dynamic
1781
1785
  result = [lexer.lineno, lexer.lpar_beg]
1782
1786
  lexer.paren_nest += 1
@@ -1788,14 +1792,14 @@ opt_block_args_tail: tCOMMA block_args_tail
1788
1792
  }
1789
1793
  lambda_body
1790
1794
  {
1791
- (line, lpar), args, _cmdarg, body = val
1795
+ _, (line, lpar), args, _cmdarg, body = val
1792
1796
  lexer.lpar_beg = lpar
1793
1797
 
1794
1798
  lexer.cmdarg.pop
1795
1799
 
1796
1800
  call = s(:lambda).line line
1797
1801
  result = new_iter call, args, body
1798
- result.line = line
1802
+ result.line line
1799
1803
  self.env.unextend # TODO: dynapush & dynapop
1800
1804
  }
1801
1805
 
@@ -1830,23 +1834,28 @@ opt_block_args_tail: tCOMMA block_args_tail
1830
1834
  ## if (nd_type($1) == NODE_YIELD) {
1831
1835
  ## compile_error(PARSER_ARG "block given to yield");
1832
1836
 
1833
- syntax_error "Both block arg and actual block given." if
1834
- val[0].block_pass?
1837
+ cmd, blk = val
1835
1838
 
1836
- val = invert_block_call val if inverted? val
1839
+ syntax_error "Both block arg and actual block given." if
1840
+ cmd.block_pass?
1837
1841
 
1838
- cmd, blk = val
1842
+ if inverted? val then
1843
+ val = invert_block_call val
1844
+ cmd, blk = val
1845
+ end
1839
1846
 
1840
1847
  result = blk
1841
1848
  result.insert 1, cmd
1842
1849
  }
1843
1850
  | block_call call_op2 operation2 opt_paren_args
1844
1851
  {
1845
- result = new_call val[0], val[2].to_sym, val[3]
1852
+ lhs, _, (id, _line), args = val
1853
+
1854
+ result = new_call lhs, id.to_sym, args
1846
1855
  }
1847
1856
  | block_call call_op2 operation2 opt_paren_args brace_block
1848
1857
  {
1849
- iter1, _, name, args, iter2 = val
1858
+ iter1, _, (name, _line), args, iter2 = val
1850
1859
 
1851
1860
  call = new_call iter1, name.to_sym, args
1852
1861
  iter2.insert 1, call
@@ -1855,7 +1864,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1855
1864
  }
1856
1865
  | block_call call_op2 operation2 command_args do_block
1857
1866
  {
1858
- iter1, _, name, args, iter2 = val
1867
+ iter1, _, (name, _line), args, iter2 = val
1859
1868
 
1860
1869
  call = new_call iter1, name.to_sym, args
1861
1870
  iter2.insert 1, call
@@ -1863,28 +1872,29 @@ opt_block_args_tail: tCOMMA block_args_tail
1863
1872
  result = iter2
1864
1873
  }
1865
1874
 
1866
- method_call: fcall
1867
- {
1868
- result = self.lexer.lineno
1869
- }
1870
- paren_args
1875
+ method_call: fcall paren_args
1871
1876
  {
1872
- call, lineno, args = val
1877
+ call, args = val
1873
1878
 
1874
1879
  result = call.concat args.sexp_body if args
1875
- result.line lineno
1876
1880
  }
1877
1881
  | primary_value call_op operation2 opt_paren_args
1878
1882
  {
1879
- result = new_call val[0], val[2].to_sym, val[3], val[1]
1883
+ recv, call_op, (op, _line), args = val
1884
+
1885
+ result = new_call recv, op.to_sym, args, call_op
1880
1886
  }
1881
1887
  | primary_value tCOLON2 operation2 paren_args
1882
1888
  {
1883
- result = new_call val[0], val[2].to_sym, val[3]
1889
+ recv, _, (op, _line), args = val
1890
+
1891
+ result = new_call recv, op.to_sym, args
1884
1892
  }
1885
1893
  | primary_value tCOLON2 operation3
1886
1894
  {
1887
- result = new_call val[0], val[2].to_sym
1895
+ lhs, _, (id, _line) = val
1896
+
1897
+ result = new_call lhs, id.to_sym
1888
1898
  }
1889
1899
  | primary_value call_op paren_args
1890
1900
  {
@@ -1917,7 +1927,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1917
1927
  _, line, body, _ = val
1918
1928
 
1919
1929
  result = body
1920
- result.line = line
1930
+ result.line line
1921
1931
 
1922
1932
  self.env.unextend
1923
1933
  }
@@ -1931,7 +1941,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1931
1941
  _, line, body, _ = val
1932
1942
 
1933
1943
  result = body
1934
- result.line = line
1944
+ result.line line
1935
1945
 
1936
1946
  self.env.unextend
1937
1947
  }
@@ -1951,11 +1961,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1951
1961
  do_body: { self.env.extend :dynamic; result = self.lexer.lineno }
1952
1962
  { lexer.cmdarg.push false }
1953
1963
  opt_block_param
1954
- #if V >= 25
1955
1964
  bodystmt
1956
- #else
1957
- compstmt
1958
- #endif
1959
1965
  {
1960
1966
  line, _cmdarg, param, cmpstmt = val
1961
1967
 
@@ -1964,18 +1970,546 @@ opt_block_args_tail: tCOMMA block_args_tail
1964
1970
  self.env.unextend
1965
1971
  }
1966
1972
 
1973
+ case_args: arg_value
1974
+ {
1975
+ arg, = val
1976
+
1977
+ result = s(:array, arg).line arg.line
1978
+ }
1979
+ | tSTAR arg_value
1980
+ {
1981
+ _, arg = val
1982
+
1983
+ result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1984
+ }
1985
+ | case_args tCOMMA arg_value
1986
+ {
1987
+ args, _, id = val
1988
+
1989
+ result = self.list_append args, id
1990
+ }
1991
+ | case_args tCOMMA tSTAR arg_value
1992
+ {
1993
+ args, _, _, id = val
1994
+
1995
+ result = self.list_append args, s(:splat, id).line(id.line)
1996
+ }
1997
+
1967
1998
  case_body: k_when
1968
1999
  {
1969
2000
  result = self.lexer.lineno
1970
2001
  }
1971
- args then compstmt cases
2002
+ case_args then compstmt cases
1972
2003
  {
1973
2004
  result = new_when(val[2], val[4])
1974
- result.line = val[1]
2005
+ result.line val[1]
1975
2006
  result << val[5] if val[5]
1976
2007
  }
1977
2008
 
1978
2009
  cases: opt_else | case_body
2010
+ ######################################################################
2011
+
2012
+ p_case_body: kIN
2013
+ {
2014
+ self.lexer.lex_state = EXPR_BEG|EXPR_LABEL
2015
+ self.lexer.command_start = false
2016
+ result = self.in_kwarg
2017
+ self.in_kwarg = true
2018
+ push_pvtbl
2019
+ push_pktbl
2020
+ }
2021
+ p_top_expr then
2022
+ {
2023
+ pop_pktbl
2024
+ pop_pvtbl
2025
+ old_kwargs = _values[-3]
2026
+ self.in_kwarg = old_kwargs
2027
+ }
2028
+ compstmt
2029
+ p_cases
2030
+ {
2031
+ (_, line), _, pat, _, _, body, cases = val
2032
+
2033
+ result = new_in pat, body, cases, line
2034
+ }
2035
+
2036
+ p_cases: opt_else
2037
+ | p_case_body
2038
+
2039
+ p_top_expr: p_top_expr_body
2040
+ | p_top_expr_body kIF_MOD expr_value
2041
+ {
2042
+ body, _, cond = val
2043
+ body = remove_begin body
2044
+
2045
+ result = s(:if, cond, body, nil).line body.line
2046
+ }
2047
+ | p_top_expr_body kUNLESS_MOD expr_value
2048
+ {
2049
+ body, _, cond = val
2050
+ body = remove_begin body
2051
+
2052
+ result = s(:if, cond, nil, body).line body.line
2053
+ }
2054
+
2055
+ p_top_expr_body: p_expr
2056
+ | p_expr tCOMMA
2057
+ {
2058
+ expr, _ = val
2059
+
2060
+ tail = new_array_pattern_tail nil, true, nil, nil
2061
+ result = new_array_pattern nil, expr, tail, expr.line
2062
+ }
2063
+ | p_expr tCOMMA p_args
2064
+ {
2065
+ expr, _, args = val
2066
+
2067
+ result = new_array_pattern nil, expr, args, expr.line
2068
+ }
2069
+ | p_args_tail
2070
+ {
2071
+ args, = val
2072
+ result = new_array_pattern nil, nil, args, args.line
2073
+ }
2074
+ | p_kwargs
2075
+ {
2076
+ kwargs, = val
2077
+ result = new_hash_pattern nil, kwargs, kwargs.line
2078
+ }
2079
+
2080
+ p_expr: p_as
2081
+
2082
+ p_as: p_expr tASSOC p_variable
2083
+ {
2084
+ # NODE *n = NEW_LIST($1, &@$);
2085
+ # n = list_append(p, n, $3);
2086
+ # $$ = new_hash(p, n, &@$);
2087
+
2088
+ expr, _, var = val
2089
+
2090
+ id = var.last
2091
+
2092
+ self.env[id] = :lvar # HACK: need to extend env
2093
+ lhs = s(:lasgn, id).line var.line
2094
+
2095
+ result = new_assign lhs, expr
2096
+ }
2097
+ | p_alt
2098
+
2099
+ p_alt: p_alt tPIPE p_expr_basic
2100
+ {
2101
+ lhs, _, rhs = val
2102
+
2103
+ result = s(:or, lhs, rhs).line lhs.line
2104
+ }
2105
+ | p_expr_basic
2106
+
2107
+ p_lparen: tLPAREN2 { push_pktbl }
2108
+ p_lbracket: tLBRACK2 { push_pktbl }
2109
+
2110
+ p_expr_basic: p_value
2111
+ | p_const p_lparen p_args tRPAREN
2112
+ {
2113
+ lhs, _, args, _ = val
2114
+
2115
+ pop_pktbl
2116
+ result = new_array_pattern(lhs, nil, args, lhs.line)
2117
+ }
2118
+ | p_const p_lparen p_kwargs tRPAREN
2119
+ {
2120
+ lhs, _, kwargs, _ = val
2121
+
2122
+ pop_pktbl
2123
+ result = new_hash_pattern(lhs, kwargs, lhs.line)
2124
+ }
2125
+ | p_const tLPAREN2 tRPAREN
2126
+ {
2127
+ const, _, _ = val
2128
+
2129
+ tail = new_array_pattern_tail nil, nil, nil, nil
2130
+ result = new_array_pattern const, nil, tail, const.line
2131
+ }
2132
+ | p_const p_lbracket p_args rbracket
2133
+ {
2134
+ const, _, pre_arg, _ = val
2135
+
2136
+ pop_pktbl
2137
+ result = new_array_pattern const, nil, pre_arg, const.line
2138
+ }
2139
+ | p_const p_lbracket p_kwargs rbracket
2140
+ {
2141
+ const, _, kwargs, _ = val
2142
+
2143
+ result = new_hash_pattern const, kwargs, const.line
2144
+ }
2145
+ | p_const tLBRACK2 rbracket
2146
+ {
2147
+ const, _, _ = val
2148
+
2149
+ tail = new_array_pattern_tail nil, nil, nil, nil
2150
+ result = new_array_pattern const, nil, tail, const.line
2151
+ }
2152
+ | tLBRACK { push_pktbl } p_args rbracket
2153
+ {
2154
+ _, _, pat, _ = val
2155
+
2156
+ pop_pktbl
2157
+ result = new_array_pattern nil, nil, pat, pat.line
2158
+ }
2159
+ | tLBRACK rbracket
2160
+ {
2161
+ (_, line), _ = val
2162
+
2163
+ result = s(:array_pat).line line
2164
+ }
2165
+ | tLBRACE
2166
+ {
2167
+ push_pktbl
2168
+ result = self.in_kwarg
2169
+ self.in_kwarg = false
2170
+ }
2171
+ p_kwargs rbrace
2172
+ {
2173
+ _, in_kwarg, kwargs, _ = val
2174
+
2175
+ pop_pktbl
2176
+ self.in_kwarg = in_kwarg
2177
+
2178
+ result = new_hash_pattern(nil, kwargs, kwargs.line)
2179
+ }
2180
+ | tLBRACE rbrace
2181
+ {
2182
+ (_, line), _ = val
2183
+
2184
+ tail = new_hash_pattern_tail nil, nil, line
2185
+ result = new_hash_pattern nil, tail, line
2186
+ }
2187
+ | tLPAREN { push_pktbl } p_expr tRPAREN
2188
+ {
2189
+ _, _, expr, _ = val
2190
+
2191
+ pop_pktbl
2192
+ result = expr
2193
+ }
2194
+
2195
+ p_args: p_expr
2196
+ {
2197
+ expr, = val
2198
+
2199
+ ary = s(:array_TAIL, expr).line expr.line
2200
+ result = new_array_pattern_tail(ary, nil, nil, nil).line expr.line
2201
+ }
2202
+ | p_args_head
2203
+ {
2204
+ head, = val
2205
+
2206
+ result = new_array_pattern_tail head, true, nil, nil
2207
+ }
2208
+ | p_args_head p_arg
2209
+ {
2210
+ head, tail = val
2211
+
2212
+ both = array_pat_concat head, tail
2213
+
2214
+ result = new_array_pattern_tail both, nil, nil, nil
2215
+ result.line head.line
2216
+ }
2217
+ | p_args_head tSTAR tIDENTIFIER
2218
+ {
2219
+ head, _, (id, _line) = val
2220
+
2221
+ result = new_array_pattern_tail head, true, id.to_sym, nil
2222
+ result.line head.line
2223
+ }
2224
+ | p_args_head tSTAR tIDENTIFIER tCOMMA p_args_post
2225
+ {
2226
+ head, _, (id, _line), _, post = val
2227
+
2228
+ result = new_array_pattern_tail head, true, id.to_sym, post
2229
+ result.line head.line
2230
+ }
2231
+ | p_args_head tSTAR
2232
+ {
2233
+ expr, _ = val
2234
+
2235
+ result = new_array_pattern_tail(expr, true, nil, nil).line expr.line
2236
+ }
2237
+ | p_args_head tSTAR tCOMMA p_args_post
2238
+ {
2239
+ head, _, _, post = val
2240
+
2241
+ result = new_array_pattern_tail(head, true, nil, post).line head.line
2242
+ }
2243
+ | p_args_tail
2244
+
2245
+ p_args_head: p_arg tCOMMA
2246
+ {
2247
+ arg, _ = val
2248
+ result = arg
2249
+ }
2250
+ | p_args_head p_arg tCOMMA
2251
+ {
2252
+ head, tail, _ = val
2253
+
2254
+ result = s(:PATTERN, *head.sexp_body, *tail.sexp_body)
2255
+ result.line head.line
2256
+ }
2257
+
2258
+ p_args_tail: tSTAR tIDENTIFIER
2259
+ {
2260
+ _, (id, line) = val
2261
+
2262
+ result = new_array_pattern_tail nil, true, id.to_sym, nil
2263
+ result.line line
2264
+ }
2265
+ | tSTAR tIDENTIFIER tCOMMA p_args_post
2266
+ {
2267
+ _, (id, line), _, rhs = val
2268
+
2269
+ result = new_array_pattern_tail nil, true, id.to_sym, rhs
2270
+ result.line line
2271
+ }
2272
+ | tSTAR
2273
+ {
2274
+ (_, line), = val
2275
+
2276
+ result = new_array_pattern_tail nil, true, nil, nil
2277
+ result.line line
2278
+ }
2279
+ | tSTAR tCOMMA p_args_post
2280
+ {
2281
+ (_, line), _, args = val
2282
+
2283
+ result = new_array_pattern_tail nil, true, nil, args
2284
+ result.line line
2285
+ }
2286
+
2287
+ p_args_post: p_arg
2288
+ | p_args_post tCOMMA p_arg
2289
+ {
2290
+ lhs, _, rhs = val
2291
+
2292
+ result = array_pat_concat lhs, rhs
2293
+ }
2294
+
2295
+ p_arg: p_expr
2296
+ {
2297
+ expr, = val
2298
+ expr = s(:array_TAIL, expr).line expr.line unless
2299
+ expr.sexp_type == :array_TAIL
2300
+ result = expr
2301
+ }
2302
+
2303
+ p_kwargs: p_kwarg tCOMMA p_kwrest
2304
+ {
2305
+ kw_arg, _, rest = val
2306
+ # TODO? new_unique_key_hash(p, $1, &@$)
2307
+ result = new_hash_pattern_tail kw_arg, rest, kw_arg.line
2308
+ }
2309
+ | p_kwarg
2310
+ {
2311
+ kwarg, = val
2312
+ # TODO? new_unique_key_hash(p, $1, &@$)
2313
+ result = new_hash_pattern_tail kwarg, nil, kwarg.line
2314
+ }
2315
+ | p_kwarg tCOMMA
2316
+ {
2317
+ kwarg, _ = val
2318
+ # TODO? new_unique_key_hash(p, $1, &@$)
2319
+ result = new_hash_pattern_tail kwarg, nil, kwarg.line
2320
+ }
2321
+ | p_kwrest
2322
+ {
2323
+ rest, = val
2324
+
2325
+ result = new_hash_pattern_tail nil, rest, rest.line
2326
+ }
2327
+ | p_kwarg tCOMMA p_kwnorest
2328
+ {
2329
+ kwarg, _, norest = val
2330
+
2331
+ # TODO? new_unique_key_hash(p, $1, &@$)
2332
+ result = new_hash_pattern_tail kwarg, norest, kwarg.line
2333
+ }
2334
+ | p_kwnorest
2335
+ {
2336
+ norest, = val
2337
+
2338
+ result = new_hash_pattern_tail nil, norest, norest.line
2339
+ }
2340
+
2341
+ p_kwarg: p_kw # TODO? rb_ary_new_from_args(1, $1)
2342
+ | p_kwarg tCOMMA p_kw
2343
+ {
2344
+ kwarg, _, kw = val
2345
+ kwarg.concat kw.sexp_body
2346
+ result = kwarg
2347
+ }
2348
+
2349
+ p_kw: p_kw_label p_expr
2350
+ {
2351
+ # TODO: error_duplicate_pattern_key(p, get_id($1), &@1);
2352
+ lhs, rhs = val
2353
+
2354
+ result = s(:PAIR, lhs, rhs).line lhs.line
2355
+ }
2356
+ | p_kw_label
2357
+ {
2358
+ lhs, = val
2359
+
2360
+ # TODO: error_duplicate_pattern_variable(p, get_id($1), &@1);
2361
+
2362
+ # TODO: if ($1 && !is_local_id(get_id($1))) {
2363
+ # yyerror1(&@1, "key must be valid as local variables");
2364
+ # }
2365
+
2366
+ # $$ = list_append(p, NEW_LIST(NEW_LIT(ID2SYM($1), &@$), &@$),
2367
+ # assignable(p, $1, 0, &@$));
2368
+
2369
+
2370
+ case lhs.sexp_type
2371
+ when :lit then
2372
+ assignable [lhs.value, lhs.line]
2373
+ else
2374
+ # TODO or done?
2375
+ debug 666
2376
+ end
2377
+
2378
+ # TODO PAIR -> LIST ?
2379
+ result = s(:PAIR, lhs, nil).line lhs.line
2380
+ }
2381
+
2382
+ p_kw_label: tLABEL
2383
+ {
2384
+ (id, line), = val
2385
+
2386
+ result = s(:lit, id.to_sym).line line
2387
+ }
2388
+
2389
+ p_kwrest: kwrest_mark tIDENTIFIER
2390
+ {
2391
+ _, (id, line) = val
2392
+
2393
+ name = id.to_sym
2394
+ self.assignable [name, line]
2395
+ result = s(:kwrest, :"**#{name}").line line
2396
+ }
2397
+ | kwrest_mark
2398
+ {
2399
+ (_, line), = val
2400
+
2401
+ result = s(:kwrest, :"**").line line
2402
+ }
2403
+
2404
+ p_kwnorest: kwrest_mark kNIL
2405
+ {
2406
+ (_, line), _ = val
2407
+
2408
+ # TODO: or s(:norest)? s(:**nil)?
2409
+ result = s(:kwrest, :"**nil").line line
2410
+ }
2411
+
2412
+ p_value: p_primitive
2413
+ | p_primitive tDOT2 p_primitive
2414
+ {
2415
+ lhs, _, rhs = val
2416
+
2417
+ lhs = value_expr lhs
2418
+ rhs = value_expr rhs
2419
+
2420
+ result = s(:dot2, lhs, rhs).line lhs.line
2421
+ }
2422
+ | p_primitive tDOT3 p_primitive
2423
+ {
2424
+ lhs, _, rhs = val
2425
+
2426
+ lhs = value_expr lhs
2427
+ rhs = value_expr rhs
2428
+
2429
+ result = s(:dot3, lhs, rhs).line lhs.line
2430
+ }
2431
+ | p_primitive tDOT2
2432
+ {
2433
+ v1, _ = val
2434
+
2435
+ result = s(:dot2, v1, nil).line v1.line
2436
+ }
2437
+ | p_primitive tDOT3
2438
+ {
2439
+ v1, _ = val
2440
+
2441
+ result = s(:dot3, v1, nil).line v1.line
2442
+ }
2443
+ | p_variable
2444
+ | p_var_ref
2445
+ | p_const
2446
+ | tBDOT2 p_primitive
2447
+ {
2448
+ _, v1 = val
2449
+
2450
+ result = s(:dot2, nil, v1).line v1.line
2451
+ }
2452
+ | tBDOT3 p_primitive
2453
+ {
2454
+ _, v1 = val
2455
+
2456
+ result = s(:dot3, nil, v1).line v1.line
2457
+ }
2458
+
2459
+ p_primitive: literal
2460
+ | strings
2461
+ | xstring
2462
+ | regexp
2463
+ | words
2464
+ | qwords
2465
+ | symbols
2466
+ | qsymbols
2467
+ | keyword_variable
2468
+ {
2469
+ # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
2470
+ var, = val
2471
+
2472
+ result = var
2473
+ }
2474
+ | lambda
2475
+
2476
+ p_variable: tIDENTIFIER
2477
+ {
2478
+ (id, line), = val
2479
+
2480
+ # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2481
+ # TODO: assignable(p, $1, 0, &@$);
2482
+ result = s(:lvar, id.to_sym).line line
2483
+ }
2484
+
2485
+ p_var_ref: tCARET tIDENTIFIER
2486
+ {
2487
+ _, (id, line) = val
2488
+
2489
+ # TODO: check id against env for lvar or dvar
2490
+
2491
+ result = s(:lvar, id.to_sym).line line
2492
+ }
2493
+
2494
+ p_const: tCOLON3 cname
2495
+ {
2496
+ _, (id, line) = val
2497
+ result = s(:colon3, id.to_sym).line line
2498
+ }
2499
+ | p_const tCOLON2 cname
2500
+ {
2501
+ lhs, _, (id, _line) = val
2502
+
2503
+ l = lhs.line
2504
+ result = s(:const, s(:colon2, lhs, id.to_sym).line(l)).line l
2505
+ }
2506
+ | tCONSTANT
2507
+ {
2508
+ # TODO $$ = gettable(p, $1, &@$);
2509
+ (id, line), = val
2510
+ result = s(:const, id.to_sym).line line
2511
+ }
2512
+ ######################################################################
1979
2513
 
1980
2514
  opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
1981
2515
  {
@@ -2017,17 +2551,10 @@ opt_block_args_tail: tCOMMA block_args_tail
2017
2551
 
2018
2552
  literal: numeric
2019
2553
  {
2020
- line = lexer.lineno
2021
- result = s(:lit, val[0])
2022
- result.line = line
2554
+ (lit, line), = val
2555
+ result = s(:lit, lit).line line
2023
2556
  }
2024
2557
  | symbol
2025
- {
2026
- line = lexer.lineno
2027
- result = s(:lit, val[0])
2028
- result.line = line
2029
- }
2030
- | dsym
2031
2558
 
2032
2559
  strings: string
2033
2560
  {
@@ -2038,7 +2565,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2038
2565
 
2039
2566
  string: tCHAR
2040
2567
  {
2041
- debug20 23, val, result
2568
+ debug 37
2042
2569
  }
2043
2570
  | string1
2044
2571
  | string string1
@@ -2048,11 +2575,11 @@ opt_block_args_tail: tCOMMA block_args_tail
2048
2575
 
2049
2576
  string1: tSTRING_BEG string_contents tSTRING_END
2050
2577
  {
2051
- _, str, (_, func) = val
2578
+ (_, line), str, (_, func) = val
2052
2579
 
2053
- str = dedent str if func =~ RubyLexer::STR_FUNC_ICNTNT
2580
+ str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
2054
2581
 
2055
- result = str
2582
+ result = str.line line
2056
2583
  }
2057
2584
  | tSTRING
2058
2585
  {
@@ -2072,11 +2599,15 @@ opt_block_args_tail: tCOMMA block_args_tail
2072
2599
 
2073
2600
  words: tWORDS_BEG tSPACE tSTRING_END
2074
2601
  {
2075
- result = s(:array).line lexer.lineno
2602
+ (_, line), _, _ = val
2603
+
2604
+ result = s(:array).line line
2076
2605
  }
2077
2606
  | tWORDS_BEG word_list tSTRING_END
2078
2607
  {
2079
- result = val[1]
2608
+ (_, line), list, _ = val
2609
+
2610
+ result = list.line line
2080
2611
  }
2081
2612
 
2082
2613
  word_list: none
@@ -2096,18 +2627,20 @@ opt_block_args_tail: tCOMMA block_args_tail
2096
2627
 
2097
2628
  symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2098
2629
  {
2099
- result = s(:array).line lexer.lineno
2630
+ (_, line), _, _ = val
2631
+
2632
+ result = s(:array).line line
2100
2633
  }
2101
- | tSYMBOLS_BEG { result = lexer.lineno } symbol_list tSTRING_END
2634
+ | tSYMBOLS_BEG symbol_list tSTRING_END
2102
2635
  {
2103
- _, line, list, _, = val
2104
- list.line = line
2636
+ (_, line), list, _, = val
2637
+ list.line line
2105
2638
  result = list
2106
2639
  }
2107
2640
 
2108
2641
  symbol_list: none
2109
2642
  {
2110
- result = new_symbol_list.line lexer.lineno
2643
+ result = new_symbol_list
2111
2644
  }
2112
2645
  | symbol_list word tSPACE
2113
2646
  {
@@ -2117,20 +2650,28 @@ opt_block_args_tail: tCOMMA block_args_tail
2117
2650
 
2118
2651
  qwords: tQWORDS_BEG tSPACE tSTRING_END
2119
2652
  {
2120
- result = s(:array).line lexer.lineno
2653
+ (_, line), _, _ = val
2654
+
2655
+ result = s(:array).line line
2121
2656
  }
2122
2657
  | tQWORDS_BEG qword_list tSTRING_END
2123
2658
  {
2124
- result = val[1]
2659
+ (_, line), list, _ = val
2660
+
2661
+ result = list.line line
2125
2662
  }
2126
2663
 
2127
2664
  qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2128
2665
  {
2129
- result = s(:array).line lexer.lineno # FIX
2666
+ (_, line), _, _ = val
2667
+
2668
+ result = s(:array).line line
2130
2669
  }
2131
2670
  | tQSYMBOLS_BEG qsym_list tSTRING_END
2132
2671
  {
2133
- result = val[1]
2672
+ (_, line), list, _ = val
2673
+
2674
+ result = list.line line
2134
2675
  }
2135
2676
 
2136
2677
  qword_list: none
@@ -2153,7 +2694,8 @@ opt_block_args_tail: tCOMMA block_args_tail
2153
2694
 
2154
2695
  string_contents: none
2155
2696
  {
2156
- result = s(:str, "").line lexer.lineno
2697
+ line = prev_value_to_lineno _values.last
2698
+ result = s(:str, +"").line line
2157
2699
  }
2158
2700
  | string_contents string_content
2159
2701
  {
@@ -2228,8 +2770,8 @@ regexp_contents: none
2228
2770
  lexer.brace_nest = brace_nest
2229
2771
  lexer.string_nest = string_nest
2230
2772
 
2231
- lexer.cmdarg.pop
2232
2773
  lexer.cond.pop
2774
+ lexer.cmdarg.pop
2233
2775
 
2234
2776
  lexer.lex_state = oldlex_state
2235
2777
 
@@ -2244,29 +2786,49 @@ regexp_contents: none
2244
2786
  when nil then
2245
2787
  result = s(:evstr).line line
2246
2788
  else
2247
- debug20 25
2789
+ debug 38
2248
2790
  raise "unknown string body: #{stmt.inspect}"
2249
2791
  end
2250
2792
  }
2251
2793
 
2252
- string_dvar: tGVAR { result = s(:gvar, val[0].to_sym).line lexer.lineno }
2253
- | tIVAR { result = s(:ivar, val[0].to_sym).line lexer.lineno }
2254
- | tCVAR { result = s(:cvar, val[0].to_sym).line lexer.lineno }
2794
+ string_dvar: tGVAR
2795
+ {
2796
+ (id, line), = val
2797
+ result = s(:gvar, id.to_sym).line line
2798
+ }
2799
+ | tIVAR
2800
+ {
2801
+ (id, line), = val
2802
+ result = s(:ivar, id.to_sym).line line
2803
+ }
2804
+ | tCVAR
2805
+ {
2806
+ (id, line), = val
2807
+ result = s(:cvar, id.to_sym).line line
2808
+ }
2255
2809
  | backref
2256
2810
 
2257
- symbol: tSYMBEG sym
2811
+ symbol: ssym
2812
+ | dsym
2813
+
2814
+ ssym: tSYMBEG sym
2258
2815
  {
2816
+ _, (id, line) = val
2817
+
2259
2818
  lexer.lex_state = EXPR_END
2260
- result = val[1].to_sym
2819
+ result = s(:lit, id.to_sym).line line
2261
2820
  }
2262
2821
  | tSYMBOL
2263
2822
  {
2264
- result = val[0].to_sym
2823
+ (id, line), = val
2824
+
2825
+ lexer.lex_state = EXPR_END
2826
+ result = s(:lit, id.to_sym).line line
2265
2827
  }
2266
2828
 
2267
2829
  sym: fname | tIVAR | tGVAR | tCVAR
2268
2830
 
2269
- dsym: tSYMBEG xstring_contents tSTRING_END
2831
+ dsym: tSYMBEG string_contents tSTRING_END
2270
2832
  {
2271
2833
  _, result, _ = val
2272
2834
 
@@ -2282,35 +2844,22 @@ regexp_contents: none
2282
2844
  when :evstr then
2283
2845
  result = s(:dsym, "", result).line result.line
2284
2846
  else
2285
- debug20 26, val, result
2847
+ debug 39
2286
2848
  end
2287
2849
  }
2288
2850
 
2289
- #if V == 20
2290
- numeric: tINTEGER
2291
- | tFLOAT
2292
- | tUMINUS_NUM tINTEGER =tLOWEST
2293
- #else
2294
2851
  numeric: simple_numeric
2295
- | tUMINUS_NUM simple_numeric
2296
- #endif
2297
- {
2298
- result = -val[1] # TODO: pt_testcase
2299
- #if V == 20
2300
- }
2301
- | tUMINUS_NUM tFLOAT =tLOWEST
2852
+ | tUMINUS_NUM simple_numeric =tLOWEST
2302
2853
  {
2303
- result = -val[1] # TODO: pt_testcase
2304
- #endif
2854
+ _, (num, line) = val
2855
+ result = [-num, line]
2305
2856
  }
2306
2857
 
2307
- #if V >= 21
2308
2858
  simple_numeric: tINTEGER
2309
2859
  | tFLOAT
2310
2860
  | tRATIONAL
2311
2861
  | tIMAGINARY
2312
2862
 
2313
- #endif
2314
2863
  user_variable: tIDENTIFIER
2315
2864
  | tIVAR
2316
2865
  | tGVAR
@@ -2336,8 +2885,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2336
2885
 
2337
2886
  var_ref: user_variable
2338
2887
  {
2339
- var = val[0]
2888
+ raise "NO: #{val.inspect}" if Sexp === val.first
2889
+ (var, line), = val
2340
2890
  result = Sexp === var ? var : self.gettable(var)
2891
+ result.line line
2341
2892
  }
2342
2893
  | keyword_variable
2343
2894
  {
@@ -2352,11 +2903,19 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2352
2903
  | keyword_variable
2353
2904
  {
2354
2905
  result = self.assignable val[0]
2355
- debug20 29, val, result
2906
+ debug 40
2356
2907
  }
2357
2908
 
2358
- backref: tNTH_REF { result = s(:nth_ref, val[0]).line lexer.lineno }
2359
- | tBACK_REF { result = s(:back_ref, val[0]).line lexer.lineno }
2909
+ backref: tNTH_REF
2910
+ {
2911
+ (ref, line), = val
2912
+ result = s(:nth_ref, ref).line line
2913
+ }
2914
+ | tBACK_REF
2915
+ {
2916
+ (ref, line), = val
2917
+ result = s(:back_ref, ref).line line
2918
+ }
2360
2919
 
2361
2920
  superclass: tLT
2362
2921
  {
@@ -2374,25 +2933,16 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2374
2933
 
2375
2934
  f_arglist: tLPAREN2 f_args rparen
2376
2935
  {
2377
- result = val[1]
2378
- self.lexer.lex_state = EXPR_BEG
2379
- self.lexer.command_start = true
2936
+ result = end_args val
2937
+ }
2938
+ | tLPAREN2 f_arg tCOMMA args_forward rparen
2939
+ {
2940
+ result = end_args val
2380
2941
  }
2381
- #if V >= 27
2382
2942
  | tLPAREN2 args_forward rparen
2383
2943
  {
2384
- args_rest = :"*"
2385
- kwargs_rest = :"**"
2386
- block_fwd = :"&"
2387
- self.env[args_rest] = :lvar
2388
- self.env[kwargs_rest] = :lvar
2389
- self.env[block_fwd] = :lvar
2390
-
2391
- result = s(:args, s(:forward_args)).line lexer.lineno
2392
- self.lexer.lex_state = EXPR_BEG
2393
- self.lexer.command_start = true
2944
+ result = end_args val
2394
2945
  }
2395
- #endif
2396
2946
  | {
2397
2947
  result = self.in_kwarg
2398
2948
  self.in_kwarg = true
@@ -2400,12 +2950,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2400
2950
  }
2401
2951
  f_args term
2402
2952
  {
2403
- kwarg, args, _ = val
2404
-
2405
- self.in_kwarg = kwarg
2406
- result = args
2407
- lexer.lex_state = EXPR_BEG
2408
- lexer.command_start = true
2953
+ result = end_args val
2409
2954
  }
2410
2955
 
2411
2956
  args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -2420,6 +2965,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2420
2965
  {
2421
2966
  result = args val
2422
2967
  }
2968
+ | f_no_kwarg opt_f_block_arg
2969
+ {
2970
+ result = args val
2971
+ }
2423
2972
  | f_block_arg
2424
2973
 
2425
2974
  opt_args_tail: tCOMMA args_tail
@@ -2490,9 +3039,13 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2490
3039
  |
2491
3040
  {
2492
3041
  result = args val
3042
+ # result.line lexer.lineno
2493
3043
  }
2494
3044
 
2495
- args_forward: tBDOT3
3045
+ args_forward: tBDOT3
3046
+ {
3047
+ result = s(:forward_args).line lexer.lineno
3048
+ }
2496
3049
 
2497
3050
  f_bad_arg: tCONSTANT
2498
3051
  {
@@ -2514,41 +3067,26 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2514
3067
  f_norm_arg: f_bad_arg
2515
3068
  | tIDENTIFIER
2516
3069
  {
2517
- identifier = val[0].to_sym
3070
+ (id, line), = val
3071
+ identifier = id.to_sym
2518
3072
  self.env[identifier] = :lvar
2519
3073
 
2520
- result = identifier
3074
+ result = [identifier, line]
2521
3075
  }
2522
3076
 
2523
- #if V >= 22
2524
3077
  f_arg_asgn: f_norm_arg
2525
3078
 
2526
3079
  f_arg_item: f_arg_asgn
2527
3080
  | tLPAREN f_margs rparen
2528
3081
  {
2529
- result = val[1]
2530
- }
2531
- #else
2532
- f_arg_item: f_norm_arg
2533
- | tLPAREN f_margs rparen
2534
- {
2535
- result = val[1]
3082
+ _, margs, _ = val
3083
+
3084
+ result = margs
2536
3085
  }
2537
- #endif
2538
3086
 
2539
3087
  f_arg: f_arg_item
2540
3088
  {
2541
- arg, = val
2542
-
2543
- case arg
2544
- when Symbol then
2545
- result = s(:args, arg).line lexer.lineno
2546
- when Sexp then
2547
- result = arg
2548
- else
2549
- debug20 32
2550
- raise "Unknown f_arg type: #{val.inspect}"
2551
- end
3089
+ result = new_arg val
2552
3090
  }
2553
3091
  | f_arg tCOMMA f_arg_item
2554
3092
  {
@@ -2560,16 +3098,12 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2560
3098
  result = s(:args, list).line list.line
2561
3099
  end
2562
3100
 
2563
- result << item
3101
+ result << (Sexp === item ? item : item.first)
2564
3102
  }
2565
3103
 
2566
- #if V == 20
2567
- f_kw: tLABEL arg_value
2568
- #else
2569
3104
  f_label: tLABEL
2570
3105
 
2571
3106
  f_kw: f_label arg_value
2572
- #endif
2573
3107
  {
2574
3108
  # TODO: new_kw_arg
2575
3109
  (label, line), arg = val
@@ -2580,7 +3114,6 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2580
3114
  kwarg = s(:kwarg, identifier, arg).line line
2581
3115
  result = s(:array, kwarg).line line
2582
3116
  }
2583
- #if V >= 21
2584
3117
  | f_label
2585
3118
  {
2586
3119
  (label, line), = val
@@ -2590,13 +3123,8 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2590
3123
 
2591
3124
  result = s(:array, s(:kwarg, id).line(line)).line line
2592
3125
  }
2593
- #endif
2594
3126
 
2595
- #if V == 20
2596
- f_block_kw: tLABEL primary_value
2597
- #else
2598
3127
  f_block_kw: f_label primary_value
2599
- #endif
2600
3128
  {
2601
3129
  # TODO: new_kw_arg
2602
3130
  (label, line), expr = val
@@ -2605,7 +3133,6 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2605
3133
 
2606
3134
  result = s(:array, s(:kwarg, id, expr).line(line)).line line
2607
3135
  }
2608
- #if V >= 21
2609
3136
  | f_label
2610
3137
  {
2611
3138
  # TODO: new_kw_arg
@@ -2615,7 +3142,6 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2615
3142
 
2616
3143
  result = s(:array, s(:kwarg, id).line(line)).line line
2617
3144
  }
2618
- #endif
2619
3145
 
2620
3146
  f_block_kwarg: f_block_kw
2621
3147
  | f_block_kwarg tCOMMA f_block_kw
@@ -2633,39 +3159,37 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2633
3159
  kwrest_mark: tPOW
2634
3160
  | tDSTAR
2635
3161
 
3162
+ f_no_kwarg: kwrest_mark kNIL
3163
+ {
3164
+ result = :"**nil"
3165
+ }
3166
+
2636
3167
  f_kwrest: kwrest_mark tIDENTIFIER
2637
3168
  {
2638
- name = val[1].to_sym
2639
- self.assignable name
2640
- result = :"**#{name}"
3169
+ _, (id, line) = val
3170
+
3171
+ name = id.to_sym
3172
+ self.assignable [name, line]
3173
+ result = [:"**#{name}", line]
2641
3174
  }
2642
3175
  | kwrest_mark
2643
3176
  {
2644
- result = :"**"
2645
- self.env[result] = :lvar
3177
+ id = :"**"
3178
+ self.env[id] = :lvar # TODO: needed?!?
3179
+ result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
2646
3180
  }
2647
3181
 
2648
- #if V == 20
2649
- f_opt: tIDENTIFIER tEQL arg_value
2650
- #elif V == 21
2651
- f_opt: f_norm_arg tEQL arg_value
2652
- #else
2653
3182
  f_opt: f_arg_asgn tEQL arg_value
2654
- #endif
2655
3183
  {
2656
- result = self.assignable val[0], val[2]
3184
+ lhs, _, rhs = val
3185
+ result = self.assignable lhs, rhs
2657
3186
  # TODO: detect duplicate names
2658
3187
  }
2659
3188
 
2660
- #if V == 20
2661
- f_block_opt: tIDENTIFIER tEQL primary_value
2662
- #elif V == 21
2663
- f_block_opt: f_norm_arg tEQL primary_value
2664
- #else
2665
3189
  f_block_opt: f_arg_asgn tEQL primary_value
2666
- #endif
2667
3190
  {
2668
- result = self.assignable val[0], val[2]
3191
+ lhs, _, rhs = val
3192
+ result = self.assignable lhs, rhs
2669
3193
  }
2670
3194
 
2671
3195
  f_block_optarg: f_block_opt
@@ -2695,30 +3219,33 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2695
3219
  f_rest_arg: restarg_mark tIDENTIFIER
2696
3220
  {
2697
3221
  # TODO: differs from parse.y - needs tests
2698
- name = val[1].to_sym
2699
- self.assignable name
2700
- result = :"*#{name}"
3222
+ _, (id, line) = val
3223
+ name = id.to_sym
3224
+ self.assignable [name, line]
3225
+ result = [:"*#{name}", line]
2701
3226
  }
2702
3227
  | restarg_mark
2703
3228
  {
2704
3229
  name = :"*"
2705
3230
  self.env[name] = :lvar
2706
- result = name
3231
+ result = [name, lexer.lineno] # FIX: tSTAR to include lineno
2707
3232
  }
2708
3233
 
2709
3234
  blkarg_mark: tAMPER2 | tAMPER
2710
3235
 
2711
3236
  f_block_arg: blkarg_mark tIDENTIFIER
2712
3237
  {
2713
- identifier = val[1].to_sym
3238
+ _, (id, line) = val
3239
+ identifier = id.to_sym
2714
3240
 
2715
3241
  self.env[identifier] = :lvar
2716
- result = "&#{identifier}".to_sym
3242
+ result = ["&#{identifier}".to_sym, line]
2717
3243
  }
2718
3244
 
2719
3245
  opt_f_block_arg: tCOMMA f_block_arg
2720
3246
  {
2721
- result = val[1]
3247
+ _, arg = val
3248
+ result = arg
2722
3249
  }
2723
3250
  |
2724
3251
  {
@@ -2765,14 +3292,14 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2765
3292
  lit = s(:lit, label.to_sym).line line
2766
3293
  result = s(:array, lit, arg).line line
2767
3294
  }
2768
- #if V >= 22
2769
3295
  | tSTRING_BEG string_contents tLABEL_END arg_value
2770
3296
  {
2771
- _, sym, _, value = val
3297
+ (_, line), sym, _, value = val
3298
+
2772
3299
  sym.sexp_type = :dsym
2773
- result = s(:array, sym, value).line sym.line
3300
+
3301
+ result = s(:array, sym, value).line line
2774
3302
  }
2775
- #endif
2776
3303
  | tDSTAR arg_value
2777
3304
  {
2778
3305
  _, arg = val
@@ -2785,9 +3312,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2785
3312
  operation3: tIDENTIFIER | tFID | op
2786
3313
  dot_or_colon: tDOT | tCOLON2
2787
3314
  call_op: tDOT
2788
- #if V >= 23
2789
3315
  | tLONELY # TODO: rename tANDDOT?
2790
- #endif
2791
3316
 
2792
3317
  call_op2: call_op
2793
3318
  | tCOLON2
@@ -2796,6 +3321,7 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2796
3321
  opt_nl: | tNL
2797
3322
  rparen: opt_nl tRPAREN
2798
3323
  rbracket: opt_nl tRBRACK
3324
+ rbrace: opt_nl tRCURLY
2799
3325
  trailer: | tNL | tCOMMA
2800
3326
 
2801
3327
  term: tSEMI { yyerrok }