brakeman 5.0.4 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +53 -1
- data/README.md +1 -1
- data/bundle/load.rb +5 -4
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/CHANGELOG.md +8 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/FAQ.md +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/Gemfile +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/MIT-LICENSE +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/README.md +19 -13
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/REFERENCE.md +10 -3
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/TODO +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/haml.gemspec +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/attribute_builder.rb +55 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/attribute_compiler.rb +4 -2
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/attribute_parser.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/buffer.rb +0 -56
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/compiler.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/engine.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/error.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/escapable.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/exec.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/filters.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/generator.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/action_view_extensions.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/action_view_mods.rb +0 -0
- 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
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/safe_erubi_template.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/safe_erubis_template.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers/xss_mods.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/helpers.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/options.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/parser.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/plugin.rb +18 -1
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/railtie.rb +5 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/sass_rails_filter.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/template/options.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/template.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/temple_engine.rb +2 -1
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/temple_line_counter.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/util.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml/version.rb +1 -1
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/lib/haml.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/yard/default/fulldoc/html/css/common.sass +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.2}/yard/default/layout/html/footer.erb +0 -0
- data/bundle/ruby/2.7.0/gems/parallel-1.21.0/MIT-LICENSE.txt +20 -0
- data/bundle/ruby/2.7.0/gems/parallel-1.21.0/lib/parallel/processor_count.rb +45 -0
- data/bundle/ruby/2.7.0/gems/parallel-1.21.0/lib/parallel/version.rb +4 -0
- data/bundle/ruby/2.7.0/gems/parallel-1.21.0/lib/parallel.rb +532 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/History.rdoc +88 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/Manifest.txt +3 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/README.rdoc +1 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/compare/normalize.rb +6 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/debugging.md +0 -0
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/gauntlet.md +106 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/rp_extensions.rb +15 -36
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/rp_stringscanner.rb +33 -0
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby20_parser.rb +7128 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby20_parser.y +335 -252
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby21_parser.rb +7182 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby21_parser.y +330 -249
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby22_parser.rb +7228 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby22_parser.y +334 -251
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby23_parser.rb +7237 -0
- 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
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby24_parser.rb +7268 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby24_parser.y +334 -251
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby25_parser.rb +7268 -0
- 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
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby26_parser.rb +7287 -0
- 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
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby27_parser.rb +8517 -0
- 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
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby30_parser.rb +8751 -0
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby30_parser.y +3472 -0
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby3_parser.yy +3476 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_lexer.rb +261 -609
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_lexer.rex +27 -20
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_lexer.rex.rb +59 -23
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby_lexer_strings.rb +638 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_parser.rb +0 -0
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/lib/ruby_parser.yy +3487 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_parser_extras.rb +296 -115
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/tools/munge.rb +34 -6
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.18.1/tools/ripper.rb +44 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/History.rdoc +15 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/Manifest.txt +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/README.rdoc +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/composite_sexp_processor.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/pt_testcase.rb +7 -2
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/sexp.rb +19 -9
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/sexp_matcher.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/sexp_processor.rb +1 -1
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/strict_sexp.rb +25 -3
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.3 → sexp_processor-4.16.0}/lib/unique.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/CHANGELOG.md +4 -0
- data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/MIT-LICENSE.txt +0 -0
- data/bundle/ruby/2.7.0/gems/{unicode-display_width-1.7.0 → unicode-display_width-1.8.0}/README.md +1 -1
- data/bundle/ruby/2.7.0/gems/unicode-display_width-1.8.0/data/display_width.marshal.gz +0 -0
- 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
- 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
- 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
- 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
- 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
- data/lib/brakeman/app_tree.rb +1 -1
- data/lib/brakeman/checks/base_check.rb +10 -0
- data/lib/brakeman/checks/check_detailed_exceptions.rb +1 -1
- data/lib/brakeman/checks/check_eol_rails.rb +23 -0
- data/lib/brakeman/checks/check_eol_ruby.rb +26 -0
- data/lib/brakeman/checks/check_evaluation.rb +1 -1
- data/lib/brakeman/checks/check_execute.rb +10 -0
- data/lib/brakeman/checks/check_json_parsing.rb +1 -1
- data/lib/brakeman/checks/check_render.rb +15 -1
- data/lib/brakeman/checks/check_sql.rb +58 -7
- data/lib/brakeman/checks/check_symbol_dos.rb +1 -1
- data/lib/brakeman/checks/check_verb_confusion.rb +1 -1
- data/lib/brakeman/checks/eol_check.rb +47 -0
- data/lib/brakeman/file_parser.rb +45 -15
- data/lib/brakeman/options.rb +15 -2
- data/lib/brakeman/processors/alias_processor.rb +91 -9
- data/lib/brakeman/processors/controller_alias_processor.rb +6 -43
- data/lib/brakeman/processors/gem_processor.rb +3 -0
- data/lib/brakeman/processors/haml_template_processor.rb +9 -0
- data/lib/brakeman/processors/lib/call_conversion_helper.rb +12 -6
- data/lib/brakeman/processors/lib/rails3_route_processor.rb +2 -0
- data/lib/brakeman/processors/library_processor.rb +9 -0
- data/lib/brakeman/processors/model_processor.rb +32 -0
- data/lib/brakeman/report/ignore/config.rb +1 -1
- data/lib/brakeman/report/ignore/interactive.rb +1 -1
- data/lib/brakeman/report/report_csv.rb +1 -1
- data/lib/brakeman/report/report_github.rb +31 -0
- data/lib/brakeman/report/report_sarif.rb +22 -3
- data/lib/brakeman/report/report_text.rb +1 -1
- data/lib/brakeman/report.rb +4 -1
- data/lib/brakeman/rescanner.rb +1 -1
- data/lib/brakeman/scanner.rb +19 -14
- data/lib/brakeman/tracker/collection.rb +57 -7
- data/lib/brakeman/tracker/config.rb +8 -1
- data/lib/brakeman/tracker/method_info.rb +70 -0
- data/lib/brakeman/tracker.rb +33 -4
- data/lib/brakeman/util.rb +34 -18
- data/lib/brakeman/version.rb +1 -1
- data/lib/brakeman/warning_codes.rb +4 -0
- data/lib/brakeman.rb +8 -2
- data/lib/ruby_parser/bm_sexp.rb +24 -0
- metadata +107 -95
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/rp_stringscanner.rb +0 -64
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby20_parser.rb +0 -7075
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby21_parser.rb +0 -7148
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby22_parser.rb +0 -7185
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.rb +0 -7199
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby23_parser.y +0 -2643
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby24_parser.rb +0 -7219
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.rb +0 -7218
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby25_parser.y +0 -2651
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby26_parser.rb +0 -7240
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby27_parser.rb +0 -7358
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.rb +0 -7358
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/tools/ripper.rb +0 -39
- data/bundle/ruby/2.7.0/gems/unicode-display_width-1.7.0/data/display_width.marshal.gz +0 -0
data/bundle/ruby/2.7.0/gems/{ruby_parser-3.16.0 → ruby_parser-3.18.1}/lib/ruby_parser_extras.rb
RENAMED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# TODO: remove encoding comment
|
3
4
|
|
4
5
|
require "sexp"
|
5
6
|
require "ruby_lexer"
|
@@ -29,7 +30,7 @@ class Sexp
|
|
29
30
|
end
|
30
31
|
|
31
32
|
module RubyParserStuff
|
32
|
-
VERSION = "3.
|
33
|
+
VERSION = "3.18.1"
|
33
34
|
|
34
35
|
attr_accessor :lexer, :in_def, :in_single, :file
|
35
36
|
attr_accessor :in_kwarg
|
@@ -155,11 +156,31 @@ module RubyParserStuff
|
|
155
156
|
end
|
156
157
|
|
157
158
|
args.each do |arg|
|
159
|
+
if arg.instance_of? Array and arg.size == 2 and arg.last.is_a? Numeric then
|
160
|
+
arg = arg.first
|
161
|
+
end
|
162
|
+
|
158
163
|
case arg
|
159
164
|
when Sexp then
|
160
165
|
case arg.sexp_type
|
161
166
|
when :args, :block, :array, :call_args then # HACK call_args mismatch
|
162
|
-
|
167
|
+
rest = arg.sexp_body
|
168
|
+
|
169
|
+
rest.map! { |x|
|
170
|
+
if x.instance_of? Array and x.size == 2 and Numeric === x.last then
|
171
|
+
x.first
|
172
|
+
else
|
173
|
+
x
|
174
|
+
end
|
175
|
+
}
|
176
|
+
|
177
|
+
result.concat rest
|
178
|
+
when :forward_args then
|
179
|
+
self.env[:*] = :lvar # TODO: arg_var(p, idFWD_REST) ?
|
180
|
+
self.env[:**] = :lvar
|
181
|
+
self.env[:&] = :lvar
|
182
|
+
|
183
|
+
result << arg
|
163
184
|
when :block_arg then
|
164
185
|
result << :"&#{arg.last}"
|
165
186
|
when :shadow then
|
@@ -179,6 +200,8 @@ module RubyParserStuff
|
|
179
200
|
name = arg.to_s.delete("&*")
|
180
201
|
self.env[name.to_sym] = :lvar unless name.empty?
|
181
202
|
result << arg
|
203
|
+
when true, false then
|
204
|
+
self.in_kwarg = arg
|
182
205
|
when ",", "|", ";", "(", ")", nil then
|
183
206
|
# ignore
|
184
207
|
else
|
@@ -189,6 +212,23 @@ module RubyParserStuff
|
|
189
212
|
result
|
190
213
|
end
|
191
214
|
|
215
|
+
def end_args args
|
216
|
+
lexer.lex_state = RubyLexer::State::Values::EXPR_BEG
|
217
|
+
lexer.command_start = true
|
218
|
+
self.args args
|
219
|
+
end
|
220
|
+
|
221
|
+
def endless_method_name defn_or_defs
|
222
|
+
name = defn_or_defs[1]
|
223
|
+
name = defn_or_defs[2] unless Symbol === name
|
224
|
+
|
225
|
+
if name.end_with? "=" then
|
226
|
+
yyerror "setter method cannot be defined in an endless method definition"
|
227
|
+
end
|
228
|
+
|
229
|
+
# TODO? token_info_drop(p, "def", loc->beg_pos);
|
230
|
+
end
|
231
|
+
|
192
232
|
def array_to_hash array
|
193
233
|
case array.sexp_type
|
194
234
|
when :kwsplat then
|
@@ -208,17 +248,10 @@ module RubyParserStuff
|
|
208
248
|
end
|
209
249
|
|
210
250
|
def assignable(lhs, value = nil)
|
211
|
-
id = lhs
|
212
|
-
|
213
|
-
raise "WTF" if Sexp === id
|
214
|
-
id = id.to_sym if Sexp === id
|
215
|
-
|
216
|
-
raise "write a test 1" if id.to_s =~ /^(?:self|nil|true|false|__LINE__|__FILE__)$/
|
251
|
+
id, line = lhs
|
252
|
+
id = id.to_sym
|
217
253
|
|
218
|
-
|
219
|
-
id.to_s =~ /^(?:self|nil|true|false|__LINE__|__FILE__)$/
|
220
|
-
|
221
|
-
result = case id.to_s
|
254
|
+
result = case id
|
222
255
|
when /^@@/ then
|
223
256
|
asgn = in_def || in_single > 0
|
224
257
|
s((asgn ? :cvasgn : :cvdecl), id)
|
@@ -239,17 +272,9 @@ module RubyParserStuff
|
|
239
272
|
|
240
273
|
self.env[id] ||= :lvar if result.sexp_type == :lasgn
|
241
274
|
|
242
|
-
line = case lhs
|
243
|
-
when Sexp then
|
244
|
-
lhs.line
|
245
|
-
else
|
246
|
-
value && value.line || lexer.lineno
|
247
|
-
end
|
248
|
-
|
249
275
|
result << value if value
|
250
|
-
result.line
|
251
|
-
|
252
|
-
return result
|
276
|
+
result.line line
|
277
|
+
result
|
253
278
|
end
|
254
279
|
|
255
280
|
def backref_assign_error ref
|
@@ -273,9 +298,9 @@ module RubyParserStuff
|
|
273
298
|
line = [head.line, tail.line].compact.min
|
274
299
|
|
275
300
|
head = remove_begin(head)
|
276
|
-
head = s(:block, head) unless head.
|
301
|
+
head = s(:block, head).line(line) unless head.sexp_type == :block
|
277
302
|
|
278
|
-
head.line = line
|
303
|
+
# head.line = line
|
279
304
|
head << tail
|
280
305
|
end
|
281
306
|
|
@@ -301,6 +326,10 @@ module RubyParserStuff
|
|
301
326
|
end
|
302
327
|
|
303
328
|
args.each do |arg|
|
329
|
+
if arg.instance_of? Array and arg.size == 2 and arg.last.is_a? Numeric then
|
330
|
+
arg = arg.first
|
331
|
+
end
|
332
|
+
|
304
333
|
case arg
|
305
334
|
when Sexp then
|
306
335
|
case arg.sexp_type
|
@@ -311,7 +340,10 @@ module RubyParserStuff
|
|
311
340
|
end
|
312
341
|
when Symbol then
|
313
342
|
result << arg
|
314
|
-
when
|
343
|
+
when Array then
|
344
|
+
id, _line = arg
|
345
|
+
result << id
|
346
|
+
when ",", nil, "(" then
|
315
347
|
# ignore
|
316
348
|
else
|
317
349
|
raise "unhandled: #{arg.inspect} in #{args.inspect}"
|
@@ -435,7 +467,7 @@ module RubyParserStuff
|
|
435
467
|
end
|
436
468
|
else
|
437
469
|
warn "unprocessed: %p" % [s]
|
438
|
-
end.map { |l| whitespace_width l
|
470
|
+
end.map { |l| whitespace_width l.chomp }
|
439
471
|
}.compact.min
|
440
472
|
end
|
441
473
|
|
@@ -459,7 +491,6 @@ module RubyParserStuff
|
|
459
491
|
end
|
460
492
|
|
461
493
|
def gettable(id)
|
462
|
-
lineno = id.lineno if id.respond_to? :lineno
|
463
494
|
id = id.to_sym if String === id
|
464
495
|
|
465
496
|
result = case id.to_s
|
@@ -480,8 +511,6 @@ module RubyParserStuff
|
|
480
511
|
end
|
481
512
|
end
|
482
513
|
|
483
|
-
result.line lineno if lineno
|
484
|
-
|
485
514
|
raise "identifier #{id.inspect} is not valid" unless result
|
486
515
|
|
487
516
|
result
|
@@ -540,7 +569,7 @@ module RubyParserStuff
|
|
540
569
|
header.map! { |s| s.force_encoding "ASCII-8BIT" } if has_enc
|
541
570
|
|
542
571
|
first = header.first || ""
|
543
|
-
encoding, str = "utf-8", str.b[3..-1] if first =~ /\A\xEF\xBB\xBF/
|
572
|
+
encoding, str = +"utf-8", str.b[3..-1] if first =~ /\A\xEF\xBB\xBF/
|
544
573
|
|
545
574
|
encoding = $1.strip if header.find { |s|
|
546
575
|
s[/^#.*?-\*-.*?coding:\s*([^ ;]+).*?-\*-/, 1] ||
|
@@ -624,7 +653,7 @@ module RubyParserStuff
|
|
624
653
|
when :evstr then
|
625
654
|
if htype == :str then
|
626
655
|
f, l = head.file, head.line
|
627
|
-
head = s(:dstr, *head.sexp_body)
|
656
|
+
head = s(:dstr, *head.sexp_body)
|
628
657
|
head.file = f
|
629
658
|
head.line = l
|
630
659
|
end
|
@@ -643,6 +672,13 @@ module RubyParserStuff
|
|
643
672
|
return head
|
644
673
|
end
|
645
674
|
|
675
|
+
def local_pop in_def
|
676
|
+
lexer.cond.pop # group = local_pop
|
677
|
+
lexer.cmdarg.pop
|
678
|
+
self.env.unextend
|
679
|
+
self.in_def = in_def
|
680
|
+
end
|
681
|
+
|
646
682
|
def logical_op type, left, right
|
647
683
|
left = value_expr left
|
648
684
|
|
@@ -672,6 +708,73 @@ module RubyParserStuff
|
|
672
708
|
new_call val[0], :"[]", val[2]
|
673
709
|
end
|
674
710
|
|
711
|
+
def new_arg val
|
712
|
+
arg, = val
|
713
|
+
|
714
|
+
case arg
|
715
|
+
when Symbol then
|
716
|
+
result = s(:args, arg).line line
|
717
|
+
when Sexp then
|
718
|
+
result = arg
|
719
|
+
when Array then
|
720
|
+
(arg, line), = val
|
721
|
+
result = s(:args, arg).line line
|
722
|
+
else
|
723
|
+
debug20 32
|
724
|
+
raise "Unknown f_arg type: #{val.inspect}"
|
725
|
+
end
|
726
|
+
|
727
|
+
result
|
728
|
+
end
|
729
|
+
|
730
|
+
def new_array_pattern const, pre_arg, arypat, loc
|
731
|
+
result = s(:array_pat, const).line loc
|
732
|
+
result << pre_arg if pre_arg
|
733
|
+
|
734
|
+
if arypat && arypat.sexp_type == :array_TAIL then
|
735
|
+
result.concat arypat.sexp_body
|
736
|
+
else
|
737
|
+
raise "NO?: %p" % [arypat]
|
738
|
+
end
|
739
|
+
|
740
|
+
result
|
741
|
+
end
|
742
|
+
|
743
|
+
def array_pat_concat lhs, rhs
|
744
|
+
case lhs.sexp_type
|
745
|
+
when :PATTERN then
|
746
|
+
lhs.sexp_type = :array_pat
|
747
|
+
end
|
748
|
+
|
749
|
+
if rhs then
|
750
|
+
case rhs.sexp_type
|
751
|
+
when :array_pat, :array_TAIL, :PATTERN then
|
752
|
+
lhs.concat rhs.sexp_body
|
753
|
+
else
|
754
|
+
lhs << rhs
|
755
|
+
end
|
756
|
+
end
|
757
|
+
end
|
758
|
+
|
759
|
+
def new_array_pattern_tail pre_args, has_rest, rest_arg, post_args
|
760
|
+
# TODO: remove has_rest once all tests pass !!!
|
761
|
+
rest_arg = if has_rest then
|
762
|
+
:"*#{rest_arg}"
|
763
|
+
else
|
764
|
+
nil
|
765
|
+
end
|
766
|
+
|
767
|
+
result = s(:array_TAIL).line 666
|
768
|
+
|
769
|
+
array_pat_concat result, pre_args
|
770
|
+
|
771
|
+
result << rest_arg if rest_arg
|
772
|
+
|
773
|
+
array_pat_concat result, post_args
|
774
|
+
|
775
|
+
result
|
776
|
+
end
|
777
|
+
|
675
778
|
def new_assign lhs, rhs
|
676
779
|
return nil unless lhs
|
677
780
|
|
@@ -691,6 +794,8 @@ module RubyParserStuff
|
|
691
794
|
end
|
692
795
|
|
693
796
|
def new_attrasgn recv, meth, call_op = :"."
|
797
|
+
call_op = call_op.first if Array === call_op
|
798
|
+
|
694
799
|
meth = :"#{meth}="
|
695
800
|
|
696
801
|
result = case call_op.to_sym
|
@@ -755,6 +860,8 @@ module RubyParserStuff
|
|
755
860
|
end
|
756
861
|
|
757
862
|
def new_call recv, meth, args = nil, call_op = :"."
|
863
|
+
call_op = call_op.first if Array === call_op
|
864
|
+
|
758
865
|
result = case call_op.to_sym
|
759
866
|
when :"."
|
760
867
|
s(:call, recv, meth)
|
@@ -782,10 +889,14 @@ module RubyParserStuff
|
|
782
889
|
result
|
783
890
|
end
|
784
891
|
|
892
|
+
def new_in pat, body, cases, line
|
893
|
+
s(:in, pat, body, cases).line line
|
894
|
+
end
|
895
|
+
|
785
896
|
def new_case expr, body, line
|
786
897
|
result = s(:case, expr)
|
787
898
|
|
788
|
-
while body and body.
|
899
|
+
while body and [:when, :in].include? body.sexp_type
|
789
900
|
result << body
|
790
901
|
body = body.delete_at 3
|
791
902
|
end
|
@@ -804,8 +915,11 @@ module RubyParserStuff
|
|
804
915
|
end
|
805
916
|
|
806
917
|
def new_class val
|
918
|
+
# TODO: get line from class keyword
|
807
919
|
line, path, superclass, body = val[1], val[2], val[3], val[5]
|
808
920
|
|
921
|
+
path = path.first if path.instance_of? Array
|
922
|
+
|
809
923
|
result = s(:class, path, superclass)
|
810
924
|
|
811
925
|
if body then
|
@@ -828,7 +942,8 @@ module RubyParserStuff
|
|
828
942
|
end
|
829
943
|
|
830
944
|
def new_const_op_asgn val
|
831
|
-
lhs, asgn_op, rhs = val
|
945
|
+
lhs, (asgn_op, _), rhs = val
|
946
|
+
asgn_op = asgn_op.to_sym
|
832
947
|
|
833
948
|
result = case asgn_op
|
834
949
|
when :"||" then
|
@@ -844,55 +959,71 @@ module RubyParserStuff
|
|
844
959
|
end
|
845
960
|
|
846
961
|
def new_defn val
|
847
|
-
|
848
|
-
|
962
|
+
_, (name, line), in_def, args, body, _ = val
|
963
|
+
|
964
|
+
body ||= s(:nil).line line
|
849
965
|
|
850
966
|
args.line line
|
851
967
|
|
852
968
|
result = s(:defn, name.to_sym, args).line line
|
853
969
|
|
854
|
-
if body then
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
result.push body
|
859
|
-
end
|
970
|
+
if body.sexp_type == :block then
|
971
|
+
result.push(*body.sexp_body)
|
972
|
+
else
|
973
|
+
result.push body
|
860
974
|
end
|
861
975
|
|
862
976
|
result.comments = self.comments.pop
|
863
977
|
|
864
|
-
result
|
978
|
+
[result, in_def]
|
865
979
|
end
|
866
980
|
|
867
981
|
def new_defs val
|
868
|
-
_, recv,
|
982
|
+
_, recv, (name, line), in_def, args, body, _ = val
|
869
983
|
|
870
984
|
body ||= s(:nil).line line
|
871
985
|
|
872
986
|
args.line line
|
873
987
|
|
874
|
-
result = s(:defs, recv, name.to_sym, args)
|
988
|
+
result = s(:defs, recv, name.to_sym, args).line line
|
875
989
|
|
876
990
|
# TODO: remove_begin
|
877
991
|
# TODO: reduce_nodes
|
878
992
|
|
879
|
-
if body then
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
result.push body
|
884
|
-
end
|
993
|
+
if body.sexp_type == :block then
|
994
|
+
result.push(*body.sexp_body)
|
995
|
+
else
|
996
|
+
result.push body
|
885
997
|
end
|
886
998
|
|
887
|
-
result.line = recv.line
|
888
999
|
result.comments = self.comments.pop
|
889
|
-
|
1000
|
+
|
1001
|
+
[result, in_def]
|
890
1002
|
end
|
891
1003
|
|
892
1004
|
def new_do_body args, body, lineno
|
893
1005
|
new_iter(nil, args, body).line(lineno)
|
894
1006
|
end
|
895
1007
|
|
1008
|
+
def new_find_pattern const, pat
|
1009
|
+
pat.sexp_type = :find_pat
|
1010
|
+
pat.insert 1, const
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
def new_find_pattern_tail lhs, mid, rhs
|
1014
|
+
lhs_id, line = lhs
|
1015
|
+
rhs_id, _line = rhs
|
1016
|
+
|
1017
|
+
# TODO: fpinfo->pre_rest_arg = pre_rest_arg ? assignable(p, pre_rest_arg, 0, loc) : NODE_SPECIAL_NO_NAME_REST;
|
1018
|
+
|
1019
|
+
lhs_id = "*#{lhs_id}".to_sym
|
1020
|
+
rhs_id = "*#{rhs_id}".to_sym
|
1021
|
+
|
1022
|
+
mid.sexp_type = :array_pat # HACK?
|
1023
|
+
|
1024
|
+
s(:find_pat_TAIL, lhs_id, mid, rhs_id).line line
|
1025
|
+
end
|
1026
|
+
|
896
1027
|
def new_for expr, var, body
|
897
1028
|
result = s(:for, expr, var).line(var.line)
|
898
1029
|
result << body if body
|
@@ -902,7 +1033,47 @@ module RubyParserStuff
|
|
902
1033
|
def new_hash val
|
903
1034
|
_, line, assocs = val
|
904
1035
|
|
905
|
-
s(:hash).line(line).concat assocs.
|
1036
|
+
s(:hash).line(line).concat assocs.sexp_body
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
def new_hash_pattern const, hash_pat, loc
|
1040
|
+
_, pat, kw_args, kw_rest_arg = hash_pat
|
1041
|
+
|
1042
|
+
line = (const||hash_pat).line
|
1043
|
+
|
1044
|
+
result = s(:hash_pat, const).line line
|
1045
|
+
result.concat pat.sexp_body if pat
|
1046
|
+
result << kw_args if kw_args
|
1047
|
+
result << kw_rest_arg if kw_rest_arg
|
1048
|
+
result
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
def new_hash_pattern_tail kw_args, kw_rest_arg, line # TODO: remove line arg
|
1052
|
+
# kw_rest_arg = assignable(kw_rest_arg, nil).line line if kw_rest_arg
|
1053
|
+
|
1054
|
+
result = s(:hash_pat).line line
|
1055
|
+
result << kw_args
|
1056
|
+
|
1057
|
+
if kw_rest_arg then
|
1058
|
+
name = kw_rest_arg.value
|
1059
|
+
# TODO: I _hate_ this:
|
1060
|
+
assignable [name, kw_rest_arg.line] if name != :**
|
1061
|
+
result << kw_rest_arg
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
result
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
def push_pktbl
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
def pop_pktbl
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
def push_pvtbl
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
def pop_pvtbl
|
906
1077
|
end
|
907
1078
|
|
908
1079
|
def new_if c, t, f
|
@@ -979,9 +1150,12 @@ module RubyParserStuff
|
|
979
1150
|
end
|
980
1151
|
|
981
1152
|
def new_module val
|
1153
|
+
# TODO: get line from module keyword
|
982
1154
|
line, path, body = val[1], val[2], val[4]
|
983
1155
|
|
984
|
-
|
1156
|
+
path = path.first if path.instance_of? Array
|
1157
|
+
|
1158
|
+
result = s(:module, path).line line
|
985
1159
|
|
986
1160
|
if body then # REFACTOR?
|
987
1161
|
if body.sexp_type == :block then
|
@@ -991,32 +1165,33 @@ module RubyParserStuff
|
|
991
1165
|
end
|
992
1166
|
end
|
993
1167
|
|
994
|
-
result.line = line
|
995
1168
|
result.comments = self.comments.pop
|
996
1169
|
result
|
997
1170
|
end
|
998
1171
|
|
999
1172
|
def new_op_asgn val
|
1000
|
-
lhs,
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1173
|
+
lhs, (op, _line), rhs = val
|
1174
|
+
op = op.to_sym
|
1175
|
+
|
1176
|
+
name = gettable(lhs.last).line lhs.line
|
1177
|
+
arg = remove_begin rhs
|
1178
|
+
result = case op # REFACTOR
|
1004
1179
|
when :"||" then
|
1005
1180
|
lhs << arg
|
1006
|
-
s(:op_asgn_or, name, lhs)
|
1181
|
+
s(:op_asgn_or, name, lhs).line lhs.line
|
1007
1182
|
when :"&&" then
|
1008
1183
|
lhs << arg
|
1009
|
-
s(:op_asgn_and, name, lhs)
|
1184
|
+
s(:op_asgn_and, name, lhs).line lhs.line
|
1010
1185
|
else
|
1011
|
-
lhs << new_call(name,
|
1186
|
+
lhs << new_call(name, op, argl(arg))
|
1012
1187
|
lhs
|
1013
1188
|
end
|
1014
|
-
|
1189
|
+
|
1015
1190
|
result
|
1016
1191
|
end
|
1017
1192
|
|
1018
1193
|
def new_op_asgn1 val
|
1019
|
-
lhs, _, args, _, op, rhs = val
|
1194
|
+
lhs, _, args, _, (op, _), rhs = val
|
1020
1195
|
|
1021
1196
|
args.sexp_type = :arglist if args
|
1022
1197
|
|
@@ -1026,7 +1201,7 @@ module RubyParserStuff
|
|
1026
1201
|
end
|
1027
1202
|
|
1028
1203
|
def new_op_asgn2 val
|
1029
|
-
recv, call_op, meth, op, arg = val
|
1204
|
+
recv, (call_op, _), (meth, _), (op, _), arg = val
|
1030
1205
|
meth = :"#{meth}="
|
1031
1206
|
|
1032
1207
|
result = case call_op.to_sym
|
@@ -1043,36 +1218,28 @@ module RubyParserStuff
|
|
1043
1218
|
end
|
1044
1219
|
|
1045
1220
|
def new_qsym_list
|
1046
|
-
|
1047
|
-
self.lexer.fixup_lineno
|
1048
|
-
result
|
1221
|
+
s(:array).line lexer.lineno
|
1049
1222
|
end
|
1050
1223
|
|
1051
1224
|
def new_qsym_list_entry val
|
1052
|
-
_, str, _ = val
|
1053
|
-
|
1054
|
-
self.lexer.fixup_lineno
|
1055
|
-
result
|
1225
|
+
_, (str, line), _ = val
|
1226
|
+
s(:lit, str.to_sym).line line
|
1056
1227
|
end
|
1057
1228
|
|
1058
1229
|
def new_qword_list
|
1059
|
-
|
1060
|
-
self.lexer.fixup_lineno
|
1061
|
-
result
|
1230
|
+
s(:array).line lexer.lineno
|
1062
1231
|
end
|
1063
1232
|
|
1064
1233
|
def new_qword_list_entry val
|
1065
|
-
_, str, _ = val
|
1234
|
+
_, (str, line), _ = val
|
1066
1235
|
str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
|
1067
|
-
|
1068
|
-
self.lexer.fixup_lineno
|
1069
|
-
result
|
1236
|
+
s(:str, str).line line
|
1070
1237
|
end
|
1071
1238
|
|
1072
1239
|
def new_regexp val
|
1073
|
-
_, node, options = val
|
1240
|
+
(_, line), node, (options, _) = val
|
1074
1241
|
|
1075
|
-
node ||= s(:str, "").line
|
1242
|
+
node ||= s(:str, "").line line
|
1076
1243
|
|
1077
1244
|
o, k = 0, nil
|
1078
1245
|
options.split(//).uniq.each do |c| # FIX: this has a better home
|
@@ -1099,12 +1266,12 @@ module RubyParserStuff
|
|
1099
1266
|
begin
|
1100
1267
|
Regexp.new(node[1], o)
|
1101
1268
|
rescue RegexpError => e
|
1102
|
-
warn "
|
1269
|
+
warn "WARNING: #{e.message} for #{node[1].inspect} #{options.inspect}"
|
1103
1270
|
begin
|
1104
|
-
warn "
|
1271
|
+
warn "WARNING: trying to recover with ENC_UTF8"
|
1105
1272
|
Regexp.new(node[1], Regexp::ENC_UTF8)
|
1106
1273
|
rescue RegexpError => e
|
1107
|
-
warn "
|
1274
|
+
warn "WARNING: trying to recover with ENC_NONE"
|
1108
1275
|
Regexp.new(node[1], Regexp::ENC_NONE)
|
1109
1276
|
end
|
1110
1277
|
end
|
@@ -1117,7 +1284,7 @@ module RubyParserStuff
|
|
1117
1284
|
end
|
1118
1285
|
node << o if o and o != 0
|
1119
1286
|
else
|
1120
|
-
node = s(:dregx, "", node).line
|
1287
|
+
node = s(:dregx, "", node).line line
|
1121
1288
|
node.sexp_type = :dregx_once if options =~ /o/
|
1122
1289
|
node << o if o and o != 0
|
1123
1290
|
end
|
@@ -1159,17 +1326,16 @@ module RubyParserStuff
|
|
1159
1326
|
end
|
1160
1327
|
|
1161
1328
|
def new_string val
|
1162
|
-
str, = val
|
1329
|
+
(str, line), = val
|
1330
|
+
|
1163
1331
|
str.force_encoding("UTF-8")
|
1164
1332
|
# TODO: remove:
|
1165
1333
|
str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
|
1166
|
-
|
1167
|
-
self.lexer.fixup_lineno str.count("\n")
|
1168
|
-
result
|
1334
|
+
s(:str, str).line line
|
1169
1335
|
end
|
1170
1336
|
|
1171
1337
|
def new_super args
|
1172
|
-
if args && args.
|
1338
|
+
if args && args.sexp_type == :block_pass then
|
1173
1339
|
s(:super, args).line args.line
|
1174
1340
|
else
|
1175
1341
|
args ||= s(:arglist).line lexer.lineno
|
@@ -1177,32 +1343,30 @@ module RubyParserStuff
|
|
1177
1343
|
end
|
1178
1344
|
end
|
1179
1345
|
|
1346
|
+
def new_symbol val
|
1347
|
+
name = val.last
|
1348
|
+
s(:lit, name.to_sym).line lexer.lineno
|
1349
|
+
end
|
1350
|
+
|
1180
1351
|
def new_symbol_list
|
1181
|
-
|
1182
|
-
|
1183
|
-
result
|
1352
|
+
# TODO: hunt down and try to remove ALL lexer.lineno usage!
|
1353
|
+
s(:array).line lexer.lineno
|
1184
1354
|
end
|
1185
1355
|
|
1186
1356
|
def new_symbol_list_entry val
|
1187
1357
|
_, sym, _ = val
|
1188
1358
|
|
1189
|
-
sym ||= s(:str, "")
|
1190
|
-
|
1191
|
-
line = lexer.lineno
|
1359
|
+
sym ||= s(:str, "").line lexer.lineno
|
1192
1360
|
|
1193
1361
|
case sym.sexp_type
|
1194
1362
|
when :dstr then
|
1195
1363
|
sym.sexp_type = :dsym
|
1196
1364
|
when :str then
|
1197
|
-
sym = s(:lit, sym.last.to_sym)
|
1365
|
+
sym = s(:lit, sym.last.to_sym).line sym.line
|
1198
1366
|
else
|
1199
|
-
sym = s(:dsym, "", sym
|
1367
|
+
sym = s(:dsym, "", sym).line sym.line
|
1200
1368
|
end
|
1201
1369
|
|
1202
|
-
sym.line line
|
1203
|
-
|
1204
|
-
self.lexer.fixup_lineno
|
1205
|
-
|
1206
1370
|
sym
|
1207
1371
|
end
|
1208
1372
|
|
@@ -1244,16 +1408,12 @@ module RubyParserStuff
|
|
1244
1408
|
end
|
1245
1409
|
|
1246
1410
|
def new_word_list
|
1247
|
-
|
1248
|
-
self.lexer.fixup_lineno
|
1249
|
-
result
|
1411
|
+
s(:array).line lexer.lineno
|
1250
1412
|
end
|
1251
1413
|
|
1252
1414
|
def new_word_list_entry val
|
1253
1415
|
_, word, _ = val
|
1254
|
-
|
1255
|
-
self.lexer.fixup_lineno
|
1256
|
-
result
|
1416
|
+
word.sexp_type == :evstr ? s(:dstr, "", word).line(word.line) : word
|
1257
1417
|
end
|
1258
1418
|
|
1259
1419
|
def new_xstring val
|
@@ -1277,9 +1437,9 @@ module RubyParserStuff
|
|
1277
1437
|
|
1278
1438
|
def new_yield args = nil
|
1279
1439
|
# TODO: raise args.inspect unless [:arglist].include? args.first # HACK
|
1280
|
-
raise "write a test 4" if args && args.
|
1440
|
+
raise "write a test 4" if args && args.sexp_type == :block_pass
|
1281
1441
|
raise SyntaxError, "Block argument should not be given." if
|
1282
|
-
args && args.
|
1442
|
+
args && args.sexp_type == :block_pass
|
1283
1443
|
|
1284
1444
|
args ||= s(:arglist).line lexer.lineno
|
1285
1445
|
|
@@ -1289,18 +1449,30 @@ module RubyParserStuff
|
|
1289
1449
|
s(:yield, *args.sexp_body).line args.line
|
1290
1450
|
end
|
1291
1451
|
|
1452
|
+
def prev_value_to_lineno v
|
1453
|
+
s, n = v
|
1454
|
+
if String === s then
|
1455
|
+
n
|
1456
|
+
else
|
1457
|
+
lexer.lineno
|
1458
|
+
end
|
1459
|
+
end
|
1460
|
+
|
1292
1461
|
def next_token
|
1293
1462
|
token = self.lexer.next_token
|
1294
1463
|
|
1295
1464
|
if token and token.first != RubyLexer::EOF then
|
1296
1465
|
self.last_token_type = token
|
1297
1466
|
return token
|
1467
|
+
elsif !token
|
1468
|
+
return self.lexer.next_token
|
1298
1469
|
else
|
1299
1470
|
return [false, false]
|
1300
1471
|
end
|
1301
1472
|
end
|
1302
1473
|
|
1303
1474
|
def on_error(et, ev, values)
|
1475
|
+
ev = ev.first if ev.instance_of?(Array) && ev.size == 2 && ev.last.is_a?(Integer)
|
1304
1476
|
super
|
1305
1477
|
rescue Racc::ParseError => e
|
1306
1478
|
# I don't like how the exception obscures the error message
|
@@ -1314,18 +1486,17 @@ module RubyParserStuff
|
|
1314
1486
|
# Timeout::Error if it runs for more than +time+ seconds.
|
1315
1487
|
|
1316
1488
|
def process(str, file = "(string)", time = 10)
|
1489
|
+
str.freeze
|
1490
|
+
|
1317
1491
|
Timeout.timeout time do
|
1318
1492
|
raise "bad val: #{str.inspect}" unless String === str
|
1319
1493
|
|
1320
|
-
|
1494
|
+
self.lexer.string = handle_encoding str
|
1321
1495
|
|
1322
1496
|
self.file = file.dup
|
1323
1497
|
|
1324
1498
|
@yydebug = ENV.has_key? "DEBUG"
|
1325
1499
|
|
1326
|
-
# HACK -- need to get tests passing more than have graceful code
|
1327
|
-
self.lexer.ss = RPStringScanner.new str
|
1328
|
-
|
1329
1500
|
do_parse
|
1330
1501
|
end
|
1331
1502
|
end
|
@@ -1381,6 +1552,14 @@ module RubyParserStuff
|
|
1381
1552
|
result
|
1382
1553
|
end
|
1383
1554
|
|
1555
|
+
def debug n
|
1556
|
+
if ENV["PRY"] then
|
1557
|
+
require "pry"; binding.pry
|
1558
|
+
end
|
1559
|
+
|
1560
|
+
raise RubyParser::SyntaxError, "debug #{n}"
|
1561
|
+
end
|
1562
|
+
|
1384
1563
|
def syntax_error msg
|
1385
1564
|
raise RubyParser::SyntaxError, msg
|
1386
1565
|
end
|
@@ -1425,6 +1604,8 @@ module RubyParserStuff
|
|
1425
1604
|
|
1426
1605
|
if remove_width then
|
1427
1606
|
line[idx..-1]
|
1607
|
+
elsif line[idx].nil?
|
1608
|
+
nil
|
1428
1609
|
else
|
1429
1610
|
col
|
1430
1611
|
end
|