| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('css'); | 5 #library('css'); |
| 6 | 6 |
| 7 #import('dart:dom'); | |
| 8 #import('../../frog/lang.dart', prefix:'lang'); | 7 #import('../../frog/lang.dart', prefix:'lang'); |
| 8 #import('../../frog/file_system.dart'); |
| 9 #import('../../frog/file_system_memory.dart'); | 9 #import('../../frog/file_system_memory.dart'); |
| 10 | |
| 11 #source('tokenkind.dart'); | 10 #source('tokenkind.dart'); |
| 12 #source('tokenizer.dart'); | 11 #source('tokenizer.dart'); |
| 13 #source('tree.dart'); | 12 #source('tree.dart'); |
| 14 #source('cssselectorexception.dart'); | 13 #source('cssselectorexception.dart'); |
| 15 #source('cssworld.dart'); | 14 #source('cssworld.dart'); |
| 16 #source('parser.dart'); | 15 #source('parser.dart'); |
| 16 #source('validate.dart'); |
| 17 #source('generate.dart'); |
| 17 | 18 |
| 18 | 19 |
| 19 void initCssWorld() { | 20 void initCssWorld([bool commandLine = true]) { |
| 20 var fs = new MemoryFileSystem(); | 21 var fs = new MemoryFileSystem(); |
| 21 lang.parseOptions('', [], fs); | 22 lang.parseOptions('', [], fs); |
| 22 lang.initializeWorld(fs); | 23 lang.initializeWorld(fs); |
| 23 lang.world.process(); | 24 lang.world.process(); |
| 24 lang.world.resolveAll(); | 25 lang.world.resolveAll(); |
| 25 | 26 |
| 26 // TODO(terry): Should be set by arguments. When run as a tool these aren't | 27 // TODO(terry): Should be set by arguments. When run as a tool these aren't |
| 27 // set when run internaly set these so we can compile CSS and catch any | 28 // set when run internaly set these so we can compile CSS and catch any |
| 28 // problems programmatically. | 29 // problems programmatically. |
| 29 lang.options.throwOnErrors = true; | 30 lang.options.throwOnErrors = true; |
| 30 lang.options.throwOnFatal = true; | 31 lang.options.throwOnFatal = true; |
| 32 lang.options.useColors = commandLine ? true : false; |
| 31 } | 33 } |
| 32 | 34 |
| 33 // TODO(terry): Add obfuscation mapping file. | 35 // TODO(terry): Add obfuscation mapping file. |
| 34 void cssParseAndValidate(String cssExpression, CssWorld world) { | 36 void cssParseAndValidate(String cssExpression, CssWorld world) { |
| 35 Parser parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, | 37 Parser parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
| 36 cssExpression)); | 38 cssExpression)); |
| 37 var tree = parser.template(); | 39 var tree = parser.parseTemplate(); |
| 38 if (tree != null) { | 40 if (tree != null) { |
| 39 parser.validateTemplate(tree.selectors, world); | 41 Validate.template(tree.selectors, world); |
| 40 } | 42 } |
| 41 } | 43 } |
| 42 | 44 |
| 43 // Returns pretty printed tree of the expression. | 45 // Returns pretty printed tree of the expression. |
| 44 String cssParseAndValidateDebug(String cssExpression, CssWorld world) { | 46 String cssParseAndValidateDebug(String cssExpression, CssWorld world) { |
| 45 Parser parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, | 47 Parser parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
| 46 cssExpression)); | 48 cssExpression)); |
| 47 String output = ""; | 49 String output = ""; |
| 48 String prettyTree = ""; | 50 String prettyTree = ""; |
| 49 try { | 51 try { |
| 50 var tree = parser.template(); | 52 var tree = parser.parseTemplate(); |
| 51 if (tree != null) { | 53 if (tree != null) { |
| 52 prettyTree = tree.toDebugString(); | 54 prettyTree = tree.toDebugString(); |
| 53 parser.validateTemplate(tree.selectors, world); | 55 Validate.template(tree.selectors, world); |
| 54 output = prettyTree; | 56 output = prettyTree; |
| 55 } | 57 } |
| 56 } catch (var e) { | 58 } catch (var e) { |
| 57 String error = e.toString(); | 59 String error = e.toString(); |
| 58 output = "$error\n$prettyTree"; | 60 output = "$error\n$prettyTree"; |
| 59 throw e; | 61 throw e; |
| 60 } | 62 } |
| 61 | 63 |
| 62 return output; | 64 return output; |
| 63 } | 65 } |
| OLD | NEW |