ruby_parser 3.0.0.a10 → 3.0.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.

Potentially problematic release.


This version of ruby_parser might be problematic. Click here for more details.

data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- �%���Ed�=�b�|��7�R46�ʼn�3w9��Cw�=�O��
1
+ FȔCd�qyC0m� cScI�=�� 
data/History.txt CHANGED
@@ -1,3 +1,23 @@
1
+ === 3.0.0 / 2012-11-02
2
+
3
+ I've hit 99.967% success rate against 558k files! 3.6σ!! 182 files
4
+ failed to parse and spot checking them shows that they're pretty much
5
+ lost causes. I'm sure I missed some stuff, but it is more important at
6
+ this point to release a version to get more people using it in more
7
+ diverse ways than I can come up with.
8
+
9
+ * 3 minor enhancements:
10
+
11
+ * Added RBStringScanner#charpos using #string_to_pos.
12
+ * Added RBStringScanner#string_to_pos using String#byteslice.
13
+ * Optimized regexp used for escape chars in strings. (presidentbeef)
14
+
15
+ * 3 bug fixes:
16
+
17
+ * Fixed current_line and unread_many depending on StringScanner#pos
18
+ * Fixed parsing of 'a[] = b'
19
+ * Fixed the worst abuse of heredocs EVER. Just because it is valid doesn't mean you should.
20
+
1
21
  === 3.0.0.a10 / 2012-10-26
2
22
 
3
23
  * 1 major enhancement:
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ Hoe.spec 'ruby_parser' do
14
14
 
15
15
  self.rubyforge_name = 'parsetree'
16
16
 
17
- dependency 'sexp_processor', '~> 4.0'
17
+ dependency 'sexp_processor', '~> 4.1'
18
18
 
19
19
  if plugin? :perforce then
20
20
  self.perforce_ignore << "lib/ruby18_parser.rb"
data/lib/ruby_lexer.rb CHANGED
@@ -21,7 +21,7 @@ class RubyLexer
21
21
  attr_accessor :tern # TODO: rename ternary damnit... wtf
22
22
  attr_accessor :nest
23
23
 
24
- ESC_RE = /\\([0-7]{1,3}|x[0-9a-fA-F]{1,2}|M-[^\\]|(C-|c)[^\\]|[^0-7xMCc])/
24
+ ESC_RE = /\\((?>[0-7]{1,3}|x[0-9a-fA-F]{1,2}|M-[^\\]|(C-|c)[^\\]|[^0-7xMCc]))/
25
25
 
26
26
  ##
27
27
  # What version of ruby to parse. 18 and 19 are the only valid values
@@ -156,7 +156,7 @@ class RubyLexer
156
156
  string_buffer << '#'
157
157
  end
158
158
 
159
- until src.check(eos_re) do
159
+ begin
160
160
  c = tokadd_string func, "\n", nil
161
161
 
162
162
  rb_compile_error err_msg if
@@ -171,7 +171,7 @@ class RubyLexer
171
171
 
172
172
  rb_compile_error err_msg if
173
173
  src.eos?
174
- end
174
+ end until src.check(eos_re)
175
175
  else
176
176
  until src.check(eos_re) do
177
177
  string_buffer << src.scan(/.*(\n|\z)/)
@@ -193,9 +193,7 @@ class RubyLexer
193
193
  case
194
194
  when src.scan(/(-?)(['"`])(.*?)\2/) then
195
195
  term = src[2]
196
- unless src[1].empty? then
197
- func |= STR_FUNC_INDENT
198
- end
196
+ func |= STR_FUNC_INDENT unless src[1].empty?
199
197
  func |= case term
200
198
  when "\'" then
201
199
  STR_SQUOTE
@@ -989,9 +987,7 @@ class RubyLexer
989
987
  :expr_endarg, :expr_class) &&
990
988
  (!is_arg? || space_seen)) then
991
989
  tok = self.heredoc_identifier
992
- if tok then
993
- return tok
994
- end
990
+ return tok if tok
995
991
  end
996
992
 
997
993
  self.fix_arg_lex_state
@@ -34,8 +34,25 @@ class RPStringScanner < StringScanner
34
34
  # old_getch
35
35
  # end
36
36
  # end
37
+
38
+ if "".respond_to? :encoding then
39
+ def string_to_pos
40
+ string.byteslice(0, pos)
41
+ end
42
+
43
+ def charpos
44
+ string_to_pos.length
45
+ end
46
+ else
47
+ alias :charpos :pos
48
+
49
+ def string_to_pos
50
+ string[0..pos]
51
+ end
52
+ end
53
+
37
54
  def current_line # HAHA fuck you (HACK)
38
- string[0..pos][/\A.*__LINE__/m].split(/\n/).size
55
+ string_to_pos[/\A.*__LINE__/m].split(/\n/).size
39
56
  end
40
57
 
41
58
  def extra_lines_added
@@ -57,7 +74,7 @@ class RPStringScanner < StringScanner
57
74
  warn({:unread_many => caller[0]}.inspect) if ENV['TALLY']
58
75
  self.extra_lines_added += str.count("\n")
59
76
  begin
60
- string[pos, 0] = str
77
+ string[charpos, 0] = str
61
78
  rescue IndexError
62
79
  # HACK -- this is a bandaid on a dirty rag on an open festering wound
63
80
  end
@@ -85,7 +102,7 @@ class RPStringScanner < StringScanner
85
102
  end
86
103
 
87
104
  module RubyParserStuff
88
- VERSION = '3.0.0.a10' unless constants.include? "VERSION" # SIGH
105
+ VERSION = '3.0.0' unless constants.include? "VERSION" # SIGH
89
106
 
90
107
  attr_accessor :lexer, :in_def, :in_single, :file
91
108
  attr_reader :env, :comments
@@ -186,6 +203,7 @@ module RubyParserStuff
186
203
  end
187
204
 
188
205
  def aryset receiver, index
206
+ index ||= []
189
207
  s(:attrasgn, receiver, :"[]=", *index[1..-1])
190
208
  end
191
209
 
@@ -890,17 +908,7 @@ module RubyParserStuff
890
908
  end
891
909
  else
892
910
  # nothing specified... ugh. try to encode as utf-8
893
- if ruby19 then
894
- begin
895
- str.encode! "utf-8"
896
- rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError
897
- # OK... You really suck. You have extended chars but didn't
898
- # specify what they were. Now we try to force it and double
899
- # check that it is valid.
900
-
901
- hack_encoding str
902
- end
903
- end
911
+ hack_encoding str if ruby19
904
912
  end
905
913
 
906
914
  str
@@ -642,6 +642,15 @@ class TestRubyLexer < MiniTest::Unit::TestCase
642
642
  :tNL, nil)
643
643
  end
644
644
 
645
+ def test_yylex_heredoc_empty
646
+ util_lex_token("<<\"\"\n\#{x}\nblah2\n\n",
647
+ :tSTRING_BEG, "\"",
648
+ :tSTRING_DBEG, "\#{",
649
+ :tSTRING_CONTENT, "x}\nblah2\n",
650
+ :tSTRING_END, "",
651
+ :tNL, nil)
652
+ end
653
+
645
654
  def test_yylex_heredoc_none
646
655
  util_lex_token("a = <<EOF\nblah\nblah\nEOF",
647
656
  :tIDENTIFIER, "a",
@@ -872,6 +872,13 @@ module TestRubyParserShared
872
872
 
873
873
  assert_parse rb, pt
874
874
  end
875
+
876
+ def test_str_heredoc_interp
877
+ rb = "<<\"\"\n\#{x}\nblah2\n\n"
878
+ pt = s(:dstr, "", s(:evstr, s(:call, nil, :x)), s(:str, "\nblah2\n"))
879
+
880
+ assert_parse rb, pt
881
+ end
875
882
  end
876
883
 
877
884
  class TestRubyParser < MiniTest::Unit::TestCase
@@ -1642,4 +1649,11 @@ class TestRuby19Parser < RubyParserTestCase
1642
1649
 
1643
1650
  assert_parse rb, pt
1644
1651
  end
1652
+
1653
+ def test_index_0
1654
+ rb = "a[] = b"
1655
+ pt = s(:attrasgn, s(:call, nil, :a), :[]=, s(:call, nil, :b))
1656
+
1657
+ assert_parse rb, pt
1658
+ end
1645
1659
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 614431433
5
- prerelease: 6
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
9
  - 0
10
- - a
11
- - 10
12
- version: 3.0.0.a10
10
+ version: 3.0.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Ryan Davis
@@ -38,7 +36,7 @@ cert_chain:
38
36
  FBHgymkyj/AOSqKRIpXPhjC6
39
37
  -----END CERTIFICATE-----
40
38
 
41
- date: 2012-10-26 00:00:00 Z
39
+ date: 2012-11-02 00:00:00 Z
42
40
  dependencies:
43
41
  - !ruby/object:Gem::Dependency
44
42
  name: sexp_processor
@@ -48,11 +46,11 @@ dependencies:
48
46
  requirements:
49
47
  - - ~>
50
48
  - !ruby/object:Gem::Version
51
- hash: 27
49
+ hash: 25
52
50
  segments:
53
51
  - 4
54
- - 0
55
- version: "4.0"
52
+ - 1
53
+ version: "4.1"
56
54
  type: :runtime
57
55
  version_requirements: *id001
58
56
  - !ruby/object:Gem::Dependency
@@ -189,14 +187,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
187
  required_rubygems_version: !ruby/object:Gem::Requirement
190
188
  none: false
191
189
  requirements:
192
- - - ">"
190
+ - - ">="
193
191
  - !ruby/object:Gem::Version
194
- hash: 25
192
+ hash: 3
195
193
  segments:
196
- - 1
197
- - 3
198
- - 1
199
- version: 1.3.1
194
+ - 0
195
+ version: "0"
200
196
  requirements: []
201
197
 
202
198
  rubyforge_project: parsetree
metadata.gz.sig CHANGED
Binary file