| 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_maps/span.dart' show SourceFile, Span, FileSpan; | 9 import 'package:source_maps/span.dart' show SourceFile, Span, FileSpan; |
| 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 part 'src/analyzer.dart'; | 15 part 'src/analyzer.dart'; |
| 16 part 'src/polyfill.dart'; |
| 16 part 'src/property.dart'; | 17 part 'src/property.dart'; |
| 17 part 'src/token.dart'; | 18 part 'src/token.dart'; |
| 18 part 'src/tokenizer_base.dart'; | 19 part 'src/tokenizer_base.dart'; |
| 19 part 'src/tokenizer.dart'; | 20 part 'src/tokenizer.dart'; |
| 20 part 'src/tokenkind.dart'; | 21 part 'src/tokenkind.dart'; |
| 21 | 22 |
| 22 | 23 |
| 23 /** Used for parser lookup ahead (used for nested selectors Less support). */ | 24 /** Used for parser lookup ahead (used for nested selectors Less support). */ |
| 24 class ParserState extends TokenizerState { | 25 class ParserState extends TokenizerState { |
| 25 final Token peekToken; | 26 final Token peekToken; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 } | 38 } |
| 38 var opt = PreprocessorOptions.parse(options); | 39 var opt = PreprocessorOptions.parse(options); |
| 39 messages = new Messages(options: opt, printHandler: errors.add); | 40 messages = new Messages(options: opt, printHandler: errors.add); |
| 40 } | 41 } |
| 41 | 42 |
| 42 /** CSS checked mode enabled. */ | 43 /** CSS checked mode enabled. */ |
| 43 bool get isChecked => messages.options.checked; | 44 bool get isChecked => messages.options.checked; |
| 44 | 45 |
| 45 // TODO(terry): Remove nested name parameter. | 46 // TODO(terry): Remove nested name parameter. |
| 46 /** Parse and analyze the CSS file. */ | 47 /** Parse and analyze the CSS file. */ |
| 47 StyleSheet compile(var input, {List errors, List options, bool nested: true}) { | 48 StyleSheet compile(var input, |
| 49 {List errors, List options, bool nested: true, bool polyfill: false}) { |
| 48 var source = _inputAsString(input); | 50 var source = _inputAsString(input); |
| 49 | 51 |
| 50 _createMessages(errors: errors, options: options); | 52 _createMessages(errors: errors, options: options); |
| 51 | 53 |
| 52 var file = new SourceFile.text(null, source); | 54 var file = new SourceFile.text(null, source); |
| 53 | 55 |
| 54 var tree = new Parser(file, source).parse(); | 56 var tree = new Parser(file, source).parse(); |
| 55 | 57 |
| 56 analyze([tree], errors: errors, options: options); | 58 analyze([tree], errors: errors, options: options); |
| 57 | 59 |
| 60 if (polyfill) { |
| 61 var processCss = new PolyFill(messages, true); |
| 62 processCss.process(tree); |
| 63 } |
| 64 |
| 58 return tree; | 65 return tree; |
| 59 } | 66 } |
| 60 | 67 |
| 61 /** Analyze the CSS file. */ | 68 /** Analyze the CSS file. */ |
| 62 void analyze(List<StyleSheet> styleSheets, {List errors, List options}) { | 69 void analyze(List<StyleSheet> styleSheets, {List errors, List options}) { |
| 63 _createMessages(errors: errors, options: options); | 70 _createMessages(errors: errors, options: options); |
| 64 new Analyzer(styleSheets, messages).run(); | 71 new Analyzer(styleSheets, messages).run(); |
| 65 } | 72 } |
| 66 | 73 |
| 67 /** | 74 /** |
| (...skipping 2325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2393 | 2400 |
| 2394 if (replace != null && result == null) { | 2401 if (replace != null && result == null) { |
| 2395 result = new StringBuffer(text.substring(0, i)); | 2402 result = new StringBuffer(text.substring(0, i)); |
| 2396 } | 2403 } |
| 2397 | 2404 |
| 2398 if (result != null) result.write(replace != null ? replace : text[i]); | 2405 if (result != null) result.write(replace != null ? replace : text[i]); |
| 2399 } | 2406 } |
| 2400 | 2407 |
| 2401 return result == null ? text : result.toString(); | 2408 return result == null ? text : result.toString(); |
| 2402 } | 2409 } |
| OLD | NEW |