ruby_parser 3.1.3 → 3.2.0

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.tar.gz.sig CHANGED
Binary file
data/.autotest CHANGED
@@ -11,7 +11,12 @@ Autotest.add_hook :initialize do |at|
11
11
  at.add_exception 'coverage'
12
12
  at.add_exception 'coverage.info'
13
13
  at.add_exception '.diff'
14
+ at.add_exception '.output'
14
15
  at.add_exception 'rubycorpus'
16
+ at.add_exception "lib/ruby18_parser.rb"
17
+ at.add_exception "lib/ruby19_parser.rb"
18
+ at.add_exception "lib/ruby20_parser.rb"
19
+ at.add_exception "lib/gauntlet_rubyparser.rb"
15
20
 
16
21
  dirs = Dir["corpus*"] + Dir["gauntlet*"]
17
22
 
@@ -23,6 +28,8 @@ Autotest.add_hook :initialize do |at|
23
28
  at.testlib = "minitest/autorun"
24
29
 
25
30
  at.add_mapping(/^lib\/.*\.y$/) do |f, _|
31
+ re = %r%^test/test_#{File.basename(f, '.y').gsub(/(\d+)/, '')}.rb$%
32
+ at.files_matching re
26
33
  at.files_matching %r%^test/.*#{File.basename(f, '.y').gsub '_', '_?'}.rb$%
27
34
  end
28
35
 
@@ -34,7 +41,7 @@ Autotest.add_hook :initialize do |at|
34
41
  at.extra_class_map[klass] = "test/test_ruby_parser_extras.rb"
35
42
  end
36
43
 
37
- %w(TestRuby18Parser TestRuby19Parser TestParseTree).each do |klass| # HACK
44
+ %w(TestRuby18Parser TestRuby19Parser TestRuby20Parser TestParseTree).each do |klass| # HACK
38
45
  at.extra_class_map[klass] = "test/test_ruby_parser.rb"
39
46
  end
40
47
  end
@@ -45,6 +52,12 @@ end
45
52
 
46
53
  class Autotest
47
54
  def ruby
48
- File.expand_path "~/.multiruby/install/1.9.0-0/bin/ruby"
55
+ File.expand_path "~/.multiruby/install/1.9.3-p194/bin/ruby"
49
56
  end
50
- end if ENV['ONENINE']
57
+ end if ENV['R19']
58
+
59
+ class Autotest
60
+ def ruby
61
+ File.expand_path "~/.multiruby/install/2.0.0-p195/bin/ruby"
62
+ end
63
+ end if ENV['R20']
data/History.txt CHANGED
@@ -1,3 +1,69 @@
1
+ === 3.2.0 / 2013-07-02
2
+
3
+ * 1 major enhancement:
4
+
5
+ * Added (rough draft) 2.0 support. Still missing some small / rare things.
6
+
7
+ * 12 minor enhancements:
8
+
9
+ * Added %i(symbol-names...) support. (%I too)
10
+ * Added 140 more tests, jumping test count from 1376 to 2143. Yay for test reuse!
11
+ * Added RubyLexer#brace_nest.
12
+ * Added compare20 rake task to diff the grammar architecture against MRI.
13
+ * Added lpar_beg and paren_nest to lexer to track state of parens in stabbies
14
+ * Added shadow nodes for scoped block args.
15
+ * Compound RubyParser now defaults to 2.0.
16
+ * Fixed rake to < 10, because 10's file dependency handling is so very broken.
17
+ * Made it possible to specify version in bin/ruby_parse_extract_error w/ -v 18|19|20
18
+ * Refactored to RubyParserStuff::ENCODING_ORDER to allow custom tweaking of encoding guessing. (samlown)
19
+ * Switched `rake debug` to default to 2.0.
20
+ * Translated some fixes across 1.8 and 1.9 from 2.0.
21
+
22
+ * 42 bug fixes:
23
+
24
+ * 2.0: Fixed a number of block args scenarios w/ kwargs
25
+ * 2.0: Fixed args_tail mismatching against lexer.
26
+ * 2.0: Fixed assocs to return a hash node.
27
+ * 2.0: Fixed f_block_kw production.
28
+ * 2.0: Fixed f_block_kwarg production.
29
+ * 2.0: Fixed handling of stabby proc args in parens.
30
+ * 2.0: Fixed lexing of kwsplat nodes.
31
+ * 2.0: Implemented kwsplat nodes.
32
+ * Added tUBANG to lexer.
33
+ * Apparently ruby doesn't warn for escaped octal that goes above 7. wtf.
34
+ * Cleaned up a LOT of arg handling (block and defn, not calls) by using #args.
35
+ * ESC_RE is set to unicode. This seems problematic. *shrug*
36
+ * Either found a bug in MRI and/or fixed paren_nest count for []=? methods.
37
+ * Extended IDENT_CHAR_RE on 1.9+ to top out at \u{10ffff}... because we NEED a million unicode chars.
38
+ * Fixed % strings with interpolation.
39
+ * Fixed BEGIN {} to return a sexp.
40
+ * Fixed a[] += b. (stormbrew)
41
+ * Fixed arg_blk_pass to allow for sub-args nodes.
42
+ * Fixed assignable to allow for sexps to be passed to it.
43
+ * Fixed assoc args in 1.9.
44
+ * Fixed block_command and block_call (eg a.b c d) to #to_sym their args properly.
45
+ * Fixed bug in compound RubyParser so it rescues RubyParser::SyntaxError.
46
+ * Fixed env registration of cdecls.
47
+ * Fixed lex value for { when expr_endfn.
48
+ * Fixed lex_state for close paren/brace/bracket.
49
+ * Fixed lex_state transition for 1.9 if we lexed a defn name. Only 1.8 is odd.
50
+ * Fixed lexer problem with state mgmt of identifiers that also have registered var name.
51
+ * Fixed lexing of "1 *\n" to have the correct lex_state.
52
+ * Fixed lexing of heredocs vs chevron for some lex_states.
53
+ * Fixed op_asgn nodes to #to_sym their args properly.
54
+ * Fixed optional value block args.
55
+ * Fixed parsing of __ENCODING__ on ruby 1.8 (vcall).
56
+ * Fixed some oddity where 1.9 lexing was blowing up on "0o". Seems invalid now.
57
+ * Fixed strings with escaped octals > 128. Also... wtf.
58
+ * Fixed support for empty symbol (wtf?).
59
+ * Lexer is now declared UTF-8 internally. Hopefully this will fix the encoding mess.
60
+ * Made UTF_8 the default guess on encodings when it isn't explicit.
61
+ * Parsing of __ENCODING__ on ruby 1.9+ (in ruby 1.9+) is now colon2 sexp. (whitequark)
62
+ * Renamed RubyLexer#nest to string_nest
63
+ * RubyLexer#unescape ignores bad octal/hex and returns unicode strings.
64
+ * Switched a number of lexical constructs to use IDENT_CHAR_RE instead of \w. I wish there were something cleaner for regexps + unicode.
65
+ * Switched ruby_parse_extract_error to use binread.
66
+
1
67
  === 3.1.3 / 2013-04-09
2
68
 
3
69
  * 2 bug fixes:
data/Manifest.txt CHANGED
@@ -10,6 +10,8 @@ lib/ruby18_parser.rb
10
10
  lib/ruby18_parser.y
11
11
  lib/ruby19_parser.rb
12
12
  lib/ruby19_parser.y
13
+ lib/ruby20_parser.rb
14
+ lib/ruby20_parser.y
13
15
  lib/ruby_lexer.rb
14
16
  lib/ruby_parser.rb
15
17
  lib/ruby_parser_extras.rb
data/Rakefile CHANGED
@@ -8,6 +8,7 @@ Hoe.plugin :racc
8
8
  Hoe.plugin :isolate
9
9
 
10
10
  Hoe.add_include_dirs "../../sexp_processor/dev/lib"
11
+ Hoe.add_include_dirs "../../minitest/dev/lib"
11
12
 
12
13
  Hoe.spec 'ruby_parser' do
13
14
  developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
@@ -15,10 +16,12 @@ Hoe.spec 'ruby_parser' do
15
16
  self.rubyforge_name = 'parsetree'
16
17
 
17
18
  dependency 'sexp_processor', '~> 4.1'
19
+ dependency 'rake', '< 10', :developer
18
20
 
19
21
  if plugin? :perforce then
20
22
  self.perforce_ignore << "lib/ruby18_parser.rb"
21
23
  self.perforce_ignore << "lib/ruby19_parser.rb"
24
+ self.perforce_ignore << "lib/ruby20_parser.rb"
22
25
  end
23
26
 
24
27
  self.racc_flags << " -t" if plugin?(:racc) && ENV["DEBUG"]
@@ -26,6 +29,7 @@ end
26
29
 
27
30
  file "lib/ruby18_parser.rb" => "lib/ruby18_parser.y"
28
31
  file "lib/ruby19_parser.rb" => "lib/ruby19_parser.y"
32
+ file "lib/ruby20_parser.rb" => "lib/ruby20_parser.y"
29
33
 
30
34
  task :clean do
31
35
  rm_rf(Dir["**/*~"] +
@@ -50,16 +54,6 @@ task :compare do
50
54
  system 'find -d unit -type d -empty -exec rmdir {} \;'
51
55
  end
52
56
 
53
- desc "Compares PT to RP and stops on first failure"
54
- task :find_bug do
55
- files = Dir["unit/**/*.rb"]
56
- puts "Parsing #{files.size} files"
57
- files.each do |file|
58
- puts file
59
- sh "./cmp.rb -q #{file}"
60
- end
61
- end
62
-
63
57
  task :sort do
64
58
  sh 'grepsort "^ +def" lib/ruby_lexer.rb'
65
59
  sh 'grepsort "^ +def (test|util)" test/test_ruby_lexer.rb'
@@ -121,6 +115,7 @@ task :isolate => :phony
121
115
 
122
116
  file "lib/ruby18_parser.rb" => :isolate
123
117
  file "lib/ruby19_parser.rb" => :isolate
118
+ file "lib/ruby20_parser.rb" => :isolate
124
119
 
125
120
  task :compare18 do
126
121
  sh "./yack.rb lib/ruby18_parser.output > racc18.txt"
@@ -138,18 +133,29 @@ task :compare19 do
138
133
  sh "diff -du racc19.txt yacc19.txt | wc -l"
139
134
  end
140
135
 
136
+ task :compare20 do
137
+ sh "./yack.rb lib/ruby20_parser.output > racc20.txt"
138
+ sh "./yack.rb parse20.output > yacc20.txt"
139
+ sh "diff -du racc20.txt yacc20.txt || true"
140
+ puts
141
+ sh "diff -du racc20.txt yacc20.txt | wc -l"
142
+ end
143
+
141
144
  task :debug => :isolate do
142
- ENV["V"] ||= "19"
145
+ ENV["V"] ||= "20"
143
146
  Rake.application[:parser].invoke # this way we can have DEBUG set
144
147
 
145
148
  $: << "lib"
146
149
  require 'ruby_parser'
147
150
  require 'pp'
148
151
 
149
- parser = if ENV["V"] == "18" then
152
+ parser = case ENV["V"]
153
+ when "18" then
150
154
  Ruby18Parser.new
151
- else
155
+ when "19" then
152
156
  Ruby19Parser.new
157
+ else
158
+ Ruby20Parser.new
153
159
  end
154
160
 
155
161
  time = (ENV["RP_TIMEOUT"] || 10).to_i
@@ -174,9 +180,13 @@ task :debug => :isolate do
174
180
  end
175
181
  end
176
182
 
183
+ def ruby20
184
+ "/Users/ryan/.multiruby/install/2.0.0-p195/bin/ruby"
185
+ end
186
+
177
187
  task :debug_ruby do
178
188
  file = ENV["F"] || ENV["FILE"]
179
- sh "ruby19 -cwy #{file} 2>&1 | ./yuck.rb"
189
+ sh "#{ruby20} -cwy #{file} 2>&1 | ./yuck.rb"
180
190
  end
181
191
 
182
192
  task :extract => :isolate do
@@ -189,7 +199,7 @@ task :extract => :isolate do
189
199
  end
190
200
 
191
201
  task :bugs do
192
- sh "for f in bug*.rb ; do rake19 debug F=$f && rm $f ; done"
202
+ sh "for f in bug*.rb ; do #{Gem.ruby} -S rake debug F=$f && rm $f ; done"
193
203
  end
194
204
 
195
205
  # vim: syntax=Ruby
@@ -8,11 +8,31 @@ $m ||= false
8
8
  $m ||= ENV["MOVE_TIMEOUT"]
9
9
  $q ||= false
10
10
  $q ||= ENV["QUIET"]
11
+ $v ||= ENV["V"] || "20"
11
12
 
12
13
  require 'rubygems'
13
14
  require 'ruby_parser'
14
15
  require 'fileutils'
15
16
 
17
+ $parser_class = case $v
18
+ when "18" then
19
+ Ruby18Parser
20
+ when "19" then
21
+ Ruby19Parser
22
+ when "20" then
23
+ Ruby20Parser
24
+ else
25
+ abort "Unknown version #{$v.inspect}. Needs to be 18, 19, or 20"
26
+ end
27
+
28
+ class IO
29
+ RUBY19 = "<3".respond_to? :encoding
30
+
31
+ class << self
32
+ alias :binread :read unless RUBY19
33
+ end
34
+ end
35
+
16
36
  ARGV.push "-" if ARGV.empty?
17
37
 
18
38
  class Racc::Parser
@@ -88,11 +108,11 @@ rescue RuntimeError, Racc::ParseError => e
88
108
  end
89
109
 
90
110
  def process file
91
- ruby = file == "-" ? $stdin.read : File.read(file)
111
+ ruby = file == "-" ? $stdin.binread : File.binread(file)
92
112
  time = (ENV["RP_TIMEOUT"] || 10).to_i
93
113
 
94
114
  $stderr.print "# Validating #{file}: "
95
- parser = Ruby19Parser.new
115
+ parser = $parser_class.new
96
116
  parser.process(ruby, file, time)
97
117
  warn "good"
98
118
  File.unlink file if $d
data/lib/ruby18_parser.rb CHANGED
@@ -3163,8 +3163,7 @@ def _reduce_20(val, _values, result)
3163
3163
  end
3164
3164
 
3165
3165
  def _reduce_21(val, _values, result)
3166
- result = new_iter s(:preexe), nil, val[3] # TODO: add test?
3167
- result = nil # TODO: since it isn't supposed to go in the AST
3166
+ result = new_iter s(:preexe), nil, val[3]
3168
3167
 
3169
3168
  result
3170
3169
  end
@@ -3203,13 +3202,13 @@ def _reduce_26(val, _values, result)
3203
3202
  end
3204
3203
 
3205
3204
  def _reduce_27(val, _values, result)
3206
- result = s(:op_asgn, val[0], val[4], val[2], val[3])
3205
+ result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
3207
3206
 
3208
3207
  result
3209
3208
  end
3210
3209
 
3211
3210
  def _reduce_28(val, _values, result)
3212
- result = s(:op_asgn, val[0], val[4], val[2], val[3])
3211
+ result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
3213
3212
 
3214
3213
  result
3215
3214
  end
@@ -3822,7 +3821,7 @@ end
3822
3821
 
3823
3822
  def _reduce_177(val, _values, result)
3824
3823
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
3825
- val[2][0] = :arglist
3824
+ val[2][0] = :arglist if val[2]
3826
3825
 
3827
3826
  result
3828
3827
  end
@@ -3840,7 +3839,7 @@ def _reduce_179(val, _values, result)
3840
3839
  end
3841
3840
 
3842
3841
  def _reduce_180(val, _values, result)
3843
- result = s(:op_asgn, val[0], val[4], val[2], val[3])
3842
+ result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
3844
3843
 
3845
3844
  result
3846
3845
  end
@@ -5249,6 +5248,7 @@ end
5249
5248
 
5250
5249
  def _reduce_419(val, _values, result)
5251
5250
  result = lexer.lex_strterm
5251
+
5252
5252
  lexer.lex_strterm = nil
5253
5253
  lexer.lex_state = :expr_beg
5254
5254
 
@@ -5263,32 +5263,44 @@ def _reduce_420(val, _values, result)
5263
5263
  end
5264
5264
 
5265
5265
  def _reduce_421(val, _values, result)
5266
- result = lexer.lex_strterm
5266
+ result = [lexer.lex_strterm, lexer.brace_nest, lexer.string_nest]
5267
+
5267
5268
  lexer.lex_strterm = nil
5268
- lexer.lex_state = :expr_beg
5269
+ lexer.brace_nest = 0
5270
+ lexer.string_nest = 0
5271
+
5269
5272
  lexer.cond.push false
5270
5273
  lexer.cmdarg.push false
5274
+
5275
+ lexer.lex_state = :expr_beg
5271
5276
 
5272
5277
  result
5273
5278
  end
5274
5279
 
5275
5280
  def _reduce_422(val, _values, result)
5276
- lexer.lex_strterm = val[1]
5281
+ _, memo, stmt, _ = val
5282
+
5283
+ lex_strterm, brace_nest, string_nest = memo
5284
+
5285
+ lexer.lex_strterm = lex_strterm
5286
+ lexer.brace_nest = brace_nest
5287
+ lexer.string_nest = string_nest
5288
+
5277
5289
  lexer.cond.lexpop
5278
5290
  lexer.cmdarg.lexpop
5279
5291
 
5280
- case val[2]
5292
+ case stmt
5281
5293
  when Sexp then
5282
- case val[2][0]
5294
+ case stmt[0]
5283
5295
  when :str, :dstr, :evstr then
5284
- result = val[2]
5296
+ result = stmt
5285
5297
  else
5286
- result = s(:evstr, val[2])
5298
+ result = s(:evstr, stmt)
5287
5299
  end
5288
5300
  when nil then
5289
5301
  result = s(:evstr)
5290
5302
  else
5291
- raise "unknown rescue body: #{val[2].inspect}"
5303
+ raise "unknown string body: #{stmt.inspect}"
5292
5304
  end
5293
5305
 
5294
5306
  result
@@ -5343,7 +5355,7 @@ def _reduce_433(val, _values, result)
5343
5355
  when :dstr then
5344
5356
  result[0] = :dsym
5345
5357
  when :str then
5346
- result = s(:lit, result.last.intern)
5358
+ result = s(:lit, result.last.to_sym)
5347
5359
  else
5348
5360
  result = s(:dsym, "", result)
5349
5361
  end
data/lib/ruby18_parser.y CHANGED
@@ -128,8 +128,7 @@ rule
128
128
  }
129
129
  tLCURLY compstmt tRCURLY
130
130
  {
131
- result = new_iter s(:preexe), nil, val[3] # TODO: add test?
132
- result = nil # TODO: since it isn't supposed to go in the AST
131
+ result = new_iter s(:preexe), nil, val[3]
133
132
  }
134
133
  | klEND tLCURLY compstmt tRCURLY
135
134
  {
@@ -156,11 +155,11 @@ rule
156
155
  }
157
156
  | primary_value tDOT tIDENTIFIER tOP_ASGN command_call
158
157
  {
159
- result = s(:op_asgn, val[0], val[4], val[2], val[3])
158
+ result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
160
159
  }
161
160
  | primary_value tDOT tCONSTANT tOP_ASGN command_call
162
161
  {
163
- result = s(:op_asgn, val[0], val[4], val[2], val[3])
162
+ result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
164
163
  }
165
164
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
166
165
  {
@@ -522,7 +521,7 @@ rule
522
521
  | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN arg
523
522
  {
524
523
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
525
- val[2][0] = :arglist
524
+ val[2][0] = :arglist if val[2]
526
525
  }
527
526
  | primary_value tDOT tIDENTIFIER tOP_ASGN arg
528
527
  {
@@ -534,7 +533,7 @@ rule
534
533
  }
535
534
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
536
535
  {
537
- result = s(:op_asgn, val[0], val[4], val[2], val[3])
536
+ result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
538
537
  }
539
538
  | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
540
539
  {
@@ -1545,6 +1544,7 @@ xstring_contents: none
1545
1544
  | tSTRING_DVAR
1546
1545
  {
1547
1546
  result = lexer.lex_strterm
1547
+
1548
1548
  lexer.lex_strterm = nil
1549
1549
  lexer.lex_state = :expr_beg
1550
1550
  }
@@ -1555,30 +1555,42 @@ xstring_contents: none
1555
1555
  }
1556
1556
  | tSTRING_DBEG
1557
1557
  {
1558
- result = lexer.lex_strterm
1558
+ result = [lexer.lex_strterm, lexer.brace_nest, lexer.string_nest]
1559
+
1559
1560
  lexer.lex_strterm = nil
1560
- lexer.lex_state = :expr_beg
1561
+ lexer.brace_nest = 0
1562
+ lexer.string_nest = 0
1563
+
1561
1564
  lexer.cond.push false
1562
1565
  lexer.cmdarg.push false
1566
+
1567
+ lexer.lex_state = :expr_beg
1563
1568
  }
1564
1569
  compstmt tRCURLY
1565
1570
  {
1566
- lexer.lex_strterm = val[1]
1571
+ _, memo, stmt, _ = val
1572
+
1573
+ lex_strterm, brace_nest, string_nest = memo
1574
+
1575
+ lexer.lex_strterm = lex_strterm
1576
+ lexer.brace_nest = brace_nest
1577
+ lexer.string_nest = string_nest
1578
+
1567
1579
  lexer.cond.lexpop
1568
1580
  lexer.cmdarg.lexpop
1569
1581
 
1570
- case val[2]
1582
+ case stmt
1571
1583
  when Sexp then
1572
- case val[2][0]
1584
+ case stmt[0]
1573
1585
  when :str, :dstr, :evstr then
1574
- result = val[2]
1586
+ result = stmt
1575
1587
  else
1576
- result = s(:evstr, val[2])
1588
+ result = s(:evstr, stmt)
1577
1589
  end
1578
1590
  when nil then
1579
1591
  result = s(:evstr)
1580
1592
  else
1581
- raise "unknown rescue body: #{val[2].inspect}"
1593
+ raise "unknown string body: #{stmt.inspect}"
1582
1594
  end
1583
1595
  }
1584
1596
 
@@ -1587,7 +1599,6 @@ xstring_contents: none
1587
1599
  | tCVAR { result = s(:cvar, val[0].to_sym) }
1588
1600
  | backref
1589
1601
 
1590
-
1591
1602
  symbol: tSYMBEG sym
1592
1603
  {
1593
1604
  lexer.lex_state = :expr_end
@@ -1612,7 +1623,7 @@ xstring_contents: none
1612
1623
  when :dstr then
1613
1624
  result[0] = :dsym
1614
1625
  when :str then
1615
- result = s(:lit, result.last.intern)
1626
+ result = s(:lit, result.last.to_sym)
1616
1627
  else
1617
1628
  result = s(:dsym, "", result)
1618
1629
  end