ruby_parser 3.3.0 → 3.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4e320a2bd80671b5ce1434876d1f85f76e63eff
4
- data.tar.gz: 9354638a4b05c8bacc5a5a50cbaa20387dc7d1d4
3
+ metadata.gz: c54a714696b5a3055f3f423bb81b3a6f4ecc2584
4
+ data.tar.gz: 5215e8bb9dccbd5f4dd6b515844fc1525ad56334
5
5
  SHA512:
6
- metadata.gz: 0332c2ba2307398ab331029a4c04e7bc4b0246a7a71735b56770ea5ab2edd94ae44da50be63c4288bf372616114bd3a038ae2ab9457a3a32a766a5034fa34b1d
7
- data.tar.gz: fcdde142a09539086dfd8b8c2371b0fddd08df31d3c1f63c3c2d6bf3518732ec2f1b1a3425a1a14d1e341420f350e9c8c9bd035cd83af9418c9c8ca7044901db
6
+ metadata.gz: ed81b97bf7ec8fc1800ab0c247cbb22850cb5e0559f9372eb19061f2d361237bc2c88cd2512ccfe7896c1515da4ded3bcadd8357b22028c9fd186ef4cbb55ed4
7
+ data.tar.gz: adc086eee5342a953f578aae3daf22685b1462f7e5444476f83babb09ff2b1940b40de5dc7a83cf249b56915057f594612849c9b2155074156cb80568e6c5d19
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- ���{P���S����M#�)���I��0m�s��CyP(�!x?�`�I�ܤ<�\�H+W��a��LqIy[16�vo��POZQ�
2
- ��= Ɇn�a�~2;} ���K�����1C��y%��$)MB�0GX���Q R�7����?���?~Y�ۺ�-
1
+ ���ְ�A%� �s�g���< ���1­��6ǭ 9��X��樀tlѽJ������<������_h�<2)`k�|.�-�J���e�g��� l^ ��»I������t+xHS>�e|~�@؍�
2
+ ���a��5���SN $-b*IJ65
data/.autotest CHANGED
@@ -7,20 +7,17 @@ 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
- at.add_exception '.diff'
14
- at.add_exception '.output'
15
- at.add_exception 'rubycorpus'
10
+ at.add_exception "unit"
11
+ at.add_exception "coverage"
12
+ at.add_exception "coverage.info"
13
+ at.add_exception ".diff"
14
+ at.add_exception ".output"
16
15
  at.add_exception "lib/ruby18_parser.rb"
17
16
  at.add_exception "lib/ruby19_parser.rb"
18
17
  at.add_exception "lib/ruby20_parser.rb"
19
- at.add_exception "lib/gauntlet_rubyparser.rb"
18
+ at.add_exception "lib/ruby_lexer.rex.rb"
20
19
 
21
- dirs = Dir["corpus*"] + Dir["gauntlet*"]
22
-
23
- dirs.each do |f|
20
+ Dir["gauntlet*"].each do |f|
24
21
  at.add_exception f
25
22
  end
26
23
 
@@ -28,7 +25,17 @@ Autotest.add_hook :initialize do |at|
28
25
  at.testlib = "minitest/autorun"
29
26
 
30
27
  at.add_mapping(/^lib\/.*\.y$/) do |f, _|
31
- at.files_matching %r%^test/.*#{File.basename(f, '.y').gsub '_', '_?'}.rb$%
28
+ g = File.basename(f, ".y").gsub("_", "_?").gsub(/1[89]|20/, '')
29
+ at.files_matching %r%^test/.*#{g}.rb$%
30
+ end
31
+
32
+ at.add_mapping(/^lib\/ruby_lexer\.rex\.rb$/) do |f, _|
33
+ at.files_matching %r%^test/.*ruby_lexer\.rb$%
34
+ end
35
+
36
+ at.add_mapping(/^lib\/.*\.rex$/) do |f, _|
37
+ g = File.basename(f, ".rex").gsub("_", "_?")
38
+ at.files_matching %r%^test/.*#{g}.rb$%
32
39
  end
33
40
 
34
41
  at.add_mapping(/pt_testcase.rb/) do |f, _|
@@ -45,17 +52,17 @@ Autotest.add_hook :initialize do |at|
45
52
  end
46
53
 
47
54
  Autotest.add_hook :run_command do |at, _|
48
- system "rake parser DEBUG=1"
55
+ system "rake parser lexer DEBUG=1"
49
56
  end
50
57
 
51
58
  class Autotest
52
59
  def ruby
53
60
  File.expand_path "~/.multiruby/install/1.9.3-p194/bin/ruby"
54
61
  end
55
- end if ENV['R19']
62
+ end if ENV["R19"]
56
63
 
57
64
  class Autotest
58
65
  def ruby
59
66
  File.expand_path "~/.multiruby/install/2.0.0-p195/bin/ruby"
60
67
  end
61
- end if ENV['R20']
68
+ end if ENV["R20"]
data/History.txt CHANGED
@@ -1,3 +1,53 @@
1
+ === 3.4.0 / 2014-02-04
2
+
3
+ * 1 major enhancement:
4
+
5
+ * Replaced hand-written/optimized f'd-up lexer with an oedipus_lex
6
+ generated lexer. This makes it roughly 40-50% faster.
7
+
8
+ * 30 minor enhancements:
9
+
10
+ * 2.0: Added support for a.b c() do d end.e do |f| g end
11
+ * 2.0: Added support for a.b c() do d end.e f do |g| h end
12
+ * Added -s flag to ruby_parse_extract_error to output timings.
13
+ * Added RubyLexer #command_state and #last_state to deal with oedipus_lex differences.
14
+ * Added String#lineno and #lineno= because I'm a bad bad person.
15
+ * Added a bunch of RubyLexer scanning methods: beginning_of_line?, check, scan, etc.
16
+ * Added a bunch of process_* methods extracted from old yylex. process_amper, etc.
17
+ * Added lib/.document to save my laptop's battery from pain and suffering
18
+ * Adjust lineno when we lex a bunch of blank lines.
19
+ * Attach lineno to tIDENTIFIER values (strings, ugh)
20
+ * Cleaned up and re-ordered node_assign to be faster (ordered by actual occurrance).
21
+ * Extend RubyParserStuff#gettable to set the lineno if it comes in with the id.
22
+ * Extended RubyParserStuff#new_case to take line number.
23
+ * Finally dropped RPStringScanner's BS #current_line.
24
+ * Finally dropped RPStringScanner's BS line number calculation (lineno).
25
+ * Implemented Sexp#add_all since we now have a test case for it.
26
+ * Removed :call case of node_assign. I don't think it is possible.
27
+ * Removed RubyLexer #extra_lines_added. No longer used. Complex heredoc lineno's possible screwed up.
28
+ * Removed RubyLexer#parse_number. Handled by oedipus_lex.
29
+ * Removed RubyLexer#yacc_value now that next_token returns pairs.
30
+ * Removed RubyLexer's @src. Now taken care of by oedipus_lex.
31
+ * Removed RubyParser#advance. RubyParser#next_token takes care of everything now.
32
+ * Removed RubyParserExtras#arg_add. (presidentbeef! YAY!)
33
+ * Removed lib/gauntlet_rubyparser.rb. I just don't use it anymore. Too slow.
34
+ * RubyLexer#is_label_possible? doesn't need an arg
35
+ * RubyLexer#process_token is now a normal oedipal lexer method.
36
+ * RubyParser#next_token now expects RubyLexer#next_token to return a pair (type, val).
37
+ * TRYING a new scheme to figure out encodings... but I'm about to throw in the towel. I hate this stuff so much.
38
+ * Turned off oedipus_lex's automatic line counting. (pushing to oedipus_lex soon).
39
+ * Updated to oedipus_lex 2.1+.
40
+
41
+ * 7 bug fixes:
42
+
43
+ * 1.8: Properly parse `a (:b, :c, :d => :e)`. (presidentbeef)
44
+ * Fixed lexing symbol!= vs symbol!. Please use your spacebar. Think of the children.
45
+ * Fixed line for dstr spanning multiple lines via backslash. (presidentbeef)
46
+ * Fixed line numbers for odd cases with trailing whitespace. (presidentbeef)
47
+ * Fixed line numbers on ambiguous calls w/ gvar/ivar args. (presidentbeef)
48
+ * Max out unicode hex values to 2-4 or 2-6 chars or pack will overflow and puke.
49
+ * Removed ESC_RE from RubyLexer. Must have slipped through.
50
+
1
51
  === 3.3.0 / 2014-01-14
2
52
 
3
53
  * Notes:
data/Manifest.txt CHANGED
@@ -5,7 +5,7 @@ README.txt
5
5
  Rakefile
6
6
  bin/ruby_parse
7
7
  bin/ruby_parse_extract_error
8
- lib/gauntlet_rubyparser.rb
8
+ lib/.document
9
9
  lib/ruby18_parser.rb
10
10
  lib/ruby18_parser.y
11
11
  lib/ruby19_parser.rb
@@ -13,6 +13,8 @@ lib/ruby19_parser.y
13
13
  lib/ruby20_parser.rb
14
14
  lib/ruby20_parser.y
15
15
  lib/ruby_lexer.rb
16
+ lib/ruby_lexer.rex
17
+ lib/ruby_lexer.rex.rb
16
18
  lib/ruby_parser.rb
17
19
  lib/ruby_parser_extras.rb
18
20
  test/test_ruby_lexer.rb
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  # -*- ruby -*-
2
2
 
3
- require 'rubygems'
4
- require 'hoe'
3
+ $:.unshift "../../hoe/dev/lib"
4
+
5
+ require "rubygems"
6
+ require "hoe"
5
7
 
6
8
  Hoe.plugin :seattlerb
7
9
  Hoe.plugin :racc
@@ -10,18 +12,20 @@ Hoe.plugin :isolate
10
12
  Hoe.add_include_dirs "../../sexp_processor/dev/lib"
11
13
  Hoe.add_include_dirs "../../minitest/dev/lib"
12
14
 
13
- Hoe.spec 'ruby_parser' do
14
- developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
15
+ Hoe.spec "ruby_parser" do
16
+ developer "Ryan Davis", "ryand-ruby@zenspider.com"
15
17
 
16
18
  license "MIT"
17
19
 
18
- dependency 'sexp_processor', '~> 4.1'
19
- dependency 'rake', '< 11', :developer
20
+ dependency "sexp_processor", "~> 4.1"
21
+ dependency "rake", "< 11", :developer
22
+ dependency "oedipus_lex", "~> 2.1", :developer
20
23
 
21
24
  if plugin? :perforce then
22
25
  self.perforce_ignore << "lib/ruby18_parser.rb"
23
26
  self.perforce_ignore << "lib/ruby19_parser.rb"
24
27
  self.perforce_ignore << "lib/ruby20_parser.rb"
28
+ self.perforce_ignore << "lib/ruby_lexer.rex.rb"
25
29
  end
26
30
 
27
31
  self.racc_flags << " -t" if plugin?(:racc) && ENV["DEBUG"]
@@ -30,10 +34,11 @@ end
30
34
  file "lib/ruby18_parser.rb" => "lib/ruby18_parser.y"
31
35
  file "lib/ruby19_parser.rb" => "lib/ruby19_parser.y"
32
36
  file "lib/ruby20_parser.rb" => "lib/ruby20_parser.y"
37
+ file "lib/ruby_lexer.rex.rb" => "lib/ruby_lexer.rex"
33
38
 
34
39
  task :clean do
35
40
  rm_rf(Dir["**/*~"] +
36
- Dir["**/*.diff"] +
41
+ Dir["diff.diff"] + # not all diffs. bit me too many times
37
42
  Dir["coverage.info"] +
38
43
  Dir["coverage"] +
39
44
  Dir["lib/*.output"])
@@ -51,12 +56,12 @@ task :compare do
51
56
  puts file
52
57
  system "./cmp.rb -q #{file} && rm #{file}"
53
58
  end
54
- system 'find -d unit -type d -empty -exec rmdir {} \;'
59
+ system "find -d unit -type d -empty -exec rmdir {} \;"
55
60
  end
56
61
 
57
62
  task :sort do
58
- sh 'grepsort "^ +def" lib/ruby_lexer.rb'
59
- sh 'grepsort "^ +def (test|util)" test/test_ruby_lexer.rb'
63
+ sh "grepsort '^ +def' lib/ruby_lexer.rb"
64
+ sh "grepsort '^ +def (test|util)' test/test_ruby_lexer.rb"
60
65
  end
61
66
 
62
67
  task :loc do
@@ -78,7 +83,7 @@ task :validate do
78
83
  end
79
84
 
80
85
  def run_and_log cmd, prefix
81
- files = ENV['FILES'] || 'unit/*.rb'
86
+ files = ENV["FILES"] || "unit/*.rb"
82
87
  p, x = prefix, "txt"
83
88
  n = Dir["#{p}.*.#{x}"].map { |s| s[/\d+/].to_i }.max + 1 rescue 1
84
89
  f = "#{p}.#{n}.#{x}"
@@ -140,10 +145,11 @@ end
140
145
  task :debug => :isolate do
141
146
  ENV["V"] ||= "20"
142
147
  Rake.application[:parser].invoke # this way we can have DEBUG set
148
+ Rake.application[:lexer].invoke # this way we can have DEBUG set
143
149
 
144
150
  $: << "lib"
145
- require 'ruby_parser'
146
- require 'pp'
151
+ require "ruby_parser"
152
+ require "pp"
147
153
 
148
154
  parser = case ENV["V"]
149
155
  when "18" then
@@ -169,7 +175,7 @@ task :debug => :isolate do
169
175
  pp parser.process(ruby, file, time)
170
176
  rescue Racc::ParseError => e
171
177
  p e
172
- ss = parser.lexer.src
178
+ ss = parser.lexer.ss
173
179
  src = ss.string
174
180
  lines = src[0..ss.pos].split(/\n/)
175
181
  abort "on #{file}:#{lines.size}"
@@ -9,6 +9,7 @@ $m ||= ENV["MOVE_TIMEOUT"]
9
9
  $q ||= false
10
10
  $q ||= ENV["QUIET"]
11
11
  $v ||= ENV["V"] || "20"
12
+ $s ||= ENV["SPEED"] || false
12
13
 
13
14
  require 'rubygems'
14
15
  require 'ruby_parser'
@@ -37,7 +38,7 @@ ARGV.push "-" if ARGV.empty?
37
38
 
38
39
  class Racc::Parser
39
40
  def extract_defs
40
- ss = lexer.src
41
+ ss = lexer.ss
41
42
 
42
43
  raise "can't access source. possible encoding issue" unless ss
43
44
 
@@ -113,8 +114,13 @@ def process file
113
114
 
114
115
  $stderr.print "# Validating #{file}: "
115
116
  parser = $parser_class.new
117
+ t0 = Time.now if $s
116
118
  parser.process(ruby, file, time)
117
- warn "good"
119
+ if $s then
120
+ warn "good: #{Time.now - t0}"
121
+ else
122
+ warn "good"
123
+ end
118
124
  File.unlink file if $d
119
125
  rescue Timeout::Error
120
126
  $exit = 1
data/lib/.document ADDED
@@ -0,0 +1 @@
1
+ *.rb
data/lib/ruby18_parser.rb CHANGED
@@ -4253,14 +4253,16 @@ def _reduce_246(val, _values, result)
4253
4253
  end
4254
4254
 
4255
4255
  def _reduce_247(val, _values, result)
4256
- result = s(:array, val[0]).add_all(val[2]).add(s(:hash, *val[4].values))
4257
- result = arg_blk_pass result, val[5]
4256
+ arg_value, _, args, _, assocs, opt_block = val
4257
+ result = s(:array, arg_value).add_all(args)
4258
+ result.add(s(:hash, *assocs.sexp_body))
4259
+ result = arg_blk_pass result, opt_block
4258
4260
 
4259
4261
  result
4260
4262
  end
4261
4263
 
4262
4264
  def _reduce_248(val, _values, result)
4263
- result = arg_concat s(:array, val[0]).add(s(:hash, *val[2].values)), val[5]
4265
+ result = arg_concat s(:array, val[0]).add(s(:hash, *val[2].sexp_body)), val[5]
4264
4266
  result = arg_blk_pass result, val[6]
4265
4267
 
4266
4268
  result
@@ -4558,19 +4560,22 @@ def _reduce_301(val, _values, result)
4558
4560
  end
4559
4561
 
4560
4562
  def _reduce_302(val, _values, result)
4561
- result = new_case val[1], val[3]
4563
+ (_, line), expr, _, body, _ = val
4564
+ result = new_case expr, body, line
4562
4565
 
4563
4566
  result
4564
4567
  end
4565
4568
 
4566
4569
  def _reduce_303(val, _values, result)
4567
- result = new_case nil, val[2]
4570
+ (_, line), _, body, _ = val
4571
+ result = new_case nil, body, line
4568
4572
 
4569
4573
  result
4570
4574
  end
4571
4575
 
4572
4576
  def _reduce_304(val, _values, result)
4573
- result = new_case nil, val[3]
4577
+ (_, line), _, _, elsebody, _ = val
4578
+ result = new_case nil, elsebody, line
4574
4579
 
4575
4580
  result
4576
4581
  end
@@ -5413,7 +5418,7 @@ def _reduce_447(val, _values, result)
5413
5418
  end
5414
5419
 
5415
5420
  def _reduce_448(val, _values, result)
5416
- result = s(:lit, lexer.src.current_line)
5421
+ result = s(:lit, lexer.lineno)
5417
5422
  result
5418
5423
  end
5419
5424
 
data/lib/ruby18_parser.y CHANGED
@@ -829,12 +829,14 @@ rule
829
829
  }
830
830
  | arg_value tCOMMA args tCOMMA assocs opt_block_arg
831
831
  {
832
- result = s(:array, val[0]).add_all(val[2]).add(s(:hash, *val[4].values))
833
- result = arg_blk_pass result, val[5]
832
+ arg_value, _, args, _, assocs, opt_block = val
833
+ result = s(:array, arg_value).add_all(args)
834
+ result.add(s(:hash, *assocs.sexp_body))
835
+ result = arg_blk_pass result, opt_block
834
836
  }
835
837
  | arg_value tCOMMA assocs tCOMMA tSTAR arg_value opt_block_arg
836
838
  {
837
- result = arg_concat s(:array, val[0]).add(s(:hash, *val[2].values)), val[5]
839
+ result = arg_concat s(:array, val[0]).add(s(:hash, *val[2].sexp_body)), val[5]
838
840
  result = arg_blk_pass result, val[6]
839
841
  }
840
842
  | arg_value tCOMMA args tCOMMA assocs tCOMMA tSTAR arg_value opt_block_arg
@@ -1042,15 +1044,18 @@ rule
1042
1044
  }
1043
1045
  | kCASE expr_value opt_terms case_body kEND
1044
1046
  {
1045
- result = new_case val[1], val[3]
1047
+ (_, line), expr, _, body, _ = val
1048
+ result = new_case expr, body, line
1046
1049
  }
1047
1050
  | kCASE opt_terms case_body kEND
1048
1051
  {
1049
- result = new_case nil, val[2]
1052
+ (_, line), _, body, _ = val
1053
+ result = new_case nil, body, line
1050
1054
  }
1051
1055
  | kCASE opt_terms kELSE compstmt kEND # TODO: need a test
1052
1056
  {
1053
- result = new_case nil, val[3]
1057
+ (_, line), _, _, elsebody, _ = val
1058
+ result = new_case nil, elsebody, line
1054
1059
  }
1055
1060
  | kFOR for_var kIN
1056
1061
  {
@@ -1653,7 +1658,7 @@ xstring_contents: none
1653
1658
  | kTRUE { result = s(:true) }
1654
1659
  | kFALSE { result = s(:false) }
1655
1660
  | k__FILE__ { result = s(:str, self.file) }
1656
- | k__LINE__ { result = s(:lit, lexer.src.current_line) }
1661
+ | k__LINE__ { result = s(:lit, lexer.lineno) }
1657
1662
 
1658
1663
  var_ref: variable
1659
1664
  {
data/lib/ruby19_parser.rb CHANGED
@@ -4650,13 +4650,15 @@ def _reduce_306(val, _values, result)
4650
4650
  end
4651
4651
 
4652
4652
  def _reduce_307(val, _values, result)
4653
- result = new_case val[1], val[3]
4653
+ (_, line), expr, _, body, _ = val
4654
+ result = new_case expr, body, line
4654
4655
 
4655
4656
  result
4656
4657
  end
4657
4658
 
4658
4659
  def _reduce_308(val, _values, result)
4659
- result = new_case nil, val[2]
4660
+ (_, line), _, body, _ = val
4661
+ result = new_case nil, body, line
4660
4662
 
4661
4663
  result
4662
4664
  end
@@ -5708,7 +5710,7 @@ def _reduce_489(val, _values, result)
5708
5710
  end
5709
5711
 
5710
5712
  def _reduce_490(val, _values, result)
5711
- result = s(:lit, lexer.src.current_line)
5713
+ result = s(:lit, lexer.lineno)
5712
5714
  result
5713
5715
  end
5714
5716
 
data/lib/ruby19_parser.y CHANGED
@@ -1025,11 +1025,13 @@ rule
1025
1025
  }
1026
1026
  | kCASE expr_value opt_terms case_body kEND
1027
1027
  {
1028
- result = new_case val[1], val[3]
1028
+ (_, line), expr, _, body, _ = val
1029
+ result = new_case expr, body, line
1029
1030
  }
1030
1031
  | kCASE opt_terms case_body kEND
1031
1032
  {
1032
- result = new_case nil, val[2]
1033
+ (_, line), _, body, _ = val
1034
+ result = new_case nil, body, line
1033
1035
  }
1034
1036
  | kFOR for_var kIN
1035
1037
  {
@@ -1787,7 +1789,7 @@ keyword_variable: kNIL { result = s(:nil) }
1787
1789
  | kTRUE { result = s(:true) }
1788
1790
  | kFALSE { result = s(:false) }
1789
1791
  | k__FILE__ { result = s(:str, self.file) }
1790
- | k__LINE__ { result = s(:lit, lexer.src.current_line) }
1792
+ | k__LINE__ { result = s(:lit, lexer.lineno) }
1791
1793
  | k__ENCODING__
1792
1794
  {
1793
1795
  result =