tests/unit/packrat/test_interpreting_parser.rb in rockit-0.7.1 vs tests/unit/packrat/test_interpreting_parser.rb in rockit-0.7.2

- old
+ new

@@ -38,14 +38,14 @@ end def test_03_grammar_with_single_rule_with_multi_prods g = Packrat::Grammar.new do start_symbol :s - rule :s, [ - [/a+/, /b+/, /dc*/], - [/a+/, /d+/] - ] + rule(:s, + [/a+/, /b+/, /dc*/], + [/a+/, /d+/] + ) end ip = g.interpreting_parser res1 = ip.parse_string("aaabdcc") assert_equal([:s, "aaa", "b", "dcc"], res1) @@ -58,14 +58,14 @@ end def test_04_grammar_with_single_rule_and_ref_to_one_external_prod g = Packrat::Grammar.new do start_symbol :s - rule :s, [ - [:a, /b+/, /dc*/], - [:a, /d+/] - ] + rule( :s, + [:a, /b+/, /dc*/], + [:a, /d+/] + ) prod :a, [/a+/] end ip = g.interpreting_parser res1 = ip.parse_string("aaabdcc") @@ -79,17 +79,17 @@ end def test_05_grammar_with_multi_rules g = Packrat::Grammar.new do start_symbol :Constant - rule :Constant, [ - [:DecimalInt], - [:HexInt], - [:OctalInt], - ] - rule :DecimalInt, [[/[1-9][0-9]*[uUlL]?/]] - rule :HexInt, [[/(0x|0X)[0-9a-fA-F]+[uUlL]?/]] + rule( :Constant, + [:DecimalInt], + [:HexInt], + [:OctalInt] + ) + rule :DecimalInt, [/[1-9][0-9]*[uUlL]?/] + rule :HexInt, [/(0x|0X)[0-9a-fA-F]+[uUlL]?/] prod :OctalInt, [/0[0-7]*[uUlL]?/] end ip = g.interpreting_parser res1 = ip.parse_string("123L") @@ -250,47 +250,7 @@ r = ip.parse_string("5*6") assert_equal([:s, "5", "*", "6"], r) r = ip.parse_string("7/18") assert_equal([:s, "7", "/", "18"], r) - end - - def test_14_ast - g = Packrat::Grammar.new do - start_symbol :s - rule :s, [ - [:Num, lift(0)], - [:Id, lift(0)], - ] - prod :Num, [/\d+/, ast(:Num)] - prod :Id, ["ID", :Num, maybe("?"), ast(:Id)] - end - ip = g.interpreting_parser - - mAst = g::ASTs - assert_kind_of(Module, mAst) - - r = ip.parse_string("1") - - # The AST classes are added during the parse so now we can see - # that they are there. - assert_kind_of(Class, mAst.const_get("Num")) - assert(mAst::Num.ancestors.include?(Packrat::AST)) - - as = mAst::Num[] - assert_kind_of(mAst::Num, as) - - assert_kind_of(Packrat::AST, r) - assert_equal('Num["1"]', r.inspect) - assert_equal("1", r[0]) - - r = ip.parse_string("ID10") - assert_kind_of(Class, mAst.const_get("Id")) - assert(mAst::Id.ancestors.include?(Packrat::AST)) - assert_kind_of(Packrat::AST, r) - assert_equal('Id["ID", Num["10"], nil]', r.inspect) - assert_equal("ID", r[0]) - assert_equal("10", r[1][0]) - assert_equal(nil, r[2]) - assert_equal("10", r.num[0]) end end