ruby_parser
Advanced tools
+13
-0
@@ -0,1 +1,14 @@ | ||
| === 3.1.0 / 2012-12-06 | ||
| * 2 minor enhancements: | ||
| * Added RubyParser.for_current_ruby to provide a parser that matches your runtime. (neilconway) | ||
| * Duck-typed IDENT_CHAR_RE instead of using RUBY_VERSION | ||
| * 3 bug fixes: | ||
| * Cleared out body comments in class/module/defn/defs | ||
| * Flipped lexer tests to US-ASCII to avoid encoding hell | ||
| * yyerror is now an alias for syntax_error | ||
| === 3.0.4 / 2012-11-26 | ||
@@ -2,0 +15,0 @@ |
@@ -7,9 +7,6 @@ # encoding: US-ASCII | ||
| IDENT_CHAR_RE = case RUBY_VERSION | ||
| when /^1\.8/ then | ||
| /[\w\x80-\xFF]/ | ||
| when /^(1\.9|2\.0)/ then # HACK - matching 2.0 for now | ||
| IDENT_CHAR_RE = if RUBY19 then | ||
| /[\w\u0080-\uFFFF]/u | ||
| else | ||
| raise "bork" | ||
| /[\w\x80-\xFF]/ | ||
| end | ||
@@ -756,3 +753,2 @@ | ||
| elsif src.scan(/\=begin(?=\s)/) then | ||
| # @comments << '=' << src.matched | ||
| @comments << src.matched | ||
@@ -759,0 +755,0 @@ |
@@ -111,3 +111,3 @@ # encoding: ASCII-8BIT | ||
| module RubyParserStuff | ||
| VERSION = '3.0.4' unless constants.include? "VERSION" # SIGH | ||
| VERSION = '3.1.0' unless constants.include? "VERSION" # SIGH | ||
@@ -1053,6 +1053,3 @@ attr_accessor :lexer, :in_def, :in_single, :file | ||
| def yyerror msg | ||
| warn msg if $DEBUG | ||
| super() | ||
| end | ||
| alias yyerror syntax_error | ||
@@ -1306,2 +1303,13 @@ def on_error(et, ev, values) | ||
| end | ||
| def self.for_current_ruby | ||
| case RUBY_VERSION | ||
| when /^1\.8/ then | ||
| Ruby18Parser.new | ||
| when /^1\.9/ then | ||
| Ruby19Parser.new | ||
| else | ||
| raise "unrecognized RUBY_VERSION #{RUBY_VERSION}" | ||
| end | ||
| end | ||
| end | ||
@@ -1308,0 +1316,0 @@ |
| #!/usr/local/bin/ruby | ||
| # encoding: US-ASCII | ||
@@ -3,0 +4,0 @@ require 'rubygems' |
+62
-32
@@ -30,2 +30,4 @@ #!/usr/local/bin/ruby | ||
| make_my_diffs_pretty! | ||
| def self.previous key | ||
@@ -884,4 +886,4 @@ "Ruby" | ||
| def test_i_fucking_hate_line_numbers | ||
| rb = <<-EOM.gsub(/^ {6}/, '') | ||
| def a | ||
| rb = <<-END.gsub(/^ {6}/, '') | ||
| if true | ||
| p 1 | ||
@@ -898,24 +900,25 @@ a.b 2 | ||
| end | ||
| EOM | ||
| END | ||
| pt = s(:defn, :a, s(:args).line(2), | ||
| s(:call, nil, :p, s(:lit, 1).line(2)).line(2), | ||
| s(:call, s(:call, nil, :a).line(3), :b, | ||
| s(:lit, 2).line(3)).line(3), | ||
| s(:call, s(:call, nil, :c).line(4), :d, | ||
| s(:lit, 3).line(4), s(:lit, 4).line(4)).line(4), | ||
| s(:call, s(:call, nil, :e).line(5), :f, | ||
| s(:lit, 5).line(5)).line(5), | ||
| s(:call, s(:call, nil, :g).line(6), :h, | ||
| s(:lit, 6).line(6), s(:lit, 7).line(6)).line(6), | ||
| s(:call, nil, :p, s(:lit, 1).line(7)).line(7), | ||
| s(:call, s(:call, nil, :a).line(8), :b, | ||
| s(:lit, 2).line(8)).line(8), | ||
| s(:call, s(:call, nil, :c).line(9), :d, | ||
| s(:lit, 3).line(9), s(:lit, 4).line(9)).line(9), | ||
| s(:call, s(:call, nil, :e).line(10), :f, | ||
| s(:lit, 5).line(10)).line(10), | ||
| s(:call, s(:call, nil, :g).line(11), :h, | ||
| s(:lit, 6).line(11), s(:lit, 7).line(11)).line(11) | ||
| ).line(1) | ||
| pt = s(:if, s(:true).line(1), | ||
| s(:block, | ||
| s(:call, nil, :p, s(:lit, 1).line(2)).line(2), | ||
| s(:call, s(:call, nil, :a).line(3), :b, | ||
| s(:lit, 2).line(3)).line(3), | ||
| s(:call, s(:call, nil, :c).line(4), :d, | ||
| s(:lit, 3).line(4), s(:lit, 4).line(4)).line(4), | ||
| s(:call, s(:call, nil, :e).line(5), :f, | ||
| s(:lit, 5).line(5)).line(5), | ||
| s(:call, s(:call, nil, :g).line(6), :h, | ||
| s(:lit, 6).line(6), s(:lit, 7).line(6)).line(6), | ||
| s(:call, nil, :p, s(:lit, 1).line(7)).line(7), | ||
| s(:call, s(:call, nil, :a).line(8), :b, | ||
| s(:lit, 2).line(8)).line(8), | ||
| s(:call, s(:call, nil, :c).line(9), :d, | ||
| s(:lit, 3).line(9), s(:lit, 4).line(9)).line(9), | ||
| s(:call, s(:call, nil, :e).line(10), :f, | ||
| s(:lit, 5).line(10)).line(10), | ||
| s(:call, s(:call, nil, :g).line(11), :h, | ||
| s(:lit, 6).line(11), s(:lit, 7).line(11)).line(11)).line(2), | ||
| nil).line(1) | ||
@@ -927,7 +930,7 @@ assert_parse rb, pt | ||
| rb = <<-EOM.gsub(/^ {6}/, '') | ||
| def a | ||
| p('a') | ||
| b = 1 | ||
| p b | ||
| c =1 | ||
| if true then | ||
| p('a') | ||
| b = 1 | ||
| p b | ||
| c =1 | ||
| end | ||
@@ -937,12 +940,39 @@ a | ||
| pt = s(:block, | ||
| s(:defn, :a, s(:args).line(2), | ||
| pt = s(:block, | ||
| s(:if, s(:true).line(1), | ||
| s(:block, | ||
| s(:call, nil, :p, s(:str, "a").line(2)).line(2), | ||
| s(:lasgn, :b, s(:lit, 1).line(3)).line(3), | ||
| s(:call, nil, :p, s(:lvar, :b).line(4)).line(4), | ||
| s(:lasgn, :c, s(:lit, 1).line(5)).line(5)).line(1), | ||
| s(:call, nil, :a).line(7)).line(1) | ||
| s(:lasgn, :c, s(:lit, 1).line(5)).line(5)).line(2), # TODO line 2? | ||
| nil).line(1), | ||
| s(:call, nil, :a).line(7)).line(1) | ||
| assert_parse rb, pt | ||
| end | ||
| def test_parse_comments | ||
| p = RubyParser.new | ||
| sexp = p.parse <<-CODE | ||
| # class comment | ||
| class Inline | ||
| def show | ||
| # woot | ||
| end | ||
| # Returns a list of things | ||
| def list | ||
| # woot | ||
| end | ||
| end | ||
| CODE | ||
| assert_equal "# class comment\n", sexp.comments | ||
| act = sexp.find_nodes(:defn).map(&:comments) | ||
| exp = ["", "# Returns a list of things\n"] | ||
| assert_equal exp, act | ||
| assert_equal [], processor.comments | ||
| assert_equal "", processor.lexer.comments | ||
| end | ||
| end | ||
@@ -949,0 +979,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet