Skip to content
Newer
Older
100644 163 lines (146 sloc) 6.25 KB
3333498 @bmavity Modified file reading to fix (hopefully) newline selector issues
authored Dec 6, 2011
1 ometa CssSelector <: Parser {
17c9390 @bmavity added grammar invoker as well as cssSelector grammar file
authored Sep 15, 2010
2 crChar = '\r',
3 ffChar = '\f',
4 nlChar = '\n',
5 tabChar = '\t',
6 lineEnding = crChar | ffChar | nlChar,
7 tabOrLineEnding = tabChar | lineEnding,
8
9
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
10 ident = '-' nmstart:s nmchar*:cs -> { '-' + s + cs.join('') }
11 | nmstart:s nmchar*:cs -> { s + cs.join('') },
12 name = nmchar+:n -> { n.join('') },
13 nmstart = ('_' | letter | nonascii | escape):n -> { n },
17c9390 @bmavity added grammar invoker as well as cssSelector grammar file
authored Sep 15, 2010
14 nonascii = '',
15 unicode = '',
16 escape = unicode | '',
17 nmchar = '_' | '-' | letterOrDigit | nonascii | escape,
18 num = digit+: d -> d.join('')
19 | digit* '.' digit+,
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
20 string = (string1 | string2):s -> { s },
21 //string1 = '\"' (~(lineEnding | '\"') | '\\' nl | nonascii | escape)*:s '\"' -> { '\"' + s.join('') + '\"' },
9856a7c @bmavity Fixed quoted attributes
authored Sep 21, 2010
22 string1 = '"' letter*:s '"' -> { '"' + s.join('') + '"' },
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
23 string2 = '\'' (~(lineEnding | '\'') | '\\' nl | nonascii | escape)*:s '\'' -> { '\'' + s.join('') + '\'' },
9856a7c @bmavity Fixed quoted attributes
authored Sep 21, 2010
24 //invalid = invalid1 | invalid2,
25 //invalid1 = '\"' (~(lineEnding | '\"') | '\\' nl | nonascii | escape)*,
26 //invalid2 = '\'' (~(lineEnding | '\'') | '\\' nl | nonascii | escape)*,
17c9390 @bmavity added grammar invoker as well as cssSelector grammar file
authored Sep 15, 2010
27 nl = crChar nlChar
28 | lineEnding,
29 D = 'd' | 'D',
30 E = 'e' | 'E',
31 N = 'n' | 'N',
32 O = 'o' | 'O',
33 T = 't' | 'T',
34 V = 'v' | 'V',
35
36
75a0f0c @bmavity Implemented Selectors with Newlines
authored Sep 24, 2010
37 S = ' ' -> { ' ' }
38 | '\n' -> { '\n' },
9856a7c @bmavity Fixed quoted attributes
authored Sep 21, 2010
39 INCLUDES = '~' '=' -> { '~=' },
40 DASHMATCH = '|' '=' -> { '|=' },
41 PREFIXMATCH = '^' '=' -> { '^=' },
42 SUFFIXMATCH = '$' '=' -> { '$=' },
43 SUBSTRINGMATCH = '*' '=' -> { '*=' },
17c9390 @bmavity added grammar invoker as well as cssSelector grammar file
authored Sep 15, 2010
44 IDENT = ident,
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
45 STRING = string:s -> { s },
46 FUNCTION = ident:i '(' -> { i + '(' },
47 NUMBER = num:n -> { n },
48 HASH = '#' name:n -> { '#' + n },
b2af308 @bmavity Implemented Selector Hacks
authored Sep 23, 2010
49 PLUS = S+ '+' -> { ' +' }
50 | '+' -> { '+' },
51 // First line of next selector is a Css Hack
52 GREATER = '>' '>' -> { '> >' }
53 | S+ '>' -> { ' >' }
54 | '>' -> { '>' },
55 COMMA = S+ ',' -> { ' ,' }
56 | ',' -> { ',' },
57 TILDE = S+ '~' -> { ' ~' }
58 | '~' -> { '~' },
f015997 @bmavity Added Negation Selectors for selectors types that have been already i…
authored Sep 22, 2010
59 NOT = ':' N O T '(' -> { ':not(' },
17c9390 @bmavity added grammar invoker as well as cssSelector grammar file
authored Sep 15, 2010
60 ATKEYWORD = '@' ident,
61 INVALID = invalid,
8fb886b @bmavity Implemented Expression Fallback Selectors
authored Sep 23, 2010
62 PERCENTAGE = num:n '%' -> { n + '%' },
dc5999c @bmavity Added tests for Nth Selectors
authored Sep 21, 2010
63 DIMENSION = num:n ident:i -> { n + i },
17c9390 @bmavity added grammar invoker as well as cssSelector grammar file
authored Sep 15, 2010
64 CDO = '<' '!' '-' '-',
65 CDC = '-' '-' '>',
66
67
73cfa00 @bmavity Implemented CssSelector grammar in Scss grammar
authored Sep 27, 2010
68 selectors_group = selector:pre comma_separated_selector* -> { self.addSelector(pre); self },
69 comma_separated_selector = COMMA:com S*:spacing selector:sel -> { self.addCommaSeparatedSelector(com + spacing.join(''), sel) },
b2af308 @bmavity Implemented Selector Hacks
authored Sep 23, 2010
70 selector = simple_selector_sequence:sim (combined_sequence)*:additional -> { sim + additional.join('') }
71 // Css Hack
72 | combined_sequence*:comb -> { comb.join('') },
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
73 combinator = PLUS:p S+ -> { p + ' ' }
dc5999c @bmavity Added tests for Nth Selectors
authored Sep 21, 2010
74 | PLUS:p -> { p }
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
75 | GREATER:g S+ -> { g + ' ' }
dc5999c @bmavity Added tests for Nth Selectors
authored Sep 21, 2010
76 | GREATER:g -> { g }
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
77 | TILDE:t S+ -> { t + ' ' }
dc5999c @bmavity Added tests for Nth Selectors
authored Sep 21, 2010
78 | TILDE:t -> { t }
75a0f0c @bmavity Implemented Selectors with Newlines
authored Sep 25, 2010
79 | S+:spacing -> { spacing.join('') },
73cfa00 @bmavity Implemented CssSelector grammar in Scss grammar
authored Sep 27, 2010
80 combined_sequence = combinator+:comb simple_selector_sequence:sel -> { comb.join('') + sel },
4f41af4 @bmavity Implemented Namespaced Selectors
authored Sep 23, 2010
81 non_namespaced_selector = (HASH | class | attrib | negation | pseudo):sel -> { sel },
82 simple_selector_sequence = namespace_prefix:pre '*' non_namespaced_selector*:post -> { pre + '*' + post.join('') }
83 | namespace_prefix:pre element_name:ele non_namespaced_selector*:post -> { pre + ele + post.join('') }
84 | '*' non_namespaced_selector*:post -> { '*' + post.join('') }
85 | element_name:ele non_namespaced_selector*:post -> { ele + post.join('') }
8fb886b @bmavity Implemented Expression Fallback Selectors
authored Sep 23, 2010
86 | non_namespaced_selector+:sels -> { sels.join('') }
87 // Css Hack
88 | expression:ex -> { ex },
4f41af4 @bmavity Implemented Namespaced Selectors
authored Sep 23, 2010
89 namespace_prefix = ('*' | IDENT):pre '|' -> { pre + '|' }
90 | '|' -> { '|' },
b2af308 @bmavity Implemented Selector Hacks
authored Sep 23, 2010
91 // First line of the next selector is a Css Hack
92 element_name = IDENT:i '*' -> { i + '*' }
93 | IDENT:i -> { i },
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
94 class = '.' IDENT:i -> { '.' + i },
95
96 attrib = '[' S* possible_namespaced_attrib:att ']' -> { '[' + att + ']' },
97 possible_namespaced_attrib = namespace_prefix:pre ident_with_possible_postfix:post -> { pre + post }
98 | ident_with_possible_postfix:post -> { post },
9856a7c @bmavity Fixed quoted attributes
authored Sep 21, 2010
99 ident_with_possible_postfix = IDENT:left S* attrib_match:match S* (IDENT | STRING):right S* -> { left + match + right }
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
100 | IDENT:i S* -> { i },
9856a7c @bmavity Fixed quoted attributes
authored Sep 21, 2010
101 attrib_match = (PREFIXMATCH | SUFFIXMATCH | SUBSTRINGMATCH | equals_match | INCLUDES | DASHMATCH):m -> { m },
102 equals_match = '=' -> { '=' },
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
103 pseudo = ':' ':' (functional_pseudo | IDENT):i -> { '::' + i }
104 | ':' (functional_pseudo | IDENT):i -> { ':' + i },
93ea15b @bmavity Implemented moz-any Selector
authored Sep 23, 2010
105 functional_pseudo = FUNCTION:f S* full_expression:e ')' -> { f + e + ')' }
106 // Css Hack for :-moz-any(...)
73cfa00 @bmavity Implemented CssSelector grammar in Scss grammar
authored Sep 27, 2010
107 | FUNCTION:f S* selectors_group:sel ')' -> { f + sel.toString() + ')' },
17c9390 @bmavity added grammar invoker as well as cssSelector grammar file
authored Sep 15, 2010
108
8fb886b @bmavity Implemented Expression Fallback Selectors
authored Sep 23, 2010
109 expression_content = (PLUS | '-' | PERCENTAGE | DIMENSION | NUMBER | STRING | IDENT):e -> { e },
572a14e @bmavity Added additional Nth selector with odd spacing
authored Sep 22, 2010
110 expression = expression_content:ec S+ expression:e -> { ec + ' ' + e }
111 | expression_content:ec expression:e -> { ec + e }
112 | expression_content:ec S* -> { ec },
113 full_expression = (expression)+:ea -> { ea.join('') },
f015997 @bmavity Added Negation Selectors for selectors types that have been already i…
authored Sep 22, 2010
114 negation = NOT:n S* negation_arg:na S* ')' -> { n + na + ')' },
115
116 //negation_arg = (type_selector | universal | HASH | class | attrib | pseudo):na -> { na }
117 //Technically not allowed, but here for scss compatibility
73cfa00 @bmavity Implemented CssSelector grammar in Scss grammar
authored Sep 27, 2010
118 negation_arg = selectors_group:sg -> { sg.toString() }
17c9390 @bmavity added grammar invoker as well as cssSelector grammar file
authored Sep 15, 2010
119 }
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
120
121 CssSelector.initialize = function() {
73cfa00 @bmavity Implemented CssSelector grammar in Scss grammar
authored Sep 27, 2010
122 var hasBeenStringified = false,
123 self = this;
124
125 this.selector;
126 this.selectors = [];
127 this.commaSeparatedSelectors = [];
128
129 var resetFields = function() {
130 self.selector = null;
131 self.selectors = [];
132 self.commaSeparatedSelectors = [];
133 hasBeenStrigified = false;
134 };
135
136 this.addSelector = function(sel) {
137 if(hasBeenStringified) {
138 resetFields();
139 }
140 this.selector = sel;
141 };
142
143 this.addCommaSeparatedSelector = function(commaAndSpacing, selector) {
144 if(hasBeenStringified) {
145 resetFields();
146 }
147 this.selectors.push(selector);
148 this.commaSeparatedSelectors.push({
149 commaAndSpacing: commaAndSpacing,
150 selector: selector
151 });
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
152 };
153
73cfa00 @bmavity Implemented CssSelector grammar in Scss grammar
authored Sep 27, 2010
154 this.toString = function() {
155 hasBeenStringified = true;
156 return this.selector + this.commaSeparatedSelectors.map(function(csSel) {
157 return csSel.commaAndSpacing + csSel.selector;
158 }).join('');
938284c @bmavity First round of converted css selector tests
authored Sep 21, 2010
159 };
160 };
161
162 CssSelector
Something went wrong with that request. Please try again.