ruby_parser
Advanced tools
+10
-0
@@ -0,1 +1,11 @@ | ||
| === 3.0.0.a5 / 2012-07-31 | ||
| * 5 bug fixes: | ||
| * 1.9: Fix construction of 'f(:x, y: nil,)' w/ trailing comma. | ||
| * 1.9: cleaned up lexing exit lex_state handling. Fixes bug parsing 'if f :x; end' | ||
| * 1.9: fixed building of right-leaning masgns: 'f { |a, (b, c)| }' | ||
| * 1.9: fixed lexing 'when *splat' | ||
| * 1.9: fixed lexing of regexps in whens | ||
| === 3.0.0.a4 / 2012-07-26 | ||
@@ -2,0 +12,0 @@ |
+22
-15
@@ -242,3 +242,3 @@ class RubyLexer | ||
| def lex_state= o | ||
| # warn "wtf lex_state = #{o.inspect}" | ||
| # warn "wtf lex_state = #{o.inspect} from #{caller.first}" | ||
| raise "wtf\?" unless Symbol === o | ||
@@ -489,2 +489,6 @@ @lex_state = o | ||
| def ruby19 | ||
| Ruby19Parser === parser | ||
| end | ||
| def src= src | ||
@@ -774,3 +778,4 @@ raise "bad src: #{src.inspect}" unless String === src | ||
| return :tCOLON2 | ||
| elsif lex_state != :expr_end && lex_state != :expr_endarg && src.scan(/:([a-zA-Z_]\w*(?:[?!]|=(?!>))?)/) then | ||
| elsif ! is_end? && src.scan(/:([a-zA-Z_]\w*(?:[?!]|=(?!>))?)/) then | ||
| # scanning shortcut to symbols | ||
| self.yacc_value = src[1] | ||
@@ -781,5 +786,5 @@ self.lex_state = :expr_end | ||
| # ?: / then / when | ||
| if (lex_state == :expr_end || lex_state == :expr_endarg|| | ||
| src.check(/\s/)) then | ||
| if is_end? || src.check(/\s/) then | ||
| self.lex_state = :expr_beg | ||
| # TODO warn_balanced(":", "symbol literal"); | ||
| self.yacc_value = ":" | ||
@@ -940,3 +945,3 @@ return :tCOLON | ||
| :tSTAR | ||
| elsif lex_state == :expr_beg || lex_state == :expr_mid then | ||
| elsif is_beg? then | ||
| :tSTAR | ||
@@ -1099,3 +1104,3 @@ else | ||
| elsif src.scan(/\//) then | ||
| if lex_state == :expr_beg || lex_state == :expr_mid then | ||
| if is_beg? then | ||
| self.lex_strterm = [:strterm, STR_REGEXP, '/', "\0"] | ||
@@ -1403,13 +1408,15 @@ self.yacc_value = "/" | ||
| if (lex_state == :expr_beg || lex_state == :expr_mid || | ||
| lex_state == :expr_dot || lex_state == :expr_arg || | ||
| lex_state == :expr_cmdarg) then | ||
| if command_state then | ||
| self.lex_state = :expr_cmdarg | ||
| self.lex_state = | ||
| if is_beg? || lex_state == :expr_dot || is_arg? then | ||
| if command_state then | ||
| :expr_cmdarg | ||
| else | ||
| :expr_arg | ||
| end | ||
| elsif ruby19 && lex_state == :expr_fname then | ||
| :expr_endfn | ||
| else | ||
| self.lex_state = :expr_arg | ||
| :expr_end | ||
| end | ||
| else | ||
| self.lex_state = :expr_end | ||
| end | ||
| end | ||
@@ -1416,0 +1423,0 @@ |
@@ -81,3 +81,3 @@ require 'stringio' | ||
| module RubyParserStuff | ||
| VERSION = '3.0.0.a4' unless constants.include? "VERSION" # SIGH | ||
| VERSION = '3.0.0.a5' unless constants.include? "VERSION" # SIGH | ||
@@ -205,3 +205,12 @@ attr_accessor :lexer, :in_def, :in_single, :file | ||
| when :args then | ||
| r.concat v[1..-1].map { |s| s(:lasgn, s) } | ||
| r.concat v[1..-1].map { |s| # FIX: this is a smell | ||
| case s | ||
| when Symbol then | ||
| s(:lasgn, s) | ||
| when Sexp then | ||
| s | ||
| else | ||
| raise "unhandled type: #{s.inspect}" | ||
| end | ||
| } | ||
| when :block_arg then | ||
@@ -1226,2 +1235,3 @@ r << s(:lasgn, :"&#{v.last}") | ||
| def to_sym | ||
| raise "no" | ||
| self.value.to_sym | ||
@@ -1228,0 +1238,0 @@ end |
+91
-13
@@ -649,5 +649,20 @@ #!/usr/local/bin/ruby | ||
| def test_bug_args_masgn | ||
| # according to 2.3.1 parser: | ||
| # rp.process("f { |(a,b),c| }") == rp.process("f { |((a,b),c)| }") | ||
| # def test_bug_args_masgn | ||
| # rb = "f { |(a, b), c| }" | ||
| # pt = s(:iter, | ||
| # s(:call, nil, :f), | ||
| # s(:masgn, | ||
| # s(:array, | ||
| # s(:masgn, s(:array, s(:lasgn, :a), s(:lasgn, :b))), | ||
| # s(:lasgn, :c)))) | ||
| # | ||
| # assert_parse rb, pt.dup | ||
| # end | ||
| def test_bug_args_masgn_outer_parens | ||
| rb = "f { |((a, b), c)| }" | ||
| pt = s(:iter, | ||
| pt = s(:iter, # NOTE: same sexp as test_bug_args_masgn | ||
| s(:call, nil, :f), | ||
@@ -659,3 +674,3 @@ s(:masgn, | ||
| assert_parse rb, pt | ||
| assert_parse rb, pt.dup | ||
| end | ||
@@ -680,12 +695,57 @@ | ||
| # TODO: | ||
| # def test_bug_comma | ||
| # rb = "if test ?d, dir then end" | ||
| # pt = s(:if, | ||
| # s(:call, nil, :test, s(:lit, 100), s(:call, nil, :dir)), | ||
| # nil, | ||
| # nil) | ||
| # | ||
| # assert_parse rb, pt | ||
| # end | ||
| def test_bug_comma | ||
| val = case self.processor | ||
| when Ruby18Parser then | ||
| s(:lit, 100) | ||
| when Ruby19Parser then | ||
| s(:str, "d") | ||
| else | ||
| raise "wtf" | ||
| end | ||
| rb = "if test ?d, dir then end" | ||
| pt = s(:if, | ||
| s(:call, nil, :test, val, s(:call, nil, :dir)), | ||
| nil, | ||
| nil) | ||
| assert_parse rb, pt | ||
| end | ||
| def test_bug_case_when_regexp | ||
| rb = "case :x; when /x/ then end" | ||
| pt = s(:case, s(:lit, :x), | ||
| s(:when, s(:array, s(:lit, /x/)), nil), | ||
| nil) | ||
| assert_parse rb, pt | ||
| end | ||
| def test_bug_masgn_right | ||
| rb = "f { |a, (b, c)| }" | ||
| pt = s(:iter, | ||
| s(:call, nil, :f), | ||
| s(:masgn, | ||
| s(:array, | ||
| s(:lasgn, :a), | ||
| s(:masgn, s(:array, s(:lasgn, :b), s(:lasgn, :c)))))) | ||
| assert_parse rb, pt | ||
| end | ||
| def test_when_splat | ||
| rb = "case a; when *b then; end" | ||
| pt = s(:case, s(:call, nil, :a), | ||
| s(:when, s(:array, s(:splat, s(:call, nil, :b))), nil), | ||
| nil) | ||
| assert_parse rb, pt | ||
| end | ||
| def test_if_symbol | ||
| rb = "if f :x; end" | ||
| pt = s(:if, s(:call, nil, :f, s(:lit, :x)), nil, nil) | ||
| assert_parse rb, pt | ||
| end | ||
| end | ||
@@ -1040,2 +1100,20 @@ | ||
| def test_bug_hash_args | ||
| rb = "foo(:bar, baz: nil)" | ||
| pt = s(:call, nil, :foo, | ||
| s(:lit, :bar), | ||
| s(:hash, s(:lit, :baz), s(:nil))) | ||
| assert_parse rb, pt | ||
| end | ||
| def test_bug_hash_args_trailing_comma | ||
| rb = "foo(:bar, baz: nil,)" | ||
| pt = s(:call, nil, :foo, # NOTE: same sexp as test_bug_hash_args | ||
| s(:lit, :bar), | ||
| s(:hash, s(:lit, :baz), s(:nil))) | ||
| assert_parse rb, pt | ||
| end | ||
| # HACK: need to figure out the desired structure and get this working | ||
@@ -1042,0 +1120,0 @@ # def test_wtf |
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