ruby_parser 3.13.1 → 3.15.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92087c0c745fee6dd8a060c3180c8254e0f23fd0d252b23f3988a3d92890ce64
4
- data.tar.gz: 4ff9742257ffdf393892e293b1548587f552b6bb92fc2484bda6805c27cf1cff
3
+ metadata.gz: 0adcb0c06b7ee6d29360bd8dd9641dfcce867cdd7167f59bef5134c3092cb091
4
+ data.tar.gz: ef51691d5a0e2f09a38a0c6d8bd8d3fccdebf19bd1c1ce41a99f761112a43c4a
5
5
  SHA512:
6
- metadata.gz: 8585bd8ef2918e9a31907b71dfada37f2f4d2755685ff976702bcfa90ec0137afd1b6e71bced5c631f8549188dc62169c8137eb3cf8475b393ec65174a0ac7bc
7
- data.tar.gz: ead3c27d85cae963568e98c53ded6d7199da7ea781b29895eecdd54756af714b154528dc20920b3f8982519d1fd6a2f80c933489844c1d81052cc991b88172d6
6
+ metadata.gz: 85e6684d7a8a6207f1040ca97768d4792ba52e2f039eee5fa83047e8e5c83a7a913f98fc5384ac8b3387829078e294e22fb009163ac4eee272557cbed715849e
7
+ data.tar.gz: 7e996bef3411d3f63dfd8e2af388bddb16dc8a4206bd309611aeda038feb4c66041fb2b7ba5136015d4b0453e34fdebf8c1f8d408d68dccb9031514ebff6f728
Binary file
data.tar.gz.sig CHANGED
Binary file
data/.autotest CHANGED
@@ -7,20 +7,20 @@ require 'autotest/rcov' if ENV['RCOV']
7
7
  Autotest.add_hook :initialize do |at|
8
8
  at.extra_files << "../../sexp_processor/dev/lib/pt_testcase.rb"
9
9
  at.libs << ":../../sexp_processor/dev/lib"
10
- at.add_exception "unit"
11
- at.add_exception "coverage"
12
- at.add_exception "coverage.info"
13
10
  at.add_exception ".diff"
11
+ at.add_exception ".rdoc"
12
+ at.add_exception ".yml"
13
+ at.add_exception ".txt"
14
14
  at.add_exception ".output"
15
- at.add_exception "lib/ruby18_parser.rb"
16
- at.add_exception "lib/ruby19_parser.rb"
17
- at.add_exception "lib/ruby20_parser.rb"
18
- at.add_exception "lib/ruby21_parser.rb"
19
- at.add_exception "lib/ruby22_parser.rb"
20
- at.add_exception "lib/ruby20_parser.y"
21
- at.add_exception "lib/ruby21_parser.y"
22
- at.add_exception "lib/ruby22_parser.y"
23
- at.add_exception "lib/ruby_lexer.rex.rb"
15
+ at.add_exception "bin"
16
+ at.add_exception "compare"
17
+ at.add_exception "coverage"
18
+ at.add_exception "coverage.info"
19
+ at.add_exception "misc"
20
+
21
+ Dir["lib/ruby??_parser.{rb,y}"].each do |f|
22
+ at.add_exception f
23
+ end
24
24
 
25
25
  Dir["gauntlet*"].each do |f|
26
26
  at.add_exception f
@@ -30,12 +30,12 @@ Autotest.add_hook :initialize do |at|
30
30
  at.testlib = "minitest/autorun"
31
31
 
32
32
  at.add_mapping(/^lib\/.*\.y$/) do |f, _|
33
- g = File.basename(f, ".y").gsub("_", "_?").gsub(/1[89]|2[012]/, '')
33
+ g = File.basename(f, ".y").gsub("_", "_?").gsub(/2\d/, '')
34
34
  at.files_matching %r%^test/.*#{g}.rb$%
35
35
  end
36
36
 
37
37
  at.add_mapping(/^lib\/.*\.yy$/) do |f, _|
38
- g = File.basename(f, ".yy").gsub("_", "_?").gsub(/1[89]|2[012]/, '')
38
+ g = File.basename(f, ".yy").gsub("_", "_?")
39
39
  at.files_matching %r%^test/.*#{g}.rb$%
40
40
  end
41
41
 
@@ -52,27 +52,16 @@ Autotest.add_hook :initialize do |at|
52
52
  at.files_matching(/test_.*rb$/)
53
53
  end
54
54
 
55
- %w(TestEnvironment TestStackState).each do |klass|
55
+ %w(TestEnvironment TestStackState TestValueExpr).each do |klass|
56
56
  at.extra_class_map[klass] = "test/test_ruby_parser_extras.rb"
57
57
  end
58
58
 
59
- %w(TestRuby18Parser TestRuby19Parser TestRuby20Parser TestRuby21Parser TestRuby22Parser TestRuby23Parser TestParseTree).each do |klass| # HACK
60
- at.extra_class_map[klass] = "test/test_ruby_parser.rb"
59
+ Dir["lib/ruby??_parser.rb"].each do |s|
60
+ n = s[/\d+/]
61
+ at.extra_class_map["TestRubyParserV#{n}"] = "test/test_ruby_parser.rb"
61
62
  end
62
63
  end
63
64
 
64
65
  Autotest.add_hook :run_command do |at, _|
65
66
  system "rake parser lexer DEBUG=1"
66
67
  end
67
-
68
- class Autotest
69
- def ruby
70
- File.expand_path "~/.multiruby/install/1.9.3-p194/bin/ruby"
71
- end
72
- end if ENV["R19"]
73
-
74
- class Autotest
75
- def ruby
76
- File.expand_path "~/.multiruby/install/2.0.0-p195/bin/ruby"
77
- end
78
- end if ENV["R20"]
@@ -1,3 +1,100 @@
1
+ === 3.15.1 / 2021-01-10
2
+
3
+ * 1 bug fix:
4
+
5
+ * Bumped ruby version to include < 4 (trunk).
6
+
7
+ === 3.15.0 / 2020-08-31
8
+
9
+ * 1 major enhancement:
10
+
11
+ * Added tentative 2.7 support.
12
+
13
+ * 1 minor enhancement:
14
+
15
+ * Improved ruby_parse_extract_error's handling of moving slow files out.
16
+
17
+ * 22 bug fixes:
18
+
19
+ * Bumped ruby version to include 3.0 (trunk).
20
+ * Fix an error related to empty ensure bodies. (presidentbeef)
21
+ * Fix handling of bad magic encoding comment.
22
+ * Fixed SystemStackError when parsing a huoooge hash, caused by a splat arg.
23
+ * Fixed a number of errors parsing do blocks in strange edge cases.
24
+ * Fixed a string backslash lexing bug when the string is an invalid encoding. (nijikon, gmcgibbon)
25
+ * Fixed bug assigning line number to some arg nodes.
26
+ * Fixed bug concatinating string literals with differing encodings.
27
+ * Fixed bug lexing heredoc w/ nasty mix of \r\n and \n.
28
+ * Fixed bug lexing multiple codepoints in \u{0000 1111 2222} forms.
29
+ * Fixed bug setting line numbers in empty xstrings in some contexts.
30
+ * Fixed edge case on call w/ begin + do block as an arg.
31
+ * Fixed handling of UTF BOM.
32
+ * Fixed handling of lexer state across string interpolation braces.
33
+ * Fixed infinite loop when lexing backslash+cr+newline (aka dos-files)
34
+ * Fixed lambda + do block edge case.
35
+ * Fixed lexing of some ?\M... and ?\C... edge cases.
36
+ * Fixed more do/brace block edge case failures.
37
+ * Fixed parsing bug where splat was used in the middle of a list.
38
+ * Fixed parsing of interpolation in heredoc-like strings. (presidentbeef)
39
+ * Fixed parsing some esoteric edge cases in op_asgn.
40
+ * Fixed unicode processing in ident chars so now they better mix.
41
+
42
+ === 3.14.2 / 2020-02-06
43
+
44
+ * 1 minor enhancement:
45
+
46
+ * Cleaned up call_args and removed arg_blk_pass from ruby_parser_extras.rb! Yay!
47
+
48
+ === 3.14.1 / 2019-10-29
49
+
50
+ * 1 minor enhancement:
51
+
52
+ * Declared that ruby_parser supports ruby 2.2 and up.
53
+
54
+ * 3 bug fixes:
55
+
56
+ * Fixed a problem with %W with a null-byte terminator. (wtf?) (spohlenz)
57
+ * Fixed line numbering for command (eg methods without parentheses) arguments. (mvz)
58
+ * Fixed lineno on new dxstrs. (presidentbeef)
59
+
60
+ === 3.14.0 / 2019-09-24
61
+
62
+ * 8 minor enhancements:
63
+
64
+ * Added Sexp#line_min & new line number debugging feature.
65
+ * Allow bin/ruby_parse to use RP_TIMEOUT to tweak default timeout for large files & slow debugging modes.
66
+ * Did you know that custom inspect can't be > 65 chars? 65! Me neither. Fixed.
67
+ * For now, value_expr == remove_begin.
68
+ * Improved error messages for unterminated regexps.
69
+ * Moved all STR_* consts into State::Values and made them State instances.
70
+ * Overhauled RubyLexer::State + Values to allow for completely separate groups of States.
71
+ * RubyParserExtras#remove_begin removes nested begins and patches line numbers.
72
+
73
+ * 22 bug fixes:
74
+
75
+ * Changed EOF signaling to return [false, false] per doco.
76
+ * Changed RubyParserStuff#remove_begin to keep inner line number, if any. (mvz)
77
+ * Differentiated between lambda call and stabby proc. Added :lambda sexp. (whitequark)
78
+ * Extended State#== to check equal? first as an optimization.
79
+ * Fixed a bug in tab indent width.
80
+ * Fixed a line numbering bug for assignables.
81
+ * Fixed a line numbering bug for defns w/ nil bodies.
82
+ * Fixed another missing line number, driven out by ruby_to_ruby bootstrap.
83
+ * Fixed dedenting squiggle heredocs if interpolation is in the mix. (mvz)
84
+ * Fixed differentiation of `{ |a| ... }` vs `{ |a,| ... }`. Fixes #236 (whitequark).
85
+ * Fixed lex_state for symbols.
86
+ * Fixed lex_state for tSTRING_END and tREGEXP_END.
87
+ * Fixed line numbers for BEGIN block. (mvz)
88
+ * Fixed op_asgn1 w/ command_call having array instead of arglist. (mvz)
89
+ * Fixed parsing of () in a command-call (eg p).
90
+ * Fixed remaining missing line numbers by forcing extra checks during test and blowing up. They may still be wrong (esp after heredocs, ugh), but they're there! Special thank you to mvz for pushing on this and providing tests and PRs.
91
+ * Fixed some lex_state versioning issues with closing braces/bracket on ruby<25.
92
+ * Keep carriage return escapes in heredocs. (mvz)
93
+ * Massive overhaul of line number code.
94
+ * More line number fixes and extra tests from mvz. Thank you!
95
+ * Parsing BEGIN block when not at top level should raise an error. (mvz)
96
+ * Removed irb task from Rakefile as it has been pushed up to Hoe and doubles up here.
97
+
1
98
  === 3.13.1 / 2019-03-25
2
99
 
3
100
  * 1 major enhancement:
@@ -24,6 +24,8 @@ lib/ruby25_parser.rb
24
24
  lib/ruby25_parser.y
25
25
  lib/ruby26_parser.rb
26
26
  lib/ruby26_parser.y
27
+ lib/ruby27_parser.rb
28
+ lib/ruby27_parser.y
27
29
  lib/ruby_lexer.rb
28
30
  lib/ruby_lexer.rex
29
31
  lib/ruby_lexer.rex.rb
@@ -7,9 +7,9 @@ rdoc :: http://docs.seattlerb.org/ruby_parser
7
7
  == DESCRIPTION:
8
8
 
9
9
  ruby_parser (RP) is a ruby parser written in pure ruby (utilizing
10
- racc--which does by default use a C extension). RP's output is
11
- the same as ParseTree's output: s-expressions using ruby's arrays and
12
- base types.
10
+ racc--which does by default use a C extension). It outputs
11
+ s-expressions which can be manipulated and converted back to ruby via
12
+ the ruby2ruby gem.
13
13
 
14
14
  As an example:
15
15
 
data/Rakefile CHANGED
@@ -8,11 +8,12 @@ Hoe.plugin :racc
8
8
  Hoe.plugin :isolate
9
9
  Hoe.plugin :rdoc
10
10
 
11
+ Hoe.add_include_dirs "lib"
11
12
  Hoe.add_include_dirs "../../sexp_processor/dev/lib"
12
13
  Hoe.add_include_dirs "../../minitest/dev/lib"
13
14
  Hoe.add_include_dirs "../../oedipus_lex/dev/lib"
14
15
 
15
- V2 = %w[20 21 22 23 24 25 26]
16
+ V2 = %w[20 21 22 23 24 25 26 27]
16
17
  V2.replace [V2.last] if ENV["FAST"] # HACK
17
18
 
18
19
  Hoe.spec "ruby_parser" do
@@ -24,6 +25,8 @@ Hoe.spec "ruby_parser" do
24
25
  dependency "rake", "< 11", :developer
25
26
  dependency "oedipus_lex", "~> 2.5", :developer
26
27
 
28
+ require_ruby_version [">= 2.1", "< 4"]
29
+
27
30
  if plugin? :perforce then # generated files
28
31
  V2.each do |n|
29
32
  self.perforce_ignore << "lib/ruby#{n}_parser.rb"
@@ -54,6 +57,8 @@ end
54
57
 
55
58
  file "lib/ruby_lexer.rex.rb" => "lib/ruby_lexer.rex"
56
59
 
60
+ task :generate => [:lexer, :parser]
61
+
57
62
  task :clean do
58
63
  rm_rf(Dir["**/*~"] +
59
64
  Dir["diff.diff"] + # not all diffs. bit me too many times
@@ -73,10 +78,6 @@ task :huh? do
73
78
  puts "ruby #{Hoe::RUBY_FLAGS} bin/ruby_parse -q -g ..."
74
79
  end
75
80
 
76
- task :irb => [:isolate] do
77
- sh "GEM_HOME=#{Gem.path.first} irb -rubygems -Ilib -rruby_parser;"
78
- end
79
-
80
81
  def (task(:phony)).timestamp
81
82
  Time.at 0
82
83
  end
@@ -107,7 +108,7 @@ def ruby_parse version
107
108
  ruby_dir = "ruby-#{version}"
108
109
  diff = "diff#{v}.diff"
109
110
  rp_out = "lib/ruby#{v}_parser.output"
110
- rp_y = "lib/ruby#{v}_parser.y"
111
+ _rp_y = "lib/ruby#{v}_parser.y"
111
112
  rp_y_rb = "lib/ruby#{v}_parser.rb"
112
113
 
113
114
  c_diff = "compare/#{diff}"
@@ -125,13 +126,22 @@ def ruby_parse version
125
126
 
126
127
  file c_parse_y => c_tarball do
127
128
  in_compare do
128
- system "tar yxf #{tarball} #{ruby_dir}/{id.h,parse.y,tool/{id2token.rb,vpath.rb}}"
129
+ extract_glob = case version
130
+ when /2\.7/
131
+ "{id.h,parse.y,tool/{id2token.rb,lib/vpath.rb}}"
132
+ else
133
+ "{id.h,parse.y,tool/{id2token.rb,vpath.rb}}"
134
+ end
135
+ system "tar yxf #{tarball} #{ruby_dir}/#{extract_glob}"
136
+
129
137
  Dir.chdir ruby_dir do
130
138
  if File.exist? "tool/id2token.rb" then
131
139
  sh "ruby tool/id2token.rb --path-separator=.:./ id.h parse.y | expand > ../#{parse_y}"
132
140
  else
133
141
  sh "expand parse.y > ../#{parse_y}"
134
142
  end
143
+
144
+ ruby "-pi", "-e", 'gsub(/^%define\s+api\.pure/, "%pure-parser")', "../#{parse_y}"
135
145
  end
136
146
  sh "rm -rf #{ruby_dir}"
137
147
  end
@@ -184,16 +194,17 @@ ruby_parse "2.0.0-p648"
184
194
  ruby_parse "2.1.9"
185
195
  ruby_parse "2.2.9"
186
196
  ruby_parse "2.3.8"
187
- ruby_parse "2.4.5"
188
- ruby_parse "2.5.3"
189
- ruby_parse "2.6.1"
197
+ ruby_parse "2.4.9"
198
+ ruby_parse "2.5.8"
199
+ ruby_parse "2.6.6"
200
+ ruby_parse "2.7.1"
190
201
 
191
202
  task :debug => :isolate do
192
203
  ENV["V"] ||= V2.last
193
204
  Rake.application[:parser].invoke # this way we can have DEBUG set
194
205
  Rake.application[:lexer].invoke # this way we can have DEBUG set
195
206
 
196
- $: << "lib"
207
+ $:.unshift "lib"
197
208
  require "ruby_parser"
198
209
  require "pp"
199
210
 
@@ -204,19 +215,21 @@ task :debug => :isolate do
204
215
  time = (ENV["RP_TIMEOUT"] || 10).to_i
205
216
 
206
217
  n = ENV["BUG"]
207
- file = (n && "bug#{n}.rb") || ENV["F"] || ENV["FILE"]
218
+ file = (n && "bug#{n}.rb") || ENV["F"] || ENV["FILE"] || "bug.rb"
219
+ ruby = ENV["R"] || ENV["RUBY"]
220
+
221
+ if ruby then
222
+ file = "env"
223
+ else
224
+ ruby = File.read file
225
+ end
208
226
 
209
- ruby = if file then
210
- File.read(file)
211
- else
212
- file = "env"
213
- ENV["R"] || ENV["RUBY"]
214
- end
215
227
 
216
228
  begin
217
229
  pp parser.process(ruby, file, time)
218
- rescue Racc::ParseError => e
230
+ rescue ArgumentError, Racc::ParseError => e
219
231
  p e
232
+ puts e.backtrace.join "\n "
220
233
  ss = parser.lexer.ss
221
234
  src = ss.string
222
235
  lines = src[0..ss.pos].split(/\n/)
@@ -225,7 +238,7 @@ task :debug => :isolate do
225
238
  end
226
239
 
227
240
  task :debug3 do
228
- file = ENV["F"]
241
+ file = ENV["F"] || "bug.rb"
229
242
  verbose = ENV["V"] ? "-v" : ""
230
243
  munge = "./tools/munge.rb #{verbose}"
231
244
 
@@ -233,12 +246,17 @@ task :debug3 do
233
246
 
234
247
  ENV.delete "V"
235
248
 
249
+ sh "ruby -v"
236
250
  sh "ruby -y #{file} 2>&1 | #{munge} > tmp/ruby"
237
251
  sh "./tools/ripper.rb -d #{file} | #{munge} > tmp/rip"
238
- sh "rake debug F=#{file} DEBUG=1 V=25 2>&1 | #{munge} > tmp/rp"
252
+ sh "rake debug F=#{file} DEBUG=1 2>&1 | #{munge} > tmp/rp"
239
253
  sh "diff -U 999 -d tmp/{rip,rp}"
240
254
  end
241
255
 
256
+ task :cmp do
257
+ sh %(emacsclient --eval '(ediff-files "tmp/ruby" "tmp/rp")')
258
+ end
259
+
242
260
  task :cmp3 do
243
261
  sh %(emacsclient --eval '(ediff-files3 "tmp/ruby" "tmp/rip" "tmp/rp")')
244
262
  end
@@ -26,6 +26,8 @@ class File
26
26
  end
27
27
 
28
28
  begin
29
+ time = (ENV["RP_TIMEOUT"] || 10).to_i
30
+
29
31
  ARGV.each do |file|
30
32
  rp = RubyParser.new
31
33
  loc = `wc -l #{file}`.strip.to_i
@@ -45,7 +47,7 @@ begin
45
47
  begin
46
48
  begin
47
49
  rp.reset
48
- r = rp.parse(File.binread(file), file)
50
+ r = rp.process(File.binread(file), file, time)
49
51
  pp r unless $q
50
52
  good += 1
51
53
  rescue SyntaxError => e
@@ -104,9 +104,14 @@ rescue Timeout::Error
104
104
  warn "TIMEOUT parsing #{file}. Skipping."
105
105
 
106
106
  if $m then
107
- dir = File.join $m, File.dirname(file)
108
- FileUtils.mkdir_p dir
109
- FileUtils.move file, dir
107
+ base_dir, *rest = file.split("/")
108
+ base_dir.sub!(/\.slow\.?.*/, "")
109
+ base_dir += ".slow.#{time}"
110
+
111
+ new_file = File.join(base_dir, *rest)
112
+
113
+ FileUtils.mkdir_p File.dirname(new_file)
114
+ FileUtils.move file, new_file, verbose:true
110
115
  elsif $t then
111
116
  File.unlink file
112
117
  end
@@ -8,6 +8,10 @@ order = []
8
8
 
9
9
  def munge s
10
10
  renames = [
11
+ # unquote... wtf?
12
+ /`(.+?)'/, proc { $1 },
13
+ /"'(.+?)'"/, proc { "\"#{$1}\"" },
14
+
11
15
  "'='", "tEQL",
12
16
  "'!'", "tBANG",
13
17
  "'%'", "tPERCENT",
@@ -100,6 +104,43 @@ def munge s
100
104
 
101
105
  "kVARIABLE", "keyword_variable", # ugh: this is a rule name
102
106
 
107
+ # 2.7 changes:
108
+
109
+ '"global variable"', "tGVAR",
110
+ '"operator-assignment"', "tOP_ASGN",
111
+ '"back reference"', "tBACK_REF",
112
+ '"numbered reference"', "tNTH_REF",
113
+ '"local variable or method"', "tIDENTIFIER",
114
+ '"constant"', "tCONSTANT",
115
+
116
+ '"(.."', "tBDOT2",
117
+ '"(..."', "tBDOT3",
118
+ '"char literal"', "tCHAR",
119
+ '"literal content"', "tSTRING_CONTENT",
120
+ '"string literal"', "tSTRING_BEG",
121
+ '"symbol literal"', "tSYMBEG",
122
+ '"backtick literal"', "tXSTRING_BEG",
123
+ '"regexp literal"', "tREGEXP_BEG",
124
+ '"word list"', "tWORDS_BEG",
125
+ '"verbatim word list"', "tQWORDS_BEG",
126
+ '"symbol list"', "tSYMBOLS_BEG",
127
+ '"verbatim symbol list"', "tQSYMBOLS_BEG",
128
+
129
+ '"float literal"', "tFLOAT",
130
+ '"imaginary literal"', "tIMAGINARY",
131
+ '"integer literal"', "tINTEGER",
132
+ '"rational literal"', "tRATIONAL",
133
+
134
+ '"instance variable"', "tIVAR",
135
+ '"class variable"', "tCVAR",
136
+ '"terminator"', "tSTRING_END", # TODO: switch this?
137
+ '"method"', "tFID",
138
+ '"}"', "tSTRING_DEND",
139
+
140
+ '"do for block"', "kDO_BLOCK",
141
+ '"do for condition"', "kDO_COND",
142
+ '"do for lambda"', "kDO_LAMBDA",
143
+
103
144
  # UGH
104
145
  "k_LINE__", "k__LINE__",
105
146
  "k_FILE__", "k__FILE__",
@@ -107,13 +148,12 @@ def munge s
107
148
 
108
149
  '"defined?"', "kDEFINED",
109
150
 
110
-
111
151
  '"do (for condition)"', "kDO_COND",
112
152
  '"do (for lambda)"', "kDO_LAMBDA",
113
153
  '"do (for block)"', "kDO_BLOCK",
114
154
 
115
- /\"(\w+) \(modifier\)\"/, proc { |x| "k#{$1.upcase}_MOD" },
116
- /\"(\w+)\"/, proc { |x| "k#{$1.upcase}" },
155
+ /\"(\w+) \(?modifier\)?\"/, proc { |x| "k#{$1.upcase}_MOD" },
156
+ /\"(\w+)\"/, proc { |x| "k#{$1.upcase}" },
117
157
 
118
158
  /@(\d+)(\s+|$)/, "",
119
159
  ]