Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Unified Diff: pkg/csslib/lib/src/validate.dart

Issue 23168002: move csslib into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/csslib/lib/src/tree_printer.dart ('k') | pkg/csslib/lib/visitor.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/csslib/lib/src/validate.dart
diff --git a/utils/css/validate.dart b/pkg/csslib/lib/src/validate.dart
similarity index 83%
copy from utils/css/validate.dart
copy to pkg/csslib/lib/src/validate.dart
index 9babe3d3c0911ab077ba6e69e438a30785ed6159..d2301d79d070b1cf5ada0a36fe475d83c5dc883e 100644
--- a/utils/css/validate.dart
+++ b/pkg/csslib/lib/src/validate.dart
@@ -1,7 +1,29 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+library csslib.src.validate;
+
+import 'package:csslib/parser.dart';
+import 'package:csslib/visitor.dart';
+import 'package:source_maps/span.dart' show Span;
+
+/** Can be thrown on any Css runtime problem includes source location. */
+class CssSelectorException implements Exception {
+ final String _message;
+ final Span _span;
+
+ CssSelectorException(this._message, [this._span]);
+
+ String toString() {
+ var msg = _span == null ? _message : _span.getLocationMessage(_message);
+ return 'CssSelectorException: $msg';
+ }
+}
+
+List<String> classes = [];
+List<String> ids = [];
+
class Validate {
static int _classNameCheck(var selector, int matches) {
if (selector.isCombinatorDescendant() ||
@@ -9,10 +31,10 @@ class Validate {
if (matches < 0) {
String tooMany = selector.simpleSelector.toString();
throw new CssSelectorException(
- 'Can not mix Id selector with class selector(s). Id ' +
+ 'Can not mix Id selector with class selector(s). Id '
'selector must be singleton too many starting at $tooMany');
}
-
+
return matches + 1;
} else {
String error = selector.toString();
@@ -38,7 +60,7 @@ class Validate {
// Validate the @{css expression} only .class and #elementId are valid inside
// of @{...}.
- static template(List<ASTNode> selectors, CssWorld cssWorld) {
+ static template(List<Selector> selectors) {
var errorSelector; // signal which selector didn't match.
bool found = false; // signal if a selector is matched.
int matches = 0; // < 0 IdSelectors, > 0 ClassSelector
@@ -56,13 +78,13 @@ class Validate {
if (!simpleSelector.name.startsWith('_')) {
// TODO(terry): For now iterate through all classes look for faster
// mechanism hash map, etc.
- for (final className in cssWorld.classes) {
+ for (final className in classes) {
if (selector.simpleSelector.name == className) {
matches = _classNameCheck(selector, matches);
found = true; // .class found.
break;
}
- for (final className2 in cssWorld.classes) {
+ for (final className2 in classes) {
print(className2);
}
}
@@ -78,7 +100,7 @@ class Validate {
// Any element id starting with an underscore is a private element id
// that doesn't have to match the world of known elemtn ids.
if (!simpleSelector.name.startsWith('_')) {
- for (final id in cssWorld.ids) {
+ for (final id in ids) {
if (simpleSelector.name == id) {
matches = _elementIdCheck(selector, matches);
found = true; // #id found.
@@ -105,7 +127,7 @@ class Validate {
}
// Every selector must match.
- var selector = selectors[0];
+ Selector selector = selectors[0];
assert((matches >= 0 ? matches : -matches) ==
selector.simpleSelectorSequences.length);
}
« no previous file with comments | « pkg/csslib/lib/src/tree_printer.dart ('k') | pkg/csslib/lib/visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698