Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: pkg/front_end/lib/src/fasta/parser/identifier_context.dart

Issue 2711463005: Add contextual information about identifiers to the parser listener API. (Closed)
Patch Set: Fix broken import Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 /// Information about the parser state which is passed to the listener at the
6 /// time an identifier is encountered.
7 ///
8 /// This can be used by the listener to determine the context in which the
9 /// identifier appears; that in turn can help the listener decide how to resolve
10 /// the identifier (if the listener is doing resolution).
11 class IdentifierContext {
12 /// Identifier is being declared as the name of an import prefix (i.e. `Foo`
13 /// in `import "..." as Foo;`)
14 static const importPrefixDeclaration =
15 const IdentifierContext._('importPrefixDeclaration');
16
17 /// Identifier is the start of a dotted name in a conditional import or
18 /// export.
19 static const dottedName = const IdentifierContext._('dottedName');
20
21 /// Identifier is part of a dotted name in a conditional import or export, but
22 /// it's not the first identifier of the dotted name.
23 static const dottedNameContinuation =
24 const IdentifierContext._('dottedNameContinuation', isContinuation: true);
25
26 /// Identifier is one of the shown/hidden names in an import/export
27 /// combinator.
28 static const combinator = const IdentifierContext._('combinator');
29
30 /// Identifier is the start of a name in an annotation that precedes a
31 /// declaration (i.e. it appears directly after an `@`).
32 static const metadataReference =
33 const IdentifierContext._('metadataReference', isScopeReference: true);
34
35 /// Identifier is part of a name in an annotation that precedes a declaration,
36 /// but it's not the first identifier in the name.
37 static const metadataContinuation =
38 const IdentifierContext._('metadataContinuation', isContinuation: true);
39
40 /// Identifier is part of a name in an annotation that precedes a declaration,
41 /// but it appears after type parameters (e.g. `foo` in `@X<Y>.foo()`).
42 static const metadataContinuationAfterTypeArguments =
43 const IdentifierContext._('metadataContinuationAfterTypeArguments',
44 isContinuation: true);
45
46 /// Identifier is the name being declared by a typedef declaration.
47 static const typedefDeclaration =
48 const IdentifierContext._('typedefDeclaration');
49
50 /// Identifier is a field initializer in a formal parameter list (i.e. it
51 /// appears directly after `this.`).
52 static const fieldInitializer =
53 const IdentifierContext._('fieldInitializer', isContinuation: true);
54
55 /// Identifier is a formal parameter being declared as part of a function,
56 /// method, or typedef declaration.
57 static const formalParameterDeclaration =
58 const IdentifierContext._('formalParameterDeclaration');
59
60 /// Identifier is the start of a library name (e.g. `foo` in the directive
61 /// 'library foo;`).
62 static const libraryName = const IdentifierContext._('libraryName',
63 inLibraryOrPartOfDeclaration: true);
64
65 /// Identifier is part of a library name, but it's not the first identifier in
66 /// the name.
67 static const libraryNameContinuation = const IdentifierContext._(
68 'libraryNameContinuation',
69 inLibraryOrPartOfDeclaration: true,
70 isContinuation: true);
71
72 /// Identifier is the start of a library name referenced by a `part of`
73 /// directive (e.g. `foo` in the directive `part of foo;`).
74 static const partName =
75 const IdentifierContext._('partName', inLibraryOrPartOfDeclaration: true);
76
77 /// Identifier is part of a library name referenced by a `part of` directive,
78 /// but it's not the first identifier in the name.
79 static const partNameContinuation = const IdentifierContext._(
80 'partNameContinuation',
81 inLibraryOrPartOfDeclaration: true,
82 isContinuation: true);
83
84 /// Identifier is the type name being declared by an enum declaration.
85 static const enumDeclaration = const IdentifierContext._('enumDeclaration');
86
87 /// Identifier is an enumerated value name being declared by an enum
88 /// declaration.
89 static const enumValueDeclaration =
90 const IdentifierContext._('enumValueDeclaration');
91
92 /// Identifier is the name being declared by a named mixin declaration (e.g.
93 /// `Foo` in `class Foo = X with Y;`).
94 static const namedMixinDeclaration =
95 const IdentifierContext._('namedMixinDeclaration');
96
97 /// Identifier is the name being declared by a class declaration.
98 static const classDeclaration = const IdentifierContext._('classDeclaration');
99
100 /// Identifier is the name of a type variable being declared (e.g. `Foo` in
101 /// `class C<Foo extends num> {}`).
102 static const typeVariableDeclaration =
103 const IdentifierContext._('typeVariableDeclaration');
104
105 /// Identifier is the start of a reference to a type declared elsewhere.
106 static const typeReference =
107 const IdentifierContext._('typeReference', isScopeReference: true);
108
109 /// Identifier is part of a reference to a type declared elsewhere, but it's
110 /// not the first identifier of the reference.
111 static const typeReferenceContinuation = const IdentifierContext._(
112 'typeReferenceContinuation',
113 isContinuation: true);
114
115 /// Identifier is a name being declared by a top level variable declaration.
116 static const topLevelVariableDeclaration =
117 const IdentifierContext._('topLevelVariableDeclaration');
118
119 /// Identifier is a name being declared by a field declaration.
120 static const fieldDeclaration = const IdentifierContext._('fieldDeclaration');
121
122 /// Identifier is the name being declared by a top level function declaration.
123 static const topLevelFunctionDeclaration =
124 const IdentifierContext._('topLevelFunctionDeclaration');
125
126 /// Identifier is the start of the name being declared by a method
127 /// declaration.
128 static const methodDeclaration =
129 const IdentifierContext._('methodDeclaration');
130
131 /// Identifier is part of the name being declared by a method declaration,
132 /// but it's not the first identifier of the name.
133 ///
134 /// In valid Dart, this can only happen if the identifier is the name of a
135 /// named constructor which is being declared, e.g. `foo` in
136 /// `class C { C.foo(); }`.
137 static const methodDeclarationContinuation = const IdentifierContext._(
138 'methodDeclarationContinuation',
139 isContinuation: true);
140
141 /// Identifier appears after the word `operator` in a method declaration.
142 ///
143 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only
144 /// occur as part of error recovery? If it's only as part of error recovery,
145 /// perhaps we should just re-use methodDeclaration.
146 static const operatorName = const IdentifierContext._('operatorName');
147
148 /// Identifier is the name being declared by a local function declaration that
149 /// uses a "get" or "set" keyword.
150 ///
151 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only
152 /// occur as part of error recovery? If it's only as part of error recovery,
153 /// perhaps we should just re-use localFunctionDeclaration.
154 static const localAccessorDeclaration =
155 const IdentifierContext._('localAccessorDeclaration');
156
157 /// Identifier is the start of the name being declared by a local function
158 /// declaration.
159 static const localFunctionDeclaration =
160 const IdentifierContext._('localFunctionDeclaration');
161
162 /// Identifier is part of the name being declared by a local function
163 /// declaration, but it's not the first identifier of the name.
164 ///
165 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only
166 /// occur as part of error recovery?
167 static const localFunctionDeclarationContinuation = const IdentifierContext._(
168 'localFunctionDeclarationContinuation',
169 isContinuation: true);
170
171 /// Identifier is the name appearing in a function exrpession.
172 ///
173 /// TODO(paulberry,ahe): What is an example of valid Dart code where this
174 /// would occur?
175 static const functionExpressionName =
176 const IdentifierContext._('functionExpressionName');
177
178 /// Identifier is the start of a reference to a constructor declared
179 /// elsewhere.
180 static const constructorReference =
181 const IdentifierContext._('constructorReference', isScopeReference: true);
182
183 /// Identifier is part of a reference to a constructor declared elsewhere, but
184 /// it's not the first identifier of the reference.
185 static const constructorReferenceContinuation = const IdentifierContext._(
186 'constructorReferenceContinuation',
187 isContinuation: true);
188
189 /// Identifier is part of a reference to a constructor declared elsewhere, but
190 /// it appears after type parameters (e.g. `foo` in `X<Y>.foo`).
191 static const constructorReferenceContinuationAfterTypeArguments =
192 const IdentifierContext._(
193 'constructorReferenceContinuationAfterTypeArguments',
194 isContinuation: true);
195
196 /// Identifier is the declaration of a label (i.e. it is followed by `:` and
197 /// then a statement).
198 static const labelDeclaration = const IdentifierContext._('labelDeclaration');
199
200 /// Identifier is the start of a reference occurring in a literal symbol (e.g.
201 /// `foo` in `#foo`).
202 static const literalSymbol =
203 const IdentifierContext._('literalSymbol', isScopeReference: true);
204
205 /// Identifier is part of a reference occurring in a literal symbol, but it's
206 /// not the first identifier of the reference (e.g. `foo` in `#prefix.foo`).
207 static const literalSymbolContinuation = const IdentifierContext._(
208 'literalSymbolContinuation',
209 isContinuation: true);
210
211 /// Identifier appears in an expression, and it does not immediately follow a
212 /// `.`.
213 static const expression =
214 const IdentifierContext._('expression', isScopeReference: true);
215
216 /// Identifier appears in an expression, and it immediately follows a `.`.
217 static const expressionContinuation =
218 const IdentifierContext._('expressionContinuation', isContinuation: true);
219
220 /// Identifier is a reference to a named argument of a function or method
221 /// invocation (e.g. `foo` in `f(foo: 0);`.
222 static const namedArgumentReference =
223 const IdentifierContext._('namedArgumentReference');
224
225 /// Identifier is a name being declared by a local variable declaration.
226 static const localVariableDeclaration =
227 const IdentifierContext._('localVariableDeclaration');
228
229 /// Identifier is a reference to a label (e.g. `foo` in `break foo;`).
230 static const labelReference =
231 const IdentifierContext._('labelReference', isScopeReference: true);
232
233 final String _name;
234
235 /// Indicates whether the identifier is within a `library` or `part of`
236 /// declaration.
237 final bool inLibraryOrPartOfDeclaration;
238
239 /// Indicates whether the identifier follows a `.`.
240 final bool isContinuation;
241
242 /// Indicates whether the identifier should be looked up in the current scope.
243 final bool isScopeReference;
244
245 const IdentifierContext._(this._name,
246 {this.inLibraryOrPartOfDeclaration: false,
247 this.isContinuation: false,
248 this.isScopeReference: false});
249
250 String toString() => _name;
251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698