Re-enabled parsing of CSS predicates.

This commit is contained in:
Yorick Peterse 2014-10-20 00:39:12 +02:00
parent d4150fd0f5
commit 174d33c597
4 changed files with 36 additions and 41 deletions

View File

@ -71,7 +71,7 @@ rule
; ;
attribute_test attribute_test
: node_name { s(:test, *val[0]) } : node_name { s(:axis, 'attribute', s(:test, *val[0])) }
; ;
node_name node_name
@ -91,7 +91,7 @@ rule
predicate_members predicate_members
: attribute_test : attribute_test
#| operator | operator
; ;
class class
@ -116,19 +116,19 @@ rule
} }
; ;
# 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]) }
# | op_members T_STARTS_WITH op_members { s(:starts_with, val[0], val[2]) } | op_members T_STARTS_WITH op_members { s(:starts_with, val[0], val[2]) }
# | op_members T_ENDS_WITH op_members { s(:ends_with, val[0], val[2]) } | op_members T_ENDS_WITH op_members { s(:ends_with, val[0], val[2]) }
# | op_members T_IN op_members { s(:in, val[0], val[2]) } | op_members T_IN op_members { s(:in, val[0], val[2]) }
# | op_members T_HYPHEN_IN op_members { s(:hyphen_in, val[0],val[2]) } | op_members T_HYPHEN_IN op_members { s(:hyphen_in, val[0],val[2]) }
# ; ;
#
# op_members op_members
# : node_test : attribute_test
# | string | string
# ; ;
# #
# axis # axis
# # x > y # # x > y
@ -188,14 +188,14 @@ rule
# | integer T_NTH { s(:nth, val[0]) } # | integer T_NTH { s(:nth, val[0]) }
# | integer T_NTH integer { s(:nth, val[0], val[2]) } # | integer T_NTH integer { s(:nth, val[0], val[2]) }
# ; # ;
#
# string string
# : T_STRING { s(:string, val[0]) } : T_STRING { s(:string, val[0]) }
# ; ;
#
# integer integer
# : T_INT { s(:int, val[0].to_i) } : T_INT { s(:int, val[0].to_i) }
# ; ;
end end
---- inner ---- inner

View File

@ -3,14 +3,12 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
context 'paths' do context 'paths' do
example 'parse a single path' do example 'parse a single path' do
parse_css('foo').should == s(:test, nil, 'foo') parse_css('foo').should == parse_xpath('descendant-or-self::foo')
end end
example 'parse a path using two selectors' do example 'parse a path using two selectors' do
parse_css('foo bar').should == s( parse_css('foo bar').should == parse_xpath(
:path, 'descendant-or-self::foo/descendant-or-self::bar'
s(:test, nil, 'foo'),
s(:test, nil, 'bar')
) )
end end
end end

View File

@ -3,23 +3,20 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
context 'predicates' do context 'predicates' do
example 'parse a predicate' do example 'parse a predicate' do
parse_css('foo[bar]').should == s(:test, nil, 'foo', s(:test, nil, 'bar')) parse_css('foo[bar]').should == parse_xpath(
'descendant-or-self::foo[@bar]'
)
end end
example 'parse a node test followed by a node test with a predicate' do example 'parse a node test followed by a node test with a predicate' do
parse_css('foo bar[baz]').should == s( parse_css('foo bar[baz]').should == parse_xpath(
:path, 'descendant-or-self::foo/descendant-or-self::bar[@baz]'
s(:test, nil, 'foo'),
s(:test, nil, 'bar', s(:test, nil, 'baz'))
) )
end end
example 'parse a predicate testing an attribute value' do example 'parse a predicate testing an attribute value' do
parse_css('foo[bar="baz"]').should == s( parse_css('foo[bar="baz"]').should == parse_xpath(
:test, 'descendant-or-self::foo[@bar="baz"]'
nil,
'foo',
s(:eq, s(:test, nil, 'bar'), s(:string, 'baz'))
) )
end end
end end

View File

@ -3,15 +3,15 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
context 'wildcards' do context 'wildcards' do
example 'parse a wildcard name test' do example 'parse a wildcard name test' do
parse_css('*').should == s(:test, nil, '*') parse_css('*').should == parse_xpath('descendant-or-self::*')
end end
example 'parse a wildcard namespace test' do example 'parse a wildcard namespace test' do
parse_css('*|foo').should == s(:test, '*', 'foo') parse_css('*|foo').should == parse_xpath('descendant-or-self::*:foo')
end end
example 'parse a wildcard namespace and name test' do example 'parse a wildcard namespace and name test' do
parse_css('*|*').should == s(:test, '*', '*') parse_css('*|*').should == parse_xpath('descendant-or-self::*:*')
end end
end end
end end