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 part of csslib.parser; | 5 part of csslib.parser; |
6 | 6 |
7 /** | 7 /** |
8 * A single token in the Dart language. | 8 * A single token in the Dart language. |
9 */ | 9 */ |
10 class Token { | 10 class Token { |
(...skipping 10 matching lines...) Expand all Loading... |
21 int get end => span.end.offset; | 21 int get end => span.end.offset; |
22 | 22 |
23 /** Returns the source text corresponding to this [Token]. */ | 23 /** Returns the source text corresponding to this [Token]. */ |
24 String get text => span.text; | 24 String get text => span.text; |
25 | 25 |
26 Token(this.kind, this.span); | 26 Token(this.kind, this.span); |
27 | 27 |
28 /** Returns a pretty representation of this token for error messages. **/ | 28 /** Returns a pretty representation of this token for error messages. **/ |
29 String toString() { | 29 String toString() { |
30 var kindText = TokenKind.kindToString(kind); | 30 var kindText = TokenKind.kindToString(kind); |
31 var actualText = text; | 31 var actualText = text.trim(); |
32 if (kindText != actualText) { | 32 if (kindText != actualText) { |
33 if (actualText.length > 10) { | 33 if (actualText.length > 10) { |
34 actualText = '${actualText.substring(0, 8)}...'; | 34 actualText = '${actualText.substring(0, 8)}...'; |
35 } | 35 } |
36 return '$kindText($actualText)'; | 36 return '$kindText($actualText)'; |
37 } else { | 37 } else { |
38 return kindText; | 38 return kindText; |
39 } | 39 } |
40 } | 40 } |
41 } | 41 } |
(...skipping 15 matching lines...) Expand all Loading... |
57 * | 57 * |
58 * See <http://dev.w3.org/csswg/css-syntax/#typedef-ident-token> and | 58 * See <http://dev.w3.org/csswg/css-syntax/#typedef-ident-token> and |
59 * <http://dev.w3.org/csswg/css-syntax/#ident-token-diagram>. | 59 * <http://dev.w3.org/csswg/css-syntax/#ident-token-diagram>. |
60 */ | 60 */ |
61 class IdentifierToken extends Token { | 61 class IdentifierToken extends Token { |
62 final String text; | 62 final String text; |
63 | 63 |
64 IdentifierToken(this.text, int kind, SourceSpan span) | 64 IdentifierToken(this.text, int kind, SourceSpan span) |
65 : super(kind, span); | 65 : super(kind, span); |
66 } | 66 } |
OLD | NEW |