OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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 yaml.token; | |
6 | |
7 import 'package:source_span/source_span.dart'; | |
8 | |
9 import 'style.dart'; | |
10 | |
11 /// A token emitted by a [Scanner]. | |
12 class Token { | |
13 /// The token type. | |
14 final TokenType type; | |
15 | |
16 /// The span associated with the token. | |
17 final FileSpan span; | |
18 | |
19 Token(this.type, this.span); | |
20 | |
21 String toString() => type.toString(); | |
22 } | |
23 | |
24 /// A token representing a `%YAML` directive. | |
25 class VersionDirectiveToken implements Token { | |
26 get type => TokenType.VERSION_DIRECTIVE; | |
27 final FileSpan span; | |
28 | |
29 /// The declared major version of the document. | |
30 final int major; | |
31 | |
32 /// The declared minor version of the document. | |
33 final int minor; | |
34 | |
35 VersionDirectiveToken(this.span, this.major, this.minor); | |
36 | |
37 String toString() => "VERSION_DIRECTIVE $major.$minor"; | |
38 } | |
39 | |
40 /// A token representing a `%TAG` directive. | |
41 class TagDirectiveToken implements Token { | |
42 get type => TokenType.TAG_DIRECTIVE; | |
43 final FileSpan span; | |
44 | |
45 /// The tag handle used in the document. | |
46 final String handle; | |
47 | |
48 /// The tag prefix that the handle maps to. | |
49 final String prefix; | |
50 | |
51 TagDirectiveToken(this.span, this.handle, this.prefix); | |
52 | |
53 String toString() => "TAG_DIRECTIVE $handle $prefix"; | |
54 } | |
55 | |
56 /// A token representing an anchor (`&foo`). | |
57 class AnchorToken implements Token { | |
58 get type => TokenType.ANCHOR; | |
59 final FileSpan span; | |
60 | |
61 /// The name of the anchor. | |
62 final String name; | |
63 | |
64 AnchorToken(this.span, this.name); | |
65 | |
66 String toString() => "ANCHOR $name"; | |
67 } | |
68 | |
69 /// A token representing an alias (`*foo`). | |
70 class AliasToken implements Token { | |
71 get type => TokenType.ALIAS; | |
72 final FileSpan span; | |
73 | |
74 /// The name of the anchor. | |
75 final String name; | |
76 | |
77 AliasToken(this.span, this.name); | |
78 | |
79 String toString() => "ALIAS $name"; | |
80 } | |
81 | |
82 /// A token representing a tag (`!foo`). | |
83 class TagToken implements Token { | |
84 get type => TokenType.TAG; | |
85 final FileSpan span; | |
86 | |
87 /// The tag handle. | |
88 final String handle; | |
89 | |
90 /// The tag suffix, or `null`. | |
91 final String suffix; | |
92 | |
93 TagToken(this.span, this.handle, this.suffix); | |
94 | |
95 String toString() => "TAG $handle $suffix"; | |
96 } | |
97 | |
98 /// A tkoen representing a scalar value. | |
99 class ScalarToken implements Token { | |
100 get type => TokenType.SCALAR; | |
101 final FileSpan span; | |
102 | |
103 /// The contents of the scalar. | |
104 final String value; | |
105 | |
106 /// The style of the scalar in the original source. | |
107 final ScalarStyle style; | |
108 | |
109 ScalarToken(this.span, this.value, this.style); | |
110 | |
111 String toString() => "SCALAR $style \"$value\""; | |
112 } | |
113 | |
114 /// An enum of types of [Token] object. | |
115 class TokenType { | |
116 static const STREAM_START = const TokenType._("STREAM_START"); | |
117 static const STREAM_END = const TokenType._("STREAM_END"); | |
118 | |
119 static const VERSION_DIRECTIVE = const TokenType._("VERSION_DIRECTIVE"); | |
120 static const TAG_DIRECTIVE = const TokenType._("TAG_DIRECTIVE"); | |
121 static const DOCUMENT_START = const TokenType._("DOCUMENT_START"); | |
122 static const DOCUMENT_END = const TokenType._("DOCUMENT_END"); | |
123 | |
124 static const BLOCK_SEQUENCE_START = const TokenType._("BLOCK_SEQUENCE_START"); | |
125 static const BLOCK_MAPPING_START = const TokenType._("BLOCK_MAPPING_START"); | |
126 static const BLOCK_END = const TokenType._("BLOCK_END"); | |
127 | |
128 static const FLOW_SEQUENCE_START = const TokenType._("FLOW_SEQUENCE_START"); | |
129 static const FLOW_SEQUENCE_END = const TokenType._("FLOW_SEQUENCE_END"); | |
130 static const FLOW_MAPPING_START = const TokenType._("FLOW_MAPPING_START"); | |
131 static const FLOW_MAPPING_END = const TokenType._("FLOW_MAPPING_END"); | |
132 | |
133 static const BLOCK_ENTRY = const TokenType._("BLOCK_ENTRY"); | |
134 static const FLOW_ENTRY = const TokenType._("FLOW_ENTRY"); | |
135 static const KEY = const TokenType._("KEY"); | |
136 static const VALUE = const TokenType._("VALUE"); | |
137 | |
138 static const ALIAS = const TokenType._("ALIAS"); | |
139 static const ANCHOR = const TokenType._("ANCHOR"); | |
140 static const TAG = const TokenType._("TAG"); | |
141 static const SCALAR = const TokenType._("SCALAR"); | |
142 | |
143 final String name; | |
144 | |
145 const TokenType._(this.name); | |
146 | |
147 String toString() => name; | |
148 } | |
OLD | NEW |