91dd628bd8
Need unique name for library collision with template parser. Few more changes to work under VM. More changes for lang.dart seperation. Seperation from lang.dart (tokenizer can't access private fields of base class in another library). This was allowed in frog but not in the VM. VM is right so need to sever dependency. BUG= TEST= Review URL: https://chromiumcodereview.appspot.com//9695048 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@5544 260f80e4-7a28-3924-810f-c04153c831b5
61 lines
1.7 KiB
Dart
61 lines
1.7 KiB
Dart
// Copyright (c) 2011, 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.
|
|
|
|
/**
|
|
* A single token in the Dart language.
|
|
*/
|
|
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;
|
|
|
|
Token(this.kind, this.source, this.start, this.end) {}
|
|
|
|
Token.fake(this.kind, span)
|
|
: this.source = span.file, this.start = span.start, this.end = span.end;
|
|
|
|
/** Returns the source text corresponding to this [Token]. */
|
|
String get text() {
|
|
return source.text.substring(start, end);
|
|
}
|
|
|
|
/** Returns a pretty representation of this token for error messages. **/
|
|
String toString() {
|
|
var kindText = TokenKind.kindToString(kind);
|
|
var actualText = text;
|
|
if (kindText != actualText) {
|
|
if (actualText.length > 10) {
|
|
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);
|
|
}
|
|
|
|
/** A token containing error information. */
|
|
class ErrorToken extends Token {
|
|
String message;
|
|
ErrorToken(kind, source, start, end, this.message)
|
|
: super(kind, source, start, end);
|
|
}
|