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:
parent
d9a4221a0a
commit
48eb4f83df
|
@ -239,12 +239,16 @@ module Oga
|
||||||
pseudo_args := |*
|
pseudo_args := |*
|
||||||
whitespace;
|
whitespace;
|
||||||
|
|
||||||
nth => { add_token(:T_NTH) };
|
# NOTE: the priorities here are put in place to ensure that rules such
|
||||||
minus => { add_token(:T_MINUS) };
|
# as `nth` take precedence over `identifier`. The highest number has
|
||||||
odd => { add_token(:T_ODD) };
|
# the highest priority.
|
||||||
even => { add_token(:T_EVEN) };
|
nth > 5 => { add_token(:T_NTH) };
|
||||||
integer => emit_integer;
|
minus => { add_token(:T_MINUS) };
|
||||||
rparen => emit_rparen;
|
odd > 4 => { add_token(:T_ODD) };
|
||||||
|
even > 3 => { add_token(:T_EVEN) };
|
||||||
|
integer > 2 => emit_integer;
|
||||||
|
rparen => emit_rparen;
|
||||||
|
identifier > 1 => emit_identifier;
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
# Predicates
|
# Predicates
|
||||||
|
|
|
@ -142,6 +142,7 @@ rule
|
||||||
| odd
|
| odd
|
||||||
| even
|
| even
|
||||||
| nth
|
| nth
|
||||||
|
| node_test
|
||||||
;
|
;
|
||||||
|
|
||||||
odd
|
odd
|
||||||
|
|
|
@ -116,5 +116,15 @@ describe Oga::CSS::Lexer do
|
||||||
[:T_RPAREN, nil]
|
[:T_RPAREN, nil]
|
||||||
]
|
]
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -107,5 +107,14 @@ describe Oga::CSS::Parser do
|
||||||
s(:pseudo, 'focus', s(:test, nil, 'x'))
|
s(:pseudo, 'focus', s(:test, nil, 'x'))
|
||||||
)
|
)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue