Support for parsing CSS class/ID selectors.
This commit is contained in:
parent
6792127600
commit
a6b0bd96c8
|
@ -6,13 +6,14 @@ class Oga::CSS::Parser
|
||||||
token T_IDENT T_PIPE T_LBRACK T_RBRACK T_COLON T_SPACE T_LPAREN T_RPAREN T_MINUS
|
token T_IDENT T_PIPE T_LBRACK T_RBRACK T_COLON T_SPACE T_LPAREN T_RPAREN T_MINUS
|
||||||
token T_EQ T_SPACE_IN T_STARTS_WITH T_ENDS_WITH T_IN T_HYPHEN_IN
|
token T_EQ T_SPACE_IN T_STARTS_WITH T_ENDS_WITH T_IN T_HYPHEN_IN
|
||||||
token T_CHILD T_FOLLOWING T_FOLLOWING_DIRECT
|
token T_CHILD T_FOLLOWING T_FOLLOWING_DIRECT
|
||||||
token T_NTH T_INT T_STRING T_ODD T_EVEN
|
token T_NTH T_INT T_STRING T_ODD T_EVEN T_DOT T_HASH
|
||||||
|
|
||||||
options no_result_var
|
options no_result_var
|
||||||
|
|
||||||
prechigh
|
prechigh
|
||||||
left T_COLON
|
left T_COLON
|
||||||
left T_CHILD T_FOLLOWING T_FOLLOWING_DIRECT
|
left T_CHILD T_FOLLOWING T_FOLLOWING_DIRECT
|
||||||
|
left T_DOT T_HASH
|
||||||
preclow
|
preclow
|
||||||
|
|
||||||
rule
|
rule
|
||||||
|
@ -39,6 +40,8 @@ rule
|
||||||
: node_test
|
: node_test
|
||||||
| axis
|
| axis
|
||||||
| pseudo_class
|
| pseudo_class
|
||||||
|
| class
|
||||||
|
| id
|
||||||
;
|
;
|
||||||
|
|
||||||
node_test
|
node_test
|
||||||
|
@ -66,6 +69,24 @@ rule
|
||||||
| operator
|
| operator
|
||||||
;
|
;
|
||||||
|
|
||||||
|
class
|
||||||
|
: class_name { s(:class, val[0]) }
|
||||||
|
| path_member class_name { s(:class, val[1], val[0]) }
|
||||||
|
;
|
||||||
|
|
||||||
|
class_name
|
||||||
|
: T_DOT T_IDENT { val[1] }
|
||||||
|
;
|
||||||
|
|
||||||
|
id
|
||||||
|
: id_name { s(:id, val[0]) }
|
||||||
|
| path_member id_name { s(:id, val[1], val[0]) }
|
||||||
|
;
|
||||||
|
|
||||||
|
id_name
|
||||||
|
: T_HASH T_IDENT { val[1] }
|
||||||
|
;
|
||||||
|
|
||||||
operator
|
operator
|
||||||
: op_members T_EQ op_members { s(:eq, val[0], val[2]) }
|
: op_members T_EQ op_members { s(:eq, val[0], val[2]) }
|
||||||
| op_members T_SPACE_IN op_members { s(:space_in, val[0], val[2]) }
|
| op_members T_SPACE_IN op_members { s(:space_in, val[0], val[2]) }
|
||||||
|
|
|
@ -17,5 +17,17 @@ describe Oga::CSS::Parser do
|
||||||
example 'parse a selector using a class and an ID' do
|
example 'parse a selector using a class and an ID' do
|
||||||
parse_css('#foo.bar').should == s(:class, 'bar', s(:id, 'foo'))
|
parse_css('#foo.bar').should == s(:class, 'bar', s(:id, 'foo'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
example 'parse a selector using a class and a pseudo class' do
|
||||||
|
parse_css('.foo:root').should == s(:pseudo, 'root', s(:class, 'foo'))
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'parse a selector using a pseudo class and a class' do
|
||||||
|
parse_css('x:root.foo').should == s(
|
||||||
|
:class,
|
||||||
|
'foo',
|
||||||
|
s(:pseudo, 'root', s(:test, nil, 'x'))
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,5 +13,17 @@ describe Oga::CSS::Parser do
|
||||||
example 'parse a selector using an ID and a class' do
|
example 'parse a selector using an ID and a class' do
|
||||||
parse_css('.foo#bar').should == s(:id, 'bar', s(:class, 'foo'))
|
parse_css('.foo#bar').should == s(:id, 'bar', s(:class, 'foo'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
example 'parse a selector using an ID and a pseudo class' do
|
||||||
|
parse_css('#foo:root').should == s(:pseudo, 'root', s(:id, 'foo'))
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'parse a selector using a pseudo class and an ID' do
|
||||||
|
parse_css('x:root#foo').should == s(
|
||||||
|
:id,
|
||||||
|
'foo',
|
||||||
|
s(:pseudo, 'root', s(:test, nil, 'x'))
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue