Wrap predicate nodes around others in CSS ASTs.

This commit is contained in:
Yorick Peterse 2014-11-13 00:47:26 +01:00
parent 97a9a11db1
commit b0f6409d1e
1 changed files with 28 additions and 30 deletions

View File

@ -40,8 +40,23 @@ rule
; ;
selector selector
: descendant_or_self # .foo, :bar, etc
: predicates
{
s(:predicate, s(:axis, 'descendant', s(:test, nil, '*')), val[0])
}
# foo
| descendant_or_self
# foo.bar
| descendant_or_self predicates { s(:predicate, val[0], val[1]) }
# > foo
| axis | axis
# > foo.bar
| axis predicates { s(:predicate, val[0], val[1]) }
; ;
descendant_or_self descendant_or_self
@ -49,18 +64,27 @@ rule
; ;
axis axis
# > foo
: T_GREATER axis_selector : T_GREATER axis_selector
{ {
s(:axis, 'child', val[1]) s(:axis, 'child', val[1])
} }
# ~ foo
| T_TILDE axis_selector | T_TILDE axis_selector
{ {
s(:axis, 'following-sibling', val[1]) s(:axis, 'following-sibling', val[1])
} }
# + foo
| T_PLUS axis_selector | T_PLUS axis_selector
{ {
[ [
s(:axis, 'following-sibling', s(:test, nil, '*', s(:int, 1))), s(
:predicate,
s(:axis, 'following-sibling', s(:test, nil, '*')),
s(:int, 1)
),
s(:axis, 'self', val[1]) s(:axis, 'self', val[1])
] ]
} }
@ -73,34 +97,7 @@ rule
node_test node_test
# foo # foo
: node_name : node_name { s(:test, *val[0]) }
{
s(:test, *val[0])
}
# .foo, :root, etc
| predicates
{
s(:test, nil, '*', val[0])
}
# foo.bar
| node_name predicates
{
s(:test, *val[0], val[1])
}
# foo[bar]
| node_name attribute_predicate
{
s(:test, *val[0], val[1])
}
# foo[bar].baz
| node_name attribute_predicate predicates
{
s(:test, *val[0], s(:and, val[1], val[2]))
}
; ;
node_name node_name
@ -120,6 +117,7 @@ rule
: class : class
| id | id
| pseudo_class | pseudo_class
| attribute_predicate
; ;
attribute_predicate attribute_predicate