OLD | NEW |
---|---|
(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 library fasta.parser.type_continuation; | |
6 | |
7 import '../problems.dart' show unhandled; | |
ahe
2017/07/18 10:13:38
This import causes the parser to depend on Compile
| |
8 | |
9 import 'formal_parameter_kind.dart' show FormalParameterKind; | |
10 | |
11 /// Indication of how the parser should continue after (attempting) to parse a | |
12 /// type. | |
13 /// | |
14 /// Depending on the continuation, the parser may not parse a type at all. | |
15 enum TypeContinuation { | |
16 /// Indicates that a type is unconditionally expected. | |
17 Required, | |
18 | |
19 /// Indicates that a type may follow. If the following matches one of these | |
20 /// productions, it is parsed as a type: | |
21 /// | |
22 /// - `'void'` | |
23 /// - `'Function' ( '(' | '<' )` | |
24 /// - `identifier ('.' identifier)? ('<' ... '>')? identifer` | |
25 /// | |
26 /// Otherwise, do nothing. | |
27 Optional, | |
28 | |
29 /// Same as [Optional], but we have seen `var`. | |
30 OptionalAfterVar, | |
31 | |
32 /// Indicates that the keyword `typedef` has just been seen, and the parser | |
33 /// should parse the following as a type unless it is followed by `=`. | |
34 Typedef, | |
35 | |
36 /// Indicates that what follows is either a local declaration or an | |
37 /// expression. | |
38 ExpressionStatementOrDeclaration, | |
39 | |
40 /// Indicates that the keyword `const` has just been seen, and what follows | |
41 /// may be a local variable declaration or an expression. | |
42 ExpressionStatementOrConstDeclaration, | |
43 | |
44 /// Indicates that the parser is parsing an expression and has just seen an | |
45 /// identifier. | |
46 SendOrFunctionLiteral, | |
47 | |
48 /// Indicates that the parser has just parsed `for '('` and is looking to | |
49 /// parse a variable declaration or expression. | |
50 VariablesDeclarationOrExpression, | |
51 | |
52 /// Indicates that an optional type followed by a normal formal parameter is | |
53 /// expected. | |
54 NormalFormalParameter, | |
55 | |
56 /// Indicates that an optional type followed by an optional positional formal | |
57 /// parameter is expected. | |
58 OptionalPositionalFormalParameter, | |
59 | |
60 /// Indicates that an optional type followed by a named formal parameter is | |
61 /// expected. | |
62 NamedFormalParameter, | |
63 | |
64 /// Same as [NormalFormalParameter], but we have seen `var`. | |
65 NormalFormalParameterAfterVar, | |
66 | |
67 /// Same as [OptionalPositionalFormalParameter], but we have seen `var`. | |
68 OptionalPositionalFormalParameterAfterVar, | |
69 | |
70 /// Same as [NamedFormalParameter], but we have seen `var`. | |
71 NamedFormalParameterAfterVar, | |
72 } | |
73 | |
74 TypeContinuation typeContiunationFromFormalParameterKind( | |
75 FormalParameterKind type) { | |
76 if (type == null) return null; | |
77 switch (type) { | |
78 case FormalParameterKind.mandatory: | |
79 return TypeContinuation.NormalFormalParameter; | |
80 | |
81 case FormalParameterKind.optionalNamed: | |
82 return TypeContinuation.NamedFormalParameter; | |
83 | |
84 case FormalParameterKind.optionalPositional: | |
85 return TypeContinuation.OptionalPositionalFormalParameter; | |
86 } | |
87 return unhandled( | |
88 "$type", "typeContiunationFromFormalParameterKind", -1, null); | |
89 } | |
OLD | NEW |