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 |
| 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 /// A token representing an identifier. |
| 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 { |
| 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 |