OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 library unittest.backend.platform_selector.token; | |
6 | |
7 import 'package:source_span/source_span.dart'; | |
8 | |
9 /// A token in a platform selector. | |
10 class Token { | |
11 /// The type of the token. | |
12 final TokenType type; | |
13 | |
14 /// The span indicating where this token came from. | |
15 /// | |
16 /// This is a [FileSpan] because the tokens are parsed from a single | |
17 /// continuous string, but the string itself isn't actually a file. It might | |
Bob Nystrom
2015/03/11 20:05:52
This is confusing. Does that mean this should *not
nweiz
2015/03/12 19:48:57
No; "FileSpan" is somewhat of a misnomer. It just
| |
18 /// come from a statically-parsed annotation or from a parameter. | |
19 final FileSpan span; | |
20 | |
21 Token(this.type, this.span); | |
22 } | |
23 | |
24 /// An token representing an identifier. | |
Bob Nystrom
2015/03/11 20:05:53
"An" -> "A".
nweiz
2015/03/12 19:48:57
Done.
| |
25 class IdentifierToken implements Token { | |
26 final type = TokenType.identifier; | |
27 final FileSpan span; | |
28 | |
29 /// The name of the identifier. | |
30 final String name; | |
31 | |
32 IdentifierToken(this.name, this.span); | |
33 | |
34 String toString() => 'identifier "$name"'; | |
35 } | |
36 | |
37 /// An enumeration of types of tokens. | |
38 class TokenType { | |
Bob Nystrom
2015/03/11 20:05:53
Sigh, yet another case where enum should be used b
| |
39 /// A `(` character. | |
40 static const leftParen = const TokenType._("left paren"); | |
41 | |
42 /// A `)` character. | |
43 static const rightParen = const TokenType._("right paren"); | |
44 | |
45 /// A `||` sequence. | |
46 static const or = const TokenType._("or"); | |
47 | |
48 /// A `&&` sequence. | |
49 static const and = const TokenType._("and"); | |
50 | |
51 /// A `!` character. | |
52 static const not = const TokenType._("not"); | |
53 | |
54 /// A `?` character. | |
55 static const questionMark = const TokenType._("question mark"); | |
56 | |
57 /// A `:` character. | |
58 static const colon = const TokenType._("colon"); | |
59 | |
60 /// A named identifier. | |
61 static const identifier = const TokenType._("identifier"); | |
62 | |
63 /// The end of the selector. | |
64 static const endOfFile = const TokenType._("end of file"); | |
65 | |
66 /// The name of the token type. | |
67 final String name; | |
68 | |
69 const TokenType._(this.name); | |
70 | |
71 String toString() => name; | |
72 } | |
OLD | NEW |