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