Index: pkg/csslib/lib/src/token.dart |
diff --git a/utils/css/token.dart b/pkg/csslib/lib/src/token.dart |
similarity index 51% |
copy from utils/css/token.dart |
copy to pkg/csslib/lib/src/token.dart |
index 144e39c296449fea5452806edcd2e32e7cbc3ffd..cf9e376eefe26afb94dd8a200bd4bc019ef37c6f 100644 |
--- a/utils/css/token.dart |
+++ b/pkg/csslib/lib/src/token.dart |
@@ -1,7 +1,9 @@ |
-// 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. |
+part of csslib.parser; |
+ |
/** |
* A single token in the Dart language. |
*/ |
@@ -9,21 +11,19 @@ class Token { |
/** A member of [TokenKind] specifying what kind of token this is. */ |
final int kind; |
- /** The [SourceFile] this token came from. */ |
- final SourceFile source; |
- |
- /** The start and end indexes into the [SourceFile] of this [Token]. */ |
- final int start, end; |
+ /** The location where this token was parsed from. */ |
+ final Span span; |
- Token(this.kind, this.source, this.start, this.end) {} |
+ /** The start offset of this token. */ |
+ int get start => span.start.offset; |
- Token.fake(this.kind, span) |
- : this.source = span.file, this.start = span.start, this.end = span.end; |
+ /** The end offset of this token. */ |
+ int get end => span.end.offset; |
/** Returns the source text corresponding to this [Token]. */ |
- String get text { |
- return source.text.substring(start, end); |
- } |
+ String get text => span.text; |
+ |
+ Token(this.kind, this.span); |
/** Returns a pretty representation of this token for error messages. **/ |
String toString() { |
@@ -31,30 +31,23 @@ class Token { |
var actualText = text; |
if (kindText != actualText) { |
if (actualText.length > 10) { |
- actualText = actualText.substring(0, 8) + '...'; |
+ actualText = '${actualText.substring(0, 8)}...'; |
} |
return '$kindText($actualText)'; |
} else { |
return kindText; |
} |
} |
- |
- /** Returns a [SourceSpan] representing the source location. */ |
- SourceSpan get span { |
- return new SourceSpan(source, start, end); |
- } |
} |
/** A token containing a parsed literal value. */ |
class LiteralToken extends Token { |
var value; |
- LiteralToken(kind, source, start, end, this.value) |
- : super(kind, source, start, end); |
+ LiteralToken(int kind, Span span, this.value) : super(kind, span); |
} |
/** A token containing error information. */ |
class ErrorToken extends Token { |
String message; |
- ErrorToken(kind, source, start, end, this.message) |
- : super(kind, source, start, end); |
+ ErrorToken(int kind, Span span, this.message) : super(kind, span); |
} |