Rename CSS "node operators" to "axes".

This commit is contained in:
Yorick Peterse 2014-10-05 23:33:46 +02:00
parent 197cb052be
commit 50ee66419e
3 changed files with 59 additions and 31 deletions

View File

@ -14,11 +14,12 @@ rule
expression
: path
| node_test
| node_operators
| axis
;
path_member
: node_test
| axis
;
path_members
@ -51,8 +52,8 @@ rule
;
predicate_members
: node_test { val[0] }
| operator { val[0] }
: node_test
| operator
;
operator
@ -64,12 +65,23 @@ rule
| op_members T_HYPHEN_IN op_members { s(:hyphen_in, val[0],val[2]) }
;
node_operators
: node_test T_CHILD node_test { s(:child, val[0], val[2]) }
| node_test T_FOLLOWING node_test { s(:following, val[0], val[2]) }
axis
# x > y
: node_test T_CHILD node_test
{
s(:axis, 'child', val[0], val[2])
}
# x + y
| node_test T_FOLLOWING node_test
{
s(:axis, 'following', val[0], val[2])
}
# x ~ y
| node_test T_FOLLOWING_DIRECT node_test
{
s(:following_direct, val[0], val[2])
s(:axis, 'following-direct', val[0], val[2])
}
;

View File

@ -0,0 +1,40 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'axes' do
example 'parse the > axis' do
parse_css('x > y').should == s(
:axis,
'child',
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
example 'parse the + axis' do
parse_css('x + y').should == s(
:axis,
'following-direct',
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
example 'parse the ~ axis' do
parse_css('x ~ y').should == s(
:axis,
'following',
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
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(:test, nil, 'z')
)
end
end
end

View File

@ -55,29 +55,5 @@ describe Oga::CSS::Parser do
s(:hyphen_in, s(:test, nil, 'a'), s(:string, 'b'))
)
end
example 'parse the > operator' do
parse_css('x > y').should == s(
:child,
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
example 'parse the + operator' do
parse_css('x + y').should == s(
:following_direct,
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
example 'parse the ~ operator' do
parse_css('x ~ y').should == s(
:following,
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
end
end