Skip to content

Commit

Permalink
Implemented Selector Hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bmavity committed Sep 23, 2010
1 parent cf25be8 commit d4907a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/cssSelector.ometa
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -64,15 +69,18 @@ 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 + ' ' }
| GREATER:g -> { g }
| 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('') }
Expand All @@ -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 + ']' },
Expand Down
4 changes: 2 additions & 2 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d4907a6

Please sign in to comment.