Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented Selector Hacks

  • Loading branch information...
commit b2af308cdd84cab99fabe2da7983c784f08c722c 1 parent 0143b8a
@bmavity authored
Showing with 20 additions and 10 deletions.
  1. +18 −8 src/cssSelector.ometa
  2. +2 −2 tests/test.js
View
26 src/cssSelector.ometa
@@ -48,11 +48,16 @@ ometa CssSelector <: Parser {
FUNCTION = ident:i '(' -> { i + '(' },
NUMBER = num:n -> { n },
HASH = '#' name:n -> { '#' + n },
- PLUS = '+' -> { '+' }
- | w '+' -> { ' +' },
- GREATER = w '>' -> { ' >' },
- COMMA = w ',' -> { ' ,' },
- TILDE = w '~' -> { ' ~' },
+ PLUS = S+ '+' -> { ' +' }
+ | '+' -> { '+' },
+ // First line of next selector is a Css Hack
+ GREATER = '>' '>' -> { '> >' }
+ | S+ '>' -> { ' >' }
+ | '>' -> { '>' },
+ COMMA = S+ ',' -> { ' ,' }
+ | ',' -> { ',' },
+ TILDE = S+ '~' -> { ' ~' }
+ | '~' -> { '~' },
NOT = ':' N O T '(' -> { ':not(' },
ATKEYWORD = '@' ident,
INVALID = invalid,
@@ -64,7 +69,9 @@ ometa CssSelector <: Parser {
selectors_group = selector:pre comma_separated_selector*:post -> { self.add(pre + post.join('')); self },
comma_separated_selector = COMMA S* selector:sel -> { ', ' + sel },
- selector = simple_selector_sequence:sim (combined_sequence)*:additional -> { sim + additional.join('') },
+ selector = simple_selector_sequence:sim (combined_sequence)*:additional -> { sim + additional.join('') }
+ // Css Hack
+ | combined_sequence*:comb -> { comb.join('') },
combinator = PLUS:p S+ -> { p + ' ' }
| PLUS:p -> { p }
| GREATER:g S+ -> { g + ' ' }
@@ -72,7 +79,8 @@ ometa CssSelector <: Parser {
| TILDE:t S+ -> { t + ' ' }
| TILDE:t -> { t }
| S+ -> { ' ' },
- combined_sequence = combinator:comb simple_selector_sequence:sel -> { comb + sel },
+ combined_sequence = combinator:comb simple_selector_sequence:sel -> { comb + sel }
+ | combinator+:comb simple_selector_sequence:sel -> { comb.join('') + sel },
non_namespaced_selector = (HASH | class | attrib | negation | pseudo):sel -> { sel },
simple_selector_sequence = namespace_prefix:pre '*' non_namespaced_selector*:post -> { pre + '*' + post.join('') }
| namespace_prefix:pre element_name:ele non_namespaced_selector*:post -> { pre + ele + post.join('') }
@@ -81,7 +89,9 @@ ometa CssSelector <: Parser {
| non_namespaced_selector+:sels -> { sels.join('') },
namespace_prefix = ('*' | IDENT):pre '|' -> { pre + '|' }
| '|' -> { '|' },
- element_name = IDENT:i -> { i },
+ // First line of the next selector is a Css Hack
+ element_name = IDENT:i '*' -> { i + '*' }
+ | IDENT:i -> { i },
class = '.' IDENT:i -> { '.' + i },
attrib = '[' S* possible_namespaced_attrib:att ']' -> { '[' + att + ']' },
View
4 tests/test.js
@@ -248,12 +248,12 @@ vows.describe('Functional Pseudo Selectors').addBatch({
}).run();
-vows.describe('Functional Pseudo Selectors').addBatch({
+vows.describe('Selector Hacks').addBatch({
'> E': shouldParse(),
'+ E': shouldParse(),
'~ E': shouldParse(),
'> > E': shouldParse(),
- '> > E': shouldParseTo('>> E'),
+ '>> E': shouldParseTo('> > E'),
'E*': shouldParse(),
'E*.foo': shouldParse(),
'E*:hover': shouldParse()
Please sign in to comment.
Something went wrong with that request. Please try again.