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