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.src.validate; | 5 library csslib.src.validate; |
6 | 6 |
7 import 'package:csslib/visitor.dart'; | 7 import 'package:csslib/visitor.dart'; |
8 import 'package:source_maps/span.dart' show Span; | 8 import 'package:source_span/source_span.dart'; |
9 | 9 |
10 /** Can be thrown on any Css runtime problem includes source location. */ | 10 /** Can be thrown on any Css runtime problem includes source location. */ |
11 class CssSelectorException implements Exception { | 11 class CssSelectorException extends SourceSpanException { |
12 final String _message; | 12 CssSelectorException(String message, [SourceSpan span]) |
13 final Span _span; | 13 : super(message, span); |
14 | |
15 CssSelectorException(this._message, [this._span]); | |
16 | |
17 String toString() { | |
18 var msg = _span == null ? _message : _span.getLocationMessage(_message); | |
19 return 'CssSelectorException: $msg'; | |
20 } | |
21 } | 14 } |
22 | 15 |
23 List<String> classes = []; | 16 List<String> classes = []; |
24 List<String> ids = []; | 17 List<String> ids = []; |
25 | 18 |
26 class Validate { | 19 class Validate { |
27 static int _classNameCheck(var selector, int matches) { | 20 static int _classNameCheck(var selector, int matches) { |
28 if (selector.isCombinatorDescendant() || | 21 if (selector.isCombinatorDescendant() || |
29 (selector.isCombinatorNone() && matches == 0)) { | 22 (selector.isCombinatorNone() && matches == 0)) { |
30 if (matches < 0) { | 23 if (matches < 0) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 118 } |
126 } | 119 } |
127 | 120 |
128 // Every selector must match. | 121 // Every selector must match. |
129 Selector selector = selectors[0]; | 122 Selector selector = selectors[0]; |
130 assert((matches >= 0 ? matches : -matches) == | 123 assert((matches >= 0 ? matches : -matches) == |
131 selector.simpleSelectorSequences.length); | 124 selector.simpleSelectorSequences.length); |
132 } | 125 } |
133 } | 126 } |
134 | 127 |
OLD | NEW |