Lexing/parsing of CSS pseudos with ident arguments

This allows the lexing/parsing of expressions such as "html:lang(en)".
This commit is contained in:
Yorick Peterse 2014-10-15 09:42:26 +02:00
parent d9a4221a0a
commit 48eb4f83df
4 changed files with 30 additions and 6 deletions

View File

@ -239,12 +239,16 @@ module Oga
pseudo_args := |*
whitespace;
nth => { add_token(:T_NTH) };
# NOTE: the priorities here are put in place to ensure that rules such
# as `nth` take precedence over `identifier`. The highest number has
# the highest priority.
nth > 5 => { add_token(:T_NTH) };
minus => { add_token(:T_MINUS) };
odd => { add_token(:T_ODD) };
even => { add_token(:T_EVEN) };
integer => emit_integer;
odd > 4 => { add_token(:T_ODD) };
even > 3 => { add_token(:T_EVEN) };
integer > 2 => emit_integer;
rparen => emit_rparen;
identifier > 1 => emit_identifier;
*|;
# Predicates

View File

@ -142,6 +142,7 @@ rule
| odd
| even
| nth
| node_test
;
odd

View File

@ -116,5 +116,15 @@ describe Oga::CSS::Lexer do
[:T_RPAREN, nil]
]
end
example 'lex the :lang(fr) pseudo class' do
lex_css(':lang(fr)').should == [
[:T_COLON, nil],
[:T_IDENT, 'lang'],
[:T_LPAREN, nil],
[:T_IDENT, 'fr'],
[:T_RPAREN, nil]
]
end
end
end

View File

@ -107,5 +107,14 @@ describe Oga::CSS::Parser do
s(:pseudo, 'focus', s(:test, nil, 'x'))
)
end
example 'parse a pseudo class with an identifier as the argument' do
parse_css('x:lang(fr)').should == s(
:pseudo,
'lang',
s(:test, nil, 'x'),
s(:test, nil, 'fr')
)
end
end
end