| 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"; | 11 import "visitor.dart"; |
| 12 import 'src/messages.dart'; | 12 import 'src/messages.dart'; |
| 13 import 'src/options.dart'; | 13 import 'src/options.dart'; |
| 14 | 14 |
| 15 export 'src/options.dart'; |
| 16 |
| 15 part 'src/analyzer.dart'; | 17 part 'src/analyzer.dart'; |
| 16 part 'src/polyfill.dart'; | 18 part 'src/polyfill.dart'; |
| 17 part 'src/property.dart'; | 19 part 'src/property.dart'; |
| 18 part 'src/token.dart'; | 20 part 'src/token.dart'; |
| 19 part 'src/tokenizer_base.dart'; | 21 part 'src/tokenizer_base.dart'; |
| 20 part 'src/tokenizer.dart'; | 22 part 'src/tokenizer.dart'; |
| 21 part 'src/tokenkind.dart'; | 23 part 'src/tokenkind.dart'; |
| 22 | 24 |
| 23 /** Used for parser lookup ahead (used for nested selectors Less support). */ | 25 /** Used for parser lookup ahead (used for nested selectors Less support). */ |
| 24 class ParserState extends TokenizerState { | 26 class ParserState extends TokenizerState { |
| 25 final Token peekToken; | 27 final Token peekToken; |
| 26 final Token previousToken; | 28 final Token previousToken; |
| 27 | 29 |
| 28 ParserState(this.peekToken, this.previousToken, Tokenizer tokenizer) | 30 ParserState(this.peekToken, this.previousToken, Tokenizer tokenizer) |
| 29 : super(tokenizer); | 31 : super(tokenizer); |
| 30 } | 32 } |
| 31 | 33 |
| 32 // TODO(jmesserly): this should not be global | 34 // TODO(jmesserly): this should not be global |
| 33 void _createMessages({List<Message> errors, List<String> options}) { | 35 void _createMessages({List<Message> errors, PreprocessorOptions options}) { |
| 34 if (errors == null) errors = []; | 36 if (errors == null) errors = []; |
| 35 | 37 |
| 36 if (options == null) { | 38 if (options == null) { |
| 37 options = ['--no-colors', 'memory']; | 39 options = new PreprocessorOptions(useColors: false, inputFile: 'memory'); |
| 38 } | 40 } |
| 39 var opt = PreprocessorOptions.parse(options); | 41 |
| 40 messages = new Messages(options: opt, printHandler: errors.add); | 42 messages = new Messages(options: options, printHandler: errors.add); |
| 41 } | 43 } |
| 42 | 44 |
| 43 /** CSS checked mode enabled. */ | 45 /** CSS checked mode enabled. */ |
| 44 bool get isChecked => messages.options.checked; | 46 bool get isChecked => messages.options.checked; |
| 45 | 47 |
| 46 // TODO(terry): Remove nested name parameter. | 48 // TODO(terry): Remove nested name parameter. |
| 47 /** Parse and analyze the CSS file. */ | 49 /** Parse and analyze the CSS file. */ |
| 48 StyleSheet compile(input, {List<Message> errors, List<String> options, | 50 StyleSheet compile(input, {List<Message> errors, PreprocessorOptions options, |
| 49 bool nested: true, bool polyfill: false, List<StyleSheet> includes: null}) { | 51 bool nested: true, bool polyfill: false, List<StyleSheet> includes: null}) { |
| 50 if (includes == null) { | 52 if (includes == null) { |
| 51 includes = []; | 53 includes = []; |
| 52 } | 54 } |
| 53 | 55 |
| 54 var source = _inputAsString(input); | 56 var source = _inputAsString(input); |
| 55 | 57 |
| 56 _createMessages(errors: errors, options: options); | 58 _createMessages(errors: errors, options: options); |
| 57 | 59 |
| 58 var file = new SourceFile(source); | 60 var file = new SourceFile(source); |
| 59 | 61 |
| 60 var tree = new _Parser(file, source).parse(); | 62 var tree = new _Parser(file, source).parse(); |
| 61 | 63 |
| 62 analyze([tree], errors: errors, options: options); | 64 analyze([tree], errors: errors, options: options); |
| 63 | 65 |
| 64 if (polyfill) { | 66 if (polyfill) { |
| 65 var processCss = new PolyFill(messages, true); | 67 var processCss = new PolyFill(messages, true); |
| 66 processCss.process(tree, includes: includes); | 68 processCss.process(tree, includes: includes); |
| 67 } | 69 } |
| 68 | 70 |
| 69 return tree; | 71 return tree; |
| 70 } | 72 } |
| 71 | 73 |
| 72 /** Analyze the CSS file. */ | 74 /** Analyze the CSS file. */ |
| 73 void analyze(List<StyleSheet> styleSheets, | 75 void analyze(List<StyleSheet> styleSheets, |
| 74 {List<Message> errors, List<String> options}) { | 76 {List<Message> errors, PreprocessorOptions options}) { |
| 75 _createMessages(errors: errors, options: options); | 77 _createMessages(errors: errors, options: options); |
| 76 new Analyzer(styleSheets, messages).run(); | 78 new Analyzer(styleSheets, messages).run(); |
| 77 } | 79 } |
| 78 | 80 |
| 79 /** | 81 /** |
| 80 * Parse the [input] CSS stylesheet into a tree. The [input] can be a [String], | 82 * Parse the [input] CSS stylesheet into a tree. The [input] can be a [String], |
| 81 * or [List<int>] of bytes and returns a [StyleSheet] AST. The optional | 83 * or [List<int>] of bytes and returns a [StyleSheet] AST. The optional |
| 82 * [errors] list will contain each error/warning as a [Message]. | 84 * [errors] list will contain each error/warning as a [Message]. |
| 83 */ | 85 */ |
| 84 StyleSheet parse(input, {List<Message> errors, List<String> options}) { | 86 StyleSheet parse(input, {List<Message> errors, PreprocessorOptions options}) { |
| 85 var source = _inputAsString(input); | 87 var source = _inputAsString(input); |
| 86 | 88 |
| 87 _createMessages(errors: errors, options: options); | 89 _createMessages(errors: errors, options: options); |
| 88 | 90 |
| 89 var file = new SourceFile(source); | 91 var file = new SourceFile(source); |
| 90 return new _Parser(file, source).parse(); | 92 return new _Parser(file, source).parse(); |
| 91 } | 93 } |
| 92 | 94 |
| 93 /** | 95 /** |
| 94 * Parse the [input] CSS selector into a tree. The [input] can be a [String], | 96 * Parse the [input] CSS selector into a tree. The [input] can be a [String], |
| (...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2688 | 2690 |
| 2689 if (replace != null && result == null) { | 2691 if (replace != null && result == null) { |
| 2690 result = new StringBuffer(text.substring(0, i)); | 2692 result = new StringBuffer(text.substring(0, i)); |
| 2691 } | 2693 } |
| 2692 | 2694 |
| 2693 if (result != null) result.write(replace != null ? replace : text[i]); | 2695 if (result != null) result.write(replace != null ? replace : text[i]); |
| 2694 } | 2696 } |
| 2695 | 2697 |
| 2696 return result == null ? text : result.toString(); | 2698 return result == null ? text : result.toString(); |
| 2697 } | 2699 } |
| OLD | NEW |