ruby_parser 2.0.5 → 3.0.0.a1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.autotest CHANGED
@@ -1,11 +1,12 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'autotest/restart'
4
+ require 'autotest/isolate'
4
5
  require 'autotest/rcov' if ENV['RCOV']
5
6
 
6
7
  Autotest.add_hook :initialize do |at|
7
- at.extra_files << "../../ParseTree/dev/test/pt_testcase.rb"
8
- at.libs << ":../../ParseTree/dev/test:../../sexp_processor/dev/lib"
8
+ at.extra_files << "../../sexp_processor/dev/lib/pt_testcase.rb"
9
+ at.libs << ":../../sexp_processor/dev/lib"
9
10
  at.add_exception 'unit'
10
11
  at.add_exception 'coverage'
11
12
  at.add_exception 'coverage.info'
@@ -13,7 +14,6 @@ Autotest.add_hook :initialize do |at|
13
14
 
14
15
  at.libs << ':../../minitest/dev/lib'
15
16
  at.testlib = "minitest/autorun"
16
- at.unit_diff = "unit_diff -u -b"
17
17
 
18
18
  at.add_mapping(/^lib\/.*\.y$/) do |f, _|
19
19
  at.files_matching %r%^test/.*#{File.basename(f, '.y').gsub '_', '_?'}.rb$%
@@ -27,7 +27,7 @@ Autotest.add_hook :initialize do |at|
27
27
  at.extra_class_map[klass] = "test/test_ruby_parser_extras.rb"
28
28
  end
29
29
 
30
- %w(TestRubyParser TestParseTree).each do |klass| # HACK
30
+ %w(TestRuby18Parser TestRuby19Parser TestParseTree).each do |klass| # HACK
31
31
  at.extra_class_map[klass] = "test/test_ruby_parser.rb"
32
32
  end
33
33
  end
data/.gemtest ADDED
File without changes
data/History.txt CHANGED
@@ -1,3 +1,127 @@
1
+ === 3.0.0.a1 / 2012-05-22
2
+
3
+ This is the first alpha release of the 3.0.0 series. It is probably
4
+ woefully incomplete, bug ridden, and hasn't showered in several days.
5
+ Please please please beat the crap out of it and send
6
+ bugs/patches/complaints/suggestions.
7
+
8
+ * 5 major enhancements:
9
+
10
+ * 1.9 parsing! Thanks to EVERYONE for submitting patches for this!
11
+ * Removed :arglist from everything but :op_asgn1
12
+ * Removed :block from resbody
13
+ * Removed :block from when
14
+ * Removed :block nodes inside of scope nodes (defn/defs/class/sclass).
15
+ * Removed :scope nodes in defn/defs/class/sclass nodes.
16
+ * (probably more sexp cleanup to come before 3.0.0 final)
17
+
18
+ * 25 minor enhancements:
19
+
20
+ * 1.9: Fix \!a. (wanabe)
21
+ * 1.9: Method calling with postargs. (wanabe)
22
+ * 1.9: Method definition with postargs. (wanabe)
23
+ * 1.9: Support lambda args without parentheses. (wanabe)
24
+ * Added R arg to `rake debug` to debug ruby straight up
25
+ * Added RubyParser, subclassing Ruby18Parser but warning on instantiation.
26
+ * Added backref_assign_error (needs tests)
27
+ * Added bin/ruby_parse_extract_error to help with error submissions
28
+ * Added debug task to help quickly get into a bug
29
+ * Added more 18 vs 19 lexing tests for ?c.
30
+ * Added ruby_parser.rb that pulls everything together in proper order.
31
+ * Added tLABEL. (brynary)
32
+ * Branched ruby_parser.y to ruby18_parser.y
33
+ * Fix to pass test_lambda_args_block__19 test. (mrmargolis)
34
+ * Got rid of one instance of unread_many. (Confusion)
35
+ * Moved everything from RubyParser to RubyParserStuff and included module in both.
36
+ * Refactored 1.9 args handling
37
+ * Refactored and added new_resbody to ruby_parser_extras.
38
+ * Refactored and added new_when
39
+ * Refactored tests infrastructure and added both 1.8 and 1.9 test branches.
40
+ * Removed unused methods: unread, begin_of_line? was_begin_of_line. (YAY!) (Confusion)
41
+ * Renamed ruby_parser.y to ruby19_parser.y
42
+ * RubyLexer now takes a version specifier.
43
+ * Started doing comparative refactoring between MRI's 1.9 parser and RP's. Shouldn't differ functionally except where we missed stuff in RP.
44
+ * `rake debug` prints the output if it succeeds.
45
+
46
+ * 21 bug fixes:
47
+
48
+ * Added missing gvar arg error. (1.8)
49
+ * Attach parser files to isolate to ensure they can build
50
+ * Conditionalize handling of tLABEL to ruby19+. Fixes issue #33.
51
+ * DOH. I deactivated some tests and never reactivated them. (Confusion ftw)
52
+ * Duplicate the input so that heredoc processing doesn't morph original. (banister)
53
+ * Entirely reworked block arg handling. (1.8)
54
+ * Fix ?x char literal. (nobu)
55
+ * Fixed 4/5 of literal lambda tests (jamie)
56
+ * Fixed deps for parser
57
+ * Fixed lexing of ?c for ruby 1.8 and 1.9.
58
+ * Fixed more Ruby 1.9 args tests (brynary)
59
+ * Fixed reswords to match MRI (1.8, 1.9)
60
+ * Fixed symbols with no spaces in method calls (e.g. foo:bar) (YAY! brynary)
61
+ * Fixed ternary_nil_no_space and other ternary edge cases for 1.9. (lastobelus)
62
+ * Fixed test_call_not_equal__19. First bug bounty! (albus522)
63
+ * Made lambda w/o arg list zero out the arg slot.
64
+ * Renamed awords to qwords to match stupid MRI naming. (1.8, 1.9) :(
65
+ * Rolled out brynary's symbols-no-spaces (foo:bar) changes when parsing 1.8 code
66
+ * Split 1.8 from 1.9 open paren lexer. Gawd that's ugly code.
67
+ * Split block_var from for_var. (1.8, 1.9)
68
+ * Use binread (and emulate in ruby 1.8) to avoid encoding issues
69
+
70
+ === 2.3.1 / 2011-09-21
71
+
72
+ * 2 bug fixes:
73
+
74
+ * Fixed line numbers at end of special var+whitespace (larsch)
75
+ * Holy crap I was smokin' something good... Fixed 1.9.3 warning
76
+
77
+ === 2.3.0 / 2011-09-06
78
+
79
+ * 2 minor enhancements:
80
+
81
+ * Add -g flag to parser compile if DEBUG
82
+ * Lexer now embeds line number in yacc_value for keywords, helping fix up line numbers
83
+
84
+ * 3 bug fixes:
85
+
86
+ * Fix method line numbers when no args and no parens (quix)
87
+ * Fixed line numbers on return/break/next w/ result expr. (pjnz)
88
+ * Fixed some lexing state in order to parse: 'f (1), 2' as 'f(1, 2)'. (invernizzi)
89
+
90
+ === 2.2.0 / 2011-08-23
91
+
92
+ * 2 minor enhancements:
93
+
94
+ * Moved Keyword, Environment, and StackState inside of RubyParser
95
+ * Added proper dsym and dsym->sym support.
96
+
97
+ * 3 bug fixes:
98
+
99
+ * Added extra (failing) tests for call/iter line number checking (quix)
100
+ * Fixed line numbers for certain call/iter edge cases
101
+ * Fixed parsing of: alias :"<<" :">>".
102
+
103
+ === 2.1.0 / 2011-08-15
104
+
105
+ * 2 minor enhancements:
106
+
107
+ * Added new accessor canonicalize_conditions to toggle conditional canonicalization (on by default). (confused)
108
+ * Awesome cleanup: Replaced call to append_block by block_append. (Confusion)
109
+
110
+ * 2 bug fixes:
111
+
112
+ * Fixed handling last line of =begin/=end. (raybaxter)
113
+ * Fixed source line numbers after heredocs. (jbarreneche)
114
+
115
+ === 2.0.6 / 2011-02-18
116
+
117
+ * 1 minor enhancement:
118
+
119
+ * Switched to hoe's racc plugin to clean up rakefile and builds
120
+
121
+ * 1 bug fix:
122
+
123
+ * Fixed empty =begin/end.
124
+
1
125
  === 2.0.5 / 2010-09-01
2
126
 
3
127
  * 1 minor enhancement:
data/Manifest.txt CHANGED
@@ -4,9 +4,14 @@ Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
6
  bin/ruby_parse
7
+ bin/ruby_parse_extract_error
7
8
  lib/gauntlet_rubyparser.rb
9
+ lib/ruby18_parser.rb
10
+ lib/ruby18_parser.y
11
+ lib/ruby19_parser.rb
12
+ lib/ruby19_parser.y
8
13
  lib/ruby_lexer.rb
9
- lib/ruby_parser.y
14
+ lib/ruby_parser.rb
10
15
  lib/ruby_parser_extras.rb
11
16
  test/test_ruby_lexer.rb
12
17
  test/test_ruby_parser.rb
data/README.txt CHANGED
@@ -1,6 +1,8 @@
1
1
  = ruby_parser
2
2
 
3
- * http://parsetree.rubyforge.org/
3
+ home :: https://github.com/seattlerb/ruby_parser
4
+ bugs :: https://github.com/seattlerb/ruby_parser/issues
5
+ rdoc :: http://docs.seattlerb.org/ruby_parser
4
6
 
5
7
  == DESCRIPTION:
6
8
 
@@ -46,14 +48,13 @@ becomes:
46
48
 
47
49
  == SYNOPSIS:
48
50
 
49
- RubyParser.new.parse "1+1"
50
- # => s(:call, s(:lit, 1), :+, s(:array, s(:lit, 1)))
51
+ Ruby19Parser.new.parse "1+1"
52
+ # => s(:call, s(:lit, 1), :+, s(:lit, 1))
51
53
 
52
54
  == REQUIREMENTS:
53
55
 
54
56
  * ruby. woot.
55
- * sexp_processor for Sexp and SexpProcessor classes.
56
- * ParseTree for testing.
57
+ * sexp_processor for Sexp and SexpProcessor classes, and testing.
57
58
  * racc full package for parser development (compiling .y to .rb).
58
59
 
59
60
  == INSTALL:
@@ -64,7 +65,7 @@ becomes:
64
65
 
65
66
  (The MIT License)
66
67
 
67
- Copyright (c) 2007-2008 Ryan Davis
68
+ Copyright (c) Ryan Davis, seattle.rb
68
69
 
69
70
  Permission is hereby granted, free of charge, to any person obtaining
70
71
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -4,49 +4,34 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
6
  Hoe.plugin :seattlerb
7
+ Hoe.plugin :racc
8
+ Hoe.plugin :isolate
7
9
 
8
- Hoe.add_include_dirs("../../ParseTree/dev/test",
9
- "../../RubyInline/dev/lib",
10
- "../../sexp_processor/dev/lib")
10
+ Hoe.add_include_dirs "../../sexp_processor/dev/lib"
11
11
 
12
- hoe = Hoe.spec 'ruby_parser' do
12
+ Hoe.spec 'ruby_parser' do
13
13
  developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
14
14
 
15
15
  self.rubyforge_name = 'parsetree'
16
16
 
17
- extra_dev_deps << ['ParseTree', '~> 3.0']
18
- extra_deps << ['sexp_processor', '~> 3.0']
19
- end
20
-
21
- hoe.spec.files += ['lib/ruby_parser.rb'] # jim.... cmon man
17
+ dependency 'sexp_processor', '~> 3.0'
22
18
 
23
- [:default, :multi, :test].each do |t|
24
- task t => :parser
25
- end
26
-
27
- path = "pkg/ruby_parser-#{hoe.version}"
28
- task path => :parser do
29
- Dir.chdir path do
30
- sh "rake parser"
19
+ if plugin? :perforce then
20
+ self.perforce_ignore << "lib/ruby18_parser.rb"
21
+ self.perforce_ignore << "lib/ruby19_parser.rb"
31
22
  end
32
- end
33
23
 
34
- desc "build the parser"
35
- task :parser => ["lib/ruby_parser.rb"]
36
-
37
- rule '.rb' => '.y' do |t|
38
- # -v = verbose
39
- # -t = debugging parser ~4% reduction in speed -- keep for now
40
- # -l = no-line-convert
41
- sh "racc -v -t -l -o #{t.name} #{t.source}"
24
+ self.racc_flags << " -g" if plugin?(:racc) && ENV["DEBUG"]
42
25
  end
43
26
 
27
+ file "lib/ruby18_parser.rb" => "lib/ruby18_parser.y"
28
+ file "lib/ruby19_parser.rb" => "lib/ruby19_parser.y"
29
+
44
30
  task :clean do
45
31
  rm_rf(Dir["**/*~"] +
46
32
  Dir["**/*.diff"] +
47
33
  Dir["coverage.info"] +
48
34
  Dir["coverage"] +
49
- Dir["lib/ruby_parser.rb"] +
50
35
  Dir["lib/*.output"])
51
36
  end
52
37
 
@@ -124,4 +109,66 @@ task :huh? do
124
109
  puts "ruby #{Hoe::RUBY_FLAGS} bin/ruby_parse -q -g ..."
125
110
  end
126
111
 
112
+ task :irb => [:isolate] do
113
+ sh "GEM_HOME=#{Gem.path.first} irb -rubygems -Ilib -rruby_parser;"
114
+ end
115
+
116
+ def (task(:phony)).timestamp
117
+ Time.at 0
118
+ end
119
+
120
+ task :isolate => :phony
121
+
122
+ file "lib/ruby18_parser.rb" => :isolate
123
+ file "lib/ruby19_parser.rb" => :isolate
124
+
125
+ task :compare18 do
126
+ sh "./yack.rb lib/ruby18_parser.output > racc18.txt"
127
+ sh "./yack.rb parse18.output > yacc18.txt"
128
+ sh "diff -du racc18.txt yacc18.txt || true"
129
+ puts
130
+ sh "diff -du racc18.txt yacc18.txt | wc -l"
131
+ end
132
+
133
+ task :compare19 do
134
+ sh "./yack.rb lib/ruby19_parser.output > racc19.txt"
135
+ sh "./yack.rb parse19.output > yacc19.txt"
136
+ sh "diff -du racc19.txt yacc19.txt || true"
137
+ puts
138
+ sh "diff -du racc19.txt yacc19.txt | wc -l"
139
+ end
140
+
141
+ task :debug => :isolate do
142
+ ENV["V"] ||= "18"
143
+ Rake.application[:parser].invoke # this way we can have DEBUG set
144
+
145
+ $: << "lib"
146
+ require 'ruby_parser'
147
+
148
+ parser = if ENV["V"] == "18" then
149
+ Ruby18Parser.new
150
+ else
151
+ Ruby19Parser.new
152
+ end
153
+
154
+ file = ENV["F"] || ENV["FILE"]
155
+
156
+ ruby = if file then
157
+ File.read(file)
158
+ else
159
+ file = "env"
160
+ ENV["R"] || ENV["RUBY"]
161
+ end
162
+
163
+ begin
164
+ p parser.process(ruby, file)
165
+ rescue Racc::ParseError => e
166
+ p e
167
+ ss = parser.lexer.src
168
+ src = ss.string
169
+ lines = src[0..ss.pos].split(/\n/)
170
+ abort "on #{file}:#{lines.size}"
171
+ end
172
+ end
173
+
127
174
  # vim: syntax=Ruby
data/bin/ruby_parse CHANGED
@@ -17,6 +17,14 @@ times = {}
17
17
  locs = {}
18
18
  kbytes = {}
19
19
 
20
+ class File
21
+ RUBY19 = "<3".respond_to? :encoding
22
+
23
+ class << self
24
+ alias :binread :read unless RUBY19
25
+ end
26
+ end
27
+
20
28
  begin
21
29
  ARGV.each do |file|
22
30
  rp = RubyParser.new
@@ -37,7 +45,7 @@ begin
37
45
  begin
38
46
  begin
39
47
  rp.reset
40
- r = rp.parse(File.read(file), file)
48
+ r = rp.parse(File.binread(file), file)
41
49
  pp r unless $q
42
50
  good += 1
43
51
  rescue SyntaxError => e
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/ruby -ws
2
+
3
+ require 'rubygems'
4
+ require 'ruby_parser'
5
+
6
+ ARGV.push "-" if ARGV.empty?
7
+
8
+ parser = Ruby18Parser.new
9
+
10
+ class Racc::Parser
11
+ def extract_defs
12
+ ss = lexer.src
13
+ src = ss.string
14
+ pre_error = src[0...ss.pos]
15
+
16
+ defs = pre_error.grep(/^ *def/)
17
+
18
+ last_def_indent = defs.last[/^ */]
19
+
20
+ post_error = src[ss.pos..-1]
21
+ idx = post_error =~ /^#{last_def_indent}end.*/
22
+
23
+ raise "can't figure out where the bad code ends" unless idx
24
+
25
+ src = pre_error + post_error[0..idx+$&.length]
26
+
27
+ src.scan(/^(( *)def .*?^\2end)/m)
28
+ end
29
+
30
+ def retest_for_errors defs
31
+ d :retest => defs.size
32
+
33
+ parser = self.class.new
34
+
35
+ parser.process(defs.join("\n\n")) rescue nil
36
+ end
37
+ end
38
+
39
+ ARGV.replace ARGV.map { |path|
40
+ if File.directory? path then
41
+ Dir.glob File.join path, "**/*.rb"
42
+ else
43
+ path
44
+ end
45
+ }.flatten
46
+
47
+ ARGV.each do |file|
48
+ ruby = file == "-" ? $stdin.read : File.read(file)
49
+
50
+ begin
51
+ $stderr.print "Validating #{file}: "
52
+ parser.process(ruby, file)
53
+ $stderr.puts "good"
54
+ rescue Racc::ParseError => e
55
+ $stderr.puts "error: #{e.description}"
56
+ $stderr.puts
57
+
58
+ defs = parser.extract_defs
59
+
60
+ abort "Can't reproduce error with just methods, punting..." if
61
+ parser.retest_for_errors defs
62
+
63
+ mandatory = defs.pop
64
+
65
+ (1..defs.size).each do |perm_size|
66
+ defs.combination(perm_size).each do |trial|
67
+ trial << mandatory
68
+ unless parser.retest_for_errors trial then
69
+ puts trial.join "\n"
70
+ abort "reduced repro found!"
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end