| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 csslib.parser; | 5 library csslib.parser; |
| 6 | 6 |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import 'package:source_span/source_span.dart'; | 9 import 'package:source_span/source_span.dart'; |
| 10 | 10 |
| 11 import 'visitor.dart'; | |
| 12 import 'src/messages.dart'; | 11 import 'src/messages.dart'; |
| 13 import 'src/options.dart'; | 12 import 'src/options.dart'; |
| 13 import 'visitor.dart'; |
| 14 | 14 |
| 15 export 'src/messages.dart' show Message; | 15 export 'src/messages.dart' show Message; |
| 16 export 'src/options.dart'; | 16 export 'src/options.dart'; |
| 17 | 17 |
| 18 part 'src/analyzer.dart'; | 18 part 'src/analyzer.dart'; |
| 19 part 'src/polyfill.dart'; | 19 part 'src/polyfill.dart'; |
| 20 part 'src/property.dart'; | 20 part 'src/property.dart'; |
| 21 part 'src/token.dart'; | 21 part 'src/token.dart'; |
| 22 part 'src/tokenizer_base.dart'; | 22 part 'src/tokenizer_base.dart'; |
| 23 part 'src/tokenizer.dart'; | 23 part 'src/tokenizer.dart'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 bool polyfill: false, | 61 bool polyfill: false, |
| 62 List<StyleSheet> includes: null}) { | 62 List<StyleSheet> includes: null}) { |
| 63 if (includes == null) { | 63 if (includes == null) { |
| 64 includes = []; | 64 includes = []; |
| 65 } | 65 } |
| 66 | 66 |
| 67 var source = _inputAsString(input); | 67 var source = _inputAsString(input); |
| 68 | 68 |
| 69 _createMessages(errors: errors, options: options); | 69 _createMessages(errors: errors, options: options); |
| 70 | 70 |
| 71 var file = new SourceFile(source); | 71 var file = new SourceFile.fromString(source); |
| 72 | 72 |
| 73 var tree = new _Parser(file, source).parse(); | 73 var tree = new _Parser(file, source).parse(); |
| 74 | 74 |
| 75 analyze([tree], errors: errors, options: options); | 75 analyze([tree], errors: errors, options: options); |
| 76 | 76 |
| 77 if (polyfill) { | 77 if (polyfill) { |
| 78 var processCss = new PolyFill(messages); | 78 var processCss = new PolyFill(messages); |
| 79 processCss.process(tree, includes: includes); | 79 processCss.process(tree, includes: includes); |
| 80 } | 80 } |
| 81 | 81 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 /** | 92 /** |
| 93 * Parse the [input] CSS stylesheet into a tree. The [input] can be a [String], | 93 * Parse the [input] CSS stylesheet into a tree. The [input] can be a [String], |
| 94 * or [List<int>] of bytes and returns a [StyleSheet] AST. The optional | 94 * or [List<int>] of bytes and returns a [StyleSheet] AST. The optional |
| 95 * [errors] list will contain each error/warning as a [Message]. | 95 * [errors] list will contain each error/warning as a [Message]. |
| 96 */ | 96 */ |
| 97 StyleSheet parse(input, {List<Message> errors, PreprocessorOptions options}) { | 97 StyleSheet parse(input, {List<Message> errors, PreprocessorOptions options}) { |
| 98 var source = _inputAsString(input); | 98 var source = _inputAsString(input); |
| 99 | 99 |
| 100 _createMessages(errors: errors, options: options); | 100 _createMessages(errors: errors, options: options); |
| 101 | 101 |
| 102 var file = new SourceFile(source); | 102 var file = new SourceFile.fromString(source); |
| 103 return new _Parser(file, source).parse(); | 103 return new _Parser(file, source).parse(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Parse the [input] CSS selector into a tree. The [input] can be a [String], | 107 * Parse the [input] CSS selector into a tree. The [input] can be a [String], |
| 108 * or [List<int>] of bytes and returns a [StyleSheet] AST. The optional | 108 * or [List<int>] of bytes and returns a [StyleSheet] AST. The optional |
| 109 * [errors] list will contain each error/warning as a [Message]. | 109 * [errors] list will contain each error/warning as a [Message]. |
| 110 */ | 110 */ |
| 111 // TODO(jmesserly): should rename "parseSelector" and return Selector | 111 // TODO(jmesserly): should rename "parseSelector" and return Selector |
| 112 StyleSheet selector(input, {List<Message> errors}) { | 112 StyleSheet selector(input, {List<Message> errors}) { |
| 113 var source = _inputAsString(input); | 113 var source = _inputAsString(input); |
| 114 | 114 |
| 115 _createMessages(errors: errors); | 115 _createMessages(errors: errors); |
| 116 | 116 |
| 117 var file = new SourceFile(source); | 117 var file = new SourceFile.fromString(source); |
| 118 return (new _Parser(file, source)..tokenizer.inSelector = true) | 118 return (new _Parser(file, source)..tokenizer.inSelector = true) |
| 119 .parseSelector(); | 119 .parseSelector(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 SelectorGroup parseSelectorGroup(input, {List<Message> errors}) { | 122 SelectorGroup parseSelectorGroup(input, {List<Message> errors}) { |
| 123 var source = _inputAsString(input); | 123 var source = _inputAsString(input); |
| 124 | 124 |
| 125 _createMessages(errors: errors); | 125 _createMessages(errors: errors); |
| 126 | 126 |
| 127 var file = new SourceFile(source); | 127 var file = new SourceFile.fromString(source); |
| 128 return (new _Parser(file, source) | 128 return (new _Parser(file, source) |
| 129 // TODO(jmesserly): this fix should be applied to the parser. It's trick
y | 129 // TODO(jmesserly): this fix should be applied to the parser. It's trick
y |
| 130 // because by the time the flag is set one token has already been fetche
d. | 130 // because by the time the flag is set one token has already been fetche
d. |
| 131 ..tokenizer.inSelector = true) | 131 ..tokenizer.inSelector = true) |
| 132 .processSelectorGroup(); | 132 .processSelectorGroup(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 String _inputAsString(input) { | 135 String _inputAsString(input) { |
| 136 String source; | 136 String source; |
| 137 | 137 |
| (...skipping 2805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2943 | 2943 |
| 2944 if (replace != null && result == null) { | 2944 if (replace != null && result == null) { |
| 2945 result = new StringBuffer(text.substring(0, i)); | 2945 result = new StringBuffer(text.substring(0, i)); |
| 2946 } | 2946 } |
| 2947 | 2947 |
| 2948 if (result != null) result.write(replace != null ? replace : text[i]); | 2948 if (result != null) result.write(replace != null ? replace : text[i]); |
| 2949 } | 2949 } |
| 2950 | 2950 |
| 2951 return result == null ? text : result.toString(); | 2951 return result == null ? text : result.toString(); |
| 2952 } | 2952 } |
| OLD | NEW |