From d9a4221a0a9e4c0434367fb717b5fcb6afd9f18b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sun, 12 Oct 2014 18:08:35 +0200 Subject: [PATCH] Remove :axis CSS node types. The various axes are now simply their own node types. --- lib/oga/css/parser.y | 12 +++------- spec/oga/css/parser/axes_spec.rb | 38 ++++++++++++-------------------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index 2eb99a2..5379d15 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -103,21 +103,15 @@ rule axis # x > y - : path_member T_CHILD path_member - { - s(:axis, 'child', val[0], val[2]) - } + : path_member T_CHILD path_member { s(:child, val[0], val[2]) } # x + y - | path_member T_FOLLOWING path_member - { - s(:axis, 'following', val[0], val[2]) - } + | path_member T_FOLLOWING path_member { s(:following, val[0], val[2]) } # x ~ y | path_member T_FOLLOWING_DIRECT path_member { - s(:axis, 'following-direct', val[0], val[2]) + s(:following_direct, val[0], val[2]) } ; diff --git a/spec/oga/css/parser/axes_spec.rb b/spec/oga/css/parser/axes_spec.rb index 665f4c8..e402d0a 100644 --- a/spec/oga/css/parser/axes_spec.rb +++ b/spec/oga/css/parser/axes_spec.rb @@ -4,8 +4,7 @@ describe Oga::CSS::Parser do context 'axes' do example 'parse the > axis' do parse_css('x > y').should == s( - :axis, - 'child', + :child, s(:test, nil, 'x'), s(:test, nil, 'y') ) @@ -13,17 +12,15 @@ describe Oga::CSS::Parser do example 'parse the > axis called on another > axis' do parse_css('a > b > c').should == s( - :axis, - 'child', - s(:axis, 'child', s(:test, nil, 'a'), s(:test, nil, 'b')), + :child, + s(:child, s(:test, nil, 'a'), s(:test, nil, 'b')), s(:test, nil, 'c') ) end example 'parse an > axis followed by an element with an ID' do parse_css('x > foo#bar').should == s( - :axis, - 'child', + :child, s(:test, nil, 'x'), s(:id, 'bar', s(:test, nil, 'foo')) ) @@ -31,8 +28,7 @@ describe Oga::CSS::Parser do example 'parse an > axis followed by an element with a class' do parse_css('x > foo.bar').should == s( - :axis, - 'child', + :child, s(:test, nil, 'x'), s(:class, 'bar', s(:test, nil, 'foo')) ) @@ -40,8 +36,7 @@ describe Oga::CSS::Parser do example 'parse the + axis' do parse_css('x + y').should == s( - :axis, - 'following-direct', + :following_direct, s(:test, nil, 'x'), s(:test, nil, 'y') ) @@ -49,17 +44,15 @@ describe Oga::CSS::Parser do example 'parse the + axis called on another + axis' do parse_css('a + b + c').should == s( - :axis, - 'following-direct', - s(:axis, 'following-direct', s(:test, nil, 'a'), s(:test, nil, 'b')), + :following_direct, + s(:following_direct, s(:test, nil, 'a'), s(:test, nil, 'b')), s(:test, nil, 'c') ) end example 'parse the ~ axis' do parse_css('x ~ y').should == s( - :axis, - 'following', + :following, s(:test, nil, 'x'), s(:test, nil, 'y') ) @@ -68,24 +61,22 @@ describe Oga::CSS::Parser do example 'parse the ~ axis followed by another node test' do parse_css('x ~ y z').should == s( :path, - s(:axis, 'following', s(:test, nil, 'x'), s(:test, nil, 'y')), + s(:following, s(:test, nil, 'x'), s(:test, nil, 'y')), s(:test, nil, 'z') ) end example 'parse the ~ axis called on another ~ axis' do parse_css('a ~ b ~ c').should == s( - :axis, - 'following', - s(:axis, 'following', s(:test, nil, 'a'), s(:test, nil, 'b')), + :following, + s(:following, s(:test, nil, 'a'), s(:test, nil, 'b')), s(:test, nil, 'c') ) end example 'parse a pseudo class followed by the ~ axis' do parse_css('x:root ~ a').should == s( - :axis, - 'following', + :following, s(:pseudo, 'root', s(:test, nil, 'x')), s(:test, nil, 'a') ) @@ -93,8 +84,7 @@ describe Oga::CSS::Parser do example 'parse the ~ axis followed by a pseudo class' do parse_css('a ~ x:root').should == s( - :axis, - 'following', + :following, s(:test, nil, 'a'), s(:pseudo, 'root', s(:test, nil, 'x')) )