Emit tokens for whitespace in the CSS lexer.
This commit is contained in:
parent
6e18287a1d
commit
619c0bbc14
|
@ -132,7 +132,10 @@ module Oga
|
||||||
|
|
||||||
whitespace = [\t ]+;
|
whitespace = [\t ]+;
|
||||||
|
|
||||||
comma = ',' %{ add_token(:T_COMMA) };
|
action emit_whitespace {
|
||||||
|
add_token(:T_SPACE)
|
||||||
|
}
|
||||||
|
|
||||||
hash = '#' %{ add_token(:T_HASH) };
|
hash = '#' %{ add_token(:T_HASH) };
|
||||||
dot = '.' %{ add_token(:T_DOT) };
|
dot = '.' %{ add_token(:T_DOT) };
|
||||||
lbrack = '[' %{ add_token(:T_LBRACK) };
|
lbrack = '[' %{ add_token(:T_LBRACK) };
|
||||||
|
@ -145,6 +148,15 @@ module Oga
|
||||||
even = 'even';
|
even = 'even';
|
||||||
minus = '-';
|
minus = '-';
|
||||||
nth = 'n';
|
nth = 'n';
|
||||||
|
comma = whitespace* ',' whitespace*;
|
||||||
|
|
||||||
|
action emit_pipe {
|
||||||
|
add_token(:T_PIPE)
|
||||||
|
}
|
||||||
|
|
||||||
|
action emit_comma {
|
||||||
|
add_token(:T_COMMA)
|
||||||
|
}
|
||||||
|
|
||||||
# Identifiers
|
# Identifiers
|
||||||
#
|
#
|
||||||
|
@ -226,6 +238,8 @@ module Oga
|
||||||
# allowed elsewhere. For example, "2n" is not allowed to appear outside
|
# allowed elsewhere. For example, "2n" is not allowed to appear outside
|
||||||
# of the arguments list.
|
# of the arguments list.
|
||||||
pseudo_args := |*
|
pseudo_args := |*
|
||||||
|
whitespace;
|
||||||
|
|
||||||
nth => { add_token(:T_NTH) };
|
nth => { add_token(:T_NTH) };
|
||||||
minus => { add_token(:T_MINUS) };
|
minus => { add_token(:T_MINUS) };
|
||||||
odd => { add_token(:T_ODD) };
|
odd => { add_token(:T_ODD) };
|
||||||
|
@ -235,7 +249,7 @@ module Oga
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
main := |*
|
main := |*
|
||||||
whitespace | comma | hash | dot | lbrack | rbrack | colon;
|
hash | dot | lbrack | rbrack | colon;
|
||||||
|
|
||||||
# Some of the operators have similar characters (e.g. the "="). As a
|
# Some of the operators have similar characters (e.g. the "="). As a
|
||||||
# result we can't use rules like the following:
|
# result we can't use rules like the following:
|
||||||
|
@ -258,8 +272,9 @@ module Oga
|
||||||
|
|
||||||
# The pipe character is also used in the |= operator so the action for
|
# The pipe character is also used in the |= operator so the action for
|
||||||
# this is handled separately.
|
# this is handled separately.
|
||||||
pipe => { add_token(:T_PIPE) };
|
pipe => emit_pipe;
|
||||||
|
comma => emit_comma;
|
||||||
|
whitespace => emit_whitespace;
|
||||||
lparen => emit_lparen;
|
lparen => emit_lparen;
|
||||||
identifier => emit_identifier;
|
identifier => emit_identifier;
|
||||||
integer => emit_integer;
|
integer => emit_integer;
|
||||||
|
|
|
@ -23,7 +23,11 @@ describe Oga::CSS::Lexer do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex an identifier followed by the *= operator' do
|
example 'lex an identifier followed by the *= operator' do
|
||||||
lex_css('foo *=').should == [[:T_IDENT, 'foo'], [:T_IN, nil]]
|
lex_css('foo *=').should == [
|
||||||
|
[:T_IDENT, 'foo'],
|
||||||
|
[:T_SPACE, nil],
|
||||||
|
[:T_IN, nil]
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex the |= operator' do
|
example 'lex the |= operator' do
|
||||||
|
|
|
@ -9,6 +9,15 @@ describe Oga::CSS::Lexer do
|
||||||
example 'lex a path with two members' do
|
example 'lex a path with two members' do
|
||||||
lex_css('div h3').should == [
|
lex_css('div h3').should == [
|
||||||
[:T_IDENT, 'div'],
|
[:T_IDENT, 'div'],
|
||||||
|
[:T_SPACE, nil],
|
||||||
|
[:T_IDENT, 'h3']
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'lex a path with two members separated by multiple spaces' do
|
||||||
|
lex_css('div h3').should == [
|
||||||
|
[:T_IDENT, 'div'],
|
||||||
|
[:T_SPACE, nil],
|
||||||
[:T_IDENT, 'h3']
|
[:T_IDENT, 'h3']
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,16 @@ describe Oga::CSS::Lexer do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
example 'lex the :nth-child pseudo class with extra whitespace' do
|
||||||
|
lex_css(':nth-child( 1)').should == [
|
||||||
|
[:T_COLON, nil],
|
||||||
|
[:T_IDENT, 'nth-child'],
|
||||||
|
[:T_LPAREN, nil],
|
||||||
|
[:T_INT, 1],
|
||||||
|
[:T_RPAREN, nil]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
example 'lex the :nth-child(odd) pseudo class' do
|
example 'lex the :nth-child(odd) pseudo class' do
|
||||||
lex_css(':nth-child(odd)').should == [
|
lex_css(':nth-child(odd)').should == [
|
||||||
[:T_COLON, nil],
|
[:T_COLON, nil],
|
||||||
|
|
Loading…
Reference in New Issue