Skip to content

Commit b5c7945

Browse files
committed
[css3-syntax] Add (not in the draft yet) railroad diagrams for parsing.
1 parent e4d08f2 commit b5c7945

1 file changed

Lines changed: 94 additions & 1 deletion

File tree

css3-syntax/Diagrams.src.html

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ <h1>Railroad diagrams for CSS Syntax Level 3</h1>
1818
</p>
1919

2020
<h2>Preview</h2>
21+
<h3 id=tokens>Tokens</h3>
2122
<dl>
2223
</dl>
24+
<h3 id=parsing>Parsing</h3>
25+
<p>All comments are ignored.</p>
26+
<dl>
27+
</dl>
28+
2329

2430
<h2 id=markup>Markup</h2>
31+
<h3>Tokens</h3>
32+
<textarea style="box-sizing: border-box; width: 100%; height: 20em">
33+
</textarea>
34+
<h3>Parsing</h3>
2535
<textarea style="box-sizing: border-box; width: 100%; height: 20em">
2636
</textarea>
2737

@@ -46,7 +56,7 @@ <h2 id=markup>Markup</h2>
4656
NonTerminal('not NL or hex digit'),
4757
Sequence(
4858
OneOrMore(NonTerminal('hex digit'), Comment('1-6 times')),
49-
Optional(NonTerminal('WS'), 'skip')))));
59+
Optional(NonTerminal('WS*'), 'skip')))));
5060

5161
add('IDENT', Diagram(
5262
Choice(0, Skip(), '-'),
@@ -155,4 +165,87 @@ <h2 id=markup>Markup</h2>
155165
// XXX work around a bug/limitation in the spec pre-processor.
156166
// Single quotes have a special meaning there.
157167
.replace(/'/g, '&apos;');
168+
169+
preview = document.getElementsByTagName('dl')[1];
170+
171+
// Tree items:
172+
173+
var NT = NonTerminal
174+
175+
add('Stylesheet', Diagram(ZeroOrMore(Choice(0,
176+
NT('Style rule'), NT('At-rule'), NT('WHITESPACE'), NT('CDO'), NT('CDC')))));
177+
178+
add('Style rule', Diagram(
179+
Optional(Sequence(
180+
NT('Component value, except AT-KEYWORD or {} block'),
181+
ZeroOrMore(NT('Component value, except {} block')))), // selector
182+
NT('{'), NT('Declaration/at-rule list'), NT('}')));
183+
184+
add('At-rule', Diagram(
185+
NT('AT-KEYWORD'),
186+
ZeroOrMore(NT('Component value, except SEMICOLON or {} block')),
187+
Choice(0,
188+
Sequence(NT('{'), NT('Declaration/at-rule list'), NT('}')),
189+
Sequence(NT('{'), NT('Rule list'), NT('}')),
190+
NT('SEMICOLON'))));
191+
192+
add('Rule list', Diagram(
193+
ZeroOrMore(Choice(0, NT('Style rule'), NT('At-rule'), NT('WHITESPACE')))));
194+
195+
add('WS*', Diagram(ZeroOrMore(NT('WHITESPACE'))));
196+
197+
add('Declaration/at-rule list', Diagram(
198+
NT('WS*'),
199+
Optional(Choice(0,
200+
Sequence(
201+
Optional(NT('Declaration')),
202+
Optional(Sequence(NT(';'), NT('Declaration/at-rule list')))),
203+
Sequence(
204+
NT('At-rule'),
205+
NT('Declaration/at-rule list'))))));
206+
207+
add('Declaration', Diagram(
208+
NT('IDENT'), NT('WS*'), NT('COLON'), NT('WS*'),
209+
ZeroOrMore(NT('Component value, except SEMICOLON or DELIM(!)')),
210+
Optional(Sequence(
211+
// XXX Mention ASCII case-insensitivity?
212+
NT('DELIM(!)'), NT('WS*'), NT('IDENT(important)')))));
213+
214+
add('Component value', Diagram(Choice(0,
215+
NT("IDENT"),
216+
NT("HASH"),
217+
NT("STRING"),
218+
NT("URL"),
219+
NT("DELIM"),
220+
NT("NUMBER"),
221+
NT("PERCENTAGE"),
222+
NT("DIMENSION"),
223+
NT("UNICODE-RANGE"),
224+
NT("WHITESPACE"),
225+
NT("COLON"),
226+
NT("SEMICOLON"),
227+
NT("AT-KEYWORD"),
228+
229+
NT("{} block"),
230+
NT("() block"),
231+
NT("[] block"),
232+
NT("Function block"))));
233+
234+
235+
add('{} block', Diagram(NT('{'), ZeroOrMore(NT('Component value')), NT('}')));
236+
add('() block', Diagram(NT('('), ZeroOrMore(NT('Component value')), NT(')')));
237+
add('[] block', Diagram(NT('['), ZeroOrMore(NT('Component value')), NT(']')));
238+
239+
add('Function block', Diagram(
240+
NT('FUNCTION'), ZeroOrMore(
241+
ZeroOrMore(NT('Component value, except DELIM(,)')),
242+
NT('DELIM(,)')),
243+
')'));
244+
245+
246+
document.getElementsByTagName('textarea')[1].value = '\t' + preview.outerHTML
247+
// XXX work around a bug/limitation in the spec pre-processor.
248+
// Single quotes have a special meaning there.
249+
.replace(/'/g, '&apos;');
250+
158251
</script>

0 commit comments

Comments
 (0)