OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #library('css'); | |
6 | |
7 #import('../../frog/lang.dart', prefix:'lang'); | |
8 #import('../../frog/file_system_memory.dart'); | |
9 | |
10 #source('tokenkind.dart'); | |
11 #source('tokenizer.dart'); | |
12 #source('tree.dart'); | |
13 #source('cssselectorexception.dart'); | |
14 #source('cssworld.dart'); | |
15 #source('parser.dart'); | |
16 | |
17 | |
18 void initCssWorld() { | |
19 var fs = new MemoryFileSystem(); | |
20 lang.parseOptions('', [], fs); | |
21 lang.initializeWorld(fs); | |
22 lang.world.process(); | |
23 lang.world.resolveAll(); | |
24 | |
25 // Set these here so that we can compile the corelib without its errors | |
jimhug
2011/11/10 17:58:56
I'd make this a TODO if you really need it - this
terry
2011/11/16 14:00:22
This comment was wrong. I've updated the comment
| |
26 // killing us | |
27 lang.options.throwOnErrors = true; | |
28 lang.options.throwOnFatal = true; | |
29 } | |
30 | |
31 // TODO(terry): Add obfuscation mapping file. | |
32 void cssParseAndValidate(String cssExpression, CssWorld world) { | |
33 Parser parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, | |
34 cssExpression)); | |
35 var tree = parser.template(); | |
36 if (tree != null) { | |
37 parser.validateTemplate(tree.selectors, world); | |
38 } | |
39 } | |
40 | |
41 // Returns pretty printed tree of the expression. | |
42 String cssParseAndValidateDebug(String cssExpression, CssWorld world) { | |
jimhug
2011/11/10 17:58:56
Nice helper.
| |
43 Parser parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, | |
44 cssExpression)); | |
45 String output = ""; | |
46 String prettyTree = ""; | |
47 try { | |
48 var tree = parser.template(); | |
49 if (tree != null) { | |
50 prettyTree = tree.toDebugString(); | |
51 parser.validateTemplate(tree.selectors, world); | |
52 output = prettyTree; | |
53 } | |
54 } catch (var e) { | |
55 String error = e.toString(); | |
56 output = "$error\n$prettyTree"; | |
57 throw e; | |
58 } | |
59 | |
60 return output; | |
61 } | |
OLD | NEW |