Skip to content

Commit 90e18aa

Browse files
author
Tab Atkins
committed
Write the parser
1 parent 8d1fde8 commit 90e18aa

File tree

3 files changed

+385
-11
lines changed

3 files changed

+385
-11
lines changed

example.html

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
<!doctype html>
2-
<textarea id='css'>u+5 u+a?</textarea>
3-
<button onclick='parseStuff()'>Parse</button>
4-
<textarea id='json'></textarea>
2+
<div>
3+
<textarea id='css'>foo { bar: baz; }</textarea>
4+
<button onclick='parseStuff()'>Parse</button>
5+
<textarea id='tokens'></textarea>
6+
</div>
7+
<textarea id='tree'></textarea>
58
<style>
69
html,body { height: 100%; margin: 0; padding: 0; }
7-
body {
10+
body > div {
11+
height: 50%;
812
display: -webkit-flex;
913
-webkit-align-items: center;
1014
}
11-
textarea {
15+
#css, #tokens {
1216
-webkit-flex: 1;
1317
-webkit-align-self: stretch;
1418
height: 100%;
1519
}
20+
#tree {
21+
width: 99%;
22+
height: 45%;
23+
}
24+
1625
</style>
1726
<script>
1827
var debug;
1928
function parseStuff() {
29+
AtRule.registry.foo = 'decl';
30+
2031
var css = document.querySelector('#css').value;
21-
var tokens = tokenize(css);
22-
debug = tokens;
23-
console.log(tokens);
24-
var txt = document.querySelector('#json');
25-
txt.value = tokens.join(' ');
32+
var tokenlist = tokenize(css);
33+
var sheet = parse(tokenlist);
34+
console.log(tokenlist);
35+
console.log(sheet);
36+
debug = sheet;
37+
var txt = document.querySelector('#tokens');
38+
txt.value = tokenlist.join(' ');
39+
var tree = document.querySelector('#tree');
40+
tree.value = sheet.toString(' ');
41+
2642
}
2743
</script>
28-
<script src="tokenizer.js"></script>
44+
<script src="tokenizer.js"></script>
45+
<script src="parser.js"></script>

0 commit comments

Comments
 (0)