| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 | 3 |
| 4 library engine.parser; | 4 library engine.parser; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'java_core.dart'; | 7 import 'java_core.dart'; |
| 8 import 'java_engine.dart'; | 8 import 'java_engine.dart'; |
| 9 import 'instrumentation.dart'; | 9 import 'instrumentation.dart'; |
| 10 import 'error.dart'; | 10 import 'error.dart'; |
| 11 import 'source.dart'; | 11 import 'source.dart'; |
| 12 import 'scanner.dart'; | 12 import 'scanner.dart'; |
| 13 import 'ast.dart'; | 13 import 'ast.dart'; |
| 14 import 'utilities_dart.dart'; | 14 import 'utilities_dart.dart'; |
| 15 | 15 |
| 16 |
| 16 /** | 17 /** |
| 17 * Instances of the class {@code CommentAndMetadata} implement a simple data-hol
der for a method | 18 * Instances of the class {@code CommentAndMetadata} implement a simple data-hol
der for a method |
| 18 * that needs to return multiple values. | 19 * that needs to return multiple values. |
| 19 * @coverage dart.engine.parser | 20 * @coverage dart.engine.parser |
| 20 */ | 21 */ |
| 21 class CommentAndMetadata { | 22 class CommentAndMetadata { |
| 23 |
| 22 /** | 24 /** |
| 23 * The documentation comment that was parsed, or {@code null} if none was give
n. | 25 * The documentation comment that was parsed, or {@code null} if none was give
n. |
| 24 */ | 26 */ |
| 25 Comment _comment; | 27 Comment _comment; |
| 28 |
| 26 /** | 29 /** |
| 27 * The metadata that was parsed. | 30 * The metadata that was parsed. |
| 28 */ | 31 */ |
| 29 List<Annotation> _metadata; | 32 List<Annotation> _metadata; |
| 33 |
| 30 /** | 34 /** |
| 31 * Initialize a newly created holder with the given data. | 35 * Initialize a newly created holder with the given data. |
| 32 * @param comment the documentation comment that was parsed | 36 * @param comment the documentation comment that was parsed |
| 33 * @param metadata the metadata that was parsed | 37 * @param metadata the metadata that was parsed |
| 34 */ | 38 */ |
| 35 CommentAndMetadata(Comment comment, List<Annotation> metadata) { | 39 CommentAndMetadata(Comment comment, List<Annotation> metadata) { |
| 36 this._comment = comment; | 40 this._comment = comment; |
| 37 this._metadata = metadata; | 41 this._metadata = metadata; |
| 38 } | 42 } |
| 43 |
| 39 /** | 44 /** |
| 40 * Return the documentation comment that was parsed, or {@code null} if none w
as given. | 45 * Return the documentation comment that was parsed, or {@code null} if none w
as given. |
| 41 * @return the documentation comment that was parsed | 46 * @return the documentation comment that was parsed |
| 42 */ | 47 */ |
| 43 Comment get comment => _comment; | 48 Comment get comment => _comment; |
| 49 |
| 44 /** | 50 /** |
| 45 * Return the metadata that was parsed. If there was no metadata, then the lis
t will be empty. | 51 * Return the metadata that was parsed. If there was no metadata, then the lis
t will be empty. |
| 46 * @return the metadata that was parsed | 52 * @return the metadata that was parsed |
| 47 */ | 53 */ |
| 48 List<Annotation> get metadata => _metadata; | 54 List<Annotation> get metadata => _metadata; |
| 49 } | 55 } |
| 56 |
| 50 /** | 57 /** |
| 51 * Instances of the class {@code FinalConstVarOrType} implement a simple data-ho
lder for a method | 58 * Instances of the class {@code FinalConstVarOrType} implement a simple data-ho
lder for a method |
| 52 * that needs to return multiple values. | 59 * that needs to return multiple values. |
| 53 * @coverage dart.engine.parser | 60 * @coverage dart.engine.parser |
| 54 */ | 61 */ |
| 55 class FinalConstVarOrType { | 62 class FinalConstVarOrType { |
| 63 |
| 56 /** | 64 /** |
| 57 * The 'final', 'const' or 'var' keyword, or {@code null} if none was given. | 65 * The 'final', 'const' or 'var' keyword, or {@code null} if none was given. |
| 58 */ | 66 */ |
| 59 Token _keyword; | 67 Token _keyword; |
| 68 |
| 60 /** | 69 /** |
| 61 * The type, of {@code null} if no type was specified. | 70 * The type, of {@code null} if no type was specified. |
| 62 */ | 71 */ |
| 63 TypeName _type; | 72 TypeName _type; |
| 73 |
| 64 /** | 74 /** |
| 65 * Initialize a newly created holder with the given data. | 75 * Initialize a newly created holder with the given data. |
| 66 * @param keyword the 'final', 'const' or 'var' keyword | 76 * @param keyword the 'final', 'const' or 'var' keyword |
| 67 * @param type the type | 77 * @param type the type |
| 68 */ | 78 */ |
| 69 FinalConstVarOrType(Token keyword, TypeName type) { | 79 FinalConstVarOrType(Token keyword, TypeName type) { |
| 70 this._keyword = keyword; | 80 this._keyword = keyword; |
| 71 this._type = type; | 81 this._type = type; |
| 72 } | 82 } |
| 83 |
| 73 /** | 84 /** |
| 74 * Return the 'final', 'const' or 'var' keyword, or {@code null} if none was g
iven. | 85 * Return the 'final', 'const' or 'var' keyword, or {@code null} if none was g
iven. |
| 75 * @return the 'final', 'const' or 'var' keyword | 86 * @return the 'final', 'const' or 'var' keyword |
| 76 */ | 87 */ |
| 77 Token get keyword => _keyword; | 88 Token get keyword => _keyword; |
| 89 |
| 78 /** | 90 /** |
| 79 * Return the type, of {@code null} if no type was specified. | 91 * Return the type, of {@code null} if no type was specified. |
| 80 * @return the type | 92 * @return the type |
| 81 */ | 93 */ |
| 82 TypeName get type => _type; | 94 TypeName get type => _type; |
| 83 } | 95 } |
| 96 |
| 84 /** | 97 /** |
| 85 * Instances of the class {@code Modifiers} implement a simple data-holder for a
method that needs | 98 * Instances of the class {@code Modifiers} implement a simple data-holder for a
method that needs |
| 86 * to return multiple values. | 99 * to return multiple values. |
| 87 * @coverage dart.engine.parser | 100 * @coverage dart.engine.parser |
| 88 */ | 101 */ |
| 89 class Modifiers { | 102 class Modifiers { |
| 103 |
| 90 /** | 104 /** |
| 91 * The token representing the keyword 'abstract', or {@code null} if the keywo
rd was not found. | 105 * The token representing the keyword 'abstract', or {@code null} if the keywo
rd was not found. |
| 92 */ | 106 */ |
| 93 Token _abstractKeyword; | 107 Token _abstractKeyword; |
| 108 |
| 94 /** | 109 /** |
| 95 * The token representing the keyword 'const', or {@code null} if the keyword
was not found. | 110 * The token representing the keyword 'const', or {@code null} if the keyword
was not found. |
| 96 */ | 111 */ |
| 97 Token _constKeyword; | 112 Token _constKeyword; |
| 113 |
| 98 /** | 114 /** |
| 99 * The token representing the keyword 'external', or {@code null} if the keywo
rd was not found. | 115 * The token representing the keyword 'external', or {@code null} if the keywo
rd was not found. |
| 100 */ | 116 */ |
| 101 Token _externalKeyword; | 117 Token _externalKeyword; |
| 118 |
| 102 /** | 119 /** |
| 103 * The token representing the keyword 'factory', or {@code null} if the keywor
d was not found. | 120 * The token representing the keyword 'factory', or {@code null} if the keywor
d was not found. |
| 104 */ | 121 */ |
| 105 Token _factoryKeyword; | 122 Token _factoryKeyword; |
| 123 |
| 106 /** | 124 /** |
| 107 * The token representing the keyword 'final', or {@code null} if the keyword
was not found. | 125 * The token representing the keyword 'final', or {@code null} if the keyword
was not found. |
| 108 */ | 126 */ |
| 109 Token _finalKeyword; | 127 Token _finalKeyword; |
| 128 |
| 110 /** | 129 /** |
| 111 * The token representing the keyword 'static', or {@code null} if the keyword
was not found. | 130 * The token representing the keyword 'static', or {@code null} if the keyword
was not found. |
| 112 */ | 131 */ |
| 113 Token _staticKeyword; | 132 Token _staticKeyword; |
| 133 |
| 114 /** | 134 /** |
| 115 * The token representing the keyword 'var', or {@code null} if the keyword wa
s not found. | 135 * The token representing the keyword 'var', or {@code null} if the keyword wa
s not found. |
| 116 */ | 136 */ |
| 117 Token _varKeyword; | 137 Token _varKeyword; |
| 118 /** | 138 |
| 119 * Initialize a newly created and empty set of modifiers. | |
| 120 */ | |
| 121 Modifiers() : super() { | |
| 122 } | |
| 123 /** | 139 /** |
| 124 * Return the token representing the keyword 'abstract', or {@code null} if th
e keyword was not | 140 * Return the token representing the keyword 'abstract', or {@code null} if th
e keyword was not |
| 125 * found. | 141 * found. |
| 126 * @return the token representing the keyword 'abstract' | 142 * @return the token representing the keyword 'abstract' |
| 127 */ | 143 */ |
| 128 Token get abstractKeyword => _abstractKeyword; | 144 Token get abstractKeyword => _abstractKeyword; |
| 145 |
| 129 /** | 146 /** |
| 130 * Return the token representing the keyword 'const', or {@code null} if the k
eyword was not | 147 * Return the token representing the keyword 'const', or {@code null} if the k
eyword was not |
| 131 * found. | 148 * found. |
| 132 * @return the token representing the keyword 'const' | 149 * @return the token representing the keyword 'const' |
| 133 */ | 150 */ |
| 134 Token get constKeyword => _constKeyword; | 151 Token get constKeyword => _constKeyword; |
| 152 |
| 135 /** | 153 /** |
| 136 * Return the token representing the keyword 'external', or {@code null} if th
e keyword was not | 154 * Return the token representing the keyword 'external', or {@code null} if th
e keyword was not |
| 137 * found. | 155 * found. |
| 138 * @return the token representing the keyword 'external' | 156 * @return the token representing the keyword 'external' |
| 139 */ | 157 */ |
| 140 Token get externalKeyword => _externalKeyword; | 158 Token get externalKeyword => _externalKeyword; |
| 159 |
| 141 /** | 160 /** |
| 142 * Return the token representing the keyword 'factory', or {@code null} if the
keyword was not | 161 * Return the token representing the keyword 'factory', or {@code null} if the
keyword was not |
| 143 * found. | 162 * found. |
| 144 * @return the token representing the keyword 'factory' | 163 * @return the token representing the keyword 'factory' |
| 145 */ | 164 */ |
| 146 Token get factoryKeyword => _factoryKeyword; | 165 Token get factoryKeyword => _factoryKeyword; |
| 166 |
| 147 /** | 167 /** |
| 148 * Return the token representing the keyword 'final', or {@code null} if the k
eyword was not | 168 * Return the token representing the keyword 'final', or {@code null} if the k
eyword was not |
| 149 * found. | 169 * found. |
| 150 * @return the token representing the keyword 'final' | 170 * @return the token representing the keyword 'final' |
| 151 */ | 171 */ |
| 152 Token get finalKeyword => _finalKeyword; | 172 Token get finalKeyword => _finalKeyword; |
| 173 |
| 153 /** | 174 /** |
| 154 * Return the token representing the keyword 'static', or {@code null} if the
keyword was not | 175 * Return the token representing the keyword 'static', or {@code null} if the
keyword was not |
| 155 * found. | 176 * found. |
| 156 * @return the token representing the keyword 'static' | 177 * @return the token representing the keyword 'static' |
| 157 */ | 178 */ |
| 158 Token get staticKeyword => _staticKeyword; | 179 Token get staticKeyword => _staticKeyword; |
| 180 |
| 159 /** | 181 /** |
| 160 * Return the token representing the keyword 'var', or {@code null} if the key
word was not found. | 182 * Return the token representing the keyword 'var', or {@code null} if the key
word was not found. |
| 161 * @return the token representing the keyword 'var' | 183 * @return the token representing the keyword 'var' |
| 162 */ | 184 */ |
| 163 Token get varKeyword => _varKeyword; | 185 Token get varKeyword => _varKeyword; |
| 186 |
| 164 /** | 187 /** |
| 165 * Set the token representing the keyword 'abstract' to the given token. | 188 * Set the token representing the keyword 'abstract' to the given token. |
| 166 * @param abstractKeyword the token representing the keyword 'abstract' | 189 * @param abstractKeyword the token representing the keyword 'abstract' |
| 167 */ | 190 */ |
| 168 void set abstractKeyword(Token abstractKeyword2) { | 191 void set abstractKeyword(Token abstractKeyword2) { |
| 169 this._abstractKeyword = abstractKeyword2; | 192 this._abstractKeyword = abstractKeyword2; |
| 170 } | 193 } |
| 194 |
| 171 /** | 195 /** |
| 172 * Set the token representing the keyword 'const' to the given token. | 196 * Set the token representing the keyword 'const' to the given token. |
| 173 * @param constKeyword the token representing the keyword 'const' | 197 * @param constKeyword the token representing the keyword 'const' |
| 174 */ | 198 */ |
| 175 void set constKeyword(Token constKeyword2) { | 199 void set constKeyword(Token constKeyword2) { |
| 176 this._constKeyword = constKeyword2; | 200 this._constKeyword = constKeyword2; |
| 177 } | 201 } |
| 202 |
| 178 /** | 203 /** |
| 179 * Set the token representing the keyword 'external' to the given token. | 204 * Set the token representing the keyword 'external' to the given token. |
| 180 * @param externalKeyword the token representing the keyword 'external' | 205 * @param externalKeyword the token representing the keyword 'external' |
| 181 */ | 206 */ |
| 182 void set externalKeyword(Token externalKeyword2) { | 207 void set externalKeyword(Token externalKeyword2) { |
| 183 this._externalKeyword = externalKeyword2; | 208 this._externalKeyword = externalKeyword2; |
| 184 } | 209 } |
| 210 |
| 185 /** | 211 /** |
| 186 * Set the token representing the keyword 'factory' to the given token. | 212 * Set the token representing the keyword 'factory' to the given token. |
| 187 * @param factoryKeyword the token representing the keyword 'factory' | 213 * @param factoryKeyword the token representing the keyword 'factory' |
| 188 */ | 214 */ |
| 189 void set factoryKeyword(Token factoryKeyword2) { | 215 void set factoryKeyword(Token factoryKeyword2) { |
| 190 this._factoryKeyword = factoryKeyword2; | 216 this._factoryKeyword = factoryKeyword2; |
| 191 } | 217 } |
| 218 |
| 192 /** | 219 /** |
| 193 * Set the token representing the keyword 'final' to the given token. | 220 * Set the token representing the keyword 'final' to the given token. |
| 194 * @param finalKeyword the token representing the keyword 'final' | 221 * @param finalKeyword the token representing the keyword 'final' |
| 195 */ | 222 */ |
| 196 void set finalKeyword(Token finalKeyword2) { | 223 void set finalKeyword(Token finalKeyword2) { |
| 197 this._finalKeyword = finalKeyword2; | 224 this._finalKeyword = finalKeyword2; |
| 198 } | 225 } |
| 226 |
| 199 /** | 227 /** |
| 200 * Set the token representing the keyword 'static' to the given token. | 228 * Set the token representing the keyword 'static' to the given token. |
| 201 * @param staticKeyword the token representing the keyword 'static' | 229 * @param staticKeyword the token representing the keyword 'static' |
| 202 */ | 230 */ |
| 203 void set staticKeyword(Token staticKeyword2) { | 231 void set staticKeyword(Token staticKeyword2) { |
| 204 this._staticKeyword = staticKeyword2; | 232 this._staticKeyword = staticKeyword2; |
| 205 } | 233 } |
| 234 |
| 206 /** | 235 /** |
| 207 * Set the token representing the keyword 'var' to the given token. | 236 * Set the token representing the keyword 'var' to the given token. |
| 208 * @param varKeyword the token representing the keyword 'var' | 237 * @param varKeyword the token representing the keyword 'var' |
| 209 */ | 238 */ |
| 210 void set varKeyword(Token varKeyword2) { | 239 void set varKeyword(Token varKeyword2) { |
| 211 this._varKeyword = varKeyword2; | 240 this._varKeyword = varKeyword2; |
| 212 } | 241 } |
| 213 String toString() { | 242 String toString() { |
| 214 JavaStringBuilder builder = new JavaStringBuilder(); | 243 JavaStringBuilder builder = new JavaStringBuilder(); |
| 215 bool needsSpace = appendKeyword(builder, false, _abstractKeyword); | 244 bool needsSpace = appendKeyword(builder, false, _abstractKeyword); |
| 216 needsSpace = appendKeyword(builder, needsSpace, _constKeyword); | 245 needsSpace = appendKeyword(builder, needsSpace, _constKeyword); |
| 217 needsSpace = appendKeyword(builder, needsSpace, _externalKeyword); | 246 needsSpace = appendKeyword(builder, needsSpace, _externalKeyword); |
| 218 needsSpace = appendKeyword(builder, needsSpace, _factoryKeyword); | 247 needsSpace = appendKeyword(builder, needsSpace, _factoryKeyword); |
| 219 needsSpace = appendKeyword(builder, needsSpace, _finalKeyword); | 248 needsSpace = appendKeyword(builder, needsSpace, _finalKeyword); |
| 220 needsSpace = appendKeyword(builder, needsSpace, _staticKeyword); | 249 needsSpace = appendKeyword(builder, needsSpace, _staticKeyword); |
| 221 appendKeyword(builder, needsSpace, _varKeyword); | 250 appendKeyword(builder, needsSpace, _varKeyword); |
| 222 return builder.toString(); | 251 return builder.toString(); |
| 223 } | 252 } |
| 253 |
| 224 /** | 254 /** |
| 225 * If the given keyword is not {@code null}, append it to the given builder, p
refixing it with a | 255 * If the given keyword is not {@code null}, append it to the given builder, p
refixing it with a |
| 226 * space if needed. | 256 * space if needed. |
| 227 * @param builder the builder to which the keyword will be appended | 257 * @param builder the builder to which the keyword will be appended |
| 228 * @param needsSpace {@code true} if the keyword needs to be prefixed with a s
pace | 258 * @param needsSpace {@code true} if the keyword needs to be prefixed with a s
pace |
| 229 * @param keyword the keyword to be appended | 259 * @param keyword the keyword to be appended |
| 230 * @return {@code true} if subsequent keywords need to be prefixed with a spac
e | 260 * @return {@code true} if subsequent keywords need to be prefixed with a spac
e |
| 231 */ | 261 */ |
| 232 bool appendKeyword(JavaStringBuilder builder, bool needsSpace, Token keyword)
{ | 262 bool appendKeyword(JavaStringBuilder builder, bool needsSpace, Token keyword)
{ |
| 233 if (keyword != null) { | 263 if (keyword != null) { |
| 234 if (needsSpace) { | 264 if (needsSpace) { |
| 235 builder.appendChar(0x20); | 265 builder.appendChar(0x20); |
| 236 } | 266 } |
| 237 builder.append(keyword.lexeme); | 267 builder.append(keyword.lexeme); |
| 238 return true; | 268 return true; |
| 239 } | 269 } |
| 240 return needsSpace; | 270 return needsSpace; |
| 241 } | 271 } |
| 242 } | 272 } |
| 273 |
| 243 /** | 274 /** |
| 244 * Instances of the class {@code Parser} are used to parse tokens into an AST st
ructure. | 275 * Instances of the class {@code Parser} are used to parse tokens into an AST st
ructure. |
| 245 * @coverage dart.engine.parser | 276 * @coverage dart.engine.parser |
| 246 */ | 277 */ |
| 247 class Parser { | 278 class Parser { |
| 279 |
| 248 /** | 280 /** |
| 249 * The source being parsed. | 281 * The source being parsed. |
| 250 */ | 282 */ |
| 251 Source _source; | 283 Source _source; |
| 284 |
| 252 /** | 285 /** |
| 253 * The error listener that will be informed of any errors that are found durin
g the parse. | 286 * The error listener that will be informed of any errors that are found durin
g the parse. |
| 254 */ | 287 */ |
| 255 AnalysisErrorListener _errorListener; | 288 AnalysisErrorListener _errorListener; |
| 289 |
| 256 /** | 290 /** |
| 257 * The next token to be parsed. | 291 * The next token to be parsed. |
| 258 */ | 292 */ |
| 259 Token _currentToken; | 293 Token _currentToken; |
| 294 |
| 260 /** | 295 /** |
| 261 * A flag indicating whether the parser is currently in the body of a loop. | 296 * A flag indicating whether the parser is currently in the body of a loop. |
| 262 */ | 297 */ |
| 263 bool _inLoop = false; | 298 bool _inLoop = false; |
| 299 |
| 264 /** | 300 /** |
| 265 * A flag indicating whether the parser is currently in a switch statement. | 301 * A flag indicating whether the parser is currently in a switch statement. |
| 266 */ | 302 */ |
| 267 bool _inSwitch = false; | 303 bool _inSwitch = false; |
| 268 static String _HIDE = "hide"; | 304 static String _HIDE = "hide"; |
| 269 static String _OF = "of"; | 305 static String _OF = "of"; |
| 270 static String _ON = "on"; | 306 static String _ON = "on"; |
| 271 static String _SHOW = "show"; | 307 static String _SHOW = "show"; |
| 272 static String _NATIVE = "native"; | 308 static String _NATIVE = "native"; |
| 309 |
| 273 /** | 310 /** |
| 274 * Initialize a newly created parser. | 311 * Initialize a newly created parser. |
| 275 * @param source the source being parsed | 312 * @param source the source being parsed |
| 276 * @param errorListener the error listener that will be informed of any errors
that are found | 313 * @param errorListener the error listener that will be informed of any errors
that are found |
| 277 * during the parse | 314 * during the parse |
| 278 */ | 315 */ |
| 279 Parser(Source source, AnalysisErrorListener errorListener) { | 316 Parser(Source source, AnalysisErrorListener errorListener) { |
| 280 this._source = source; | 317 this._source = source; |
| 281 this._errorListener = errorListener; | 318 this._errorListener = errorListener; |
| 282 } | 319 } |
| 320 |
| 283 /** | 321 /** |
| 284 * Parse a compilation unit, starting with the given token. | 322 * Parse a compilation unit, starting with the given token. |
| 285 * @param token the first token of the compilation unit | 323 * @param token the first token of the compilation unit |
| 286 * @return the compilation unit that was parsed | 324 * @return the compilation unit that was parsed |
| 287 */ | 325 */ |
| 288 CompilationUnit parseCompilationUnit(Token token) { | 326 CompilationUnit parseCompilationUnit(Token token) { |
| 289 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.Parser.parseCompilationUnit"); | 327 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.Parser.parseCompilationUnit"); |
| 290 try { | 328 try { |
| 291 _currentToken = token; | 329 _currentToken = token; |
| 292 return parseCompilationUnit2(); | 330 return parseCompilationUnit2(); |
| 293 } finally { | 331 } finally { |
| 294 instrumentation.log(); | 332 instrumentation.log(); |
| 295 } | 333 } |
| 296 } | 334 } |
| 335 |
| 297 /** | 336 /** |
| 298 * Parse an expression, starting with the given token. | 337 * Parse an expression, starting with the given token. |
| 299 * @param token the first token of the expression | 338 * @param token the first token of the expression |
| 300 * @return the expression that was parsed, or {@code null} if the tokens do no
t represent a | 339 * @return the expression that was parsed, or {@code null} if the tokens do no
t represent a |
| 301 * recognizable expression | 340 * recognizable expression |
| 302 */ | 341 */ |
| 303 Expression parseExpression(Token token) { | 342 Expression parseExpression(Token token) { |
| 304 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.Parser.parseExpression"); | 343 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.Parser.parseExpression"); |
| 305 try { | 344 try { |
| 306 _currentToken = token; | 345 _currentToken = token; |
| 307 return parseExpression2(); | 346 return parseExpression2(); |
| 308 } finally { | 347 } finally { |
| 309 instrumentation.log(); | 348 instrumentation.log(); |
| 310 } | 349 } |
| 311 } | 350 } |
| 351 |
| 312 /** | 352 /** |
| 313 * Parse a statement, starting with the given token. | 353 * Parse a statement, starting with the given token. |
| 314 * @param token the first token of the statement | 354 * @param token the first token of the statement |
| 315 * @return the statement that was parsed, or {@code null} if the tokens do not
represent a | 355 * @return the statement that was parsed, or {@code null} if the tokens do not
represent a |
| 316 * recognizable statement | 356 * recognizable statement |
| 317 */ | 357 */ |
| 318 Statement parseStatement(Token token) { | 358 Statement parseStatement(Token token) { |
| 319 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.Parser.parseStatement"); | 359 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.Parser.parseStatement"); |
| 320 try { | 360 try { |
| 321 _currentToken = token; | 361 _currentToken = token; |
| 322 return parseStatement2(); | 362 return parseStatement2(); |
| 323 } finally { | 363 } finally { |
| 324 instrumentation.log(); | 364 instrumentation.log(); |
| 325 } | 365 } |
| 326 } | 366 } |
| 367 |
| 327 /** | 368 /** |
| 328 * Parse a sequence of statements, starting with the given token. | 369 * Parse a sequence of statements, starting with the given token. |
| 329 * @param token the first token of the sequence of statement | 370 * @param token the first token of the sequence of statement |
| 330 * @return the statements that were parsed, or {@code null} if the tokens do n
ot represent a | 371 * @return the statements that were parsed, or {@code null} if the tokens do n
ot represent a |
| 331 * recognizable sequence of statements | 372 * recognizable sequence of statements |
| 332 */ | 373 */ |
| 333 List<Statement> parseStatements(Token token) { | 374 List<Statement> parseStatements(Token token) { |
| 334 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.Parser.parseStatements"); | 375 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.Parser.parseStatements"); |
| 335 try { | 376 try { |
| 336 _currentToken = token; | 377 _currentToken = token; |
| 337 return parseStatements2(); | 378 return parseStatements2(); |
| 338 } finally { | 379 } finally { |
| 339 instrumentation.log(); | 380 instrumentation.log(); |
| 340 } | 381 } |
| 341 } | 382 } |
| 342 void set currentToken(Token currentToken2) { | 383 void set currentToken(Token currentToken2) { |
| 343 this._currentToken = currentToken2; | 384 this._currentToken = currentToken2; |
| 344 } | 385 } |
| 386 |
| 345 /** | 387 /** |
| 346 * Advance to the next token in the token stream. | 388 * Advance to the next token in the token stream. |
| 347 */ | 389 */ |
| 348 void advance() { | 390 void advance() { |
| 349 _currentToken = _currentToken.next; | 391 _currentToken = _currentToken.next; |
| 350 } | 392 } |
| 393 |
| 351 /** | 394 /** |
| 352 * Append the character equivalent of the given scalar value to the given buil
der. Use the start | 395 * Append the character equivalent of the given scalar value to the given buil
der. Use the start |
| 353 * and end indices to report an error, and don't append anything to the builde
r, if the scalar | 396 * and end indices to report an error, and don't append anything to the builde
r, if the scalar |
| 354 * value is invalid. | 397 * value is invalid. |
| 355 * @param builder the builder to which the scalar value is to be appended | 398 * @param builder the builder to which the scalar value is to be appended |
| 356 * @param escapeSequence the escape sequence that was parsed to produce the sc
alar value | 399 * @param escapeSequence the escape sequence that was parsed to produce the sc
alar value |
| 357 * @param scalarValue the value to be appended | 400 * @param scalarValue the value to be appended |
| 358 * @param startIndex the index of the first character representing the scalar
value | 401 * @param startIndex the index of the first character representing the scalar
value |
| 359 * @param endIndex the index of the last character representing the scalar val
ue | 402 * @param endIndex the index of the last character representing the scalar val
ue |
| 360 */ | 403 */ |
| 361 void appendScalarValue(JavaStringBuilder builder, String escapeSequence, int s
calarValue, int startIndex, int endIndex) { | 404 void appendScalarValue(JavaStringBuilder builder, String escapeSequence, int s
calarValue, int startIndex, int endIndex) { |
| 362 if (scalarValue < 0 || scalarValue > Character.MAX_CODE_POINT || (scalarValu
e >= 0xD800 && scalarValue <= 0xDFFF)) { | 405 if (scalarValue < 0 || scalarValue > Character.MAX_CODE_POINT || (scalarValu
e >= 0xD800 && scalarValue <= 0xDFFF)) { |
| 363 reportError4(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]); | 406 reportError7(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]); |
| 364 return; | 407 return; |
| 365 } | 408 } |
| 366 if (scalarValue < Character.MAX_VALUE) { | 409 if (scalarValue < Character.MAX_VALUE) { |
| 367 builder.appendChar((scalarValue as int)); | 410 builder.appendChar((scalarValue as int)); |
| 368 } else { | 411 } else { |
| 369 builder.append(Character.toChars(scalarValue)); | 412 builder.append(Character.toChars(scalarValue)); |
| 370 } | 413 } |
| 371 } | 414 } |
| 415 |
| 372 /** | 416 /** |
| 373 * Compute the content of a string with the given literal representation. | 417 * Compute the content of a string with the given literal representation. |
| 374 * @param lexeme the literal representation of the string | 418 * @param lexeme the literal representation of the string |
| 375 * @return the actual value of the string | 419 * @return the actual value of the string |
| 376 */ | 420 */ |
| 377 String computeStringValue(String lexeme) { | 421 String computeStringValue(String lexeme) { |
| 378 if (lexeme.startsWith("r\"\"\"") || lexeme.startsWith("r'''")) { | 422 if (lexeme.startsWith("r\"\"\"") || lexeme.startsWith("r'''")) { |
| 379 if (lexeme.length > 4) { | 423 if (lexeme.length > 4) { |
| 380 return lexeme.substring(4, lexeme.length - 3); | 424 return lexeme.substring(4, lexeme.length - 3); |
| 381 } | 425 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 396 } else if (end > 1 && (lexeme.endsWith("\"") || lexeme.endsWith("'"))) { | 440 } else if (end > 1 && (lexeme.endsWith("\"") || lexeme.endsWith("'"))) { |
| 397 end -= 1; | 441 end -= 1; |
| 398 } | 442 } |
| 399 JavaStringBuilder builder = new JavaStringBuilder(); | 443 JavaStringBuilder builder = new JavaStringBuilder(); |
| 400 int index = start; | 444 int index = start; |
| 401 while (index < end) { | 445 while (index < end) { |
| 402 index = translateCharacter(builder, lexeme, index); | 446 index = translateCharacter(builder, lexeme, index); |
| 403 } | 447 } |
| 404 return builder.toString(); | 448 return builder.toString(); |
| 405 } | 449 } |
| 450 |
| 451 /** |
| 452 * Convert the given method declaration into the nearest valid top-level funct
ion declaration. |
| 453 * @param method the method to be converted |
| 454 * @return the function declaration that most closely captures the components
of the given method |
| 455 * declaration |
| 456 */ |
| 457 FunctionDeclaration convertToFunctionDeclaration(MethodDeclaration method) =>
new FunctionDeclaration.full(method.documentationComment, method.metadata, metho
d.externalKeyword, method.returnType, method.propertyKeyword, method.name, new F
unctionExpression.full(method.parameters, method.body)); |
| 458 |
| 459 /** |
| 460 * Return {@code true} if the current token could be the start of a compilatio
n unit member. This |
| 461 * method is used for recovery purposes to decide when to stop skipping tokens
after finding an |
| 462 * error while parsing a compilation unit member. |
| 463 * @return {@code true} if the current token could be the start of a compilati
on unit member |
| 464 */ |
| 465 bool couldBeStartOfCompilationUnitMember() { |
| 466 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword.L
IBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !mat
ches4(peek(), TokenType.LT)) { |
| 467 return true; |
| 468 } else if (matches(Keyword.CLASS)) { |
| 469 return true; |
| 470 } else if (matches(Keyword.TYPEDEF) && !matches4(peek(), TokenType.PERIOD) &
& !matches4(peek(), TokenType.LT)) { |
| 471 return true; |
| 472 } else if (matches(Keyword.VOID) || ((matches(Keyword.GET) || matches(Keywor
d.SET)) && matchesIdentifier2(peek())) || (matches(Keyword.OPERATOR) && isOperat
or(peek()))) { |
| 473 return true; |
| 474 } else if (matchesIdentifier()) { |
| 475 if (matches4(peek(), TokenType.OPEN_PAREN)) { |
| 476 return true; |
| 477 } |
| 478 Token token = skipReturnType(_currentToken); |
| 479 if (token == null) { |
| 480 return false; |
| 481 } |
| 482 if (matches(Keyword.GET) || matches(Keyword.SET) || (matches(Keyword.OPERA
TOR) && isOperator(peek())) || matchesIdentifier()) { |
| 483 return true; |
| 484 } |
| 485 } |
| 486 return false; |
| 487 } |
| 488 |
| 406 /** | 489 /** |
| 407 * Create a synthetic identifier. | 490 * Create a synthetic identifier. |
| 408 * @return the synthetic identifier that was created | 491 * @return the synthetic identifier that was created |
| 409 */ | 492 */ |
| 410 SimpleIdentifier createSyntheticIdentifier() => new SimpleIdentifier.full(crea
teSyntheticToken2(TokenType.IDENTIFIER)); | 493 SimpleIdentifier createSyntheticIdentifier() => new SimpleIdentifier.full(crea
teSyntheticToken2(TokenType.IDENTIFIER)); |
| 494 |
| 411 /** | 495 /** |
| 412 * Create a synthetic string literal. | 496 * Create a synthetic string literal. |
| 413 * @return the synthetic string literal that was created | 497 * @return the synthetic string literal that was created |
| 414 */ | 498 */ |
| 415 SimpleStringLiteral createSyntheticStringLiteral() => new SimpleStringLiteral.
full(createSyntheticToken2(TokenType.STRING), ""); | 499 SimpleStringLiteral createSyntheticStringLiteral() => new SimpleStringLiteral.
full(createSyntheticToken2(TokenType.STRING), ""); |
| 500 |
| 416 /** | 501 /** |
| 417 * Create a synthetic token representing the given keyword. | 502 * Create a synthetic token representing the given keyword. |
| 418 * @return the synthetic token that was created | 503 * @return the synthetic token that was created |
| 419 */ | 504 */ |
| 420 Token createSyntheticToken(Keyword keyword) => new KeywordToken_11(keyword, _c
urrentToken.offset); | 505 Token createSyntheticToken(Keyword keyword) => new KeywordToken_11(keyword, _c
urrentToken.offset); |
| 506 |
| 421 /** | 507 /** |
| 422 * Create a synthetic token with the given type. | 508 * Create a synthetic token with the given type. |
| 423 * @return the synthetic token that was created | 509 * @return the synthetic token that was created |
| 424 */ | 510 */ |
| 425 Token createSyntheticToken2(TokenType type) => new StringToken(type, "", _curr
entToken.offset); | 511 Token createSyntheticToken2(TokenType type) => new StringToken(type, "", _curr
entToken.offset); |
| 512 |
| 426 /** | 513 /** |
| 427 * Check that the given expression is assignable and report an error if it isn
't. | 514 * Check that the given expression is assignable and report an error if it isn
't. |
| 428 * <pre> | 515 * <pre> |
| 429 * assignableExpression ::= | 516 * assignableExpression ::= |
| 430 * primary (arguments* assignableSelector)+ | 517 * primary (arguments* assignableSelector)+ |
| 431 * | 'super' assignableSelector | 518 * | 'super' assignableSelector |
| 432 * | identifier | 519 * | identifier |
| 433 * assignableSelector ::= | 520 * assignableSelector ::= |
| 434 * '\[' expression '\]' | 521 * '\[' expression '\]' |
| 435 * | '.' identifier | 522 * | '.' identifier |
| 436 * </pre> | 523 * </pre> |
| 437 * @param expression the expression being checked | 524 * @param expression the expression being checked |
| 438 */ | 525 */ |
| 439 void ensureAssignable(Expression expression) { | 526 void ensureAssignable(Expression expression) { |
| 440 if (expression != null && !expression.isAssignable()) { | 527 if (expression != null && !expression.isAssignable()) { |
| 441 reportError4(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []); | 528 reportError7(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []); |
| 442 } | 529 } |
| 443 } | 530 } |
| 531 |
| 444 /** | 532 /** |
| 445 * If the current token is a keyword matching the given string, return it afte
r advancing to the | 533 * If the current token is a keyword matching the given string, return it afte
r advancing to the |
| 446 * next token. Otherwise report an error and return the current token without
advancing. | 534 * next token. Otherwise report an error and return the current token without
advancing. |
| 447 * @param keyword the keyword that is expected | 535 * @param keyword the keyword that is expected |
| 448 * @return the token that matched the given type | 536 * @return the token that matched the given type |
| 449 */ | 537 */ |
| 450 Token expect(Keyword keyword) { | 538 Token expect(Keyword keyword) { |
| 451 if (matches(keyword)) { | 539 if (matches(keyword)) { |
| 452 return andAdvance; | 540 return andAdvance; |
| 453 } | 541 } |
| 454 reportError4(ParserErrorCode.EXPECTED_TOKEN, [keyword.syntax]); | 542 reportError7(ParserErrorCode.EXPECTED_TOKEN, [keyword.syntax]); |
| 455 return _currentToken; | 543 return _currentToken; |
| 456 } | 544 } |
| 545 |
| 457 /** | 546 /** |
| 458 * If the current token has the expected type, return it after advancing to th
e next token. | 547 * If the current token has the expected type, return it after advancing to th
e next token. |
| 459 * Otherwise report an error and return the current token without advancing. | 548 * Otherwise report an error and return the current token without advancing. |
| 460 * @param type the type of token that is expected | 549 * @param type the type of token that is expected |
| 461 * @return the token that matched the given type | 550 * @return the token that matched the given type |
| 462 */ | 551 */ |
| 463 Token expect2(TokenType type) { | 552 Token expect2(TokenType type) { |
| 464 if (matches5(type)) { | 553 if (matches5(type)) { |
| 465 return andAdvance; | 554 return andAdvance; |
| 466 } | 555 } |
| 467 if (identical(type, TokenType.SEMICOLON)) { | 556 if (identical(type, TokenType.SEMICOLON)) { |
| 468 reportError5(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [type
.lexeme]); | 557 reportError8(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [type
.lexeme]); |
| 469 } else { | 558 } else { |
| 470 reportError4(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]); | 559 reportError7(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]); |
| 471 } | 560 } |
| 472 return _currentToken; | 561 return _currentToken; |
| 473 } | 562 } |
| 563 |
| 474 /** | 564 /** |
| 475 * Search the given list of ranges for a range that contains the given index.
Return the range | 565 * Search the given list of ranges for a range that contains the given index.
Return the range |
| 476 * that was found, or {@code null} if none of the ranges contain the index. | 566 * that was found, or {@code null} if none of the ranges contain the index. |
| 477 * @param ranges the ranges to be searched | 567 * @param ranges the ranges to be searched |
| 478 * @param index the index contained in the returned range | 568 * @param index the index contained in the returned range |
| 479 * @return the range that was found | 569 * @return the range that was found |
| 480 */ | 570 */ |
| 481 List<int> findRange(List<List<int>> ranges, int index) { | 571 List<int> findRange(List<List<int>> ranges, int index) { |
| 482 for (List<int> range in ranges) { | 572 for (List<int> range in ranges) { |
| 483 if (range[0] <= index && index <= range[1]) { | 573 if (range[0] <= index && index <= range[1]) { |
| 484 return range; | 574 return range; |
| 485 } else if (index < range[0]) { | 575 } else if (index < range[0]) { |
| 486 return null; | 576 return null; |
| 487 } | 577 } |
| 488 } | 578 } |
| 489 return null; | 579 return null; |
| 490 } | 580 } |
| 581 |
| 491 /** | 582 /** |
| 492 * Advance to the next token in the token stream, making it the new current to
ken. | 583 * Advance to the next token in the token stream, making it the new current to
ken. |
| 493 * @return the token that was current before this method was invoked | 584 * @return the token that was current before this method was invoked |
| 494 */ | 585 */ |
| 495 Token get andAdvance { | 586 Token get andAdvance { |
| 496 Token token = _currentToken; | 587 Token token = _currentToken; |
| 497 advance(); | 588 advance(); |
| 498 return token; | 589 return token; |
| 499 } | 590 } |
| 591 |
| 500 /** | 592 /** |
| 501 * Return a list of the ranges of characters in the given comment string that
should be treated as | 593 * Return a list of the ranges of characters in the given comment string that
should be treated as |
| 502 * code blocks. | 594 * code blocks. |
| 503 * @param comment the comment being processed | 595 * @param comment the comment being processed |
| 504 * @return the ranges of characters that should be treated as code blocks | 596 * @return the ranges of characters that should be treated as code blocks |
| 505 */ | 597 */ |
| 506 List<List<int>> getCodeBlockRanges(String comment) { | 598 List<List<int>> getCodeBlockRanges(String comment) { |
| 507 List<List<int>> ranges = new List<List<int>>(); | 599 List<List<int>> ranges = new List<List<int>>(); |
| 508 int length2 = comment.length; | 600 int length2 = comment.length; |
| 509 int index = 0; | 601 int index = 0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 531 end = length2; | 623 end = length2; |
| 532 } | 624 } |
| 533 ranges.add(<int> [index, end]); | 625 ranges.add(<int> [index, end]); |
| 534 index = end + 1; | 626 index = end + 1; |
| 535 } else { | 627 } else { |
| 536 index = index + 1; | 628 index = index + 1; |
| 537 } | 629 } |
| 538 } | 630 } |
| 539 return ranges; | 631 return ranges; |
| 540 } | 632 } |
| 633 |
| 634 /** |
| 635 * Return the end token associated with the given begin token, or {@code null}
if either the given |
| 636 * token is not a begin token or it does not have an end token associated with
it. |
| 637 * @param beginToken the token that is expected to have an end token associate
d with it |
| 638 * @return the end token associated with the begin token |
| 639 */ |
| 640 Token getEndToken(Token beginToken) { |
| 641 if (beginToken is BeginToken) { |
| 642 return ((beginToken as BeginToken)).endToken; |
| 643 } |
| 644 return null; |
| 645 } |
| 646 |
| 541 /** | 647 /** |
| 542 * Return {@code true} if the current token is the first token of a return typ
e that is followed | 648 * Return {@code true} if the current token is the first token of a return typ
e that is followed |
| 543 * by an identifier, possibly followed by a list of type parameters, followed
by a | 649 * by an identifier, possibly followed by a list of type parameters, followed
by a |
| 544 * left-parenthesis. This is used by parseTypeAlias to determine whether or no
t to parse a return | 650 * left-parenthesis. This is used by parseTypeAlias to determine whether or no
t to parse a return |
| 545 * type. | 651 * type. |
| 546 * @return {@code true} if we can successfully parse the rest of a type alias
if we first parse a | 652 * @return {@code true} if we can successfully parse the rest of a type alias
if we first parse a |
| 547 * return type. | 653 * return type. |
| 548 */ | 654 */ |
| 549 bool hasReturnTypeInTypeAlias() { | 655 bool hasReturnTypeInTypeAlias() { |
| 550 Token next = skipReturnType(_currentToken); | 656 Token next = skipReturnType(_currentToken); |
| 551 if (next == null) { | 657 if (next == null) { |
| 552 return false; | 658 return false; |
| 553 } | 659 } |
| 554 return matchesIdentifier2(next); | 660 return matchesIdentifier2(next); |
| 555 } | 661 } |
| 662 |
| 556 /** | 663 /** |
| 557 * Return {@code true} if the current token appears to be the beginning of a f
unction declaration. | 664 * Return {@code true} if the current token appears to be the beginning of a f
unction declaration. |
| 558 * @return {@code true} if the current token appears to be the beginning of a
function declaration | 665 * @return {@code true} if the current token appears to be the beginning of a
function declaration |
| 559 */ | 666 */ |
| 560 bool isFunctionDeclaration() { | 667 bool isFunctionDeclaration() { |
| 561 if (matches(Keyword.VOID)) { | 668 if (matches(Keyword.VOID)) { |
| 562 return true; | 669 return true; |
| 563 } | 670 } |
| 564 Token afterReturnType = skipTypeName(_currentToken); | 671 Token afterReturnType = skipTypeName(_currentToken); |
| 565 if (afterReturnType == null) { | 672 if (afterReturnType == null) { |
| 566 afterReturnType = _currentToken; | 673 afterReturnType = _currentToken; |
| 567 } | 674 } |
| 568 Token afterIdentifier = skipSimpleIdentifier(afterReturnType); | 675 Token afterIdentifier = skipSimpleIdentifier(afterReturnType); |
| 569 if (afterIdentifier == null) { | 676 if (afterIdentifier == null) { |
| 570 afterIdentifier = skipSimpleIdentifier(_currentToken); | 677 afterIdentifier = skipSimpleIdentifier(_currentToken); |
| 571 } | 678 } |
| 572 if (afterIdentifier == null) { | 679 if (afterIdentifier == null) { |
| 573 return false; | 680 return false; |
| 574 } | 681 } |
| 575 return isFunctionExpression(afterIdentifier); | 682 return isFunctionExpression(afterIdentifier); |
| 576 } | 683 } |
| 684 |
| 577 /** | 685 /** |
| 578 * Return {@code true} if the given token appears to be the beginning of a fun
ction expression. | 686 * Return {@code true} if the given token appears to be the beginning of a fun
ction expression. |
| 579 * @param startToken the token that might be the start of a function expressio
n | 687 * @param startToken the token that might be the start of a function expressio
n |
| 580 * @return {@code true} if the given token appears to be the beginning of a fu
nction expression | 688 * @return {@code true} if the given token appears to be the beginning of a fu
nction expression |
| 581 */ | 689 */ |
| 582 bool isFunctionExpression(Token startToken) { | 690 bool isFunctionExpression(Token startToken) { |
| 583 Token afterParameters = skipFormalParameterList(startToken); | 691 Token afterParameters = skipFormalParameterList(startToken); |
| 584 if (afterParameters == null) { | 692 if (afterParameters == null) { |
| 585 return false; | 693 return false; |
| 586 } | 694 } |
| 587 return matchesAny(afterParameters, [TokenType.OPEN_CURLY_BRACKET, TokenType.
FUNCTION]); | 695 return matchesAny(afterParameters, [TokenType.OPEN_CURLY_BRACKET, TokenType.
FUNCTION]); |
| 588 } | 696 } |
| 697 |
| 589 /** | 698 /** |
| 590 * Return {@code true} if the given character is a valid hexadecimal digit. | 699 * Return {@code true} if the given character is a valid hexadecimal digit. |
| 591 * @param character the character being tested | 700 * @param character the character being tested |
| 592 * @return {@code true} if the character is a valid hexadecimal digit | 701 * @return {@code true} if the character is a valid hexadecimal digit |
| 593 */ | 702 */ |
| 594 bool isHexDigit(int character) => (0x30 <= character && character <= 0x39) ||
(0x41 <= character && character <= 0x46) || (0x61 <= character && character <= 0
x66); | 703 bool isHexDigit(int character) => (0x30 <= character && character <= 0x39) ||
(0x41 <= character && character <= 0x46) || (0x61 <= character && character <= 0
x66); |
| 704 |
| 595 /** | 705 /** |
| 596 * Return {@code true} if the current token is the first token in an initializ
ed variable | 706 * Return {@code true} if the current token is the first token in an initializ
ed variable |
| 597 * declaration rather than an expression. This method assumes that we have alr
eady skipped past | 707 * declaration rather than an expression. This method assumes that we have alr
eady skipped past |
| 598 * any metadata that might be associated with the declaration. | 708 * any metadata that might be associated with the declaration. |
| 599 * <pre> | 709 * <pre> |
| 600 * initializedVariableDeclaration ::= | 710 * initializedVariableDeclaration ::= |
| 601 * declaredIdentifier ('=' expression)? (',' initializedIdentifier) | 711 * declaredIdentifier ('=' expression)? (',' initializedIdentifier) |
| 602 * declaredIdentifier ::= | 712 * declaredIdentifier ::= |
| 603 * metadata finalConstVarOrType identifier | 713 * metadata finalConstVarOrType identifier |
| 604 * finalConstVarOrType ::= | 714 * finalConstVarOrType ::= |
| 605 * 'final' type? | 715 * 'final' type? |
| 606 * | 'const' type? | 716 * | 'const' type? |
| 607 * | 'var' | 717 * | 'var' |
| 608 * | type | 718 * | type |
| 609 * type ::= | 719 * type ::= |
| 610 * qualified typeArguments? | 720 * qualified typeArguments? |
| 611 * initializedIdentifier ::= | 721 * initializedIdentifier ::= |
| 612 * identifier ('=' expression)? | 722 * identifier ('=' expression)? |
| 613 * </pre> | 723 * </pre> |
| 614 * @return {@code true} if the current token is the first token in an initiali
zed variable | 724 * @return {@code true} if the current token is the first token in an initiali
zed variable |
| 615 * declaration | 725 * declaration |
| 616 */ | 726 */ |
| 617 bool isInitializedVariableDeclaration() { | 727 bool isInitializedVariableDeclaration() { |
| 618 if (matches(Keyword.FINAL) || matches(Keyword.CONST) || matches(Keyword.VAR)
) { | 728 if (matches(Keyword.FINAL) || matches(Keyword.VAR)) { |
| 619 return true; | 729 return true; |
| 620 } | 730 } |
| 731 if (matches(Keyword.CONST)) { |
| 732 return !matchesAny(peek(), [TokenType.LT, TokenType.OPEN_CURLY_BRACKET, To
kenType.OPEN_SQUARE_BRACKET, TokenType.INDEX]); |
| 733 } |
| 621 Token token = skipTypeName(_currentToken); | 734 Token token = skipTypeName(_currentToken); |
| 622 if (token == null) { | 735 if (token == null) { |
| 623 return false; | 736 return false; |
| 624 } | 737 } |
| 625 token = skipSimpleIdentifier(token); | 738 token = skipSimpleIdentifier(token); |
| 626 if (token == null) { | 739 if (token == null) { |
| 627 return false; | 740 return false; |
| 628 } | 741 } |
| 629 TokenType type2 = token.type; | 742 TokenType type2 = token.type; |
| 630 return identical(type2, TokenType.EQ) || identical(type2, TokenType.COMMA) |
| identical(type2, TokenType.SEMICOLON) || matches3(token, Keyword.IN); | 743 return identical(type2, TokenType.EQ) || identical(type2, TokenType.COMMA) |
| identical(type2, TokenType.SEMICOLON) || matches3(token, Keyword.IN); |
| 631 } | 744 } |
| 745 |
| 632 /** | 746 /** |
| 633 * Given that we have just found bracketed text within a comment, look to see
whether that text is | 747 * Given that we have just found bracketed text within a comment, look to see
whether that text is |
| 634 * (a) followed by a parenthesized link address, (b) followed by a colon, or (
c) followed by | 748 * (a) followed by a parenthesized link address, (b) followed by a colon, or (
c) followed by |
| 635 * optional whitespace and another square bracket. | 749 * optional whitespace and another square bracket. |
| 636 * <p> | 750 * <p> |
| 637 * This method uses the syntax described by the <a | 751 * This method uses the syntax described by the <a |
| 638 * href="http://daringfireball.net/projects/markdown/syntax">markdown</a> proj
ect. | 752 * href="http://daringfireball.net/projects/markdown/syntax">markdown</a> proj
ect. |
| 639 * @param comment the comment text in which the bracketed text was found | 753 * @param comment the comment text in which the bracketed text was found |
| 640 * @param rightIndex the index of the right bracket | 754 * @param rightIndex the index of the right bracket |
| 641 * @return {@code true} if the bracketed text is followed by a link address | 755 * @return {@code true} if the bracketed text is followed by a link address |
| (...skipping 10 matching lines...) Expand all Loading... |
| 652 } | 766 } |
| 653 while (Character.isWhitespace(nextChar)) { | 767 while (Character.isWhitespace(nextChar)) { |
| 654 index = index + 1; | 768 index = index + 1; |
| 655 if (index >= length2) { | 769 if (index >= length2) { |
| 656 return false; | 770 return false; |
| 657 } | 771 } |
| 658 nextChar = comment.codeUnitAt(index); | 772 nextChar = comment.codeUnitAt(index); |
| 659 } | 773 } |
| 660 return nextChar == 0x5B; | 774 return nextChar == 0x5B; |
| 661 } | 775 } |
| 776 |
| 662 /** | 777 /** |
| 663 * Return {@code true} if the given token appears to be the beginning of an op
erator declaration. | 778 * Return {@code true} if the given token appears to be the beginning of an op
erator declaration. |
| 664 * @param startToken the token that might be the start of an operator declarat
ion | 779 * @param startToken the token that might be the start of an operator declarat
ion |
| 665 * @return {@code true} if the given token appears to be the beginning of an o
perator declaration | 780 * @return {@code true} if the given token appears to be the beginning of an o
perator declaration |
| 666 */ | 781 */ |
| 667 bool isOperator(Token startToken) { | 782 bool isOperator(Token startToken) { |
| 668 if (startToken.isOperator()) { | 783 if (startToken.isOperator()) { |
| 669 Token token = startToken.next; | 784 Token token = startToken.next; |
| 670 while (token.isOperator()) { | 785 while (token.isOperator()) { |
| 671 token = token.next; | 786 token = token.next; |
| 672 } | 787 } |
| 673 return matches4(token, TokenType.OPEN_PAREN); | 788 return matches4(token, TokenType.OPEN_PAREN); |
| 674 } | 789 } |
| 675 return false; | 790 return false; |
| 676 } | 791 } |
| 792 |
| 677 /** | 793 /** |
| 678 * Return {@code true} if the current token appears to be the beginning of a s
witch member. | 794 * Return {@code true} if the current token appears to be the beginning of a s
witch member. |
| 679 * @return {@code true} if the current token appears to be the beginning of a
switch member | 795 * @return {@code true} if the current token appears to be the beginning of a
switch member |
| 680 */ | 796 */ |
| 681 bool isSwitchMember() { | 797 bool isSwitchMember() { |
| 682 Token token = _currentToken; | 798 Token token = _currentToken; |
| 683 while (matches4(token, TokenType.IDENTIFIER) && matches4(token.next, TokenTy
pe.COLON)) { | 799 while (matches4(token, TokenType.IDENTIFIER) && matches4(token.next, TokenTy
pe.COLON)) { |
| 684 token = token.next.next; | 800 token = token.next.next; |
| 685 } | 801 } |
| 686 if (identical(token.type, TokenType.KEYWORD)) { | 802 if (identical(token.type, TokenType.KEYWORD)) { |
| 687 Keyword keyword2 = ((token as KeywordToken)).keyword; | 803 Keyword keyword2 = ((token as KeywordToken)).keyword; |
| 688 return identical(keyword2, Keyword.CASE) || identical(keyword2, Keyword.DE
FAULT); | 804 return identical(keyword2, Keyword.CASE) || identical(keyword2, Keyword.DE
FAULT); |
| 689 } | 805 } |
| 690 return false; | 806 return false; |
| 691 } | 807 } |
| 808 |
| 692 /** | 809 /** |
| 693 * Compare the given tokens to find the token that appears first in the source
being parsed. That | 810 * Compare the given tokens to find the token that appears first in the source
being parsed. That |
| 694 * is, return the left-most of all of the tokens. The arguments are allowed to
be {@code null}. | 811 * is, return the left-most of all of the tokens. The arguments are allowed to
be {@code null}. |
| 695 * Return the token with the smallest offset, or {@code null} if there are no
arguments or if all | 812 * Return the token with the smallest offset, or {@code null} if there are no
arguments or if all |
| 696 * of the arguments are {@code null}. | 813 * of the arguments are {@code null}. |
| 697 * @param tokens the tokens being compared | 814 * @param tokens the tokens being compared |
| 698 * @return the token with the smallest offset | 815 * @return the token with the smallest offset |
| 699 */ | 816 */ |
| 700 Token lexicallyFirst(List<Token> tokens) { | 817 Token lexicallyFirst(List<Token> tokens) { |
| 701 Token first = null; | 818 Token first = null; |
| 702 int firstOffset = 2147483647; | 819 int firstOffset = 2147483647; |
| 703 for (Token token in tokens) { | 820 for (Token token in tokens) { |
| 704 if (token != null) { | 821 if (token != null) { |
| 705 int offset2 = token.offset; | 822 int offset2 = token.offset; |
| 706 if (offset2 < firstOffset) { | 823 if (offset2 < firstOffset) { |
| 707 first = token; | 824 first = token; |
| 825 firstOffset = offset2; |
| 708 } | 826 } |
| 709 } | 827 } |
| 710 } | 828 } |
| 711 return first; | 829 return first; |
| 712 } | 830 } |
| 831 |
| 713 /** | 832 /** |
| 714 * Return {@code true} if the current token matches the given keyword. | 833 * Return {@code true} if the current token matches the given keyword. |
| 715 * @param keyword the keyword that can optionally appear in the current locati
on | 834 * @param keyword the keyword that can optionally appear in the current locati
on |
| 716 * @return {@code true} if the current token matches the given keyword | 835 * @return {@code true} if the current token matches the given keyword |
| 717 */ | 836 */ |
| 718 bool matches(Keyword keyword) => matches3(_currentToken, keyword); | 837 bool matches(Keyword keyword) => matches3(_currentToken, keyword); |
| 838 |
| 719 /** | 839 /** |
| 720 * Return {@code true} if the current token matches the given identifier. | 840 * Return {@code true} if the current token matches the given identifier. |
| 721 * @param identifier the identifier that can optionally appear in the current
location | 841 * @param identifier the identifier that can optionally appear in the current
location |
| 722 * @return {@code true} if the current token matches the given identifier | 842 * @return {@code true} if the current token matches the given identifier |
| 723 */ | 843 */ |
| 724 bool matches2(String identifier) => identical(_currentToken.type, TokenType.ID
ENTIFIER) && _currentToken.lexeme == identifier; | 844 bool matches2(String identifier) => identical(_currentToken.type, TokenType.ID
ENTIFIER) && _currentToken.lexeme == identifier; |
| 845 |
| 725 /** | 846 /** |
| 726 * Return {@code true} if the given token matches the given keyword. | 847 * Return {@code true} if the given token matches the given keyword. |
| 727 * @param token the token being tested | 848 * @param token the token being tested |
| 728 * @param keyword the keyword that is being tested for | 849 * @param keyword the keyword that is being tested for |
| 729 * @return {@code true} if the given token matches the given keyword | 850 * @return {@code true} if the given token matches the given keyword |
| 730 */ | 851 */ |
| 731 bool matches3(Token token, Keyword keyword2) => identical(token.type, TokenTyp
e.KEYWORD) && identical(((token as KeywordToken)).keyword, keyword2); | 852 bool matches3(Token token, Keyword keyword2) => identical(token.type, TokenTyp
e.KEYWORD) && identical(((token as KeywordToken)).keyword, keyword2); |
| 853 |
| 732 /** | 854 /** |
| 733 * Return {@code true} if the given token has the given type. | 855 * Return {@code true} if the given token has the given type. |
| 734 * @param token the token being tested | 856 * @param token the token being tested |
| 735 * @param type the type of token that is being tested for | 857 * @param type the type of token that is being tested for |
| 736 * @return {@code true} if the given token has the given type | 858 * @return {@code true} if the given token has the given type |
| 737 */ | 859 */ |
| 738 bool matches4(Token token, TokenType type2) => identical(token.type, type2); | 860 bool matches4(Token token, TokenType type2) => identical(token.type, type2); |
| 861 |
| 739 /** | 862 /** |
| 740 * Return {@code true} if the current token has the given type. Note that this
method, unlike | 863 * Return {@code true} if the current token has the given type. Note that this
method, unlike |
| 741 * other variants, will modify the token stream if possible to match a wider r
ange of tokens. In | 864 * other variants, will modify the token stream if possible to match a wider r
ange of tokens. In |
| 742 * particular, if we are attempting to match a '>' and the next token is eithe
r a '>>' or '>>>', | 865 * particular, if we are attempting to match a '>' and the next token is eithe
r a '>>' or '>>>', |
| 743 * the token stream will be re-written and {@code true} will be returned. | 866 * the token stream will be re-written and {@code true} will be returned. |
| 744 * @param type the type of token that can optionally appear in the current loc
ation | 867 * @param type the type of token that can optionally appear in the current loc
ation |
| 745 * @return {@code true} if the current token has the given type | 868 * @return {@code true} if the current token has the given type |
| 746 */ | 869 */ |
| 747 bool matches5(TokenType type2) { | 870 bool matches5(TokenType type2) { |
| 748 TokenType currentType = _currentToken.type; | 871 TokenType currentType = _currentToken.type; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 776 first.setNext(second); | 899 first.setNext(second); |
| 777 _currentToken.previous.setNext(first); | 900 _currentToken.previous.setNext(first); |
| 778 _currentToken = first; | 901 _currentToken = first; |
| 779 return true; | 902 return true; |
| 780 } | 903 } |
| 781 } | 904 } |
| 782 return false; | 905 return false; |
| 783 } | 906 } |
| 784 return true; | 907 return true; |
| 785 } | 908 } |
| 909 |
| 786 /** | 910 /** |
| 787 * Return {@code true} if the given token has any one of the given types. | 911 * Return {@code true} if the given token has any one of the given types. |
| 788 * @param token the token being tested | 912 * @param token the token being tested |
| 789 * @param types the types of token that are being tested for | 913 * @param types the types of token that are being tested for |
| 790 * @return {@code true} if the given token has any of the given types | 914 * @return {@code true} if the given token has any of the given types |
| 791 */ | 915 */ |
| 792 bool matchesAny(Token token, List<TokenType> types) { | 916 bool matchesAny(Token token, List<TokenType> types) { |
| 793 TokenType actualType = token.type; | 917 TokenType actualType = token.type; |
| 794 for (TokenType type in types) { | 918 for (TokenType type in types) { |
| 795 if (identical(actualType, type)) { | 919 if (identical(actualType, type)) { |
| 796 return true; | 920 return true; |
| 797 } | 921 } |
| 798 } | 922 } |
| 799 return false; | 923 return false; |
| 800 } | 924 } |
| 925 |
| 801 /** | 926 /** |
| 802 * Return {@code true} if the current token is a valid identifier. Valid ident
ifiers include | 927 * Return {@code true} if the current token is a valid identifier. Valid ident
ifiers include |
| 803 * built-in identifiers (pseudo-keywords). | 928 * built-in identifiers (pseudo-keywords). |
| 804 * @return {@code true} if the current token is a valid identifier | 929 * @return {@code true} if the current token is a valid identifier |
| 805 */ | 930 */ |
| 806 bool matchesIdentifier() => matchesIdentifier2(_currentToken); | 931 bool matchesIdentifier() => matchesIdentifier2(_currentToken); |
| 932 |
| 807 /** | 933 /** |
| 808 * Return {@code true} if the given token is a valid identifier. Valid identif
iers include | 934 * Return {@code true} if the given token is a valid identifier. Valid identif
iers include |
| 809 * built-in identifiers (pseudo-keywords). | 935 * built-in identifiers (pseudo-keywords). |
| 810 * @return {@code true} if the given token is a valid identifier | 936 * @return {@code true} if the given token is a valid identifier |
| 811 */ | 937 */ |
| 812 bool matchesIdentifier2(Token token) => matches4(token, TokenType.IDENTIFIER)
|| (matches4(token, TokenType.KEYWORD) && ((token as KeywordToken)).keyword.isPs
eudoKeyword()); | 938 bool matchesIdentifier2(Token token) => matches4(token, TokenType.IDENTIFIER)
|| (matches4(token, TokenType.KEYWORD) && ((token as KeywordToken)).keyword.isPs
eudoKeyword()); |
| 939 |
| 813 /** | 940 /** |
| 814 * If the current token has the given type, then advance to the next token and
return {@code true}. Otherwise, return {@code false} without advancing. | 941 * If the current token has the given type, then advance to the next token and
return {@code true}. Otherwise, return {@code false} without advancing. |
| 815 * @param type the type of token that can optionally appear in the current loc
ation | 942 * @param type the type of token that can optionally appear in the current loc
ation |
| 816 * @return {@code true} if the current token has the given type | 943 * @return {@code true} if the current token has the given type |
| 817 */ | 944 */ |
| 818 bool optional(TokenType type) { | 945 bool optional(TokenType type) { |
| 819 if (matches5(type)) { | 946 if (matches5(type)) { |
| 820 advance(); | 947 advance(); |
| 821 return true; | 948 return true; |
| 822 } | 949 } |
| 823 return false; | 950 return false; |
| 824 } | 951 } |
| 952 |
| 825 /** | 953 /** |
| 826 * Parse an additive expression. | 954 * Parse an additive expression. |
| 827 * <pre> | 955 * <pre> |
| 828 * additiveExpression ::= | 956 * additiveExpression ::= |
| 829 * multiplicativeExpression (additiveOperator multiplicativeExpression) | 957 * multiplicativeExpression (additiveOperator multiplicativeExpression) |
| 830 * | 'super' (additiveOperator multiplicativeExpression)+ | 958 * | 'super' (additiveOperator multiplicativeExpression)+ |
| 831 * </pre> | 959 * </pre> |
| 832 * @return the additive expression that was parsed | 960 * @return the additive expression that was parsed |
| 833 */ | 961 */ |
| 834 Expression parseAdditiveExpression() { | 962 Expression parseAdditiveExpression() { |
| 835 Expression expression; | 963 Expression expression; |
| 836 if (matches(Keyword.SUPER) && _currentToken.next.type.isAdditiveOperator())
{ | 964 if (matches(Keyword.SUPER) && _currentToken.next.type.isAdditiveOperator())
{ |
| 837 expression = new SuperExpression.full(andAdvance); | 965 expression = new SuperExpression.full(andAdvance); |
| 838 } else { | 966 } else { |
| 839 expression = parseMultiplicativeExpression(); | 967 expression = parseMultiplicativeExpression(); |
| 840 } | 968 } |
| 841 while (_currentToken.type.isAdditiveOperator()) { | 969 while (_currentToken.type.isAdditiveOperator()) { |
| 842 Token operator = andAdvance; | 970 Token operator = andAdvance; |
| 843 expression = new BinaryExpression.full(expression, operator, parseMultipli
cativeExpression()); | 971 expression = new BinaryExpression.full(expression, operator, parseMultipli
cativeExpression()); |
| 844 } | 972 } |
| 845 return expression; | 973 return expression; |
| 846 } | 974 } |
| 975 |
| 847 /** | 976 /** |
| 848 * Parse an annotation. | 977 * Parse an annotation. |
| 849 * <pre> | 978 * <pre> |
| 850 * annotation ::= | 979 * annotation ::= |
| 851 * '@' qualified ('.' identifier)? arguments? | 980 * '@' qualified ('.' identifier)? arguments? |
| 852 * </pre> | 981 * </pre> |
| 853 * @return the annotation that was parsed | 982 * @return the annotation that was parsed |
| 854 */ | 983 */ |
| 855 Annotation parseAnnotation() { | 984 Annotation parseAnnotation() { |
| 856 Token atSign = expect2(TokenType.AT); | 985 Token atSign = expect2(TokenType.AT); |
| 857 Identifier name = parsePrefixedIdentifier(); | 986 Identifier name = parsePrefixedIdentifier(); |
| 858 Token period = null; | 987 Token period = null; |
| 859 SimpleIdentifier constructorName = null; | 988 SimpleIdentifier constructorName = null; |
| 860 if (matches5(TokenType.PERIOD)) { | 989 if (matches5(TokenType.PERIOD)) { |
| 861 period = andAdvance; | 990 period = andAdvance; |
| 862 constructorName = parseSimpleIdentifier(); | 991 constructorName = parseSimpleIdentifier(); |
| 863 } | 992 } |
| 864 ArgumentList arguments = null; | 993 ArgumentList arguments = null; |
| 865 if (matches5(TokenType.OPEN_PAREN)) { | 994 if (matches5(TokenType.OPEN_PAREN)) { |
| 866 arguments = parseArgumentList(); | 995 arguments = parseArgumentList(); |
| 867 } | 996 } |
| 868 return new Annotation.full(atSign, name, period, constructorName, arguments)
; | 997 return new Annotation.full(atSign, name, period, constructorName, arguments)
; |
| 869 } | 998 } |
| 999 |
| 870 /** | 1000 /** |
| 871 * Parse an argument. | 1001 * Parse an argument. |
| 872 * <pre> | 1002 * <pre> |
| 873 * argument ::= | 1003 * argument ::= |
| 874 * namedArgument | 1004 * namedArgument |
| 875 * | expression | 1005 * | expression |
| 876 * namedArgument ::= | 1006 * namedArgument ::= |
| 877 * label expression | 1007 * label expression |
| 878 * </pre> | 1008 * </pre> |
| 879 * @return the argument that was parsed | 1009 * @return the argument that was parsed |
| 880 */ | 1010 */ |
| 881 Expression parseArgument() { | 1011 Expression parseArgument() { |
| 882 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { | 1012 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { |
| 883 SimpleIdentifier label = new SimpleIdentifier.full(andAdvance); | 1013 SimpleIdentifier label = new SimpleIdentifier.full(andAdvance); |
| 884 Label name = new Label.full(label, andAdvance); | 1014 Label name = new Label.full(label, andAdvance); |
| 885 return new NamedExpression.full(name, parseExpression2()); | 1015 return new NamedExpression.full(name, parseExpression2()); |
| 886 } else { | 1016 } else { |
| 887 return parseExpression2(); | 1017 return parseExpression2(); |
| 888 } | 1018 } |
| 889 } | 1019 } |
| 1020 |
| 890 /** | 1021 /** |
| 891 * Parse an argument definition test. | 1022 * Parse an argument definition test. |
| 892 * <pre> | 1023 * <pre> |
| 893 * argumentDefinitionTest ::= | 1024 * argumentDefinitionTest ::= |
| 894 * '?' identifier | 1025 * '?' identifier |
| 895 * </pre> | 1026 * </pre> |
| 896 * @return the argument definition test that was parsed | 1027 * @return the argument definition test that was parsed |
| 897 */ | 1028 */ |
| 898 ArgumentDefinitionTest parseArgumentDefinitionTest() { | 1029 ArgumentDefinitionTest parseArgumentDefinitionTest() { |
| 899 Token question = expect2(TokenType.QUESTION); | 1030 Token question = expect2(TokenType.QUESTION); |
| 900 SimpleIdentifier identifier = parseSimpleIdentifier(); | 1031 SimpleIdentifier identifier = parseSimpleIdentifier(); |
| 901 return new ArgumentDefinitionTest.full(question, identifier); | 1032 return new ArgumentDefinitionTest.full(question, identifier); |
| 902 } | 1033 } |
| 1034 |
| 903 /** | 1035 /** |
| 904 * Parse a list of arguments. | 1036 * Parse a list of arguments. |
| 905 * <pre> | 1037 * <pre> |
| 906 * arguments ::= | 1038 * arguments ::= |
| 907 * '(' argumentList? ')' | 1039 * '(' argumentList? ')' |
| 908 * argumentList ::= | 1040 * argumentList ::= |
| 909 * namedArgument (',' namedArgument) | 1041 * namedArgument (',' namedArgument) |
| 910 * | expressionList (',' namedArgument) | 1042 * | expressionList (',' namedArgument) |
| 911 * </pre> | 1043 * </pre> |
| 912 * @return the argument list that was parsed | 1044 * @return the argument list that was parsed |
| 913 */ | 1045 */ |
| 914 ArgumentList parseArgumentList() { | 1046 ArgumentList parseArgumentList() { |
| 915 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); | 1047 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); |
| 916 List<Expression> arguments = new List<Expression>(); | 1048 List<Expression> arguments = new List<Expression>(); |
| 917 if (matches5(TokenType.CLOSE_PAREN)) { | 1049 if (matches5(TokenType.CLOSE_PAREN)) { |
| 918 return new ArgumentList.full(leftParenthesis, arguments, andAdvance); | 1050 return new ArgumentList.full(leftParenthesis, arguments, andAdvance); |
| 919 } | 1051 } |
| 920 Expression argument = parseArgument(); | 1052 Expression argument = parseArgument(); |
| 921 arguments.add(argument); | 1053 arguments.add(argument); |
| 922 bool foundNamedArgument = argument is NamedExpression; | 1054 bool foundNamedArgument = argument is NamedExpression; |
| 923 bool generatedError = false; | 1055 bool generatedError = false; |
| 924 while (optional(TokenType.COMMA)) { | 1056 while (optional(TokenType.COMMA)) { |
| 925 argument = parseArgument(); | 1057 argument = parseArgument(); |
| 926 arguments.add(argument); | 1058 arguments.add(argument); |
| 927 if (foundNamedArgument) { | 1059 if (foundNamedArgument) { |
| 928 if (!generatedError && argument is! NamedExpression) { | 1060 if (!generatedError && argument is! NamedExpression) { |
| 929 reportError4(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []); | 1061 reportError7(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []); |
| 930 generatedError = true; | 1062 generatedError = true; |
| 931 } | 1063 } |
| 932 } else if (argument is NamedExpression) { | 1064 } else if (argument is NamedExpression) { |
| 933 foundNamedArgument = true; | 1065 foundNamedArgument = true; |
| 934 } | 1066 } |
| 935 } | 1067 } |
| 936 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 1068 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 937 return new ArgumentList.full(leftParenthesis, arguments, rightParenthesis); | 1069 return new ArgumentList.full(leftParenthesis, arguments, rightParenthesis); |
| 938 } | 1070 } |
| 1071 |
| 939 /** | 1072 /** |
| 940 * Parse an assert statement. | 1073 * Parse an assert statement. |
| 941 * <pre> | 1074 * <pre> |
| 942 * assertStatement ::= | 1075 * assertStatement ::= |
| 943 * 'assert' '(' conditionalExpression ')' ';' | 1076 * 'assert' '(' conditionalExpression ')' ';' |
| 944 * </pre> | 1077 * </pre> |
| 945 * @return the assert statement | 1078 * @return the assert statement |
| 946 */ | 1079 */ |
| 947 AssertStatement parseAssertStatement() { | 1080 AssertStatement parseAssertStatement() { |
| 948 Token keyword = expect(Keyword.ASSERT); | 1081 Token keyword = expect(Keyword.ASSERT); |
| 949 Token leftParen = expect2(TokenType.OPEN_PAREN); | 1082 Token leftParen = expect2(TokenType.OPEN_PAREN); |
| 950 Expression expression = parseConditionalExpression(); | 1083 Expression expression = parseConditionalExpression(); |
| 951 Token rightParen = expect2(TokenType.CLOSE_PAREN); | 1084 Token rightParen = expect2(TokenType.CLOSE_PAREN); |
| 952 Token semicolon = expect2(TokenType.SEMICOLON); | 1085 Token semicolon = expect2(TokenType.SEMICOLON); |
| 953 return new AssertStatement.full(keyword, leftParen, expression, rightParen,
semicolon); | 1086 return new AssertStatement.full(keyword, leftParen, expression, rightParen,
semicolon); |
| 954 } | 1087 } |
| 1088 |
| 955 /** | 1089 /** |
| 956 * Parse an assignable expression. | 1090 * Parse an assignable expression. |
| 957 * <pre> | 1091 * <pre> |
| 958 * assignableExpression ::= | 1092 * assignableExpression ::= |
| 959 * primary (arguments* assignableSelector)+ | 1093 * primary (arguments* assignableSelector)+ |
| 960 * | 'super' assignableSelector | 1094 * | 'super' assignableSelector |
| 961 * | identifier | 1095 * | identifier |
| 962 * </pre> | 1096 * </pre> |
| 963 * @param primaryAllowed {@code true} if the expression is allowed to be a pri
mary without any | 1097 * @param primaryAllowed {@code true} if the expression is allowed to be a pri
mary without any |
| 964 * assignable selector | 1098 * assignable selector |
| (...skipping 28 matching lines...) Expand all Loading... |
| 993 if (!isOptional && (expression is PrefixedIdentifier)) { | 1127 if (!isOptional && (expression is PrefixedIdentifier)) { |
| 994 PrefixedIdentifier identifier = expression as PrefixedIdentifier; | 1128 PrefixedIdentifier identifier = expression as PrefixedIdentifier; |
| 995 expression = new PropertyAccess.full(identifier.prefix, identifier.per
iod, identifier.identifier); | 1129 expression = new PropertyAccess.full(identifier.prefix, identifier.per
iod, identifier.identifier); |
| 996 } | 1130 } |
| 997 return expression; | 1131 return expression; |
| 998 } | 1132 } |
| 999 expression = selectorExpression; | 1133 expression = selectorExpression; |
| 1000 isOptional = true; | 1134 isOptional = true; |
| 1001 } | 1135 } |
| 1002 } | 1136 } |
| 1137 |
| 1003 /** | 1138 /** |
| 1004 * Parse an assignable selector. | 1139 * Parse an assignable selector. |
| 1005 * <pre> | 1140 * <pre> |
| 1006 * assignableSelector ::= | 1141 * assignableSelector ::= |
| 1007 * '\[' expression '\]' | 1142 * '\[' expression '\]' |
| 1008 * | '.' identifier | 1143 * | '.' identifier |
| 1009 * </pre> | 1144 * </pre> |
| 1010 * @param prefix the expression preceding the selector | 1145 * @param prefix the expression preceding the selector |
| 1011 * @param optional {@code true} if the selector is optional | 1146 * @param optional {@code true} if the selector is optional |
| 1012 * @return the assignable selector that was parsed | 1147 * @return the assignable selector that was parsed |
| 1013 */ | 1148 */ |
| 1014 Expression parseAssignableSelector(Expression prefix, bool optional) { | 1149 Expression parseAssignableSelector(Expression prefix, bool optional) { |
| 1015 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { | 1150 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { |
| 1016 Token leftBracket = andAdvance; | 1151 Token leftBracket = andAdvance; |
| 1017 Expression index = parseExpression2(); | 1152 Expression index = parseExpression2(); |
| 1018 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); | 1153 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); |
| 1019 return new IndexExpression.forTarget_full(prefix, leftBracket, index, righ
tBracket); | 1154 return new IndexExpression.forTarget_full(prefix, leftBracket, index, righ
tBracket); |
| 1020 } else if (matches5(TokenType.PERIOD)) { | 1155 } else if (matches5(TokenType.PERIOD)) { |
| 1021 Token period = andAdvance; | 1156 Token period = andAdvance; |
| 1022 return new PropertyAccess.full(prefix, period, parseSimpleIdentifier()); | 1157 return new PropertyAccess.full(prefix, period, parseSimpleIdentifier()); |
| 1023 } else { | 1158 } else { |
| 1024 if (!optional) { | 1159 if (!optional) { |
| 1025 reportError4(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); | 1160 reportError7(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); |
| 1026 } | 1161 } |
| 1027 return prefix; | 1162 return prefix; |
| 1028 } | 1163 } |
| 1029 } | 1164 } |
| 1165 |
| 1030 /** | 1166 /** |
| 1031 * Parse a bitwise and expression. | 1167 * Parse a bitwise and expression. |
| 1032 * <pre> | 1168 * <pre> |
| 1033 * bitwiseAndExpression ::= | 1169 * bitwiseAndExpression ::= |
| 1034 * equalityExpression ('&' equalityExpression) | 1170 * equalityExpression ('&' equalityExpression) |
| 1035 * | 'super' ('&' equalityExpression)+ | 1171 * | 'super' ('&' equalityExpression)+ |
| 1036 * </pre> | 1172 * </pre> |
| 1037 * @return the bitwise and expression that was parsed | 1173 * @return the bitwise and expression that was parsed |
| 1038 */ | 1174 */ |
| 1039 Expression parseBitwiseAndExpression() { | 1175 Expression parseBitwiseAndExpression() { |
| 1040 Expression expression; | 1176 Expression expression; |
| 1041 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.AMPERSAND)) { | 1177 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.AMPERSAND)) { |
| 1042 expression = new SuperExpression.full(andAdvance); | 1178 expression = new SuperExpression.full(andAdvance); |
| 1043 } else { | 1179 } else { |
| 1044 expression = parseEqualityExpression(); | 1180 expression = parseEqualityExpression(); |
| 1045 } | 1181 } |
| 1046 while (matches5(TokenType.AMPERSAND)) { | 1182 while (matches5(TokenType.AMPERSAND)) { |
| 1047 Token operator = andAdvance; | 1183 Token operator = andAdvance; |
| 1048 expression = new BinaryExpression.full(expression, operator, parseEquality
Expression()); | 1184 expression = new BinaryExpression.full(expression, operator, parseEquality
Expression()); |
| 1049 } | 1185 } |
| 1050 return expression; | 1186 return expression; |
| 1051 } | 1187 } |
| 1188 |
| 1052 /** | 1189 /** |
| 1053 * Parse a bitwise or expression. | 1190 * Parse a bitwise or expression. |
| 1054 * <pre> | 1191 * <pre> |
| 1055 * bitwiseOrExpression ::= | 1192 * bitwiseOrExpression ::= |
| 1056 * bitwiseXorExpression ('|' bitwiseXorExpression) | 1193 * bitwiseXorExpression ('|' bitwiseXorExpression) |
| 1057 * | 'super' ('|' bitwiseXorExpression)+ | 1194 * | 'super' ('|' bitwiseXorExpression)+ |
| 1058 * </pre> | 1195 * </pre> |
| 1059 * @return the bitwise or expression that was parsed | 1196 * @return the bitwise or expression that was parsed |
| 1060 */ | 1197 */ |
| 1061 Expression parseBitwiseOrExpression() { | 1198 Expression parseBitwiseOrExpression() { |
| 1062 Expression expression; | 1199 Expression expression; |
| 1063 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.BAR)) { | 1200 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.BAR)) { |
| 1064 expression = new SuperExpression.full(andAdvance); | 1201 expression = new SuperExpression.full(andAdvance); |
| 1065 } else { | 1202 } else { |
| 1066 expression = parseBitwiseXorExpression(); | 1203 expression = parseBitwiseXorExpression(); |
| 1067 } | 1204 } |
| 1068 while (matches5(TokenType.BAR)) { | 1205 while (matches5(TokenType.BAR)) { |
| 1069 Token operator = andAdvance; | 1206 Token operator = andAdvance; |
| 1070 expression = new BinaryExpression.full(expression, operator, parseBitwiseX
orExpression()); | 1207 expression = new BinaryExpression.full(expression, operator, parseBitwiseX
orExpression()); |
| 1071 } | 1208 } |
| 1072 return expression; | 1209 return expression; |
| 1073 } | 1210 } |
| 1211 |
| 1074 /** | 1212 /** |
| 1075 * Parse a bitwise exclusive-or expression. | 1213 * Parse a bitwise exclusive-or expression. |
| 1076 * <pre> | 1214 * <pre> |
| 1077 * bitwiseXorExpression ::= | 1215 * bitwiseXorExpression ::= |
| 1078 * bitwiseAndExpression ('^' bitwiseAndExpression) | 1216 * bitwiseAndExpression ('^' bitwiseAndExpression) |
| 1079 * | 'super' ('^' bitwiseAndExpression)+ | 1217 * | 'super' ('^' bitwiseAndExpression)+ |
| 1080 * </pre> | 1218 * </pre> |
| 1081 * @return the bitwise exclusive-or expression that was parsed | 1219 * @return the bitwise exclusive-or expression that was parsed |
| 1082 */ | 1220 */ |
| 1083 Expression parseBitwiseXorExpression() { | 1221 Expression parseBitwiseXorExpression() { |
| 1084 Expression expression; | 1222 Expression expression; |
| 1085 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.CARET)) { | 1223 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.CARET)) { |
| 1086 expression = new SuperExpression.full(andAdvance); | 1224 expression = new SuperExpression.full(andAdvance); |
| 1087 } else { | 1225 } else { |
| 1088 expression = parseBitwiseAndExpression(); | 1226 expression = parseBitwiseAndExpression(); |
| 1089 } | 1227 } |
| 1090 while (matches5(TokenType.CARET)) { | 1228 while (matches5(TokenType.CARET)) { |
| 1091 Token operator = andAdvance; | 1229 Token operator = andAdvance; |
| 1092 expression = new BinaryExpression.full(expression, operator, parseBitwiseA
ndExpression()); | 1230 expression = new BinaryExpression.full(expression, operator, parseBitwiseA
ndExpression()); |
| 1093 } | 1231 } |
| 1094 return expression; | 1232 return expression; |
| 1095 } | 1233 } |
| 1234 |
| 1096 /** | 1235 /** |
| 1097 * Parse a block. | 1236 * Parse a block. |
| 1098 * <pre> | 1237 * <pre> |
| 1099 * block ::= | 1238 * block ::= |
| 1100 * '{' statements '}' | 1239 * '{' statements '}' |
| 1101 * </pre> | 1240 * </pre> |
| 1102 * @return the block that was parsed | 1241 * @return the block that was parsed |
| 1103 */ | 1242 */ |
| 1104 Block parseBlock() { | 1243 Block parseBlock() { |
| 1105 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); | 1244 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); |
| 1106 List<Statement> statements = new List<Statement>(); | 1245 List<Statement> statements = new List<Statement>(); |
| 1107 Token statementStart = _currentToken; | 1246 Token statementStart = _currentToken; |
| 1108 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET))
{ | 1247 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET))
{ |
| 1109 Statement statement = parseStatement2(); | 1248 Statement statement = parseStatement2(); |
| 1110 if (statement != null) { | 1249 if (statement != null) { |
| 1111 statements.add(statement); | 1250 statements.add(statement); |
| 1112 } | 1251 } |
| 1113 if (identical(_currentToken, statementStart)) { | 1252 if (identical(_currentToken, statementStart)) { |
| 1114 reportError5(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); | 1253 reportError8(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); |
| 1115 advance(); | 1254 advance(); |
| 1116 } | 1255 } |
| 1117 statementStart = _currentToken; | 1256 statementStart = _currentToken; |
| 1118 } | 1257 } |
| 1119 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); | 1258 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); |
| 1120 return new Block.full(leftBracket, statements, rightBracket); | 1259 return new Block.full(leftBracket, statements, rightBracket); |
| 1121 } | 1260 } |
| 1261 |
| 1122 /** | 1262 /** |
| 1123 * Parse a break statement. | 1263 * Parse a break statement. |
| 1124 * <pre> | 1264 * <pre> |
| 1125 * breakStatement ::= | 1265 * breakStatement ::= |
| 1126 * 'break' identifier? ';' | 1266 * 'break' identifier? ';' |
| 1127 * </pre> | 1267 * </pre> |
| 1128 * @return the break statement that was parsed | 1268 * @return the break statement that was parsed |
| 1129 */ | 1269 */ |
| 1130 Statement parseBreakStatement() { | 1270 Statement parseBreakStatement() { |
| 1131 Token breakKeyword = expect(Keyword.BREAK); | 1271 Token breakKeyword = expect(Keyword.BREAK); |
| 1132 SimpleIdentifier label = null; | 1272 SimpleIdentifier label = null; |
| 1133 if (matchesIdentifier()) { | 1273 if (matchesIdentifier()) { |
| 1134 label = parseSimpleIdentifier(); | 1274 label = parseSimpleIdentifier(); |
| 1135 } | 1275 } |
| 1136 if (!_inLoop && !_inSwitch && label == null) { | 1276 if (!_inLoop && !_inSwitch && label == null) { |
| 1137 reportError5(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []); | 1277 reportError8(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []); |
| 1138 } | 1278 } |
| 1139 Token semicolon = expect2(TokenType.SEMICOLON); | 1279 Token semicolon = expect2(TokenType.SEMICOLON); |
| 1140 return new BreakStatement.full(breakKeyword, label, semicolon); | 1280 return new BreakStatement.full(breakKeyword, label, semicolon); |
| 1141 } | 1281 } |
| 1282 |
| 1142 /** | 1283 /** |
| 1143 * Parse a cascade section. | 1284 * Parse a cascade section. |
| 1144 * <pre> | 1285 * <pre> |
| 1145 * cascadeSection ::= | 1286 * cascadeSection ::= |
| 1146 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* cascadeA
ssignment? | 1287 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* cascadeA
ssignment? |
| 1147 * cascadeSelector ::= | 1288 * cascadeSelector ::= |
| 1148 * '\[' expression '\]' | 1289 * '\[' expression '\]' |
| 1149 * | identifier | 1290 * | identifier |
| 1150 * cascadeAssignment ::= | 1291 * cascadeAssignment ::= |
| 1151 * assignmentOperator expressionWithoutCascade | 1292 * assignmentOperator expressionWithoutCascade |
| 1152 * </pre> | 1293 * </pre> |
| 1153 * @return the expression representing the cascaded method invocation | 1294 * @return the expression representing the cascaded method invocation |
| 1154 */ | 1295 */ |
| 1155 Expression parseCascadeSection() { | 1296 Expression parseCascadeSection() { |
| 1156 Token period = expect2(TokenType.PERIOD_PERIOD); | 1297 Token period = expect2(TokenType.PERIOD_PERIOD); |
| 1157 Expression expression = null; | 1298 Expression expression = null; |
| 1158 SimpleIdentifier functionName = null; | 1299 SimpleIdentifier functionName = null; |
| 1159 if (matchesIdentifier()) { | 1300 if (matchesIdentifier()) { |
| 1160 functionName = parseSimpleIdentifier(); | 1301 functionName = parseSimpleIdentifier(); |
| 1161 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) { | 1302 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) { |
| 1162 Token leftBracket = andAdvance; | 1303 Token leftBracket = andAdvance; |
| 1163 Expression index = parseExpression2(); | 1304 Expression index = parseExpression2(); |
| 1164 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); | 1305 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); |
| 1165 expression = new IndexExpression.forCascade_full(period, leftBracket, inde
x, rightBracket); | 1306 expression = new IndexExpression.forCascade_full(period, leftBracket, inde
x, rightBracket); |
| 1166 period = null; | 1307 period = null; |
| 1167 } else { | 1308 } else { |
| 1168 reportError5(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentTok
en.lexeme]); | 1309 reportError8(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_currentT
oken.lexeme]); |
| 1169 return expression; | 1310 functionName = createSyntheticIdentifier(); |
| 1170 } | 1311 } |
| 1171 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) { | 1312 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) { |
| 1172 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { | 1313 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { |
| 1173 if (functionName != null) { | 1314 if (functionName != null) { |
| 1174 expression = new MethodInvocation.full(expression, period, functionNam
e, parseArgumentList()); | 1315 expression = new MethodInvocation.full(expression, period, functionNam
e, parseArgumentList()); |
| 1175 period = null; | 1316 period = null; |
| 1176 functionName = null; | 1317 functionName = null; |
| 1177 } else if (expression == null) { | 1318 } else if (expression == null) { |
| 1178 return null; | 1319 expression = new MethodInvocation.full(expression, period, createSynth
eticIdentifier(), parseArgumentList()); |
| 1179 } else { | 1320 } else { |
| 1180 expression = new FunctionExpressionInvocation.full(expression, parseAr
gumentList()); | 1321 expression = new FunctionExpressionInvocation.full(expression, parseAr
gumentList()); |
| 1181 } | 1322 } |
| 1182 } | 1323 } |
| 1183 } else if (functionName != null) { | 1324 } else if (functionName != null) { |
| 1184 expression = new PropertyAccess.full(expression, period, functionName); | 1325 expression = new PropertyAccess.full(expression, period, functionName); |
| 1185 period = null; | 1326 period = null; |
| 1186 } | 1327 } |
| 1187 bool progress = true; | 1328 bool progress = true; |
| 1188 while (progress) { | 1329 while (progress) { |
| 1189 progress = false; | 1330 progress = false; |
| 1190 Expression selector = parseAssignableSelector(expression, true); | 1331 Expression selector = parseAssignableSelector(expression, true); |
| 1191 if (selector != expression) { | 1332 if (selector != expression) { |
| 1192 expression = selector; | 1333 expression = selector; |
| 1193 progress = true; | 1334 progress = true; |
| 1194 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { | 1335 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { |
| 1195 expression = new FunctionExpressionInvocation.full(expression, parseAr
gumentList()); | 1336 expression = new FunctionExpressionInvocation.full(expression, parseAr
gumentList()); |
| 1196 } | 1337 } |
| 1197 } | 1338 } |
| 1198 } | 1339 } |
| 1199 if (_currentToken.type.isAssignmentOperator()) { | 1340 if (_currentToken.type.isAssignmentOperator()) { |
| 1200 Token operator = andAdvance; | 1341 Token operator = andAdvance; |
| 1201 ensureAssignable(expression); | 1342 ensureAssignable(expression); |
| 1202 expression = new AssignmentExpression.full(expression, operator, parseExpr
essionWithoutCascade()); | 1343 expression = new AssignmentExpression.full(expression, operator, parseExpr
essionWithoutCascade()); |
| 1203 } | 1344 } |
| 1204 return expression; | 1345 return expression; |
| 1205 } | 1346 } |
| 1347 |
| 1206 /** | 1348 /** |
| 1207 * Parse a class declaration. | 1349 * Parse a class declaration. |
| 1208 * <pre> | 1350 * <pre> |
| 1209 * classDeclaration ::= | 1351 * classDeclaration ::= |
| 1210 * metadata 'abstract'? 'class' name typeParameterList? (extendsClause withCla
use?)? implementsClause? '{' classMembers '}' | 1352 * metadata 'abstract'? 'class' name typeParameterList? (extendsClause withCla
use?)? implementsClause? '{' classMembers '}' |
| 1211 * </pre> | 1353 * </pre> |
| 1212 * @param commentAndMetadata the metadata to be associated with the member | 1354 * @param commentAndMetadata the metadata to be associated with the member |
| 1213 * @param abstractKeyword the token for the keyword 'abstract', or {@code null
} if the keyword was | 1355 * @param abstractKeyword the token for the keyword 'abstract', or {@code null
} if the keyword was |
| 1214 * not given | 1356 * not given |
| 1215 * @return the class declaration that was parsed | 1357 * @return the class declaration that was parsed |
| 1216 */ | 1358 */ |
| 1217 ClassDeclaration parseClassDeclaration(CommentAndMetadata commentAndMetadata,
Token abstractKeyword) { | 1359 ClassDeclaration parseClassDeclaration(CommentAndMetadata commentAndMetadata,
Token abstractKeyword) { |
| 1218 Token keyword = expect(Keyword.CLASS); | 1360 Token keyword = expect(Keyword.CLASS); |
| 1219 SimpleIdentifier name = parseSimpleIdentifier(); | 1361 SimpleIdentifier name = parseSimpleIdentifier(); |
| 1220 String className = name.name; | 1362 String className = name.name; |
| 1221 TypeParameterList typeParameters = null; | 1363 TypeParameterList typeParameters = null; |
| 1222 if (matches5(TokenType.LT)) { | 1364 if (matches5(TokenType.LT)) { |
| 1223 typeParameters = parseTypeParameterList(); | 1365 typeParameters = parseTypeParameterList(); |
| 1224 } | 1366 } |
| 1225 ExtendsClause extendsClause = null; | 1367 ExtendsClause extendsClause = null; |
| 1226 WithClause withClause = null; | 1368 WithClause withClause = null; |
| 1227 ImplementsClause implementsClause = null; | 1369 ImplementsClause implementsClause = null; |
| 1228 bool foundClause = true; | 1370 bool foundClause = true; |
| 1229 while (foundClause) { | 1371 while (foundClause) { |
| 1230 if (matches(Keyword.EXTENDS)) { | 1372 if (matches(Keyword.EXTENDS)) { |
| 1231 if (extendsClause == null) { | 1373 if (extendsClause == null) { |
| 1232 extendsClause = parseExtendsClause(); | 1374 extendsClause = parseExtendsClause(); |
| 1233 if (withClause != null) { | 1375 if (withClause != null) { |
| 1234 reportError5(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause.withKey
word, []); | 1376 reportError8(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause.withKey
word, []); |
| 1235 } else if (implementsClause != null) { | 1377 } else if (implementsClause != null) { |
| 1236 reportError5(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, implementsCl
ause.keyword, []); | 1378 reportError8(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, implementsCl
ause.keyword, []); |
| 1237 } | 1379 } |
| 1238 } else { | 1380 } else { |
| 1239 reportError5(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extendsClause.k
eyword, []); | 1381 reportError8(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extendsClause.k
eyword, []); |
| 1240 parseExtendsClause(); | 1382 parseExtendsClause(); |
| 1241 } | 1383 } |
| 1242 } else if (matches(Keyword.WITH)) { | 1384 } else if (matches(Keyword.WITH)) { |
| 1243 if (withClause == null) { | 1385 if (withClause == null) { |
| 1244 withClause = parseWithClause(); | 1386 withClause = parseWithClause(); |
| 1245 if (implementsClause != null) { | 1387 if (implementsClause != null) { |
| 1246 reportError5(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, implementsClaus
e.keyword, []); | 1388 reportError8(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, implementsClaus
e.keyword, []); |
| 1247 } | 1389 } |
| 1248 } else { | 1390 } else { |
| 1249 reportError5(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause.withKey
word, []); | 1391 reportError8(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause.withKey
word, []); |
| 1250 parseWithClause(); | 1392 parseWithClause(); |
| 1251 } | 1393 } |
| 1252 } else if (matches(Keyword.IMPLEMENTS)) { | 1394 } else if (matches(Keyword.IMPLEMENTS)) { |
| 1253 if (implementsClause == null) { | 1395 if (implementsClause == null) { |
| 1254 implementsClause = parseImplementsClause(); | 1396 implementsClause = parseImplementsClause(); |
| 1255 } else { | 1397 } else { |
| 1256 reportError5(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsCl
ause.keyword, []); | 1398 reportError8(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsCl
ause.keyword, []); |
| 1257 parseImplementsClause(); | 1399 parseImplementsClause(); |
| 1258 } | 1400 } |
| 1259 } else { | 1401 } else { |
| 1260 foundClause = false; | 1402 foundClause = false; |
| 1261 } | 1403 } |
| 1262 } | 1404 } |
| 1263 if (withClause != null && extendsClause == null) { | 1405 if (withClause != null && extendsClause == null) { |
| 1264 reportError5(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword,
[]); | 1406 reportError8(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword,
[]); |
| 1265 } | 1407 } |
| 1266 if (matches2(_NATIVE) && matches4(peek(), TokenType.STRING)) { | 1408 if (matches2(_NATIVE) && matches4(peek(), TokenType.STRING)) { |
| 1267 advance(); | 1409 advance(); |
| 1268 advance(); | 1410 advance(); |
| 1269 } | 1411 } |
| 1270 Token leftBracket = null; | 1412 Token leftBracket = null; |
| 1271 List<ClassMember> members = null; | 1413 List<ClassMember> members = null; |
| 1272 Token rightBracket = null; | 1414 Token rightBracket = null; |
| 1273 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { | 1415 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { |
| 1274 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); | 1416 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); |
| 1275 members = parseClassMembers(className, ((leftBracket as BeginToken)).endTo
ken != null); | 1417 members = parseClassMembers(className, getEndToken(leftBracket)); |
| 1276 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); | 1418 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); |
| 1277 } else { | 1419 } else { |
| 1278 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET); | 1420 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET); |
| 1279 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET); | 1421 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET); |
| 1280 reportError4(ParserErrorCode.MISSING_CLASS_BODY, []); | 1422 reportError7(ParserErrorCode.MISSING_CLASS_BODY, []); |
| 1281 } | 1423 } |
| 1282 return new ClassDeclaration.full(commentAndMetadata.comment, commentAndMetad
ata.metadata, abstractKeyword, keyword, name, typeParameters, extendsClause, wit
hClause, implementsClause, leftBracket, members, rightBracket); | 1424 return new ClassDeclaration.full(commentAndMetadata.comment, commentAndMetad
ata.metadata, abstractKeyword, keyword, name, typeParameters, extendsClause, wit
hClause, implementsClause, leftBracket, members, rightBracket); |
| 1283 } | 1425 } |
| 1426 |
| 1284 /** | 1427 /** |
| 1285 * Parse a class member. | 1428 * Parse a class member. |
| 1286 * <pre> | 1429 * <pre> |
| 1287 * classMemberDefinition ::= | 1430 * classMemberDefinition ::= |
| 1288 * declaration ';' | 1431 * declaration ';' |
| 1289 * | methodSignature functionBody | 1432 * | methodSignature functionBody |
| 1290 * </pre> | 1433 * </pre> |
| 1291 * @param className the name of the class containing the member being parsed | 1434 * @param className the name of the class containing the member being parsed |
| 1292 * @return the class member that was parsed | 1435 * @return the class member that was parsed, or {@code null} if what was found
was not a valid |
| 1436 * class member |
| 1293 */ | 1437 */ |
| 1294 ClassMember parseClassMember(String className) { | 1438 ClassMember parseClassMember(String className) { |
| 1295 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 1439 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 1296 Modifiers modifiers = parseModifiers(); | 1440 Modifiers modifiers = parseModifiers(); |
| 1297 if (matches(Keyword.VOID)) { | 1441 if (matches(Keyword.VOID)) { |
| 1298 TypeName returnType = parseReturnType(); | 1442 TypeName returnType = parseReturnType(); |
| 1299 if (matches(Keyword.GET) && matchesIdentifier2(peek())) { | 1443 if (matches(Keyword.GET) && matchesIdentifier2(peek())) { |
| 1300 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1444 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1301 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifi
ers.staticKeyword, returnType); | 1445 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifi
ers.staticKeyword, returnType); |
| 1302 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { | 1446 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { |
| 1303 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1447 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1304 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifi
ers.staticKeyword, returnType); | 1448 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifi
ers.staticKeyword, returnType); |
| 1305 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { | 1449 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { |
| 1306 validateModifiersForOperator(modifiers); | 1450 validateModifiersForOperator(modifiers); |
| 1307 return parseOperator(commentAndMetadata, modifiers.externalKeyword, retu
rnType); | 1451 return parseOperator(commentAndMetadata, modifiers.externalKeyword, retu
rnType); |
| 1308 } else if (matchesIdentifier() && matchesAny(peek(), [TokenType.OPEN_PAREN
, TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { | 1452 } else if (matchesIdentifier() && matchesAny(peek(), [TokenType.OPEN_PAREN
, TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { |
| 1309 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1453 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1310 return parseMethodDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, modifiers.staticKeyword, returnType); | 1454 return parseMethodDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, modifiers.staticKeyword, returnType); |
| 1311 } else { | 1455 } else { |
| 1312 if (matchesIdentifier()) { | 1456 if (matchesIdentifier()) { |
| 1313 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC
OLON])) { | 1457 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC
OLON])) { |
| 1314 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []); | 1458 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []); |
| 1315 return parseInitializedIdentifierList(commentAndMetadata, modifiers.
staticKeyword, validateModifiersForField(modifiers), returnType); | 1459 return parseInitializedIdentifierList(commentAndMetadata, modifiers.
staticKeyword, validateModifiersForField(modifiers), returnType); |
| 1316 } | 1460 } |
| 1317 } | 1461 } |
| 1318 if (isOperator(peek())) { | 1462 if (isOperator(peek())) { |
| 1319 validateModifiersForOperator(modifiers); | 1463 validateModifiersForOperator(modifiers); |
| 1320 return parseOperator(commentAndMetadata, modifiers.externalKeyword, re
turnType); | 1464 return parseOperator(commentAndMetadata, modifiers.externalKeyword, re
turnType); |
| 1321 } | 1465 } |
| 1322 reportError5(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); | 1466 reportError8(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); |
| 1323 return null; | 1467 return null; |
| 1324 } | 1468 } |
| 1325 } else if (matches(Keyword.GET) && matchesIdentifier2(peek())) { | 1469 } else if (matches(Keyword.GET) && matchesIdentifier2(peek())) { |
| 1326 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1470 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1327 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier
s.staticKeyword, null); | 1471 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier
s.staticKeyword, null); |
| 1328 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { | 1472 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { |
| 1329 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1473 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1330 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier
s.staticKeyword, null); | 1474 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier
s.staticKeyword, null); |
| 1331 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { | 1475 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { |
| 1332 validateModifiersForOperator(modifiers); | 1476 validateModifiersForOperator(modifiers); |
| 1333 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null); | 1477 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null); |
| 1334 } else if (!matchesIdentifier()) { | 1478 } else if (!matchesIdentifier()) { |
| 1335 if (isOperator(peek())) { | 1479 if (isOperator(peek())) { |
| 1336 validateModifiersForOperator(modifiers); | 1480 validateModifiersForOperator(modifiers); |
| 1337 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null
); | 1481 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null
); |
| 1338 } | 1482 } |
| 1339 reportError5(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); | 1483 reportError8(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); |
| 1340 return null; | 1484 return null; |
| 1341 } else if (matches4(peek(), TokenType.PERIOD) && matchesIdentifier2(peek2(2)
) && matches4(peek2(3), TokenType.OPEN_PAREN)) { | 1485 } else if (matches4(peek(), TokenType.PERIOD) && matchesIdentifier2(peek2(2)
) && matches4(peek2(3), TokenType.OPEN_PAREN)) { |
| 1342 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, val
idateModifiersForConstructor(modifiers), modifiers.factoryKeyword, parseSimpleId
entifier(), andAdvance, parseSimpleIdentifier(), parseFormalParameterList()); | 1486 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, val
idateModifiersForConstructor(modifiers), modifiers.factoryKeyword, parseSimpleId
entifier(), andAdvance, parseSimpleIdentifier(), parseFormalParameterList()); |
| 1343 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { | 1487 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { |
| 1344 SimpleIdentifier methodName = parseSimpleIdentifier(); | 1488 SimpleIdentifier methodName = parseSimpleIdentifier(); |
| 1345 FormalParameterList parameters = parseFormalParameterList(); | 1489 FormalParameterList parameters = parseFormalParameterList(); |
| 1346 if (matches5(TokenType.COLON) || modifiers.factoryKeyword != null || metho
dName.name == className) { | 1490 if (matches5(TokenType.COLON) || modifiers.factoryKeyword != null || metho
dName.name == className) { |
| 1347 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v
alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName,
null, null, parameters); | 1491 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v
alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName,
null, null, parameters); |
| 1348 } | 1492 } |
| 1349 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1493 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1350 validateFormalParameterList(parameters); | 1494 validateFormalParameterList(parameters); |
| 1351 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo
rd, modifiers.staticKeyword, null, methodName, parameters); | 1495 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo
rd, modifiers.staticKeyword, null, methodName, parameters); |
| 1352 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI
COLON])) { | 1496 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI
COLON])) { |
| 1497 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo
difiers.varKeyword == null) { |
| 1498 reportError7(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); |
| 1499 } |
| 1353 return parseInitializedIdentifierList(commentAndMetadata, modifiers.static
Keyword, validateModifiersForField(modifiers), null); | 1500 return parseInitializedIdentifierList(commentAndMetadata, modifiers.static
Keyword, validateModifiersForField(modifiers), null); |
| 1354 } | 1501 } |
| 1355 TypeName type = parseTypeName(); | 1502 TypeName type = parseTypeName(); |
| 1356 if (matches(Keyword.GET) && matchesIdentifier2(peek())) { | 1503 if (matches(Keyword.GET) && matchesIdentifier2(peek())) { |
| 1357 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1504 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1358 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier
s.staticKeyword, type); | 1505 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier
s.staticKeyword, type); |
| 1359 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { | 1506 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { |
| 1360 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1507 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1361 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier
s.staticKeyword, type); | 1508 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier
s.staticKeyword, type); |
| 1362 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { | 1509 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { |
| 1363 validateModifiersForOperator(modifiers); | 1510 validateModifiersForOperator(modifiers); |
| 1364 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type); | 1511 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type); |
| 1365 } else if (!matchesIdentifier()) { | 1512 } else if (!matchesIdentifier()) { |
| 1366 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { | 1513 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { |
| 1367 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat
icKeyword, validateModifiersForField(modifiers), type); | 1514 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat
icKeyword, validateModifiersForField(modifiers), type); |
| 1368 } | 1515 } |
| 1369 if (isOperator(peek())) { | 1516 if (isOperator(peek())) { |
| 1370 validateModifiersForOperator(modifiers); | 1517 validateModifiersForOperator(modifiers); |
| 1371 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type
); | 1518 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type
); |
| 1372 } | 1519 } |
| 1373 reportError5(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); | 1520 reportError8(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); |
| 1374 return null; | 1521 return null; |
| 1375 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { | 1522 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { |
| 1523 SimpleIdentifier methodName = parseSimpleIdentifier(); |
| 1524 FormalParameterList parameters = parseFormalParameterList(); |
| 1525 if (methodName.name == className) { |
| 1526 reportError(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type, []); |
| 1527 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v
alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName,
null, null, parameters); |
| 1528 } |
| 1376 validateModifiersForGetterOrSetterOrMethod(modifiers); | 1529 validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1377 return parseMethodDeclaration(commentAndMetadata, modifiers.externalKeywor
d, modifiers.staticKeyword, type); | 1530 validateFormalParameterList(parameters); |
| 1531 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo
rd, modifiers.staticKeyword, type, methodName, parameters); |
| 1378 } | 1532 } |
| 1379 return parseInitializedIdentifierList(commentAndMetadata, modifiers.staticKe
yword, validateModifiersForField(modifiers), type); | 1533 return parseInitializedIdentifierList(commentAndMetadata, modifiers.staticKe
yword, validateModifiersForField(modifiers), type); |
| 1380 } | 1534 } |
| 1535 |
| 1381 /** | 1536 /** |
| 1382 * Parse a list of class members. | 1537 * Parse a list of class members. |
| 1383 * <pre> | 1538 * <pre> |
| 1384 * classMembers ::= | 1539 * classMembers ::= |
| 1385 * (metadata memberDefinition) | 1540 * (metadata memberDefinition) |
| 1386 * </pre> | 1541 * </pre> |
| 1387 * @param className the name of the class whose members are being parsed | 1542 * @param className the name of the class whose members are being parsed |
| 1388 * @param balancedBrackets {@code true} if the opening and closing brackets fo
r the class are | 1543 * @param closingBracket the closing bracket for the class, or {@code null} if
the closing bracket |
| 1389 * balanced | 1544 * is missing |
| 1390 * @return the list of class members that were parsed | 1545 * @return the list of class members that were parsed |
| 1391 */ | 1546 */ |
| 1392 List<ClassMember> parseClassMembers(String className, bool balancedBrackets) { | 1547 List<ClassMember> parseClassMembers(String className, Token closingBracket) { |
| 1393 List<ClassMember> members = new List<ClassMember>(); | 1548 List<ClassMember> members = new List<ClassMember>(); |
| 1394 Token memberStart = _currentToken; | 1549 Token memberStart = _currentToken; |
| 1395 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)
&& (balancedBrackets || (!matches(Keyword.CLASS) && !matches(Keyword.TYPEDEF))))
{ | 1550 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)
&& (closingBracket != null || (!matches(Keyword.CLASS) && !matches(Keyword.TYPED
EF)))) { |
| 1396 if (matches5(TokenType.SEMICOLON)) { | 1551 if (matches5(TokenType.SEMICOLON)) { |
| 1397 reportError5(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); | 1552 reportError8(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); |
| 1398 advance(); | 1553 advance(); |
| 1399 } else { | 1554 } else { |
| 1400 ClassMember member = parseClassMember(className); | 1555 ClassMember member = parseClassMember(className); |
| 1401 if (member != null) { | 1556 if (member != null) { |
| 1402 members.add(member); | 1557 members.add(member); |
| 1403 } | 1558 } |
| 1404 } | 1559 } |
| 1405 if (identical(_currentToken, memberStart)) { | 1560 if (identical(_currentToken, memberStart)) { |
| 1406 reportError5(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); | 1561 reportError8(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); |
| 1407 advance(); | 1562 advance(); |
| 1408 } | 1563 } |
| 1409 memberStart = _currentToken; | 1564 memberStart = _currentToken; |
| 1410 } | 1565 } |
| 1411 return members; | 1566 return members; |
| 1412 } | 1567 } |
| 1568 |
| 1413 /** | 1569 /** |
| 1414 * Parse a class type alias. | 1570 * Parse a class type alias. |
| 1415 * <pre> | 1571 * <pre> |
| 1416 * classTypeAlias ::= | 1572 * classTypeAlias ::= |
| 1417 * identifier typeParameters? '=' 'abstract'? mixinApplication | 1573 * identifier typeParameters? '=' 'abstract'? mixinApplication |
| 1418 * mixinApplication ::= | 1574 * mixinApplication ::= |
| 1419 * type withClause implementsClause? ';' | 1575 * type withClause implementsClause? ';' |
| 1420 * </pre> | 1576 * </pre> |
| 1421 * @param commentAndMetadata the metadata to be associated with the member | 1577 * @param commentAndMetadata the metadata to be associated with the member |
| 1422 * @param keyword the token representing the 'typedef' keyword | 1578 * @param keyword the token representing the 'typedef' keyword |
| 1423 * @return the class type alias that was parsed | 1579 * @return the class type alias that was parsed |
| 1424 */ | 1580 */ |
| 1425 ClassTypeAlias parseClassTypeAlias(CommentAndMetadata commentAndMetadata, Toke
n keyword) { | 1581 ClassTypeAlias parseClassTypeAlias(CommentAndMetadata commentAndMetadata, Toke
n keyword) { |
| 1426 SimpleIdentifier name = parseSimpleIdentifier(); | 1582 SimpleIdentifier className = parseSimpleIdentifier(); |
| 1427 TypeParameterList typeParameters = null; | 1583 TypeParameterList typeParameters = null; |
| 1428 if (matches5(TokenType.LT)) { | 1584 if (matches5(TokenType.LT)) { |
| 1429 typeParameters = parseTypeParameterList(); | 1585 typeParameters = parseTypeParameterList(); |
| 1430 } | 1586 } |
| 1431 Token equals = expect2(TokenType.EQ); | 1587 Token equals = expect2(TokenType.EQ); |
| 1432 Token abstractKeyword = null; | 1588 Token abstractKeyword = null; |
| 1433 if (matches(Keyword.ABSTRACT)) { | 1589 if (matches(Keyword.ABSTRACT)) { |
| 1434 abstractKeyword = andAdvance; | 1590 abstractKeyword = andAdvance; |
| 1435 } | 1591 } |
| 1436 TypeName superclass = parseTypeName(); | 1592 TypeName superclass = parseTypeName(); |
| 1437 WithClause withClause = null; | 1593 WithClause withClause = null; |
| 1438 if (matches(Keyword.WITH)) { | 1594 if (matches(Keyword.WITH)) { |
| 1439 withClause = parseWithClause(); | 1595 withClause = parseWithClause(); |
| 1440 } | 1596 } |
| 1441 ImplementsClause implementsClause = null; | 1597 ImplementsClause implementsClause = null; |
| 1442 if (matches(Keyword.IMPLEMENTS)) { | 1598 if (matches(Keyword.IMPLEMENTS)) { |
| 1443 implementsClause = parseImplementsClause(); | 1599 implementsClause = parseImplementsClause(); |
| 1444 } | 1600 } |
| 1445 Token semicolon = expect2(TokenType.SEMICOLON); | 1601 Token semicolon; |
| 1446 return new ClassTypeAlias.full(commentAndMetadata.comment, commentAndMetadat
a.metadata, keyword, name, typeParameters, equals, abstractKeyword, superclass,
withClause, implementsClause, semicolon); | 1602 if (matches5(TokenType.SEMICOLON)) { |
| 1603 semicolon = andAdvance; |
| 1604 } else { |
| 1605 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { |
| 1606 reportError7(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexeme
]); |
| 1607 Token leftBracket = andAdvance; |
| 1608 parseClassMembers(className.name, getEndToken(leftBracket)); |
| 1609 expect2(TokenType.CLOSE_CURLY_BRACKET); |
| 1610 } else { |
| 1611 reportError8(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [To
kenType.SEMICOLON.lexeme]); |
| 1612 } |
| 1613 semicolon = createSyntheticToken2(TokenType.SEMICOLON); |
| 1614 } |
| 1615 return new ClassTypeAlias.full(commentAndMetadata.comment, commentAndMetadat
a.metadata, keyword, className, typeParameters, equals, abstractKeyword, supercl
ass, withClause, implementsClause, semicolon); |
| 1447 } | 1616 } |
| 1617 |
| 1448 /** | 1618 /** |
| 1449 * Parse a list of combinators in a directive. | 1619 * Parse a list of combinators in a directive. |
| 1450 * <pre> | 1620 * <pre> |
| 1451 * combinator ::= | 1621 * combinator ::= |
| 1452 * 'show' identifier (',' identifier) | 1622 * 'show' identifier (',' identifier) |
| 1453 * | 'hide' identifier (',' identifier) | 1623 * | 'hide' identifier (',' identifier) |
| 1454 * </pre> | 1624 * </pre> |
| 1455 * @return the combinators that were parsed | 1625 * @return the combinators that were parsed |
| 1456 */ | 1626 */ |
| 1457 List<Combinator> parseCombinators() { | 1627 List<Combinator> parseCombinators() { |
| 1458 List<Combinator> combinators = new List<Combinator>(); | 1628 List<Combinator> combinators = new List<Combinator>(); |
| 1459 while (matches2(_SHOW) || matches2(_HIDE)) { | 1629 while (matches2(_SHOW) || matches2(_HIDE)) { |
| 1460 Token keyword = expect2(TokenType.IDENTIFIER); | 1630 Token keyword = expect2(TokenType.IDENTIFIER); |
| 1461 if (keyword.lexeme == _SHOW) { | 1631 if (keyword.lexeme == _SHOW) { |
| 1462 List<SimpleIdentifier> shownNames = parseIdentifierList(); | 1632 List<SimpleIdentifier> shownNames = parseIdentifierList(); |
| 1463 combinators.add(new ShowCombinator.full(keyword, shownNames)); | 1633 combinators.add(new ShowCombinator.full(keyword, shownNames)); |
| 1464 } else { | 1634 } else { |
| 1465 List<SimpleIdentifier> hiddenNames = parseIdentifierList(); | 1635 List<SimpleIdentifier> hiddenNames = parseIdentifierList(); |
| 1466 combinators.add(new HideCombinator.full(keyword, hiddenNames)); | 1636 combinators.add(new HideCombinator.full(keyword, hiddenNames)); |
| 1467 } | 1637 } |
| 1468 } | 1638 } |
| 1469 return combinators; | 1639 return combinators; |
| 1470 } | 1640 } |
| 1641 |
| 1471 /** | 1642 /** |
| 1472 * Parse the documentation comment and metadata preceeding a declaration. This
method allows any | 1643 * Parse the documentation comment and metadata preceeding a declaration. This
method allows any |
| 1473 * number of documentation comments to occur before, after or between the meta
data, but only | 1644 * number of documentation comments to occur before, after or between the meta
data, but only |
| 1474 * returns the last (right-most) documentation comment that is found. | 1645 * returns the last (right-most) documentation comment that is found. |
| 1475 * <pre> | 1646 * <pre> |
| 1476 * metadata ::= | 1647 * metadata ::= |
| 1477 * annotation | 1648 * annotation |
| 1478 * </pre> | 1649 * </pre> |
| 1479 * @return the documentation comment and metadata that were parsed | 1650 * @return the documentation comment and metadata that were parsed |
| 1480 */ | 1651 */ |
| 1481 CommentAndMetadata parseCommentAndMetadata() { | 1652 CommentAndMetadata parseCommentAndMetadata() { |
| 1482 Comment comment = parseDocumentationComment(); | 1653 Comment comment = parseDocumentationComment(); |
| 1483 List<Annotation> metadata = new List<Annotation>(); | 1654 List<Annotation> metadata = new List<Annotation>(); |
| 1484 while (matches5(TokenType.AT)) { | 1655 while (matches5(TokenType.AT)) { |
| 1485 metadata.add(parseAnnotation()); | 1656 metadata.add(parseAnnotation()); |
| 1486 Comment optionalComment = parseDocumentationComment(); | 1657 Comment optionalComment = parseDocumentationComment(); |
| 1487 if (optionalComment != null) { | 1658 if (optionalComment != null) { |
| 1488 comment = optionalComment; | 1659 comment = optionalComment; |
| 1489 } | 1660 } |
| 1490 } | 1661 } |
| 1491 return new CommentAndMetadata(comment, metadata); | 1662 return new CommentAndMetadata(comment, metadata); |
| 1492 } | 1663 } |
| 1664 |
| 1493 /** | 1665 /** |
| 1494 * Parse a comment reference from the source between square brackets. | 1666 * Parse a comment reference from the source between square brackets. |
| 1495 * <pre> | 1667 * <pre> |
| 1496 * commentReference ::= | 1668 * commentReference ::= |
| 1497 * 'new'? prefixedIdentifier | 1669 * 'new'? prefixedIdentifier |
| 1498 * </pre> | 1670 * </pre> |
| 1499 * @param referenceSource the source occurring between the square brackets wit
hin a documentation | 1671 * @param referenceSource the source occurring between the square brackets wit
hin a documentation |
| 1500 * comment | 1672 * comment |
| 1501 * @param sourceOffset the offset of the first character of the reference sour
ce | 1673 * @param sourceOffset the offset of the first character of the reference sour
ce |
| 1502 * @return the comment reference that was parsed | 1674 * @return the comment reference that was parsed, or {@code null} if no refere
nce could be found |
| 1503 */ | 1675 */ |
| 1504 CommentReference parseCommentReference(String referenceSource, int sourceOffse
t) { | 1676 CommentReference parseCommentReference(String referenceSource, int sourceOffse
t) { |
| 1505 if (referenceSource.length == 0) { | 1677 if (referenceSource.length == 0) { |
| 1506 return null; | 1678 return null; |
| 1507 } | 1679 } |
| 1508 try { | 1680 try { |
| 1509 List<bool> errorFound = [false]; | 1681 List<bool> errorFound = [false]; |
| 1510 AnalysisErrorListener listener = new AnalysisErrorListener_12(errorFound); | 1682 AnalysisErrorListener listener = new AnalysisErrorListener_12(errorFound); |
| 1511 StringScanner scanner = new StringScanner(null, referenceSource, listener)
; | 1683 StringScanner scanner = new StringScanner(null, referenceSource, listener)
; |
| 1512 scanner.setSourceStart(1, 1, sourceOffset); | 1684 scanner.setSourceStart(1, 1, sourceOffset); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1535 return null; | 1707 return null; |
| 1536 } | 1708 } |
| 1537 return new CommentReference.full(newKeyword, identifier); | 1709 return new CommentReference.full(newKeyword, identifier); |
| 1538 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Keyw
ord.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keyword.
FALSE)) { | 1710 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Keyw
ord.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keyword.
FALSE)) { |
| 1539 return null; | 1711 return null; |
| 1540 } | 1712 } |
| 1541 } catch (exception) { | 1713 } catch (exception) { |
| 1542 } | 1714 } |
| 1543 return null; | 1715 return null; |
| 1544 } | 1716 } |
| 1717 |
| 1545 /** | 1718 /** |
| 1546 * Parse all of the comment references occurring in the given array of documen
tation comments. | 1719 * Parse all of the comment references occurring in the given array of documen
tation comments. |
| 1547 * <pre> | 1720 * <pre> |
| 1548 * commentReference ::= | 1721 * commentReference ::= |
| 1549 * '\[' 'new'? qualified '\]' libraryReference? | 1722 * '\[' 'new'? qualified '\]' libraryReference? |
| 1550 * libraryReference ::= | 1723 * libraryReference ::= |
| 1551 * '(' stringLiteral ')' | 1724 * '(' stringLiteral ')' |
| 1552 * </pre> | 1725 * </pre> |
| 1553 * @param tokens the comment tokens representing the documentation comments to
be parsed | 1726 * @param tokens the comment tokens representing the documentation comments to
be parsed |
| 1554 * @return the comment references that were parsed | 1727 * @return the comment references that were parsed |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1579 rightIndex = leftIndex + 1; | 1752 rightIndex = leftIndex + 1; |
| 1580 } | 1753 } |
| 1581 leftIndex = comment.indexOf('[', rightIndex); | 1754 leftIndex = comment.indexOf('[', rightIndex); |
| 1582 } else { | 1755 } else { |
| 1583 leftIndex = comment.indexOf('[', range[1] + 1); | 1756 leftIndex = comment.indexOf('[', range[1] + 1); |
| 1584 } | 1757 } |
| 1585 } | 1758 } |
| 1586 } | 1759 } |
| 1587 return references; | 1760 return references; |
| 1588 } | 1761 } |
| 1762 |
| 1589 /** | 1763 /** |
| 1590 * Parse a compilation unit. | 1764 * Parse a compilation unit. |
| 1591 * <p> | 1765 * <p> |
| 1592 * Specified: | 1766 * Specified: |
| 1593 * <pre> | 1767 * <pre> |
| 1594 * compilationUnit ::= | 1768 * compilationUnit ::= |
| 1595 * scriptTag? directive* topLevelDeclaration | 1769 * scriptTag? directive* topLevelDeclaration |
| 1596 * </pre> | 1770 * </pre> |
| 1597 * Actual: | 1771 * Actual: |
| 1598 * <pre> | 1772 * <pre> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1615 bool partDirectiveFound = false; | 1789 bool partDirectiveFound = false; |
| 1616 bool directiveFoundAfterDeclaration = false; | 1790 bool directiveFoundAfterDeclaration = false; |
| 1617 List<Directive> directives = new List<Directive>(); | 1791 List<Directive> directives = new List<Directive>(); |
| 1618 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>()
; | 1792 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>()
; |
| 1619 Token memberStart = _currentToken; | 1793 Token memberStart = _currentToken; |
| 1620 while (!matches5(TokenType.EOF)) { | 1794 while (!matches5(TokenType.EOF)) { |
| 1621 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 1795 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 1622 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword
.LIBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !m
atches4(peek(), TokenType.LT)) { | 1796 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword
.LIBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !m
atches4(peek(), TokenType.LT)) { |
| 1623 Directive directive = parseDirective(commentAndMetadata); | 1797 Directive directive = parseDirective(commentAndMetadata); |
| 1624 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { | 1798 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { |
| 1625 reportError4(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, []); | 1799 reportError7(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, []); |
| 1626 directiveFoundAfterDeclaration = true; | 1800 directiveFoundAfterDeclaration = true; |
| 1627 } | 1801 } |
| 1628 if (directive is LibraryDirective) { | 1802 if (directive is LibraryDirective) { |
| 1629 if (libraryDirectiveFound) { | 1803 if (libraryDirectiveFound) { |
| 1630 reportError4(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES, []); | 1804 reportError7(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES, []); |
| 1631 } else { | 1805 } else { |
| 1632 if (directives.length > 0) { | 1806 if (directives.length > 0) { |
| 1633 reportError4(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, []); | 1807 reportError7(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, []); |
| 1634 } | 1808 } |
| 1635 libraryDirectiveFound = true; | 1809 libraryDirectiveFound = true; |
| 1636 } | 1810 } |
| 1637 } else if (directive is PartDirective) { | 1811 } else if (directive is PartDirective) { |
| 1638 partDirectiveFound = true; | 1812 partDirectiveFound = true; |
| 1639 } else if (partDirectiveFound) { | 1813 } else if (partDirectiveFound) { |
| 1640 if (directive is ExportDirective) { | 1814 if (directive is ExportDirective) { |
| 1641 reportError4(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE,
[]); | 1815 reportError8(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE,
((directive as NamespaceDirective)).keyword, []); |
| 1642 } else if (directive is ImportDirective) { | 1816 } else if (directive is ImportDirective) { |
| 1643 reportError4(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE,
[]); | 1817 reportError8(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE,
((directive as NamespaceDirective)).keyword, []); |
| 1644 } | 1818 } |
| 1645 } | 1819 } |
| 1646 if (directive is PartOfDirective) { | 1820 if (directive is PartOfDirective) { |
| 1647 if (partOfDirectiveFound) { | 1821 if (partOfDirectiveFound) { |
| 1648 reportError4(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, []); | 1822 reportError7(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, []); |
| 1649 } else { | 1823 } else { |
| 1650 for (Directive preceedingDirective in directives) { | 1824 for (Directive preceedingDirective in directives) { |
| 1651 reportError5(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, precee
dingDirective.keyword, []); | 1825 reportError8(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, precee
dingDirective.keyword, []); |
| 1652 } | 1826 } |
| 1653 partOfDirectiveFound = true; | 1827 partOfDirectiveFound = true; |
| 1654 } | 1828 } |
| 1655 } else { | 1829 } else { |
| 1656 if (partOfDirectiveFound) { | 1830 if (partOfDirectiveFound) { |
| 1657 reportError5(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directiv
e.keyword, []); | 1831 reportError8(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directiv
e.keyword, []); |
| 1658 } | 1832 } |
| 1659 } | 1833 } |
| 1660 directives.add(directive); | 1834 directives.add(directive); |
| 1661 } else if (matches5(TokenType.SEMICOLON)) { | 1835 } else if (matches5(TokenType.SEMICOLON)) { |
| 1662 reportError5(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); | 1836 reportError8(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); |
| 1663 advance(); | 1837 advance(); |
| 1664 } else { | 1838 } else { |
| 1665 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta
data); | 1839 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta
data); |
| 1666 if (member != null) { | 1840 if (member != null) { |
| 1667 declarations.add(member); | 1841 declarations.add(member); |
| 1668 } | 1842 } |
| 1669 } | 1843 } |
| 1670 if (identical(_currentToken, memberStart)) { | 1844 if (identical(_currentToken, memberStart)) { |
| 1671 reportError5(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); | 1845 reportError8(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); |
| 1672 advance(); | 1846 advance(); |
| 1847 while (!matches5(TokenType.EOF) && !couldBeStartOfCompilationUnitMember(
)) { |
| 1848 advance(); |
| 1849 } |
| 1673 } | 1850 } |
| 1674 memberStart = _currentToken; | 1851 memberStart = _currentToken; |
| 1675 } | 1852 } |
| 1676 return new CompilationUnit.full(firstToken, scriptTag, directives, declarati
ons, _currentToken); | 1853 return new CompilationUnit.full(firstToken, scriptTag, directives, declarati
ons, _currentToken); |
| 1677 } | 1854 } |
| 1855 |
| 1678 /** | 1856 /** |
| 1679 * Parse a compilation unit member. | 1857 * Parse a compilation unit member. |
| 1680 * <pre> | 1858 * <pre> |
| 1681 * compilationUnitMember ::= | 1859 * compilationUnitMember ::= |
| 1682 * classDefinition | 1860 * classDefinition |
| 1683 * | functionTypeAlias | 1861 * | functionTypeAlias |
| 1684 * | external functionSignature | 1862 * | external functionSignature |
| 1685 * | external getterSignature | 1863 * | external getterSignature |
| 1686 * | external setterSignature | 1864 * | external setterSignature |
| 1687 * | functionSignature functionBody | 1865 * | functionSignature functionBody |
| 1688 * | returnType? getOrSet identifier formalParameterList functionBody | 1866 * | returnType? getOrSet identifier formalParameterList functionBody |
| 1689 * | (final | const) type? staticFinalDeclarationList ';' | 1867 * | (final | const) type? staticFinalDeclarationList ';' |
| 1690 * | variableDeclaration ';' | 1868 * | variableDeclaration ';' |
| 1691 * </pre> | 1869 * </pre> |
| 1692 * @param commentAndMetadata the metadata to be associated with the member | 1870 * @param commentAndMetadata the metadata to be associated with the member |
| 1693 * @return the compilation unit member that was parsed | 1871 * @return the compilation unit member that was parsed, or {@code null} if wha
t was parsed could |
| 1872 * not be represented as a compilation unit member |
| 1694 */ | 1873 */ |
| 1695 CompilationUnitMember parseCompilationUnitMember(CommentAndMetadata commentAnd
Metadata) { | 1874 CompilationUnitMember parseCompilationUnitMember(CommentAndMetadata commentAnd
Metadata) { |
| 1696 Modifiers modifiers = parseModifiers(); | 1875 Modifiers modifiers = parseModifiers(); |
| 1697 if (matches(Keyword.CLASS)) { | 1876 if (matches(Keyword.CLASS)) { |
| 1698 return parseClassDeclaration(commentAndMetadata, validateModifiersForClass
(modifiers)); | 1877 return parseClassDeclaration(commentAndMetadata, validateModifiersForClass
(modifiers)); |
| 1699 } else if (matches(Keyword.TYPEDEF) && !matches4(peek(), TokenType.PERIOD) &
& !matches4(peek(), TokenType.LT)) { | 1878 } else if (matches(Keyword.TYPEDEF) && !matches4(peek(), TokenType.PERIOD) &
& !matches4(peek(), TokenType.LT)) { |
| 1700 validateModifiersForTypedef(modifiers); | 1879 validateModifiersForTypedef(modifiers); |
| 1701 return parseTypeAlias(commentAndMetadata); | 1880 return parseTypeAlias(commentAndMetadata); |
| 1702 } | 1881 } |
| 1703 if (matches(Keyword.VOID)) { | 1882 if (matches(Keyword.VOID)) { |
| 1704 TypeName returnType = parseReturnType(); | 1883 TypeName returnType = parseReturnType(); |
| 1705 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(p
eek())) { | 1884 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(p
eek())) { |
| 1706 validateModifiersForTopLevelFunction(modifiers); | 1885 validateModifiersForTopLevelFunction(modifiers); |
| 1707 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe
yword, null); | 1886 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe
yword, null); |
| 1708 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { | 1887 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { |
| 1709 reportError5(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); | 1888 reportError8(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); |
| 1710 return null; | 1889 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, mo
difiers.externalKeyword, returnType)); |
| 1711 } else if (matchesIdentifier() && matchesAny(peek(), [TokenType.OPEN_PAREN
, TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { | 1890 } else if (matchesIdentifier() && matchesAny(peek(), [TokenType.OPEN_PAREN
, TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { |
| 1712 validateModifiersForTopLevelFunction(modifiers); | 1891 validateModifiersForTopLevelFunction(modifiers); |
| 1713 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe
yword, returnType); | 1892 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe
yword, returnType); |
| 1714 } else { | 1893 } else { |
| 1715 if (matchesIdentifier()) { | 1894 if (matchesIdentifier()) { |
| 1716 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC
OLON])) { | 1895 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC
OLON])) { |
| 1717 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []); | 1896 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []); |
| 1718 return new TopLevelVariableDeclaration.full(commentAndMetadata.comme
nt, commentAndMetadata.metadata, parseVariableDeclarationList2(null, validateMod
ifiersForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); | 1897 return new TopLevelVariableDeclaration.full(commentAndMetadata.comme
nt, commentAndMetadata.metadata, parseVariableDeclarationList2(null, validateMod
ifiersForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); |
| 1719 } | 1898 } |
| 1720 } | 1899 } |
| 1721 reportError5(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); | 1900 reportError8(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); |
| 1722 return null; | 1901 return null; |
| 1723 } | 1902 } |
| 1724 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi
er2(peek())) { | 1903 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi
er2(peek())) { |
| 1725 validateModifiersForTopLevelFunction(modifiers); | 1904 validateModifiersForTopLevelFunction(modifiers); |
| 1726 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, null); | 1905 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, null); |
| 1727 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { | 1906 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { |
| 1728 reportError5(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); | 1907 reportError8(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); |
| 1729 return null; | 1908 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi
fiers.externalKeyword, null)); |
| 1730 } else if (!matchesIdentifier()) { | 1909 } else if (!matchesIdentifier()) { |
| 1731 reportError5(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); | 1910 reportError8(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); |
| 1732 return null; | 1911 return null; |
| 1733 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { | 1912 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { |
| 1734 validateModifiersForTopLevelFunction(modifiers); | 1913 validateModifiersForTopLevelFunction(modifiers); |
| 1735 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, null); | 1914 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, null); |
| 1736 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI
COLON])) { | 1915 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI
COLON])) { |
| 1916 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo
difiers.varKeyword == null) { |
| 1917 reportError7(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); |
| 1918 } |
| 1737 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, co
mmentAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiers
ForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); | 1919 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, co
mmentAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiers
ForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); |
| 1738 } | 1920 } |
| 1739 TypeName returnType = parseReturnType(); | 1921 TypeName returnType = parseReturnType(); |
| 1740 if (matches(Keyword.GET) || matches(Keyword.SET)) { | 1922 if (matches(Keyword.GET) || matches(Keyword.SET)) { |
| 1741 validateModifiersForTopLevelFunction(modifiers); | 1923 validateModifiersForTopLevelFunction(modifiers); |
| 1742 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, returnType); | 1924 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, returnType); |
| 1743 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { | 1925 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { |
| 1744 reportError5(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); | 1926 reportError8(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); |
| 1745 return null; | 1927 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi
fiers.externalKeyword, returnType)); |
| 1746 } else if (!matchesIdentifier()) { | 1928 } else if (!matchesIdentifier()) { |
| 1747 reportError5(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); | 1929 reportError8(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); |
| 1748 return null; | 1930 return null; |
| 1749 } | 1931 } |
| 1750 if (matchesAny(peek(), [TokenType.OPEN_PAREN, TokenType.FUNCTION, TokenType.
OPEN_CURLY_BRACKET])) { | 1932 if (matchesAny(peek(), [TokenType.OPEN_PAREN, TokenType.FUNCTION, TokenType.
OPEN_CURLY_BRACKET])) { |
| 1751 validateModifiersForTopLevelFunction(modifiers); | 1933 validateModifiersForTopLevelFunction(modifiers); |
| 1752 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, returnType); | 1934 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw
ord, returnType); |
| 1753 } | 1935 } |
| 1754 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, comm
entAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersFo
rTopLevelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON)); | 1936 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, comm
entAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersFo
rTopLevelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON)); |
| 1755 } | 1937 } |
| 1938 |
| 1756 /** | 1939 /** |
| 1757 * Parse a conditional expression. | 1940 * Parse a conditional expression. |
| 1758 * <pre> | 1941 * <pre> |
| 1759 * conditionalExpression ::= | 1942 * conditionalExpression ::= |
| 1760 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithoutCasc
ade)? | 1943 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithoutCasc
ade)? |
| 1761 * </pre> | 1944 * </pre> |
| 1762 * @return the conditional expression that was parsed | 1945 * @return the conditional expression that was parsed |
| 1763 */ | 1946 */ |
| 1764 Expression parseConditionalExpression() { | 1947 Expression parseConditionalExpression() { |
| 1765 Expression condition = parseLogicalOrExpression(); | 1948 Expression condition = parseLogicalOrExpression(); |
| 1766 if (!matches5(TokenType.QUESTION)) { | 1949 if (!matches5(TokenType.QUESTION)) { |
| 1767 return condition; | 1950 return condition; |
| 1768 } | 1951 } |
| 1769 Token question = andAdvance; | 1952 Token question = andAdvance; |
| 1770 Expression thenExpression = parseExpressionWithoutCascade(); | 1953 Expression thenExpression = parseExpressionWithoutCascade(); |
| 1771 Token colon = expect2(TokenType.COLON); | 1954 Token colon = expect2(TokenType.COLON); |
| 1772 Expression elseExpression = parseExpressionWithoutCascade(); | 1955 Expression elseExpression = parseExpressionWithoutCascade(); |
| 1773 return new ConditionalExpression.full(condition, question, thenExpression, c
olon, elseExpression); | 1956 return new ConditionalExpression.full(condition, question, thenExpression, c
olon, elseExpression); |
| 1774 } | 1957 } |
| 1958 |
| 1775 /** | 1959 /** |
| 1776 * Parse a const expression. | 1960 * Parse a const expression. |
| 1777 * <pre> | 1961 * <pre> |
| 1778 * constExpression ::= | 1962 * constExpression ::= |
| 1779 * instanceCreationExpression | 1963 * instanceCreationExpression |
| 1780 * | listLiteral | 1964 * | listLiteral |
| 1781 * | mapLiteral | 1965 * | mapLiteral |
| 1782 * </pre> | 1966 * </pre> |
| 1783 * @return the const expression that was parsed | 1967 * @return the const expression that was parsed |
| 1784 */ | 1968 */ |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 } | 2002 } |
| 1819 } while (optional(TokenType.COMMA)); | 2003 } while (optional(TokenType.COMMA)); |
| 1820 } | 2004 } |
| 1821 ConstructorName redirectedConstructor = null; | 2005 ConstructorName redirectedConstructor = null; |
| 1822 FunctionBody body; | 2006 FunctionBody body; |
| 1823 if (matches5(TokenType.EQ)) { | 2007 if (matches5(TokenType.EQ)) { |
| 1824 separator = andAdvance; | 2008 separator = andAdvance; |
| 1825 redirectedConstructor = parseConstructorName(); | 2009 redirectedConstructor = parseConstructorName(); |
| 1826 body = new EmptyFunctionBody.full(expect2(TokenType.SEMICOLON)); | 2010 body = new EmptyFunctionBody.full(expect2(TokenType.SEMICOLON)); |
| 1827 } else { | 2011 } else { |
| 1828 body = parseFunctionBody(true, false); | 2012 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals
e); |
| 1829 if (!bodyAllowed && body is! EmptyFunctionBody) { | 2013 if (constKeyword != null && factoryKeyword != null) { |
| 1830 reportError4(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, []); | 2014 reportError8(ParserErrorCode.CONST_FACTORY, factoryKeyword, []); |
| 2015 } else if (body is EmptyFunctionBody) { |
| 2016 if (factoryKeyword != null && externalKeyword == null) { |
| 2017 reportError8(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyword, [])
; |
| 2018 } |
| 2019 } else { |
| 2020 if (constKeyword != null) { |
| 2021 reportError(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []); |
| 2022 } else if (!bodyAllowed) { |
| 2023 reportError(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body, []); |
| 2024 } |
| 1831 } | 2025 } |
| 1832 } | 2026 } |
| 1833 return new ConstructorDeclaration.full(commentAndMetadata.comment, commentAn
dMetadata.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, p
eriod, name, parameters, separator, initializers, redirectedConstructor, body); | 2027 return new ConstructorDeclaration.full(commentAndMetadata.comment, commentAn
dMetadata.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, p
eriod, name, parameters, separator, initializers, redirectedConstructor, body); |
| 1834 } | 2028 } |
| 2029 |
| 1835 /** | 2030 /** |
| 1836 * Parse a field initializer within a constructor. | 2031 * Parse a field initializer within a constructor. |
| 1837 * <pre> | 2032 * <pre> |
| 1838 * fieldInitializer: | 2033 * fieldInitializer: |
| 1839 * ('this' '.')? identifier '=' conditionalExpression cascadeSection | 2034 * ('this' '.')? identifier '=' conditionalExpression cascadeSection |
| 1840 * </pre> | 2035 * </pre> |
| 1841 * @return the field initializer that was parsed | 2036 * @return the field initializer that was parsed |
| 1842 */ | 2037 */ |
| 1843 ConstructorFieldInitializer parseConstructorFieldInitializer() { | 2038 ConstructorFieldInitializer parseConstructorFieldInitializer() { |
| 1844 Token keyword = null; | 2039 Token keyword = null; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1857 Expression section = parseCascadeSection(); | 2052 Expression section = parseCascadeSection(); |
| 1858 if (section != null) { | 2053 if (section != null) { |
| 1859 cascadeSections.add(section); | 2054 cascadeSections.add(section); |
| 1860 } | 2055 } |
| 1861 tokenType = _currentToken.type; | 2056 tokenType = _currentToken.type; |
| 1862 } | 2057 } |
| 1863 expression = new CascadeExpression.full(expression, cascadeSections); | 2058 expression = new CascadeExpression.full(expression, cascadeSections); |
| 1864 } | 2059 } |
| 1865 return new ConstructorFieldInitializer.full(keyword, period, fieldName, equa
ls, expression); | 2060 return new ConstructorFieldInitializer.full(keyword, period, fieldName, equa
ls, expression); |
| 1866 } | 2061 } |
| 2062 |
| 1867 /** | 2063 /** |
| 1868 * Parse the name of a constructor. | 2064 * Parse the name of a constructor. |
| 1869 * <pre> | 2065 * <pre> |
| 1870 * constructorName: | 2066 * constructorName: |
| 1871 * type ('.' identifier)? | 2067 * type ('.' identifier)? |
| 1872 * </pre> | 2068 * </pre> |
| 1873 * @return the constructor name that was parsed | 2069 * @return the constructor name that was parsed |
| 1874 */ | 2070 */ |
| 1875 ConstructorName parseConstructorName() { | 2071 ConstructorName parseConstructorName() { |
| 1876 TypeName type = parseTypeName(); | 2072 TypeName type = parseTypeName(); |
| 1877 Token period = null; | 2073 Token period = null; |
| 1878 SimpleIdentifier name = null; | 2074 SimpleIdentifier name = null; |
| 1879 if (matches5(TokenType.PERIOD)) { | 2075 if (matches5(TokenType.PERIOD)) { |
| 1880 period = andAdvance; | 2076 period = andAdvance; |
| 1881 name = parseSimpleIdentifier(); | 2077 name = parseSimpleIdentifier(); |
| 1882 } | 2078 } |
| 1883 return new ConstructorName.full(type, period, name); | 2079 return new ConstructorName.full(type, period, name); |
| 1884 } | 2080 } |
| 2081 |
| 1885 /** | 2082 /** |
| 1886 * Parse a continue statement. | 2083 * Parse a continue statement. |
| 1887 * <pre> | 2084 * <pre> |
| 1888 * continueStatement ::= | 2085 * continueStatement ::= |
| 1889 * 'continue' identifier? ';' | 2086 * 'continue' identifier? ';' |
| 1890 * </pre> | 2087 * </pre> |
| 1891 * @return the continue statement that was parsed | 2088 * @return the continue statement that was parsed |
| 1892 */ | 2089 */ |
| 1893 Statement parseContinueStatement() { | 2090 Statement parseContinueStatement() { |
| 1894 Token continueKeyword = expect(Keyword.CONTINUE); | 2091 Token continueKeyword = expect(Keyword.CONTINUE); |
| 1895 if (!_inLoop && !_inSwitch) { | 2092 if (!_inLoop && !_inSwitch) { |
| 1896 reportError5(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, []
); | 2093 reportError8(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, []
); |
| 1897 } | 2094 } |
| 1898 SimpleIdentifier label = null; | 2095 SimpleIdentifier label = null; |
| 1899 if (matchesIdentifier()) { | 2096 if (matchesIdentifier()) { |
| 1900 label = parseSimpleIdentifier(); | 2097 label = parseSimpleIdentifier(); |
| 1901 } | 2098 } |
| 1902 if (_inSwitch && !_inLoop && label == null) { | 2099 if (_inSwitch && !_inLoop && label == null) { |
| 1903 reportError5(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeywo
rd, []); | 2100 reportError8(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeywo
rd, []); |
| 1904 } | 2101 } |
| 1905 Token semicolon = expect2(TokenType.SEMICOLON); | 2102 Token semicolon = expect2(TokenType.SEMICOLON); |
| 1906 return new ContinueStatement.full(continueKeyword, label, semicolon); | 2103 return new ContinueStatement.full(continueKeyword, label, semicolon); |
| 1907 } | 2104 } |
| 2105 |
| 1908 /** | 2106 /** |
| 1909 * Parse a directive. | 2107 * Parse a directive. |
| 1910 * <pre> | 2108 * <pre> |
| 1911 * directive ::= | 2109 * directive ::= |
| 1912 * exportDirective | 2110 * exportDirective |
| 1913 * | libraryDirective | 2111 * | libraryDirective |
| 1914 * | importDirective | 2112 * | importDirective |
| 1915 * | partDirective | 2113 * | partDirective |
| 1916 * </pre> | 2114 * </pre> |
| 1917 * @param commentAndMetadata the metadata to be associated with the directive | 2115 * @param commentAndMetadata the metadata to be associated with the directive |
| 1918 * @return the directive that was parsed | 2116 * @return the directive that was parsed |
| 1919 */ | 2117 */ |
| 1920 Directive parseDirective(CommentAndMetadata commentAndMetadata) { | 2118 Directive parseDirective(CommentAndMetadata commentAndMetadata) { |
| 1921 if (matches(Keyword.IMPORT)) { | 2119 if (matches(Keyword.IMPORT)) { |
| 1922 return parseImportDirective(commentAndMetadata); | 2120 return parseImportDirective(commentAndMetadata); |
| 1923 } else if (matches(Keyword.EXPORT)) { | 2121 } else if (matches(Keyword.EXPORT)) { |
| 1924 return parseExportDirective(commentAndMetadata); | 2122 return parseExportDirective(commentAndMetadata); |
| 1925 } else if (matches(Keyword.LIBRARY)) { | 2123 } else if (matches(Keyword.LIBRARY)) { |
| 1926 return parseLibraryDirective(commentAndMetadata); | 2124 return parseLibraryDirective(commentAndMetadata); |
| 1927 } else if (matches(Keyword.PART)) { | 2125 } else if (matches(Keyword.PART)) { |
| 1928 return parsePartDirective(commentAndMetadata); | 2126 return parsePartDirective(commentAndMetadata); |
| 1929 } else { | 2127 } else { |
| 1930 return null; | 2128 throw new IllegalStateException("parseDirective invoked in an invalid stat
e; currentToken = ${_currentToken}"); |
| 1931 } | 2129 } |
| 1932 } | 2130 } |
| 2131 |
| 1933 /** | 2132 /** |
| 1934 * Parse a documentation comment. | 2133 * Parse a documentation comment. |
| 1935 * <pre> | 2134 * <pre> |
| 1936 * documentationComment ::= | 2135 * documentationComment ::= |
| 1937 * multiLineComment? | 2136 * multiLineComment? |
| 1938 * | singleLineComment | 2137 * | singleLineComment |
| 1939 * </pre> | 2138 * </pre> |
| 1940 * @return the documentation comment that was parsed, or {@code null} if there
was no comment | 2139 * @return the documentation comment that was parsed, or {@code null} if there
was no comment |
| 1941 */ | 2140 */ |
| 1942 Comment parseDocumentationComment() { | 2141 Comment parseDocumentationComment() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1958 } | 2157 } |
| 1959 commentToken = commentToken.next; | 2158 commentToken = commentToken.next; |
| 1960 } | 2159 } |
| 1961 if (commentTokens.isEmpty) { | 2160 if (commentTokens.isEmpty) { |
| 1962 return null; | 2161 return null; |
| 1963 } | 2162 } |
| 1964 List<Token> tokens = new List.from(commentTokens); | 2163 List<Token> tokens = new List.from(commentTokens); |
| 1965 List<CommentReference> references = parseCommentReferences(tokens); | 2164 List<CommentReference> references = parseCommentReferences(tokens); |
| 1966 return Comment.createDocumentationComment2(tokens, references); | 2165 return Comment.createDocumentationComment2(tokens, references); |
| 1967 } | 2166 } |
| 2167 |
| 1968 /** | 2168 /** |
| 1969 * Parse a do statement. | 2169 * Parse a do statement. |
| 1970 * <pre> | 2170 * <pre> |
| 1971 * doStatement ::= | 2171 * doStatement ::= |
| 1972 * 'do' statement 'while' '(' expression ')' ';' | 2172 * 'do' statement 'while' '(' expression ')' ';' |
| 1973 * </pre> | 2173 * </pre> |
| 1974 * @return the do statement that was parsed | 2174 * @return the do statement that was parsed |
| 1975 */ | 2175 */ |
| 1976 Statement parseDoStatement() { | 2176 Statement parseDoStatement() { |
| 1977 bool wasInLoop = _inLoop; | 2177 bool wasInLoop = _inLoop; |
| 1978 _inLoop = true; | 2178 _inLoop = true; |
| 1979 try { | 2179 try { |
| 1980 Token doKeyword = expect(Keyword.DO); | 2180 Token doKeyword = expect(Keyword.DO); |
| 1981 Statement body = parseStatement2(); | 2181 Statement body = parseStatement2(); |
| 1982 Token whileKeyword = expect(Keyword.WHILE); | 2182 Token whileKeyword = expect(Keyword.WHILE); |
| 1983 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); | 2183 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); |
| 1984 Expression condition = parseExpression2(); | 2184 Expression condition = parseExpression2(); |
| 1985 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 2185 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 1986 Token semicolon = expect2(TokenType.SEMICOLON); | 2186 Token semicolon = expect2(TokenType.SEMICOLON); |
| 1987 return new DoStatement.full(doKeyword, body, whileKeyword, leftParenthesis
, condition, rightParenthesis, semicolon); | 2187 return new DoStatement.full(doKeyword, body, whileKeyword, leftParenthesis
, condition, rightParenthesis, semicolon); |
| 1988 } finally { | 2188 } finally { |
| 1989 _inLoop = wasInLoop; | 2189 _inLoop = wasInLoop; |
| 1990 } | 2190 } |
| 1991 } | 2191 } |
| 2192 |
| 1992 /** | 2193 /** |
| 1993 * Parse an empty statement. | 2194 * Parse an empty statement. |
| 1994 * <pre> | 2195 * <pre> |
| 1995 * emptyStatement ::= | 2196 * emptyStatement ::= |
| 1996 * ';' | 2197 * ';' |
| 1997 * </pre> | 2198 * </pre> |
| 1998 * @return the empty statement that was parsed | 2199 * @return the empty statement that was parsed |
| 1999 */ | 2200 */ |
| 2000 Statement parseEmptyStatement() => new EmptyStatement.full(andAdvance); | 2201 Statement parseEmptyStatement() => new EmptyStatement.full(andAdvance); |
| 2202 |
| 2001 /** | 2203 /** |
| 2002 * Parse an equality expression. | 2204 * Parse an equality expression. |
| 2003 * <pre> | 2205 * <pre> |
| 2004 * equalityExpression ::= | 2206 * equalityExpression ::= |
| 2005 * relationalExpression (equalityOperator relationalExpression)? | 2207 * relationalExpression (equalityOperator relationalExpression)? |
| 2006 * | 'super' equalityOperator relationalExpression | 2208 * | 'super' equalityOperator relationalExpression |
| 2007 * </pre> | 2209 * </pre> |
| 2008 * @return the equality expression that was parsed | 2210 * @return the equality expression that was parsed |
| 2009 */ | 2211 */ |
| 2010 Expression parseEqualityExpression() { | 2212 Expression parseEqualityExpression() { |
| 2011 Expression expression; | 2213 Expression expression; |
| 2012 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator())
{ | 2214 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator())
{ |
| 2013 expression = new SuperExpression.full(andAdvance); | 2215 expression = new SuperExpression.full(andAdvance); |
| 2014 } else { | 2216 } else { |
| 2015 expression = parseRelationalExpression(); | 2217 expression = parseRelationalExpression(); |
| 2016 } | 2218 } |
| 2017 while (_currentToken.type.isEqualityOperator()) { | 2219 while (_currentToken.type.isEqualityOperator()) { |
| 2018 Token operator = andAdvance; | 2220 Token operator = andAdvance; |
| 2019 expression = new BinaryExpression.full(expression, operator, parseRelation
alExpression()); | 2221 expression = new BinaryExpression.full(expression, operator, parseRelation
alExpression()); |
| 2020 } | 2222 } |
| 2021 return expression; | 2223 return expression; |
| 2022 } | 2224 } |
| 2225 |
| 2023 /** | 2226 /** |
| 2024 * Parse an export directive. | 2227 * Parse an export directive. |
| 2025 * <pre> | 2228 * <pre> |
| 2026 * exportDirective ::= | 2229 * exportDirective ::= |
| 2027 * metadata 'export' stringLiteral combinator*';' | 2230 * metadata 'export' stringLiteral combinator*';' |
| 2028 * </pre> | 2231 * </pre> |
| 2029 * @param commentAndMetadata the metadata to be associated with the directive | 2232 * @param commentAndMetadata the metadata to be associated with the directive |
| 2030 * @return the export directive that was parsed | 2233 * @return the export directive that was parsed |
| 2031 */ | 2234 */ |
| 2032 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) { | 2235 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) { |
| 2033 Token exportKeyword = expect(Keyword.EXPORT); | 2236 Token exportKeyword = expect(Keyword.EXPORT); |
| 2034 StringLiteral libraryUri = parseStringLiteral(); | 2237 StringLiteral libraryUri = parseStringLiteral(); |
| 2035 List<Combinator> combinators = parseCombinators(); | 2238 List<Combinator> combinators = parseCombinators(); |
| 2036 Token semicolon = expect2(TokenType.SEMICOLON); | 2239 Token semicolon = expect2(TokenType.SEMICOLON); |
| 2037 return new ExportDirective.full(commentAndMetadata.comment, commentAndMetada
ta.metadata, exportKeyword, libraryUri, combinators, semicolon); | 2240 return new ExportDirective.full(commentAndMetadata.comment, commentAndMetada
ta.metadata, exportKeyword, libraryUri, combinators, semicolon); |
| 2038 } | 2241 } |
| 2242 |
| 2039 /** | 2243 /** |
| 2040 * Parse an expression that does not contain any cascades. | 2244 * Parse an expression that does not contain any cascades. |
| 2041 * <pre> | 2245 * <pre> |
| 2042 * expression ::= | 2246 * expression ::= |
| 2043 * assignableExpression assignmentOperator expression | 2247 * assignableExpression assignmentOperator expression |
| 2044 * | conditionalExpression cascadeSection | 2248 * | conditionalExpression cascadeSection |
| 2045 * | throwExpression | 2249 * | throwExpression |
| 2046 * </pre> | 2250 * </pre> |
| 2047 * @return the expression that was parsed | 2251 * @return the expression that was parsed |
| 2048 */ | 2252 */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2064 tokenType = _currentToken.type; | 2268 tokenType = _currentToken.type; |
| 2065 } | 2269 } |
| 2066 return new CascadeExpression.full(expression, cascadeSections); | 2270 return new CascadeExpression.full(expression, cascadeSections); |
| 2067 } else if (tokenType.isAssignmentOperator()) { | 2271 } else if (tokenType.isAssignmentOperator()) { |
| 2068 Token operator = andAdvance; | 2272 Token operator = andAdvance; |
| 2069 ensureAssignable(expression); | 2273 ensureAssignable(expression); |
| 2070 return new AssignmentExpression.full(expression, operator, parseExpression
2()); | 2274 return new AssignmentExpression.full(expression, operator, parseExpression
2()); |
| 2071 } | 2275 } |
| 2072 return expression; | 2276 return expression; |
| 2073 } | 2277 } |
| 2278 |
| 2074 /** | 2279 /** |
| 2075 * Parse a list of expressions. | 2280 * Parse a list of expressions. |
| 2076 * <pre> | 2281 * <pre> |
| 2077 * expressionList ::= | 2282 * expressionList ::= |
| 2078 * expression (',' expression) | 2283 * expression (',' expression) |
| 2079 * </pre> | 2284 * </pre> |
| 2080 * @return the expression that was parsed | 2285 * @return the expression that was parsed |
| 2081 */ | 2286 */ |
| 2082 List<Expression> parseExpressionList() { | 2287 List<Expression> parseExpressionList() { |
| 2083 List<Expression> expressions = new List<Expression>(); | 2288 List<Expression> expressions = new List<Expression>(); |
| 2084 expressions.add(parseExpression2()); | 2289 expressions.add(parseExpression2()); |
| 2085 while (optional(TokenType.COMMA)) { | 2290 while (optional(TokenType.COMMA)) { |
| 2086 expressions.add(parseExpression2()); | 2291 expressions.add(parseExpression2()); |
| 2087 } | 2292 } |
| 2088 return expressions; | 2293 return expressions; |
| 2089 } | 2294 } |
| 2295 |
| 2090 /** | 2296 /** |
| 2091 * Parse an expression that does not contain any cascades. | 2297 * Parse an expression that does not contain any cascades. |
| 2092 * <pre> | 2298 * <pre> |
| 2093 * expressionWithoutCascade ::= | 2299 * expressionWithoutCascade ::= |
| 2094 * assignableExpression assignmentOperator expressionWithoutCascade | 2300 * assignableExpression assignmentOperator expressionWithoutCascade |
| 2095 * | conditionalExpression | 2301 * | conditionalExpression |
| 2096 * | throwExpressionWithoutCascade | 2302 * | throwExpressionWithoutCascade |
| 2097 * </pre> | 2303 * </pre> |
| 2098 * @return the expression that was parsed | 2304 * @return the expression that was parsed |
| 2099 */ | 2305 */ |
| 2100 Expression parseExpressionWithoutCascade() { | 2306 Expression parseExpressionWithoutCascade() { |
| 2101 if (matches(Keyword.THROW)) { | 2307 if (matches(Keyword.THROW)) { |
| 2102 return parseThrowExpressionWithoutCascade(); | 2308 return parseThrowExpressionWithoutCascade(); |
| 2103 } else if (matches(Keyword.RETHROW)) { | 2309 } else if (matches(Keyword.RETHROW)) { |
| 2104 return parseRethrowExpression(); | 2310 return parseRethrowExpression(); |
| 2105 } | 2311 } |
| 2106 Expression expression = parseConditionalExpression(); | 2312 Expression expression = parseConditionalExpression(); |
| 2107 if (_currentToken.type.isAssignmentOperator()) { | 2313 if (_currentToken.type.isAssignmentOperator()) { |
| 2108 Token operator = andAdvance; | 2314 Token operator = andAdvance; |
| 2109 ensureAssignable(expression); | 2315 ensureAssignable(expression); |
| 2110 expression = new AssignmentExpression.full(expression, operator, parseExpr
essionWithoutCascade()); | 2316 expression = new AssignmentExpression.full(expression, operator, parseExpr
essionWithoutCascade()); |
| 2111 } | 2317 } |
| 2112 return expression; | 2318 return expression; |
| 2113 } | 2319 } |
| 2320 |
| 2114 /** | 2321 /** |
| 2115 * Parse a class extends clause. | 2322 * Parse a class extends clause. |
| 2116 * <pre> | 2323 * <pre> |
| 2117 * classExtendsClause ::= | 2324 * classExtendsClause ::= |
| 2118 * 'extends' type | 2325 * 'extends' type |
| 2119 * </pre> | 2326 * </pre> |
| 2120 * @return the class extends clause that was parsed | 2327 * @return the class extends clause that was parsed |
| 2121 */ | 2328 */ |
| 2122 ExtendsClause parseExtendsClause() { | 2329 ExtendsClause parseExtendsClause() { |
| 2123 Token keyword = expect(Keyword.EXTENDS); | 2330 Token keyword = expect(Keyword.EXTENDS); |
| 2124 TypeName superclass = parseTypeName(); | 2331 TypeName superclass = parseTypeName(); |
| 2125 return new ExtendsClause.full(keyword, superclass); | 2332 return new ExtendsClause.full(keyword, superclass); |
| 2126 } | 2333 } |
| 2334 |
| 2127 /** | 2335 /** |
| 2128 * Parse the 'final', 'const', 'var' or type preceding a variable declaration. | 2336 * Parse the 'final', 'const', 'var' or type preceding a variable declaration. |
| 2129 * <pre> | 2337 * <pre> |
| 2130 * finalConstVarOrType ::= | 2338 * finalConstVarOrType ::= |
| 2131 * | 'final' type? | 2339 * | 'final' type? |
| 2132 * | 'const' type? | 2340 * | 'const' type? |
| 2133 * | 'var' | 2341 * | 'var' |
| 2134 * | type | 2342 * | type |
| 2135 * </pre> | 2343 * </pre> |
| 2136 * @param optional {@code true} if the keyword and type are optional | 2344 * @param optional {@code true} if the keyword and type are optional |
| 2137 * @return the 'final', 'const', 'var' or type that was parsed | 2345 * @return the 'final', 'const', 'var' or type that was parsed |
| 2138 */ | 2346 */ |
| 2139 FinalConstVarOrType parseFinalConstVarOrType(bool optional) { | 2347 FinalConstVarOrType parseFinalConstVarOrType(bool optional) { |
| 2140 Token keyword = null; | 2348 Token keyword = null; |
| 2141 TypeName type = null; | 2349 TypeName type = null; |
| 2142 if (matches(Keyword.FINAL) || matches(Keyword.CONST)) { | 2350 if (matches(Keyword.FINAL) || matches(Keyword.CONST)) { |
| 2143 keyword = andAdvance; | 2351 keyword = andAdvance; |
| 2144 if (matchesIdentifier2(peek()) || matches4(peek(), TokenType.LT) || matche
s3(peek(), Keyword.THIS)) { | 2352 if (matchesIdentifier2(peek()) || matches4(peek(), TokenType.LT) || matche
s3(peek(), Keyword.THIS) || (matches4(peek(), TokenType.PERIOD) && matchesIdenti
fier2(peek2(2)) && (matchesIdentifier2(peek2(3)) || matches4(peek2(3), TokenType
.LT) || matches3(peek2(3), Keyword.THIS)))) { |
| 2145 type = parseTypeName(); | 2353 type = parseTypeName(); |
| 2146 } | 2354 } |
| 2147 } else if (matches(Keyword.VAR)) { | 2355 } else if (matches(Keyword.VAR)) { |
| 2148 keyword = andAdvance; | 2356 keyword = andAdvance; |
| 2149 } else { | 2357 } else { |
| 2150 if (matchesIdentifier2(peek()) || matches4(peek(), TokenType.LT) || matche
s3(peek(), Keyword.THIS) || (matches4(peek(), TokenType.PERIOD) && matchesIdenti
fier2(peek2(2)) && (matchesIdentifier2(peek2(3)) || matches4(peek2(3), TokenType
.LT) || matches3(peek2(3), Keyword.THIS)))) { | 2358 if (matchesIdentifier2(peek()) || matches4(peek(), TokenType.LT) || matche
s3(peek(), Keyword.THIS) || (matches4(peek(), TokenType.PERIOD) && matchesIdenti
fier2(peek2(2)) && (matchesIdentifier2(peek2(3)) || matches4(peek2(3), TokenType
.LT) || matches3(peek2(3), Keyword.THIS)))) { |
| 2151 type = parseReturnType(); | 2359 type = parseReturnType(); |
| 2152 } else if (!optional) { | 2360 } else if (!optional) { |
| 2153 reportError4(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); | 2361 reportError7(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); |
| 2154 } | 2362 } |
| 2155 } | 2363 } |
| 2156 return new FinalConstVarOrType(keyword, type); | 2364 return new FinalConstVarOrType(keyword, type); |
| 2157 } | 2365 } |
| 2366 |
| 2158 /** | 2367 /** |
| 2159 * Parse a formal parameter. At most one of {@code isOptional} and {@code isNa
med} can be{@code true}. | 2368 * Parse a formal parameter. At most one of {@code isOptional} and {@code isNa
med} can be{@code true}. |
| 2160 * <pre> | 2369 * <pre> |
| 2161 * defaultFormalParameter ::= | 2370 * defaultFormalParameter ::= |
| 2162 * normalFormalParameter ('=' expression)? | 2371 * normalFormalParameter ('=' expression)? |
| 2163 * defaultNamedParameter ::= | 2372 * defaultNamedParameter ::= |
| 2164 * normalFormalParameter (':' expression)? | 2373 * normalFormalParameter (':' expression)? |
| 2165 * </pre> | 2374 * </pre> |
| 2166 * @param kind the kind of parameter being expected based on the presence or a
bsence of group | 2375 * @param kind the kind of parameter being expected based on the presence or a
bsence of group |
| 2167 * delimiters | 2376 * delimiters |
| 2168 * @return the formal parameter that was parsed | 2377 * @return the formal parameter that was parsed |
| 2169 */ | 2378 */ |
| 2170 FormalParameter parseFormalParameter(ParameterKind kind) { | 2379 FormalParameter parseFormalParameter(ParameterKind kind) { |
| 2171 NormalFormalParameter parameter = parseNormalFormalParameter(); | 2380 NormalFormalParameter parameter = parseNormalFormalParameter(); |
| 2172 if (matches5(TokenType.EQ)) { | 2381 if (matches5(TokenType.EQ)) { |
| 2173 Token seperator = andAdvance; | 2382 Token seperator = andAdvance; |
| 2174 Expression defaultValue = parseExpression2(); | 2383 Expression defaultValue = parseExpression2(); |
| 2175 if (identical(kind, ParameterKind.NAMED)) { | 2384 if (identical(kind, ParameterKind.NAMED)) { |
| 2176 reportError5(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, sepera
tor, []); | 2385 reportError8(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, sepera
tor, []); |
| 2177 } else if (identical(kind, ParameterKind.REQUIRED)) { | 2386 } else if (identical(kind, ParameterKind.REQUIRED)) { |
| 2178 reportError(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, paramete
r, []); | 2387 reportError(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, paramete
r, []); |
| 2179 } | 2388 } |
| 2180 return new DefaultFormalParameter.full(parameter, kind, seperator, default
Value); | 2389 return new DefaultFormalParameter.full(parameter, kind, seperator, default
Value); |
| 2181 } else if (matches5(TokenType.COLON)) { | 2390 } else if (matches5(TokenType.COLON)) { |
| 2182 Token seperator = andAdvance; | 2391 Token seperator = andAdvance; |
| 2183 Expression defaultValue = parseExpression2(); | 2392 Expression defaultValue = parseExpression2(); |
| 2184 if (identical(kind, ParameterKind.POSITIONAL)) { | 2393 if (identical(kind, ParameterKind.POSITIONAL)) { |
| 2185 reportError5(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, s
eperator, []); | 2394 reportError8(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, s
eperator, []); |
| 2186 } else if (identical(kind, ParameterKind.REQUIRED)) { | 2395 } else if (identical(kind, ParameterKind.REQUIRED)) { |
| 2187 reportError(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, []
); | 2396 reportError(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, []
); |
| 2188 } | 2397 } |
| 2189 return new DefaultFormalParameter.full(parameter, kind, seperator, default
Value); | 2398 return new DefaultFormalParameter.full(parameter, kind, seperator, default
Value); |
| 2190 } else if (kind != ParameterKind.REQUIRED) { | 2399 } else if (kind != ParameterKind.REQUIRED) { |
| 2191 return new DefaultFormalParameter.full(parameter, kind, null, null); | 2400 return new DefaultFormalParameter.full(parameter, kind, null, null); |
| 2192 } | 2401 } |
| 2193 return parameter; | 2402 return parameter; |
| 2194 } | 2403 } |
| 2404 |
| 2195 /** | 2405 /** |
| 2196 * Parse a list of formal parameters. | 2406 * Parse a list of formal parameters. |
| 2197 * <pre> | 2407 * <pre> |
| 2198 * formalParameterList ::= | 2408 * formalParameterList ::= |
| 2199 * '(' ')' | 2409 * '(' ')' |
| 2200 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' | 2410 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' |
| 2201 * | '(' optionalFormalParameters ')' | 2411 * | '(' optionalFormalParameters ')' |
| 2202 * normalFormalParameters ::= | 2412 * normalFormalParameters ::= |
| 2203 * normalFormalParameter (',' normalFormalParameter) | 2413 * normalFormalParameter (',' normalFormalParameter) |
| 2204 * optionalFormalParameters ::= | 2414 * optionalFormalParameters ::= |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2228 ParameterKind kind = ParameterKind.REQUIRED; | 2438 ParameterKind kind = ParameterKind.REQUIRED; |
| 2229 bool firstParameter = true; | 2439 bool firstParameter = true; |
| 2230 bool reportedMuliplePositionalGroups = false; | 2440 bool reportedMuliplePositionalGroups = false; |
| 2231 bool reportedMulipleNamedGroups = false; | 2441 bool reportedMulipleNamedGroups = false; |
| 2232 bool reportedMixedGroups = false; | 2442 bool reportedMixedGroups = false; |
| 2233 Token initialToken = null; | 2443 Token initialToken = null; |
| 2234 do { | 2444 do { |
| 2235 if (firstParameter) { | 2445 if (firstParameter) { |
| 2236 firstParameter = false; | 2446 firstParameter = false; |
| 2237 } else if (!optional(TokenType.COMMA)) { | 2447 } else if (!optional(TokenType.COMMA)) { |
| 2238 if ((leftParenthesis is BeginToken) && ((leftParenthesis as BeginToken))
.endToken != null) { | 2448 if (getEndToken(leftParenthesis) != null) { |
| 2239 reportError4(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme])
; | 2449 reportError7(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme])
; |
| 2240 } else { | 2450 } else { |
| 2241 reportError5(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _currentToke
n.previous, []); | 2451 reportError8(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _currentToke
n.previous, []); |
| 2242 break; | 2452 break; |
| 2243 } | 2453 } |
| 2244 } | 2454 } |
| 2245 initialToken = _currentToken; | 2455 initialToken = _currentToken; |
| 2246 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { | 2456 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { |
| 2247 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) { | 2457 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) { |
| 2248 reportError4(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, [])
; | 2458 reportError7(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, [])
; |
| 2249 reportedMuliplePositionalGroups = true; | 2459 reportedMuliplePositionalGroups = true; |
| 2250 } | 2460 } |
| 2251 if (leftCurlyBracket != null && !reportedMixedGroups) { | 2461 if (leftCurlyBracket != null && !reportedMixedGroups) { |
| 2252 reportError4(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); | 2462 reportError7(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); |
| 2253 reportedMixedGroups = true; | 2463 reportedMixedGroups = true; |
| 2254 } | 2464 } |
| 2255 leftSquareBracket = andAdvance; | 2465 leftSquareBracket = andAdvance; |
| 2256 currentParameters = positionalParameters; | 2466 currentParameters = positionalParameters; |
| 2257 kind = ParameterKind.POSITIONAL; | 2467 kind = ParameterKind.POSITIONAL; |
| 2258 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { | 2468 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { |
| 2259 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) { | 2469 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) { |
| 2260 reportError4(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS, []); | 2470 reportError7(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS, []); |
| 2261 reportedMulipleNamedGroups = true; | 2471 reportedMulipleNamedGroups = true; |
| 2262 } | 2472 } |
| 2263 if (leftSquareBracket != null && !reportedMixedGroups) { | 2473 if (leftSquareBracket != null && !reportedMixedGroups) { |
| 2264 reportError4(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); | 2474 reportError7(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); |
| 2265 reportedMixedGroups = true; | 2475 reportedMixedGroups = true; |
| 2266 } | 2476 } |
| 2267 leftCurlyBracket = andAdvance; | 2477 leftCurlyBracket = andAdvance; |
| 2268 currentParameters = namedParameters; | 2478 currentParameters = namedParameters; |
| 2269 kind = ParameterKind.NAMED; | 2479 kind = ParameterKind.NAMED; |
| 2270 } | 2480 } |
| 2271 FormalParameter parameter = parseFormalParameter(kind); | 2481 FormalParameter parameter = parseFormalParameter(kind); |
| 2272 parameters.add(parameter); | 2482 parameters.add(parameter); |
| 2273 currentParameters.add(parameter); | 2483 currentParameters.add(parameter); |
| 2274 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { | 2484 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { |
| 2275 rightSquareBracket = andAdvance; | 2485 rightSquareBracket = andAdvance; |
| 2276 currentParameters = normalParameters; | 2486 currentParameters = normalParameters; |
| 2277 if (leftSquareBracket == null) { | 2487 if (leftSquareBracket == null) { |
| 2278 if (leftCurlyBracket != null) { | 2488 if (leftCurlyBracket != null) { |
| 2279 reportError4(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, [
"}"]); | 2489 reportError7(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, [
"}"]); |
| 2280 rightCurlyBracket = rightSquareBracket; | 2490 rightCurlyBracket = rightSquareBracket; |
| 2281 rightSquareBracket = null; | 2491 rightSquareBracket = null; |
| 2282 } else { | 2492 } else { |
| 2283 reportError4(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GRO
UP, ["["]); | 2493 reportError7(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GRO
UP, ["["]); |
| 2284 } | 2494 } |
| 2285 } | 2495 } |
| 2286 kind = ParameterKind.REQUIRED; | 2496 kind = ParameterKind.REQUIRED; |
| 2287 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { | 2497 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { |
| 2288 rightCurlyBracket = andAdvance; | 2498 rightCurlyBracket = andAdvance; |
| 2289 currentParameters = normalParameters; | 2499 currentParameters = normalParameters; |
| 2290 if (leftCurlyBracket == null) { | 2500 if (leftCurlyBracket == null) { |
| 2291 if (leftSquareBracket != null) { | 2501 if (leftSquareBracket != null) { |
| 2292 reportError4(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, [
"]"]); | 2502 reportError7(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, [
"]"]); |
| 2293 rightSquareBracket = rightCurlyBracket; | 2503 rightSquareBracket = rightCurlyBracket; |
| 2294 rightCurlyBracket = null; | 2504 rightCurlyBracket = null; |
| 2295 } else { | 2505 } else { |
| 2296 reportError4(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GRO
UP, ["{"]); | 2506 reportError7(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GRO
UP, ["{"]); |
| 2297 } | 2507 } |
| 2298 } | 2508 } |
| 2299 kind = ParameterKind.REQUIRED; | 2509 kind = ParameterKind.REQUIRED; |
| 2300 } | 2510 } |
| 2301 } while (!matches5(TokenType.CLOSE_PAREN) && initialToken != _currentToken); | 2511 } while (!matches5(TokenType.CLOSE_PAREN) && initialToken != _currentToken); |
| 2302 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 2512 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 2303 if (leftSquareBracket != null && rightSquareBracket == null) { | 2513 if (leftSquareBracket != null && rightSquareBracket == null) { |
| 2304 reportError4(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["]"]
); | 2514 reportError7(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["]"]
); |
| 2305 } | 2515 } |
| 2306 if (leftCurlyBracket != null && rightCurlyBracket == null) { | 2516 if (leftCurlyBracket != null && rightCurlyBracket == null) { |
| 2307 reportError4(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]
); | 2517 reportError7(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]
); |
| 2308 } | 2518 } |
| 2309 if (leftSquareBracket == null) { | 2519 if (leftSquareBracket == null) { |
| 2310 leftSquareBracket = leftCurlyBracket; | 2520 leftSquareBracket = leftCurlyBracket; |
| 2311 } | 2521 } |
| 2312 if (rightSquareBracket == null) { | 2522 if (rightSquareBracket == null) { |
| 2313 rightSquareBracket = rightCurlyBracket; | 2523 rightSquareBracket = rightCurlyBracket; |
| 2314 } | 2524 } |
| 2315 return new FormalParameterList.full(leftParenthesis, parameters, leftSquareB
racket, rightSquareBracket, rightParenthesis); | 2525 return new FormalParameterList.full(leftParenthesis, parameters, leftSquareB
racket, rightSquareBracket, rightParenthesis); |
| 2316 } | 2526 } |
| 2527 |
| 2317 /** | 2528 /** |
| 2318 * Parse a for statement. | 2529 * Parse a for statement. |
| 2319 * <pre> | 2530 * <pre> |
| 2320 * forStatement ::= | 2531 * forStatement ::= |
| 2321 * 'for' '(' forLoopParts ')' statement | 2532 * 'for' '(' forLoopParts ')' statement |
| 2322 * forLoopParts ::= | 2533 * forLoopParts ::= |
| 2323 * forInitializerStatement expression? ';' expressionList? | 2534 * forInitializerStatement expression? ';' expressionList? |
| 2324 * | declaredIdentifier 'in' expression | 2535 * | declaredIdentifier 'in' expression |
| 2325 * | identifier 'in' expression | 2536 * | identifier 'in' expression |
| 2326 * forInitializerStatement ::= | 2537 * forInitializerStatement ::= |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2345 variables.add(new VariableDeclaration.full(null, null, variableName, n
ull, null)); | 2556 variables.add(new VariableDeclaration.full(null, null, variableName, n
ull, null)); |
| 2346 variableList = new VariableDeclarationList.full(commentAndMetadata.com
ment, commentAndMetadata.metadata, null, null, variables); | 2557 variableList = new VariableDeclarationList.full(commentAndMetadata.com
ment, commentAndMetadata.metadata, null, null, variables); |
| 2347 } else if (isInitializedVariableDeclaration()) { | 2558 } else if (isInitializedVariableDeclaration()) { |
| 2348 variableList = parseVariableDeclarationList(commentAndMetadata); | 2559 variableList = parseVariableDeclarationList(commentAndMetadata); |
| 2349 } else { | 2560 } else { |
| 2350 initialization = parseExpression2(); | 2561 initialization = parseExpression2(); |
| 2351 } | 2562 } |
| 2352 if (matches(Keyword.IN)) { | 2563 if (matches(Keyword.IN)) { |
| 2353 DeclaredIdentifier loopVariable = null; | 2564 DeclaredIdentifier loopVariable = null; |
| 2354 if (variableList == null) { | 2565 if (variableList == null) { |
| 2355 reportError4(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []); | 2566 reportError7(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []); |
| 2356 } else { | 2567 } else { |
| 2357 NodeList<VariableDeclaration> variables2 = variableList.variables; | 2568 NodeList<VariableDeclaration> variables2 = variableList.variables; |
| 2358 if (variables2.length > 1) { | 2569 if (variables2.length > 1) { |
| 2359 reportError4(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [vari
ables2.length.toString()]); | 2570 reportError7(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [vari
ables2.length.toString()]); |
| 2360 } | 2571 } |
| 2361 VariableDeclaration variable = variables2[0]; | 2572 VariableDeclaration variable = variables2[0]; |
| 2362 if (variable.initializer != null) { | 2573 if (variable.initializer != null) { |
| 2363 reportError4(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [])
; | 2574 reportError7(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [])
; |
| 2364 } | 2575 } |
| 2365 loopVariable = new DeclaredIdentifier.full(commentAndMetadata.commen
t, commentAndMetadata.metadata, variableList.keyword, variableList.type, variabl
e.name); | 2576 loopVariable = new DeclaredIdentifier.full(commentAndMetadata.commen
t, commentAndMetadata.metadata, variableList.keyword, variableList.type, variabl
e.name); |
| 2366 } | 2577 } |
| 2367 Token inKeyword = expect(Keyword.IN); | 2578 Token inKeyword = expect(Keyword.IN); |
| 2368 Expression iterator = parseExpression2(); | 2579 Expression iterator = parseExpression2(); |
| 2369 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 2580 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 2370 Statement body = parseStatement2(); | 2581 Statement body = parseStatement2(); |
| 2371 return new ForEachStatement.full(forKeyword, leftParenthesis, loopVari
able, inKeyword, iterator, rightParenthesis, body); | 2582 return new ForEachStatement.full(forKeyword, leftParenthesis, loopVari
able, inKeyword, iterator, rightParenthesis, body); |
| 2372 } | 2583 } |
| 2373 } | 2584 } |
| 2374 Token leftSeparator = expect2(TokenType.SEMICOLON); | 2585 Token leftSeparator = expect2(TokenType.SEMICOLON); |
| 2375 Expression condition = null; | 2586 Expression condition = null; |
| 2376 if (!matches5(TokenType.SEMICOLON)) { | 2587 if (!matches5(TokenType.SEMICOLON)) { |
| 2377 condition = parseExpression2(); | 2588 condition = parseExpression2(); |
| 2378 } | 2589 } |
| 2379 Token rightSeparator = expect2(TokenType.SEMICOLON); | 2590 Token rightSeparator = expect2(TokenType.SEMICOLON); |
| 2380 List<Expression> updaters = null; | 2591 List<Expression> updaters = null; |
| 2381 if (!matches5(TokenType.CLOSE_PAREN)) { | 2592 if (!matches5(TokenType.CLOSE_PAREN)) { |
| 2382 updaters = parseExpressionList(); | 2593 updaters = parseExpressionList(); |
| 2383 } | 2594 } |
| 2384 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 2595 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 2385 Statement body = parseStatement2(); | 2596 Statement body = parseStatement2(); |
| 2386 return new ForStatement.full(forKeyword, leftParenthesis, variableList, in
itialization, leftSeparator, condition, rightSeparator, updaters, rightParenthes
is, body); | 2597 return new ForStatement.full(forKeyword, leftParenthesis, variableList, in
itialization, leftSeparator, condition, rightSeparator, updaters, rightParenthes
is, body); |
| 2387 } finally { | 2598 } finally { |
| 2388 _inLoop = wasInLoop; | 2599 _inLoop = wasInLoop; |
| 2389 } | 2600 } |
| 2390 } | 2601 } |
| 2602 |
| 2391 /** | 2603 /** |
| 2392 * Parse a function body. | 2604 * Parse a function body. |
| 2393 * <pre> | 2605 * <pre> |
| 2394 * functionBody ::= | 2606 * functionBody ::= |
| 2395 * '=>' expression ';' | 2607 * '=>' expression ';' |
| 2396 * | block | 2608 * | block |
| 2397 * functionExpressionBody ::= | 2609 * functionExpressionBody ::= |
| 2398 * '=>' expression | 2610 * '=>' expression |
| 2399 * | block | 2611 * | block |
| 2400 * </pre> | 2612 * </pre> |
| 2401 * @param mayBeEmpty {@code true} if the function body is allowed to be empty | 2613 * @param mayBeEmpty {@code true} if the function body is allowed to be empty |
| 2614 * @param emptyErrorCode the error code to report if function body expecte, bu
t not found |
| 2402 * @param inExpression {@code true} if the function body is being parsed as pa
rt of an expression | 2615 * @param inExpression {@code true} if the function body is being parsed as pa
rt of an expression |
| 2403 * and therefore does not have a terminating semicolon | 2616 * and therefore does not have a terminating semicolon |
| 2404 * @return the function body that was parsed | 2617 * @return the function body that was parsed |
| 2405 */ | 2618 */ |
| 2406 FunctionBody parseFunctionBody(bool mayBeEmpty, bool inExpression) { | 2619 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode
, bool inExpression) { |
| 2407 bool wasInLoop = _inLoop; | 2620 bool wasInLoop = _inLoop; |
| 2408 bool wasInSwitch = _inSwitch; | 2621 bool wasInSwitch = _inSwitch; |
| 2409 _inLoop = false; | 2622 _inLoop = false; |
| 2410 _inSwitch = false; | 2623 _inSwitch = false; |
| 2411 try { | 2624 try { |
| 2412 if (matches5(TokenType.SEMICOLON)) { | 2625 if (matches5(TokenType.SEMICOLON)) { |
| 2413 if (!mayBeEmpty) { | 2626 if (!mayBeEmpty) { |
| 2414 reportError4(ParserErrorCode.MISSING_FUNCTION_BODY, []); | 2627 reportError7(emptyErrorCode, []); |
| 2415 } | 2628 } |
| 2416 return new EmptyFunctionBody.full(andAdvance); | 2629 return new EmptyFunctionBody.full(andAdvance); |
| 2417 } else if (matches5(TokenType.FUNCTION)) { | 2630 } else if (matches5(TokenType.FUNCTION)) { |
| 2418 Token functionDefinition = andAdvance; | 2631 Token functionDefinition = andAdvance; |
| 2419 Expression expression = parseExpression2(); | 2632 Expression expression = parseExpression2(); |
| 2420 Token semicolon = null; | 2633 Token semicolon = null; |
| 2421 if (!inExpression) { | 2634 if (!inExpression) { |
| 2422 semicolon = expect2(TokenType.SEMICOLON); | 2635 semicolon = expect2(TokenType.SEMICOLON); |
| 2423 } | 2636 } |
| 2424 return new ExpressionFunctionBody.full(functionDefinition, expression, s
emicolon); | 2637 return new ExpressionFunctionBody.full(functionDefinition, expression, s
emicolon); |
| 2425 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { | 2638 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { |
| 2426 return new BlockFunctionBody.full(parseBlock()); | 2639 return new BlockFunctionBody.full(parseBlock()); |
| 2427 } else if (matches2(_NATIVE)) { | 2640 } else if (matches2(_NATIVE)) { |
| 2428 Token nativeToken = andAdvance; | 2641 Token nativeToken = andAdvance; |
| 2429 StringLiteral stringLiteral = null; | 2642 StringLiteral stringLiteral = null; |
| 2430 if (matches5(TokenType.STRING)) { | 2643 if (matches5(TokenType.STRING)) { |
| 2431 stringLiteral = parseStringLiteral(); | 2644 stringLiteral = parseStringLiteral(); |
| 2432 } | 2645 } |
| 2433 return new NativeFunctionBody.full(nativeToken, stringLiteral, expect2(T
okenType.SEMICOLON)); | 2646 return new NativeFunctionBody.full(nativeToken, stringLiteral, expect2(T
okenType.SEMICOLON)); |
| 2434 } else { | 2647 } else { |
| 2435 reportError4(ParserErrorCode.MISSING_FUNCTION_BODY, []); | 2648 reportError7(emptyErrorCode, []); |
| 2436 return new EmptyFunctionBody.full(createSyntheticToken2(TokenType.SEMICO
LON)); | 2649 return new EmptyFunctionBody.full(createSyntheticToken2(TokenType.SEMICO
LON)); |
| 2437 } | 2650 } |
| 2438 } finally { | 2651 } finally { |
| 2439 _inLoop = wasInLoop; | 2652 _inLoop = wasInLoop; |
| 2440 _inSwitch = wasInSwitch; | 2653 _inSwitch = wasInSwitch; |
| 2441 } | 2654 } |
| 2442 } | 2655 } |
| 2656 |
| 2443 /** | 2657 /** |
| 2444 * Parse a function declaration. | 2658 * Parse a function declaration. |
| 2445 * <pre> | 2659 * <pre> |
| 2446 * functionDeclaration ::= | 2660 * functionDeclaration ::= |
| 2447 * functionSignature functionBody | 2661 * functionSignature functionBody |
| 2448 * | returnType? getOrSet identifier formalParameterList functionBody | 2662 * | returnType? getOrSet identifier formalParameterList functionBody |
| 2449 * </pre> | 2663 * </pre> |
| 2450 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the | 2664 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the |
| 2451 * declaration | 2665 * declaration |
| 2452 * @param externalKeyword the 'external' keyword, or {@code null} if the funct
ion is not external | 2666 * @param externalKeyword the 'external' keyword, or {@code null} if the funct
ion is not external |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2463 } else if (matches(Keyword.SET) && !matches4(peek(), TokenType.OPEN_PAREN))
{ | 2677 } else if (matches(Keyword.SET) && !matches4(peek(), TokenType.OPEN_PAREN))
{ |
| 2464 keyword = andAdvance; | 2678 keyword = andAdvance; |
| 2465 } | 2679 } |
| 2466 SimpleIdentifier name = parseSimpleIdentifier(); | 2680 SimpleIdentifier name = parseSimpleIdentifier(); |
| 2467 FormalParameterList parameters = null; | 2681 FormalParameterList parameters = null; |
| 2468 if (!isGetter) { | 2682 if (!isGetter) { |
| 2469 if (matches5(TokenType.OPEN_PAREN)) { | 2683 if (matches5(TokenType.OPEN_PAREN)) { |
| 2470 parameters = parseFormalParameterList(); | 2684 parameters = parseFormalParameterList(); |
| 2471 validateFormalParameterList(parameters); | 2685 validateFormalParameterList(parameters); |
| 2472 } else { | 2686 } else { |
| 2473 reportError4(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []); | 2687 reportError7(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []); |
| 2474 } | 2688 } |
| 2475 } else if (matches5(TokenType.OPEN_PAREN)) { | 2689 } else if (matches5(TokenType.OPEN_PAREN)) { |
| 2476 reportError4(ParserErrorCode.GETTER_WITH_PARAMETERS, []); | 2690 reportError7(ParserErrorCode.GETTER_WITH_PARAMETERS, []); |
| 2477 parseFormalParameterList(); | 2691 parseFormalParameterList(); |
| 2478 } | 2692 } |
| 2479 FunctionBody body; | 2693 FunctionBody body; |
| 2480 if (externalKeyword == null) { | 2694 if (externalKeyword == null) { |
| 2481 body = parseFunctionBody(false, false); | 2695 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal
se); |
| 2482 } else { | 2696 } else { |
| 2483 body = new EmptyFunctionBody.full(expect2(TokenType.SEMICOLON)); | 2697 body = new EmptyFunctionBody.full(expect2(TokenType.SEMICOLON)); |
| 2484 } | 2698 } |
| 2485 return new FunctionDeclaration.full(commentAndMetadata.comment, commentAndMe
tadata.metadata, externalKeyword, returnType, keyword, name, new FunctionExpress
ion.full(parameters, body)); | 2699 return new FunctionDeclaration.full(commentAndMetadata.comment, commentAndMe
tadata.metadata, externalKeyword, returnType, keyword, name, new FunctionExpress
ion.full(parameters, body)); |
| 2486 } | 2700 } |
| 2701 |
| 2487 /** | 2702 /** |
| 2488 * Parse a function declaration statement. | 2703 * Parse a function declaration statement. |
| 2489 * <pre> | 2704 * <pre> |
| 2490 * functionDeclarationStatement ::= | 2705 * functionDeclarationStatement ::= |
| 2491 * functionSignature functionBody | 2706 * functionSignature functionBody |
| 2492 * </pre> | 2707 * </pre> |
| 2493 * @return the function declaration statement that was parsed | 2708 * @return the function declaration statement that was parsed |
| 2494 */ | 2709 */ |
| 2495 Statement parseFunctionDeclarationStatement() => parseFunctionDeclarationState
ment2(parseCommentAndMetadata(), parseOptionalReturnType()); | 2710 Statement parseFunctionDeclarationStatement() => parseFunctionDeclarationState
ment2(parseCommentAndMetadata(), parseOptionalReturnType()); |
| 2711 |
| 2496 /** | 2712 /** |
| 2497 * Parse a function declaration statement. | 2713 * Parse a function declaration statement. |
| 2498 * <pre> | 2714 * <pre> |
| 2499 * functionDeclarationStatement ::= | 2715 * functionDeclarationStatement ::= |
| 2500 * functionSignature functionBody | 2716 * functionSignature functionBody |
| 2501 * </pre> | 2717 * </pre> |
| 2502 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the | 2718 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the |
| 2503 * declaration | 2719 * declaration |
| 2504 * @param returnType the return type, or {@code null} if there is no return ty
pe | 2720 * @param returnType the return type, or {@code null} if there is no return ty
pe |
| 2505 * @return the function declaration statement that was parsed | 2721 * @return the function declaration statement that was parsed |
| 2506 */ | 2722 */ |
| 2507 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta
data, TypeName returnType) => new FunctionDeclarationStatement.full(parseFunctio
nDeclaration(commentAndMetadata, null, returnType)); | 2723 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta
data, TypeName returnType) => new FunctionDeclarationStatement.full(parseFunctio
nDeclaration(commentAndMetadata, null, returnType)); |
| 2724 |
| 2508 /** | 2725 /** |
| 2509 * Parse a function expression. | 2726 * Parse a function expression. |
| 2510 * <pre> | 2727 * <pre> |
| 2511 * functionExpression ::= | 2728 * functionExpression ::= |
| 2512 * formalParameterList functionExpressionBody | 2729 * formalParameterList functionExpressionBody |
| 2513 * </pre> | 2730 * </pre> |
| 2514 * @return the function expression that was parsed | 2731 * @return the function expression that was parsed |
| 2515 */ | 2732 */ |
| 2516 FunctionExpression parseFunctionExpression() { | 2733 FunctionExpression parseFunctionExpression() { |
| 2517 FormalParameterList parameters = parseFormalParameterList(); | 2734 FormalParameterList parameters = parseFormalParameterList(); |
| 2518 validateFormalParameterList(parameters); | 2735 validateFormalParameterList(parameters); |
| 2519 FunctionBody body = parseFunctionBody(false, true); | 2736 FunctionBody body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTIO
N_BODY, true); |
| 2520 return new FunctionExpression.full(parameters, body); | 2737 return new FunctionExpression.full(parameters, body); |
| 2521 } | 2738 } |
| 2739 |
| 2522 /** | 2740 /** |
| 2523 * Parse a function type alias. | 2741 * Parse a function type alias. |
| 2524 * <pre> | 2742 * <pre> |
| 2525 * functionTypeAlias ::= | 2743 * functionTypeAlias ::= |
| 2526 * functionPrefix typeParameterList? formalParameterList ';' | 2744 * functionPrefix typeParameterList? formalParameterList ';' |
| 2527 * functionPrefix ::= | 2745 * functionPrefix ::= |
| 2528 * returnType? name | 2746 * returnType? name |
| 2529 * </pre> | 2747 * </pre> |
| 2530 * @param commentAndMetadata the metadata to be associated with the member | 2748 * @param commentAndMetadata the metadata to be associated with the member |
| 2531 * @param keyword the token representing the 'typedef' keyword | 2749 * @param keyword the token representing the 'typedef' keyword |
| 2532 * @return the function type alias that was parsed | 2750 * @return the function type alias that was parsed |
| 2533 */ | 2751 */ |
| 2534 FunctionTypeAlias parseFunctionTypeAlias(CommentAndMetadata commentAndMetadata
, Token keyword) { | 2752 FunctionTypeAlias parseFunctionTypeAlias(CommentAndMetadata commentAndMetadata
, Token keyword) { |
| 2535 TypeName returnType = null; | 2753 TypeName returnType = null; |
| 2536 if (hasReturnTypeInTypeAlias()) { | 2754 if (hasReturnTypeInTypeAlias()) { |
| 2537 returnType = parseReturnType(); | 2755 returnType = parseReturnType(); |
| 2538 } | 2756 } |
| 2539 SimpleIdentifier name = parseSimpleIdentifier(); | 2757 SimpleIdentifier name = parseSimpleIdentifier(); |
| 2540 TypeParameterList typeParameters = null; | 2758 TypeParameterList typeParameters = null; |
| 2541 if (matches5(TokenType.LT)) { | 2759 if (matches5(TokenType.LT)) { |
| 2542 typeParameters = parseTypeParameterList(); | 2760 typeParameters = parseTypeParameterList(); |
| 2543 } | 2761 } |
| 2544 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) { | 2762 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) { |
| 2545 reportError4(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); | 2763 reportError7(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); |
| 2546 FormalParameterList parameters = new FormalParameterList.full(createSynthe
ticToken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken2(TokenTy
pe.CLOSE_PAREN)); | 2764 FormalParameterList parameters = new FormalParameterList.full(createSynthe
ticToken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken2(TokenTy
pe.CLOSE_PAREN)); |
| 2547 Token semicolon = expect2(TokenType.SEMICOLON); | 2765 Token semicolon = expect2(TokenType.SEMICOLON); |
| 2548 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMe
tadata.metadata, keyword, returnType, name, typeParameters, parameters, semicolo
n); | 2766 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMe
tadata.metadata, keyword, returnType, name, typeParameters, parameters, semicolo
n); |
| 2549 } else if (!matches5(TokenType.OPEN_PAREN)) { | 2767 } else if (!matches5(TokenType.OPEN_PAREN)) { |
| 2550 reportError4(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); | 2768 reportError7(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); |
| 2551 return null; | 2769 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMe
tadata.metadata, keyword, returnType, name, typeParameters, new FormalParameterL
ist.full(createSyntheticToken2(TokenType.OPEN_PAREN), null, null, null, createSy
ntheticToken2(TokenType.CLOSE_PAREN)), createSyntheticToken2(TokenType.SEMICOLON
)); |
| 2552 } | 2770 } |
| 2553 FormalParameterList parameters = parseFormalParameterList(); | 2771 FormalParameterList parameters = parseFormalParameterList(); |
| 2554 validateFormalParameterList(parameters); | 2772 validateFormalParameterList(parameters); |
| 2555 Token semicolon = expect2(TokenType.SEMICOLON); | 2773 Token semicolon = expect2(TokenType.SEMICOLON); |
| 2556 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMeta
data.metadata, keyword, returnType, name, typeParameters, parameters, semicolon)
; | 2774 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMeta
data.metadata, keyword, returnType, name, typeParameters, parameters, semicolon)
; |
| 2557 } | 2775 } |
| 2776 |
| 2558 /** | 2777 /** |
| 2559 * Parse a getter. | 2778 * Parse a getter. |
| 2560 * <pre> | 2779 * <pre> |
| 2561 * getter ::= | 2780 * getter ::= |
| 2562 * getterSignature functionBody? | 2781 * getterSignature functionBody? |
| 2563 * getterSignature ::= | 2782 * getterSignature ::= |
| 2564 * 'external'? 'static'? returnType? 'get' identifier | 2783 * 'external'? 'static'? returnType? 'get' identifier |
| 2565 * </pre> | 2784 * </pre> |
| 2566 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the | 2785 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the |
| 2567 * declaration | 2786 * declaration |
| 2568 * @param externalKeyword the 'external' token | 2787 * @param externalKeyword the 'external' token |
| 2569 * @param staticKeyword the static keyword, or {@code null} if the getter is n
ot static | 2788 * @param staticKeyword the static keyword, or {@code null} if the getter is n
ot static |
| 2570 * @param the return type that has already been parsed, or {@code null} if the
re was no return | 2789 * @param the return type that has already been parsed, or {@code null} if the
re was no return |
| 2571 * type | 2790 * type |
| 2572 * @return the getter that was parsed | 2791 * @return the getter that was parsed |
| 2573 */ | 2792 */ |
| 2574 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext
ernalKeyword, Token staticKeyword, TypeName returnType) { | 2793 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext
ernalKeyword, Token staticKeyword, TypeName returnType) { |
| 2575 Token propertyKeyword = expect(Keyword.GET); | 2794 Token propertyKeyword = expect(Keyword.GET); |
| 2576 SimpleIdentifier name = parseSimpleIdentifier(); | 2795 SimpleIdentifier name = parseSimpleIdentifier(); |
| 2577 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN
)) { | 2796 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN
)) { |
| 2578 reportError4(ParserErrorCode.GETTER_WITH_PARAMETERS, []); | 2797 reportError7(ParserErrorCode.GETTER_WITH_PARAMETERS, []); |
| 2579 advance(); | 2798 advance(); |
| 2580 advance(); | 2799 advance(); |
| 2581 } | 2800 } |
| 2582 FunctionBody body = parseFunctionBody(true, false); | 2801 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo
rd == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false); |
| 2583 if (externalKeyword != null && body is! EmptyFunctionBody) { | 2802 if (externalKeyword != null && body is! EmptyFunctionBody) { |
| 2584 reportError4(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []); | 2803 reportError7(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []); |
| 2585 } | 2804 } |
| 2586 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta
data.metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null
, name, null, body); | 2805 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta
data.metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null
, name, null, body); |
| 2587 } | 2806 } |
| 2807 |
| 2588 /** | 2808 /** |
| 2589 * Parse a list of identifiers. | 2809 * Parse a list of identifiers. |
| 2590 * <pre> | 2810 * <pre> |
| 2591 * identifierList ::= | 2811 * identifierList ::= |
| 2592 * identifier (',' identifier) | 2812 * identifier (',' identifier) |
| 2593 * </pre> | 2813 * </pre> |
| 2594 * @return the list of identifiers that were parsed | 2814 * @return the list of identifiers that were parsed |
| 2595 */ | 2815 */ |
| 2596 List<SimpleIdentifier> parseIdentifierList() { | 2816 List<SimpleIdentifier> parseIdentifierList() { |
| 2597 List<SimpleIdentifier> identifiers = new List<SimpleIdentifier>(); | 2817 List<SimpleIdentifier> identifiers = new List<SimpleIdentifier>(); |
| 2598 identifiers.add(parseSimpleIdentifier()); | 2818 identifiers.add(parseSimpleIdentifier()); |
| 2599 while (matches5(TokenType.COMMA)) { | 2819 while (matches5(TokenType.COMMA)) { |
| 2600 advance(); | 2820 advance(); |
| 2601 identifiers.add(parseSimpleIdentifier()); | 2821 identifiers.add(parseSimpleIdentifier()); |
| 2602 } | 2822 } |
| 2603 return identifiers; | 2823 return identifiers; |
| 2604 } | 2824 } |
| 2825 |
| 2605 /** | 2826 /** |
| 2606 * Parse an if statement. | 2827 * Parse an if statement. |
| 2607 * <pre> | 2828 * <pre> |
| 2608 * ifStatement ::= | 2829 * ifStatement ::= |
| 2609 * 'if' '(' expression ')' statement ('else' statement)? | 2830 * 'if' '(' expression ')' statement ('else' statement)? |
| 2610 * </pre> | 2831 * </pre> |
| 2611 * @return the if statement that was parsed | 2832 * @return the if statement that was parsed |
| 2612 */ | 2833 */ |
| 2613 Statement parseIfStatement() { | 2834 Statement parseIfStatement() { |
| 2614 Token ifKeyword = expect(Keyword.IF); | 2835 Token ifKeyword = expect(Keyword.IF); |
| 2615 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); | 2836 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); |
| 2616 Expression condition = parseExpression2(); | 2837 Expression condition = parseExpression2(); |
| 2617 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 2838 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 2618 Statement thenStatement = parseStatement2(); | 2839 Statement thenStatement = parseStatement2(); |
| 2619 Token elseKeyword = null; | 2840 Token elseKeyword = null; |
| 2620 Statement elseStatement = null; | 2841 Statement elseStatement = null; |
| 2621 if (matches(Keyword.ELSE)) { | 2842 if (matches(Keyword.ELSE)) { |
| 2622 elseKeyword = andAdvance; | 2843 elseKeyword = andAdvance; |
| 2623 elseStatement = parseStatement2(); | 2844 elseStatement = parseStatement2(); |
| 2624 } | 2845 } |
| 2625 return new IfStatement.full(ifKeyword, leftParenthesis, condition, rightPare
nthesis, thenStatement, elseKeyword, elseStatement); | 2846 return new IfStatement.full(ifKeyword, leftParenthesis, condition, rightPare
nthesis, thenStatement, elseKeyword, elseStatement); |
| 2626 } | 2847 } |
| 2848 |
| 2627 /** | 2849 /** |
| 2628 * Parse an implements clause. | 2850 * Parse an implements clause. |
| 2629 * <pre> | 2851 * <pre> |
| 2630 * implementsClause ::= | 2852 * implementsClause ::= |
| 2631 * 'implements' type (',' type) | 2853 * 'implements' type (',' type) |
| 2632 * </pre> | 2854 * </pre> |
| 2633 * @return the implements clause that was parsed | 2855 * @return the implements clause that was parsed |
| 2634 */ | 2856 */ |
| 2635 ImplementsClause parseImplementsClause() { | 2857 ImplementsClause parseImplementsClause() { |
| 2636 Token keyword = expect(Keyword.IMPLEMENTS); | 2858 Token keyword = expect(Keyword.IMPLEMENTS); |
| 2637 List<TypeName> interfaces = new List<TypeName>(); | 2859 List<TypeName> interfaces = new List<TypeName>(); |
| 2638 interfaces.add(parseTypeName()); | 2860 interfaces.add(parseTypeName()); |
| 2639 while (optional(TokenType.COMMA)) { | 2861 while (optional(TokenType.COMMA)) { |
| 2640 interfaces.add(parseTypeName()); | 2862 interfaces.add(parseTypeName()); |
| 2641 } | 2863 } |
| 2642 return new ImplementsClause.full(keyword, interfaces); | 2864 return new ImplementsClause.full(keyword, interfaces); |
| 2643 } | 2865 } |
| 2866 |
| 2644 /** | 2867 /** |
| 2645 * Parse an import directive. | 2868 * Parse an import directive. |
| 2646 * <pre> | 2869 * <pre> |
| 2647 * importDirective ::= | 2870 * importDirective ::= |
| 2648 * metadata 'import' stringLiteral ('as' identifier)? combinator*';' | 2871 * metadata 'import' stringLiteral ('as' identifier)? combinator*';' |
| 2649 * </pre> | 2872 * </pre> |
| 2650 * @param commentAndMetadata the metadata to be associated with the directive | 2873 * @param commentAndMetadata the metadata to be associated with the directive |
| 2651 * @return the import directive that was parsed | 2874 * @return the import directive that was parsed |
| 2652 */ | 2875 */ |
| 2653 ImportDirective parseImportDirective(CommentAndMetadata commentAndMetadata) { | 2876 ImportDirective parseImportDirective(CommentAndMetadata commentAndMetadata) { |
| 2654 Token importKeyword = expect(Keyword.IMPORT); | 2877 Token importKeyword = expect(Keyword.IMPORT); |
| 2655 StringLiteral libraryUri = parseStringLiteral(); | 2878 StringLiteral libraryUri = parseStringLiteral(); |
| 2656 Token asToken = null; | 2879 Token asToken = null; |
| 2657 SimpleIdentifier prefix = null; | 2880 SimpleIdentifier prefix = null; |
| 2658 if (matches(Keyword.AS)) { | 2881 if (matches(Keyword.AS)) { |
| 2659 asToken = andAdvance; | 2882 asToken = andAdvance; |
| 2660 prefix = parseSimpleIdentifier(); | 2883 prefix = parseSimpleIdentifier(); |
| 2661 } | 2884 } |
| 2662 List<Combinator> combinators = parseCombinators(); | 2885 List<Combinator> combinators = parseCombinators(); |
| 2663 Token semicolon = expect2(TokenType.SEMICOLON); | 2886 Token semicolon = expect2(TokenType.SEMICOLON); |
| 2664 return new ImportDirective.full(commentAndMetadata.comment, commentAndMetada
ta.metadata, importKeyword, libraryUri, asToken, prefix, combinators, semicolon)
; | 2887 return new ImportDirective.full(commentAndMetadata.comment, commentAndMetada
ta.metadata, importKeyword, libraryUri, asToken, prefix, combinators, semicolon)
; |
| 2665 } | 2888 } |
| 2889 |
| 2666 /** | 2890 /** |
| 2667 * Parse a list of initialized identifiers. | 2891 * Parse a list of initialized identifiers. |
| 2668 * <pre> | 2892 * <pre> |
| 2669 * ?? ::= | 2893 * ?? ::= |
| 2670 * 'static'? ('var' | type) initializedIdentifierList ';' | 2894 * 'static'? ('var' | type) initializedIdentifierList ';' |
| 2671 * | 'final' type? initializedIdentifierList ';' | 2895 * | 'final' type? initializedIdentifierList ';' |
| 2672 * initializedIdentifierList ::= | 2896 * initializedIdentifierList ::= |
| 2673 * initializedIdentifier (',' initializedIdentifier) | 2897 * initializedIdentifier (',' initializedIdentifier) |
| 2674 * initializedIdentifier ::= | 2898 * initializedIdentifier ::= |
| 2675 * identifier ('=' expression)? | 2899 * identifier ('=' expression)? |
| 2676 * </pre> | 2900 * </pre> |
| 2677 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the | 2901 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the |
| 2678 * declaration | 2902 * declaration |
| 2679 * @param staticKeyword the static keyword, or {@code null} if the getter is n
ot static | 2903 * @param staticKeyword the static keyword, or {@code null} if the getter is n
ot static |
| 2680 * @param keyword the token representing the 'final', 'const' or 'var' keyword
, or {@code null} if | 2904 * @param keyword the token representing the 'final', 'const' or 'var' keyword
, or {@code null} if |
| 2681 * there is no keyword | 2905 * there is no keyword |
| 2682 * @param type the type that has already been parsed, or {@code null} if 'var'
was provided | 2906 * @param type the type that has already been parsed, or {@code null} if 'var'
was provided |
| 2683 * @return the getter that was parsed | 2907 * @return the getter that was parsed |
| 2684 */ | 2908 */ |
| 2685 FieldDeclaration parseInitializedIdentifierList(CommentAndMetadata commentAndM
etadata, Token staticKeyword, Token keyword, TypeName type) { | 2909 FieldDeclaration parseInitializedIdentifierList(CommentAndMetadata commentAndM
etadata, Token staticKeyword, Token keyword, TypeName type) { |
| 2686 VariableDeclarationList fieldList = parseVariableDeclarationList2(null, keyw
ord, type); | 2910 VariableDeclarationList fieldList = parseVariableDeclarationList2(null, keyw
ord, type); |
| 2687 return new FieldDeclaration.full(commentAndMetadata.comment, commentAndMetad
ata.metadata, staticKeyword, fieldList, expect2(TokenType.SEMICOLON)); | 2911 return new FieldDeclaration.full(commentAndMetadata.comment, commentAndMetad
ata.metadata, staticKeyword, fieldList, expect2(TokenType.SEMICOLON)); |
| 2688 } | 2912 } |
| 2913 |
| 2689 /** | 2914 /** |
| 2690 * Parse an instance creation expression. | 2915 * Parse an instance creation expression. |
| 2691 * <pre> | 2916 * <pre> |
| 2692 * instanceCreationExpression ::= | 2917 * instanceCreationExpression ::= |
| 2693 * ('new' | 'const') type ('.' identifier)? argumentList | 2918 * ('new' | 'const') type ('.' identifier)? argumentList |
| 2694 * </pre> | 2919 * </pre> |
| 2695 * @param keyword the 'new' or 'const' keyword that introduces the expression | 2920 * @param keyword the 'new' or 'const' keyword that introduces the expression |
| 2696 * @return the instance creation expression that was parsed | 2921 * @return the instance creation expression that was parsed |
| 2697 */ | 2922 */ |
| 2698 InstanceCreationExpression parseInstanceCreationExpression(Token keyword) { | 2923 InstanceCreationExpression parseInstanceCreationExpression(Token keyword) { |
| 2699 ConstructorName constructorName = parseConstructorName(); | 2924 ConstructorName constructorName = parseConstructorName(); |
| 2700 ArgumentList argumentList = parseArgumentList(); | 2925 ArgumentList argumentList = parseArgumentList(); |
| 2701 return new InstanceCreationExpression.full(keyword, constructorName, argumen
tList); | 2926 return new InstanceCreationExpression.full(keyword, constructorName, argumen
tList); |
| 2702 } | 2927 } |
| 2928 |
| 2703 /** | 2929 /** |
| 2704 * Parse a library directive. | 2930 * Parse a library directive. |
| 2705 * <pre> | 2931 * <pre> |
| 2706 * libraryDirective ::= | 2932 * libraryDirective ::= |
| 2707 * metadata 'library' identifier ';' | 2933 * metadata 'library' identifier ';' |
| 2708 * </pre> | 2934 * </pre> |
| 2709 * @param commentAndMetadata the metadata to be associated with the directive | 2935 * @param commentAndMetadata the metadata to be associated with the directive |
| 2710 * @return the library directive that was parsed | 2936 * @return the library directive that was parsed |
| 2711 */ | 2937 */ |
| 2712 LibraryDirective parseLibraryDirective(CommentAndMetadata commentAndMetadata)
{ | 2938 LibraryDirective parseLibraryDirective(CommentAndMetadata commentAndMetadata)
{ |
| 2713 Token keyword = expect(Keyword.LIBRARY); | 2939 Token keyword = expect(Keyword.LIBRARY); |
| 2714 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_NAM
E_IN_LIBRARY_DIRECTIVE, keyword); | 2940 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_NAM
E_IN_LIBRARY_DIRECTIVE, keyword); |
| 2715 Token semicolon = expect2(TokenType.SEMICOLON); | 2941 Token semicolon = expect2(TokenType.SEMICOLON); |
| 2716 return new LibraryDirective.full(commentAndMetadata.comment, commentAndMetad
ata.metadata, keyword, libraryName, semicolon); | 2942 return new LibraryDirective.full(commentAndMetadata.comment, commentAndMetad
ata.metadata, keyword, libraryName, semicolon); |
| 2717 } | 2943 } |
| 2944 |
| 2718 /** | 2945 /** |
| 2719 * Parse a library identifier. | 2946 * Parse a library identifier. |
| 2720 * <pre> | 2947 * <pre> |
| 2721 * libraryIdentifier ::= | 2948 * libraryIdentifier ::= |
| 2722 * identifier ('.' identifier) | 2949 * identifier ('.' identifier) |
| 2723 * </pre> | 2950 * </pre> |
| 2724 * @return the library identifier that was parsed | 2951 * @return the library identifier that was parsed |
| 2725 */ | 2952 */ |
| 2726 LibraryIdentifier parseLibraryIdentifier() { | 2953 LibraryIdentifier parseLibraryIdentifier() { |
| 2727 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); | 2954 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); |
| 2728 components.add(parseSimpleIdentifier()); | 2955 components.add(parseSimpleIdentifier()); |
| 2729 while (matches5(TokenType.PERIOD)) { | 2956 while (matches5(TokenType.PERIOD)) { |
| 2730 advance(); | 2957 advance(); |
| 2731 components.add(parseSimpleIdentifier()); | 2958 components.add(parseSimpleIdentifier()); |
| 2732 } | 2959 } |
| 2733 return new LibraryIdentifier.full(components); | 2960 return new LibraryIdentifier.full(components); |
| 2734 } | 2961 } |
| 2962 |
| 2735 /** | 2963 /** |
| 2736 * Parse a library name. | 2964 * Parse a library name. |
| 2737 * <pre> | 2965 * <pre> |
| 2738 * libraryName ::= | 2966 * libraryName ::= |
| 2739 * libraryIdentifier | 2967 * libraryIdentifier |
| 2740 * </pre> | 2968 * </pre> |
| 2741 * @param missingNameError the error code to be used if the library name is mi
ssing | 2969 * @param missingNameError the error code to be used if the library name is mi
ssing |
| 2742 * @param missingNameToken the token associated with the error produced if the
library name is | 2970 * @param missingNameToken the token associated with the error produced if the
library name is |
| 2743 * missing | 2971 * missing |
| 2744 * @return the library name that was parsed | 2972 * @return the library name that was parsed |
| 2745 */ | 2973 */ |
| 2746 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis
singNameToken) { | 2974 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis
singNameToken) { |
| 2747 if (matchesIdentifier()) { | 2975 if (matchesIdentifier()) { |
| 2748 return parseLibraryIdentifier(); | 2976 return parseLibraryIdentifier(); |
| 2749 } else if (matches5(TokenType.STRING)) { | 2977 } else if (matches5(TokenType.STRING)) { |
| 2750 StringLiteral string = parseStringLiteral(); | 2978 StringLiteral string = parseStringLiteral(); |
| 2751 reportError(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []); | 2979 reportError(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []); |
| 2752 } else { | 2980 } else { |
| 2753 reportError5(missingNameError, missingNameToken, []); | 2981 reportError8(missingNameError, missingNameToken, []); |
| 2754 } | 2982 } |
| 2755 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); | 2983 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); |
| 2756 components.add(createSyntheticIdentifier()); | 2984 components.add(createSyntheticIdentifier()); |
| 2757 return new LibraryIdentifier.full(components); | 2985 return new LibraryIdentifier.full(components); |
| 2758 } | 2986 } |
| 2987 |
| 2759 /** | 2988 /** |
| 2760 * Parse a list literal. | 2989 * Parse a list literal. |
| 2761 * <pre> | 2990 * <pre> |
| 2762 * listLiteral ::= | 2991 * listLiteral ::= |
| 2763 * 'const'? typeArguments? '\[' (expressionList ','?)? '\]' | 2992 * 'const'? typeArguments? '\[' (expressionList ','?)? '\]' |
| 2764 * </pre> | 2993 * </pre> |
| 2765 * @param modifier the 'const' modifier appearing before the literal, or {@cod
e null} if there is | 2994 * @param modifier the 'const' modifier appearing before the literal, or {@cod
e null} if there is |
| 2766 * no modifier | 2995 * no modifier |
| 2767 * @param typeArguments the type arguments appearing before the literal, or {@
code null} if there | 2996 * @param typeArguments the type arguments appearing before the literal, or {@
code null} if there |
| 2768 * are no type arguments | 2997 * are no type arguments |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2787 elements.add(parseExpression2()); | 3016 elements.add(parseExpression2()); |
| 2788 while (optional(TokenType.COMMA)) { | 3017 while (optional(TokenType.COMMA)) { |
| 2789 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { | 3018 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { |
| 2790 return new ListLiteral.full(modifier, typeArguments, leftBracket, elemen
ts, andAdvance); | 3019 return new ListLiteral.full(modifier, typeArguments, leftBracket, elemen
ts, andAdvance); |
| 2791 } | 3020 } |
| 2792 elements.add(parseExpression2()); | 3021 elements.add(parseExpression2()); |
| 2793 } | 3022 } |
| 2794 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); | 3023 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); |
| 2795 return new ListLiteral.full(modifier, typeArguments, leftBracket, elements,
rightBracket); | 3024 return new ListLiteral.full(modifier, typeArguments, leftBracket, elements,
rightBracket); |
| 2796 } | 3025 } |
| 3026 |
| 2797 /** | 3027 /** |
| 2798 * Parse a list or map literal. | 3028 * Parse a list or map literal. |
| 2799 * <pre> | 3029 * <pre> |
| 2800 * listOrMapLiteral ::= | 3030 * listOrMapLiteral ::= |
| 2801 * listLiteral | 3031 * listLiteral |
| 2802 * | mapLiteral | 3032 * | mapLiteral |
| 2803 * </pre> | 3033 * </pre> |
| 2804 * @param modifier the 'const' modifier appearing before the literal, or {@cod
e null} if there is | 3034 * @param modifier the 'const' modifier appearing before the literal, or {@cod
e null} if there is |
| 2805 * no modifier | 3035 * no modifier |
| 2806 * @return the list or map literal that was parsed | 3036 * @return the list or map literal that was parsed |
| 2807 */ | 3037 */ |
| 2808 TypedLiteral parseListOrMapLiteral(Token modifier) { | 3038 TypedLiteral parseListOrMapLiteral(Token modifier) { |
| 2809 TypeArgumentList typeArguments = null; | 3039 TypeArgumentList typeArguments = null; |
| 2810 if (matches5(TokenType.LT)) { | 3040 if (matches5(TokenType.LT)) { |
| 2811 typeArguments = parseTypeArgumentList(); | 3041 typeArguments = parseTypeArgumentList(); |
| 2812 } | 3042 } |
| 2813 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { | 3043 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { |
| 2814 return parseMapLiteral(modifier, typeArguments); | 3044 return parseMapLiteral(modifier, typeArguments); |
| 2815 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND
EX)) { | 3045 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND
EX)) { |
| 2816 return parseListLiteral(modifier, typeArguments); | 3046 return parseListLiteral(modifier, typeArguments); |
| 2817 } | 3047 } |
| 2818 reportError4(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []); | 3048 reportError7(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []); |
| 2819 return new ListLiteral.full(modifier, typeArguments, createSyntheticToken2(T
okenType.OPEN_SQUARE_BRACKET), null, createSyntheticToken2(TokenType.CLOSE_SQUAR
E_BRACKET)); | 3049 return new ListLiteral.full(modifier, typeArguments, createSyntheticToken2(T
okenType.OPEN_SQUARE_BRACKET), null, createSyntheticToken2(TokenType.CLOSE_SQUAR
E_BRACKET)); |
| 2820 } | 3050 } |
| 3051 |
| 2821 /** | 3052 /** |
| 2822 * Parse a logical and expression. | 3053 * Parse a logical and expression. |
| 2823 * <pre> | 3054 * <pre> |
| 2824 * logicalAndExpression ::= | 3055 * logicalAndExpression ::= |
| 2825 * bitwiseOrExpression ('&&' bitwiseOrExpression) | 3056 * bitwiseOrExpression ('&&' bitwiseOrExpression) |
| 2826 * </pre> | 3057 * </pre> |
| 2827 * @return the logical and expression that was parsed | 3058 * @return the logical and expression that was parsed |
| 2828 */ | 3059 */ |
| 2829 Expression parseLogicalAndExpression() { | 3060 Expression parseLogicalAndExpression() { |
| 2830 Expression expression = parseBitwiseOrExpression(); | 3061 Expression expression = parseBitwiseOrExpression(); |
| 2831 while (matches5(TokenType.AMPERSAND_AMPERSAND)) { | 3062 while (matches5(TokenType.AMPERSAND_AMPERSAND)) { |
| 2832 Token operator = andAdvance; | 3063 Token operator = andAdvance; |
| 2833 expression = new BinaryExpression.full(expression, operator, parseBitwiseO
rExpression()); | 3064 expression = new BinaryExpression.full(expression, operator, parseBitwiseO
rExpression()); |
| 2834 } | 3065 } |
| 2835 return expression; | 3066 return expression; |
| 2836 } | 3067 } |
| 3068 |
| 2837 /** | 3069 /** |
| 2838 * Parse a logical or expression. | 3070 * Parse a logical or expression. |
| 2839 * <pre> | 3071 * <pre> |
| 2840 * logicalOrExpression ::= | 3072 * logicalOrExpression ::= |
| 2841 * logicalAndExpression ('||' logicalAndExpression) | 3073 * logicalAndExpression ('||' logicalAndExpression) |
| 2842 * </pre> | 3074 * </pre> |
| 2843 * @return the logical or expression that was parsed | 3075 * @return the logical or expression that was parsed |
| 2844 */ | 3076 */ |
| 2845 Expression parseLogicalOrExpression() { | 3077 Expression parseLogicalOrExpression() { |
| 2846 Expression expression = parseLogicalAndExpression(); | 3078 Expression expression = parseLogicalAndExpression(); |
| 2847 while (matches5(TokenType.BAR_BAR)) { | 3079 while (matches5(TokenType.BAR_BAR)) { |
| 2848 Token operator = andAdvance; | 3080 Token operator = andAdvance; |
| 2849 expression = new BinaryExpression.full(expression, operator, parseLogicalA
ndExpression()); | 3081 expression = new BinaryExpression.full(expression, operator, parseLogicalA
ndExpression()); |
| 2850 } | 3082 } |
| 2851 return expression; | 3083 return expression; |
| 2852 } | 3084 } |
| 3085 |
| 2853 /** | 3086 /** |
| 2854 * Parse a map literal. | 3087 * Parse a map literal. |
| 2855 * <pre> | 3088 * <pre> |
| 2856 * mapLiteral ::= | 3089 * mapLiteral ::= |
| 2857 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ','?)?
'}' | 3090 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ','?)?
'}' |
| 2858 * </pre> | 3091 * </pre> |
| 2859 * @param modifier the 'const' modifier appearing before the literal, or {@cod
e null} if there is | 3092 * @param modifier the 'const' modifier appearing before the literal, or {@cod
e null} if there is |
| 2860 * no modifier | 3093 * no modifier |
| 2861 * @param typeArguments the type arguments that were declared, or {@code null}
if there are no | 3094 * @param typeArguments the type arguments that were declared, or {@code null}
if there are no |
| 2862 * type arguments | 3095 * type arguments |
| 2863 * @return the map literal that was parsed | 3096 * @return the map literal that was parsed |
| 2864 */ | 3097 */ |
| 2865 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { | 3098 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { |
| 3099 if (typeArguments != null) { |
| 3100 int num = typeArguments.arguments.length; |
| 3101 if (num != 2) { |
| 3102 reportError(ParserErrorCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, typeArgumen
ts, [num]); |
| 3103 } |
| 3104 } |
| 2866 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); | 3105 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); |
| 2867 List<MapLiteralEntry> entries = new List<MapLiteralEntry>(); | 3106 List<MapLiteralEntry> entries = new List<MapLiteralEntry>(); |
| 2868 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { | 3107 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { |
| 2869 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries,
andAdvance); | 3108 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries,
andAdvance); |
| 2870 } | 3109 } |
| 2871 entries.add(parseMapLiteralEntry()); | 3110 entries.add(parseMapLiteralEntry()); |
| 2872 while (optional(TokenType.COMMA)) { | 3111 while (optional(TokenType.COMMA)) { |
| 2873 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { | 3112 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { |
| 2874 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries
, andAdvance); | 3113 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries
, andAdvance); |
| 2875 } | 3114 } |
| 2876 entries.add(parseMapLiteralEntry()); | 3115 entries.add(parseMapLiteralEntry()); |
| 2877 } | 3116 } |
| 2878 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); | 3117 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); |
| 2879 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries, ri
ghtBracket); | 3118 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries, ri
ghtBracket); |
| 2880 } | 3119 } |
| 3120 |
| 2881 /** | 3121 /** |
| 2882 * Parse a map literal entry. | 3122 * Parse a map literal entry. |
| 2883 * <pre> | 3123 * <pre> |
| 2884 * mapLiteralEntry ::= | 3124 * mapLiteralEntry ::= |
| 2885 * stringLiteral ':' expression | 3125 * expression ':' expression |
| 2886 * </pre> | 3126 * </pre> |
| 2887 * @return the map literal entry that was parsed | 3127 * @return the map literal entry that was parsed |
| 2888 */ | 3128 */ |
| 2889 MapLiteralEntry parseMapLiteralEntry() { | 3129 MapLiteralEntry parseMapLiteralEntry() { |
| 2890 StringLiteral key = parseStringLiteral(); | 3130 Expression key = parseExpression2(); |
| 2891 Token separator = expect2(TokenType.COLON); | 3131 Token separator = expect2(TokenType.COLON); |
| 2892 Expression value = parseExpression2(); | 3132 Expression value = parseExpression2(); |
| 2893 return new MapLiteralEntry.full(key, separator, value); | 3133 return new MapLiteralEntry.full(key, separator, value); |
| 2894 } | 3134 } |
| 3135 |
| 2895 /** | 3136 /** |
| 2896 * Parse a method declaration. | 3137 * Parse a method declaration. |
| 2897 * <pre> | 3138 * <pre> |
| 2898 * functionDeclaration ::= | 3139 * functionDeclaration ::= |
| 2899 * 'external'? 'static'? functionSignature functionBody | 3140 * 'external'? 'static'? functionSignature functionBody |
| 2900 * | 'external'? functionSignature ';' | 3141 * | 'external'? functionSignature ';' |
| 2901 * </pre> | 3142 * </pre> |
| 2902 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the | 3143 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the |
| 2903 * declaration | 3144 * declaration |
| 2904 * @param externalKeyword the 'external' token | 3145 * @param externalKeyword the 'external' token |
| 2905 * @param staticKeyword the static keyword, or {@code null} if the getter is n
ot static | 3146 * @param staticKeyword the static keyword, or {@code null} if the getter is n
ot static |
| 2906 * @param returnType the return type of the method | 3147 * @param returnType the return type of the method |
| 2907 * @return the method declaration that was parsed | 3148 * @return the method declaration that was parsed |
| 2908 */ | 3149 */ |
| 2909 MethodDeclaration parseMethodDeclaration(CommentAndMetadata commentAndMetadata
, Token externalKeyword, Token staticKeyword, TypeName returnType) { | 3150 MethodDeclaration parseMethodDeclaration(CommentAndMetadata commentAndMetadata
, Token externalKeyword, Token staticKeyword, TypeName returnType) { |
| 2910 SimpleIdentifier methodName = parseSimpleIdentifier(); | 3151 SimpleIdentifier methodName = parseSimpleIdentifier(); |
| 2911 FormalParameterList parameters = parseFormalParameterList(); | 3152 FormalParameterList parameters = parseFormalParameterList(); |
| 2912 validateFormalParameterList(parameters); | 3153 validateFormalParameterList(parameters); |
| 2913 return parseMethodDeclaration2(commentAndMetadata, externalKeyword, staticKe
yword, returnType, methodName, parameters); | 3154 return parseMethodDeclaration2(commentAndMetadata, externalKeyword, staticKe
yword, returnType, methodName, parameters); |
| 2914 } | 3155 } |
| 3156 |
| 2915 /** | 3157 /** |
| 2916 * Parse a method declaration. | 3158 * Parse a method declaration. |
| 2917 * <pre> | 3159 * <pre> |
| 2918 * functionDeclaration ::= | 3160 * functionDeclaration ::= |
| 2919 * ('external' 'static'?)? functionSignature functionBody | 3161 * ('external' 'static'?)? functionSignature functionBody |
| 2920 * | 'external'? functionSignature ';' | 3162 * | 'external'? functionSignature ';' |
| 2921 * </pre> | 3163 * </pre> |
| 2922 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the | 3164 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the |
| 2923 * declaration | 3165 * declaration |
| 2924 * @param externalKeyword the 'external' token | 3166 * @param externalKeyword the 'external' token |
| 2925 * @param staticKeyword the static keyword, or {@code null} if the getter is n
ot static | 3167 * @param staticKeyword the static keyword, or {@code null} if the getter is n
ot static |
| 2926 * @param returnType the return type of the method | 3168 * @param returnType the return type of the method |
| 2927 * @param name the name of the method | 3169 * @param name the name of the method |
| 2928 * @param parameters the parameters to the method | 3170 * @param parameters the parameters to the method |
| 2929 * @return the method declaration that was parsed | 3171 * @return the method declaration that was parsed |
| 2930 */ | 3172 */ |
| 2931 MethodDeclaration parseMethodDeclaration2(CommentAndMetadata commentAndMetadat
a, Token externalKeyword, Token staticKeyword, TypeName returnType, SimpleIdenti
fier name, FormalParameterList parameters) { | 3173 MethodDeclaration parseMethodDeclaration2(CommentAndMetadata commentAndMetadat
a, Token externalKeyword, Token staticKeyword, TypeName returnType, SimpleIdenti
fier name, FormalParameterList parameters) { |
| 2932 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo
rd == null, false); | 3174 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo
rd == null, ParserErrorCode.MISSING_FUNCTION_BODY, false); |
| 2933 if (externalKeyword != null) { | 3175 if (externalKeyword != null) { |
| 2934 if (body is! EmptyFunctionBody) { | 3176 if (body is! EmptyFunctionBody) { |
| 2935 reportError(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []); | 3177 reportError(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []); |
| 2936 } | 3178 } |
| 2937 } else if (staticKeyword != null) { | 3179 } else if (staticKeyword != null) { |
| 2938 if (body is EmptyFunctionBody) { | 3180 if (body is EmptyFunctionBody) { |
| 2939 reportError(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []); | 3181 reportError(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []); |
| 2940 } | 3182 } |
| 2941 } | 3183 } |
| 2942 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta
data.metadata, externalKeyword, staticKeyword, returnType, null, null, name, par
ameters, body); | 3184 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta
data.metadata, externalKeyword, staticKeyword, returnType, null, null, name, par
ameters, body); |
| 2943 } | 3185 } |
| 3186 |
| 2944 /** | 3187 /** |
| 2945 * Parse the modifiers preceding a declaration. This method allows the modifie
rs to appear in any | 3188 * Parse the modifiers preceding a declaration. This method allows the modifie
rs to appear in any |
| 2946 * order but does generate errors for duplicated modifiers. Checks for other p
roblems, such as | 3189 * order but does generate errors for duplicated modifiers. Checks for other p
roblems, such as |
| 2947 * having the modifiers appear in the wrong order or specifying both 'const' a
nd 'final', are | 3190 * having the modifiers appear in the wrong order or specifying both 'const' a
nd 'final', are |
| 2948 * reported in one of the methods whose name is prefixed with {@code validateM
odifiersFor}. | 3191 * reported in one of the methods whose name is prefixed with {@code validateM
odifiersFor}. |
| 2949 * <pre> | 3192 * <pre> |
| 2950 * modifiers ::= | 3193 * modifiers ::= |
| 2951 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | 'var'
) | 3194 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | 'var'
) |
| 2952 * </pre> | 3195 * </pre> |
| 2953 * @return the modifiers that were parsed | 3196 * @return the modifiers that were parsed |
| 2954 */ | 3197 */ |
| 2955 Modifiers parseModifiers() { | 3198 Modifiers parseModifiers() { |
| 2956 Modifiers modifiers = new Modifiers(); | 3199 Modifiers modifiers = new Modifiers(); |
| 2957 bool progress = true; | 3200 bool progress = true; |
| 2958 while (progress) { | 3201 while (progress) { |
| 2959 if (matches(Keyword.ABSTRACT) && !matches4(peek(), TokenType.PERIOD) && !m
atches4(peek(), TokenType.LT)) { | 3202 if (matches(Keyword.ABSTRACT) && !matches4(peek(), TokenType.PERIOD) && !m
atches4(peek(), TokenType.LT)) { |
| 2960 if (modifiers.abstractKeyword != null) { | 3203 if (modifiers.abstractKeyword != null) { |
| 2961 reportError4(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); | 3204 reportError7(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); |
| 2962 advance(); | 3205 advance(); |
| 2963 } else { | 3206 } else { |
| 2964 modifiers.abstractKeyword = andAdvance; | 3207 modifiers.abstractKeyword = andAdvance; |
| 2965 } | 3208 } |
| 2966 } else if (matches(Keyword.CONST)) { | 3209 } else if (matches(Keyword.CONST)) { |
| 2967 if (modifiers.constKeyword != null) { | 3210 if (modifiers.constKeyword != null) { |
| 2968 reportError4(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); | 3211 reportError7(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); |
| 2969 advance(); | 3212 advance(); |
| 2970 } else { | 3213 } else { |
| 2971 modifiers.constKeyword = andAdvance; | 3214 modifiers.constKeyword = andAdvance; |
| 2972 } | 3215 } |
| 2973 } else if (matches(Keyword.EXTERNAL) && !matches4(peek(), TokenType.PERIOD
) && !matches4(peek(), TokenType.LT)) { | 3216 } else if (matches(Keyword.EXTERNAL) && !matches4(peek(), TokenType.PERIOD
) && !matches4(peek(), TokenType.LT)) { |
| 2974 if (modifiers.externalKeyword != null) { | 3217 if (modifiers.externalKeyword != null) { |
| 2975 reportError4(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); | 3218 reportError7(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); |
| 2976 advance(); | 3219 advance(); |
| 2977 } else { | 3220 } else { |
| 2978 modifiers.externalKeyword = andAdvance; | 3221 modifiers.externalKeyword = andAdvance; |
| 2979 } | 3222 } |
| 2980 } else if (matches(Keyword.FACTORY) && !matches4(peek(), TokenType.PERIOD)
&& !matches4(peek(), TokenType.LT)) { | 3223 } else if (matches(Keyword.FACTORY) && !matches4(peek(), TokenType.PERIOD)
&& !matches4(peek(), TokenType.LT)) { |
| 2981 if (modifiers.factoryKeyword != null) { | 3224 if (modifiers.factoryKeyword != null) { |
| 2982 reportError4(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); | 3225 reportError7(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); |
| 2983 advance(); | 3226 advance(); |
| 2984 } else { | 3227 } else { |
| 2985 modifiers.factoryKeyword = andAdvance; | 3228 modifiers.factoryKeyword = andAdvance; |
| 2986 } | 3229 } |
| 2987 } else if (matches(Keyword.FINAL)) { | 3230 } else if (matches(Keyword.FINAL)) { |
| 2988 if (modifiers.finalKeyword != null) { | 3231 if (modifiers.finalKeyword != null) { |
| 2989 reportError4(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); | 3232 reportError7(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); |
| 2990 advance(); | 3233 advance(); |
| 2991 } else { | 3234 } else { |
| 2992 modifiers.finalKeyword = andAdvance; | 3235 modifiers.finalKeyword = andAdvance; |
| 2993 } | 3236 } |
| 2994 } else if (matches(Keyword.STATIC) && !matches4(peek(), TokenType.PERIOD)
&& !matches4(peek(), TokenType.LT)) { | 3237 } else if (matches(Keyword.STATIC) && !matches4(peek(), TokenType.PERIOD)
&& !matches4(peek(), TokenType.LT)) { |
| 2995 if (modifiers.staticKeyword != null) { | 3238 if (modifiers.staticKeyword != null) { |
| 2996 reportError4(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); | 3239 reportError7(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); |
| 2997 advance(); | 3240 advance(); |
| 2998 } else { | 3241 } else { |
| 2999 modifiers.staticKeyword = andAdvance; | 3242 modifiers.staticKeyword = andAdvance; |
| 3000 } | 3243 } |
| 3001 } else if (matches(Keyword.VAR)) { | 3244 } else if (matches(Keyword.VAR)) { |
| 3002 if (modifiers.varKeyword != null) { | 3245 if (modifiers.varKeyword != null) { |
| 3003 reportError4(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); | 3246 reportError7(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem
e]); |
| 3004 advance(); | 3247 advance(); |
| 3005 } else { | 3248 } else { |
| 3006 modifiers.varKeyword = andAdvance; | 3249 modifiers.varKeyword = andAdvance; |
| 3007 } | 3250 } |
| 3008 } else { | 3251 } else { |
| 3009 progress = false; | 3252 progress = false; |
| 3010 } | 3253 } |
| 3011 } | 3254 } |
| 3012 return modifiers; | 3255 return modifiers; |
| 3013 } | 3256 } |
| 3257 |
| 3014 /** | 3258 /** |
| 3015 * Parse a multiplicative expression. | 3259 * Parse a multiplicative expression. |
| 3016 * <pre> | 3260 * <pre> |
| 3017 * multiplicativeExpression ::= | 3261 * multiplicativeExpression ::= |
| 3018 * unaryExpression (multiplicativeOperator unaryExpression) | 3262 * unaryExpression (multiplicativeOperator unaryExpression) |
| 3019 * | 'super' (multiplicativeOperator unaryExpression)+ | 3263 * | 'super' (multiplicativeOperator unaryExpression)+ |
| 3020 * </pre> | 3264 * </pre> |
| 3021 * @return the multiplicative expression that was parsed | 3265 * @return the multiplicative expression that was parsed |
| 3022 */ | 3266 */ |
| 3023 Expression parseMultiplicativeExpression() { | 3267 Expression parseMultiplicativeExpression() { |
| 3024 Expression expression; | 3268 Expression expression; |
| 3025 if (matches(Keyword.SUPER) && _currentToken.next.type.isMultiplicativeOperat
or()) { | 3269 if (matches(Keyword.SUPER) && _currentToken.next.type.isMultiplicativeOperat
or()) { |
| 3026 expression = new SuperExpression.full(andAdvance); | 3270 expression = new SuperExpression.full(andAdvance); |
| 3027 } else { | 3271 } else { |
| 3028 expression = parseUnaryExpression(); | 3272 expression = parseUnaryExpression(); |
| 3029 } | 3273 } |
| 3030 while (_currentToken.type.isMultiplicativeOperator()) { | 3274 while (_currentToken.type.isMultiplicativeOperator()) { |
| 3031 Token operator = andAdvance; | 3275 Token operator = andAdvance; |
| 3032 expression = new BinaryExpression.full(expression, operator, parseUnaryExp
ression()); | 3276 expression = new BinaryExpression.full(expression, operator, parseUnaryExp
ression()); |
| 3033 } | 3277 } |
| 3034 return expression; | 3278 return expression; |
| 3035 } | 3279 } |
| 3280 |
| 3036 /** | 3281 /** |
| 3037 * Parse a new expression. | 3282 * Parse a new expression. |
| 3038 * <pre> | 3283 * <pre> |
| 3039 * newExpression ::= | 3284 * newExpression ::= |
| 3040 * instanceCreationExpression | 3285 * instanceCreationExpression |
| 3041 * </pre> | 3286 * </pre> |
| 3042 * @return the new expression that was parsed | 3287 * @return the new expression that was parsed |
| 3043 */ | 3288 */ |
| 3044 InstanceCreationExpression parseNewExpression() => parseInstanceCreationExpres
sion(expect(Keyword.NEW)); | 3289 InstanceCreationExpression parseNewExpression() => parseInstanceCreationExpres
sion(expect(Keyword.NEW)); |
| 3290 |
| 3045 /** | 3291 /** |
| 3046 * Parse a non-labeled statement. | 3292 * Parse a non-labeled statement. |
| 3047 * <pre> | 3293 * <pre> |
| 3048 * nonLabeledStatement ::= | 3294 * nonLabeledStatement ::= |
| 3049 * block | 3295 * block |
| 3050 * | assertStatement | 3296 * | assertStatement |
| 3051 * | breakStatement | 3297 * | breakStatement |
| 3052 * | continueStatement | 3298 * | continueStatement |
| 3053 * | doStatement | 3299 * | doStatement |
| 3054 * | forStatement | 3300 * | forStatement |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3107 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy
pe); | 3353 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy
pe); |
| 3108 } else { | 3354 } else { |
| 3109 if (matchesIdentifier()) { | 3355 if (matchesIdentifier()) { |
| 3110 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM
ICOLON])) { | 3356 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM
ICOLON])) { |
| 3111 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []); | 3357 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []); |
| 3112 return parseVariableDeclarationStatement(commentAndMetadata); | 3358 return parseVariableDeclarationStatement(commentAndMetadata); |
| 3113 } | 3359 } |
| 3114 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { | 3360 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { |
| 3115 return parseVariableDeclarationStatement2(commentAndMetadata, null,
returnType); | 3361 return parseVariableDeclarationStatement2(commentAndMetadata, null,
returnType); |
| 3116 } | 3362 } |
| 3117 reportError4(ParserErrorCode.MISSING_STATEMENT, []); | 3363 reportError7(ParserErrorCode.MISSING_STATEMENT, []); |
| 3118 return null; | 3364 return new EmptyStatement.full(createSyntheticToken2(TokenType.SEMICOL
ON)); |
| 3119 } | 3365 } |
| 3120 } else if (identical(keyword2, Keyword.CONST)) { | 3366 } else if (identical(keyword2, Keyword.CONST)) { |
| 3121 if (matchesAny(peek(), [TokenType.LT, TokenType.OPEN_CURLY_BRACKET, Toke
nType.OPEN_SQUARE_BRACKET, TokenType.INDEX])) { | 3367 if (matchesAny(peek(), [TokenType.LT, TokenType.OPEN_CURLY_BRACKET, Toke
nType.OPEN_SQUARE_BRACKET, TokenType.INDEX])) { |
| 3122 return new ExpressionStatement.full(parseExpression2(), expect2(TokenT
ype.SEMICOLON)); | 3368 return new ExpressionStatement.full(parseExpression2(), expect2(TokenT
ype.SEMICOLON)); |
| 3123 } else if (matches4(peek(), TokenType.IDENTIFIER)) { | 3369 } else if (matches4(peek(), TokenType.IDENTIFIER)) { |
| 3124 Token afterType = skipTypeName(peek()); | 3370 Token afterType = skipTypeName(peek()); |
| 3125 if (afterType != null) { | 3371 if (afterType != null) { |
| 3126 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType
, TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches
4(afterType.next.next, TokenType.OPEN_PAREN))) { | 3372 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType
, TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches
4(afterType.next.next, TokenType.OPEN_PAREN))) { |
| 3127 return new ExpressionStatement.full(parseExpression2(), expect2(To
kenType.SEMICOLON)); | 3373 return new ExpressionStatement.full(parseExpression2(), expect2(To
kenType.SEMICOLON)); |
| 3128 } | 3374 } |
| 3129 } | 3375 } |
| 3130 } | 3376 } |
| 3131 return parseVariableDeclarationStatement(commentAndMetadata); | 3377 return parseVariableDeclarationStatement(commentAndMetadata); |
| 3132 } else if (identical(keyword2, Keyword.NEW) || identical(keyword2, Keyword
.TRUE) || identical(keyword2, Keyword.FALSE) || identical(keyword2, Keyword.NULL
) || identical(keyword2, Keyword.SUPER) || identical(keyword2, Keyword.THIS)) { | 3378 } else if (identical(keyword2, Keyword.NEW) || identical(keyword2, Keyword
.TRUE) || identical(keyword2, Keyword.FALSE) || identical(keyword2, Keyword.NULL
) || identical(keyword2, Keyword.SUPER) || identical(keyword2, Keyword.THIS)) { |
| 3133 return new ExpressionStatement.full(parseExpression2(), expect2(TokenTyp
e.SEMICOLON)); | 3379 return new ExpressionStatement.full(parseExpression2(), expect2(TokenTyp
e.SEMICOLON)); |
| 3134 } else { | 3380 } else { |
| 3135 reportError4(ParserErrorCode.MISSING_STATEMENT, []); | 3381 reportError7(ParserErrorCode.MISSING_STATEMENT, []); |
| 3136 return null; | 3382 return new EmptyStatement.full(createSyntheticToken2(TokenType.SEMICOLON
)); |
| 3137 } | 3383 } |
| 3138 } else if (matches5(TokenType.SEMICOLON)) { | 3384 } else if (matches5(TokenType.SEMICOLON)) { |
| 3139 return parseEmptyStatement(); | 3385 return parseEmptyStatement(); |
| 3140 } else if (isInitializedVariableDeclaration()) { | 3386 } else if (isInitializedVariableDeclaration()) { |
| 3141 return parseVariableDeclarationStatement(commentAndMetadata); | 3387 return parseVariableDeclarationStatement(commentAndMetadata); |
| 3142 } else if (isFunctionDeclaration()) { | 3388 } else if (isFunctionDeclaration()) { |
| 3143 return parseFunctionDeclarationStatement(); | 3389 return parseFunctionDeclarationStatement(); |
| 3144 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { | 3390 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { |
| 3145 reportError4(ParserErrorCode.MISSING_STATEMENT, []); | 3391 reportError7(ParserErrorCode.MISSING_STATEMENT, []); |
| 3146 return new EmptyStatement.full(createSyntheticToken2(TokenType.SEMICOLON))
; | 3392 return new EmptyStatement.full(createSyntheticToken2(TokenType.SEMICOLON))
; |
| 3147 } else { | 3393 } else { |
| 3148 return new ExpressionStatement.full(parseExpression2(), expect2(TokenType.
SEMICOLON)); | 3394 return new ExpressionStatement.full(parseExpression2(), expect2(TokenType.
SEMICOLON)); |
| 3149 } | 3395 } |
| 3150 } | 3396 } |
| 3397 |
| 3151 /** | 3398 /** |
| 3152 * Parse a normal formal parameter. | 3399 * Parse a normal formal parameter. |
| 3153 * <pre> | 3400 * <pre> |
| 3154 * normalFormalParameter ::= | 3401 * normalFormalParameter ::= |
| 3155 * functionSignature | 3402 * functionSignature |
| 3156 * | fieldFormalParameter | 3403 * | fieldFormalParameter |
| 3157 * | simpleFormalParameter | 3404 * | simpleFormalParameter |
| 3158 * functionSignature: | 3405 * functionSignature: |
| 3159 * metadata returnType? identifier formalParameterList | 3406 * metadata returnType? identifier formalParameterList |
| 3160 * fieldFormalParameter ::= | 3407 * fieldFormalParameter ::= |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3176 } | 3423 } |
| 3177 SimpleIdentifier identifier = parseSimpleIdentifier(); | 3424 SimpleIdentifier identifier = parseSimpleIdentifier(); |
| 3178 if (matches5(TokenType.OPEN_PAREN)) { | 3425 if (matches5(TokenType.OPEN_PAREN)) { |
| 3179 if (thisKeyword != null) { | 3426 if (thisKeyword != null) { |
| 3180 } | 3427 } |
| 3181 FormalParameterList parameters = parseFormalParameterList(); | 3428 FormalParameterList parameters = parseFormalParameterList(); |
| 3182 return new FunctionTypedFormalParameter.full(commentAndMetadata.comment, c
ommentAndMetadata.metadata, holder.type, identifier, parameters); | 3429 return new FunctionTypedFormalParameter.full(commentAndMetadata.comment, c
ommentAndMetadata.metadata, holder.type, identifier, parameters); |
| 3183 } | 3430 } |
| 3184 TypeName type2 = holder.type; | 3431 TypeName type2 = holder.type; |
| 3185 if (type2 != null && matches3(type2.name.beginToken, Keyword.VOID)) { | 3432 if (type2 != null && matches3(type2.name.beginToken, Keyword.VOID)) { |
| 3186 reportError5(ParserErrorCode.VOID_PARAMETER, type2.name.beginToken, []); | 3433 reportError8(ParserErrorCode.VOID_PARAMETER, type2.name.beginToken, []); |
| 3187 } | 3434 } |
| 3188 if (thisKeyword != null) { | 3435 if (thisKeyword != null) { |
| 3189 return new FieldFormalParameter.full(commentAndMetadata.comment, commentAn
dMetadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier
); | 3436 return new FieldFormalParameter.full(commentAndMetadata.comment, commentAn
dMetadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier
); |
| 3190 } | 3437 } |
| 3191 return new SimpleFormalParameter.full(commentAndMetadata.comment, commentAnd
Metadata.metadata, holder.keyword, holder.type, identifier); | 3438 return new SimpleFormalParameter.full(commentAndMetadata.comment, commentAnd
Metadata.metadata, holder.keyword, holder.type, identifier); |
| 3192 } | 3439 } |
| 3440 |
| 3193 /** | 3441 /** |
| 3194 * Parse an operator declaration. | 3442 * Parse an operator declaration. |
| 3195 * <pre> | 3443 * <pre> |
| 3196 * operatorDeclaration ::= | 3444 * operatorDeclaration ::= |
| 3197 * operatorSignature (';' | functionBody) | 3445 * operatorSignature (';' | functionBody) |
| 3198 * operatorSignature ::= | 3446 * operatorSignature ::= |
| 3199 * 'external'? returnType? 'operator' operator formalParameterList | 3447 * 'external'? returnType? 'operator' operator formalParameterList |
| 3200 * </pre> | 3448 * </pre> |
| 3201 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the | 3449 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the |
| 3202 * declaration | 3450 * declaration |
| 3203 * @param externalKeyword the 'external' token | 3451 * @param externalKeyword the 'external' token |
| 3204 * @param the return type that has already been parsed, or {@code null} if the
re was no return | 3452 * @param the return type that has already been parsed, or {@code null} if the
re was no return |
| 3205 * type | 3453 * type |
| 3206 * @return the operator declaration that was parsed | 3454 * @return the operator declaration that was parsed |
| 3207 */ | 3455 */ |
| 3208 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e
xternalKeyword, TypeName returnType) { | 3456 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e
xternalKeyword, TypeName returnType) { |
| 3209 Token operatorKeyword; | 3457 Token operatorKeyword; |
| 3210 if (matches(Keyword.OPERATOR)) { | 3458 if (matches(Keyword.OPERATOR)) { |
| 3211 operatorKeyword = andAdvance; | 3459 operatorKeyword = andAdvance; |
| 3212 } else { | 3460 } else { |
| 3213 reportError5(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []); | 3461 reportError8(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []); |
| 3214 operatorKeyword = createSyntheticToken(Keyword.OPERATOR); | 3462 operatorKeyword = createSyntheticToken(Keyword.OPERATOR); |
| 3215 } | 3463 } |
| 3216 if (!_currentToken.isUserDefinableOperator()) { | 3464 if (!_currentToken.isUserDefinableOperator()) { |
| 3217 reportError4(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.l
exeme]); | 3465 reportError7(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.l
exeme]); |
| 3218 } | 3466 } |
| 3219 SimpleIdentifier name = new SimpleIdentifier.full(andAdvance); | 3467 SimpleIdentifier name = new SimpleIdentifier.full(andAdvance); |
| 3220 if (matches5(TokenType.EQ)) { | 3468 if (matches5(TokenType.EQ)) { |
| 3221 Token previous2 = _currentToken.previous; | 3469 Token previous2 = _currentToken.previous; |
| 3222 if ((matches4(previous2, TokenType.EQ_EQ) || matches4(previous2, TokenType
.BANG_EQ)) && _currentToken.offset == previous2.offset + 2) { | 3470 if ((matches4(previous2, TokenType.EQ_EQ) || matches4(previous2, TokenType
.BANG_EQ)) && _currentToken.offset == previous2.offset + 2) { |
| 3223 reportError4(ParserErrorCode.INVALID_OPERATOR, ["${previous2.lexeme}${_c
urrentToken.lexeme}"]); | 3471 reportError7(ParserErrorCode.INVALID_OPERATOR, ["${previous2.lexeme}${_c
urrentToken.lexeme}"]); |
| 3224 advance(); | 3472 advance(); |
| 3225 } | 3473 } |
| 3226 } | 3474 } |
| 3227 FormalParameterList parameters = parseFormalParameterList(); | 3475 FormalParameterList parameters = parseFormalParameterList(); |
| 3228 validateFormalParameterList(parameters); | 3476 validateFormalParameterList(parameters); |
| 3229 FunctionBody body = parseFunctionBody(true, false); | 3477 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION
_BODY, false); |
| 3230 if (externalKeyword != null && body is! EmptyFunctionBody) { | 3478 if (externalKeyword != null && body is! EmptyFunctionBody) { |
| 3231 reportError4(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []); | 3479 reportError7(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []); |
| 3232 } | 3480 } |
| 3233 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta
data.metadata, externalKeyword, null, returnType, null, operatorKeyword, name, p
arameters, body); | 3481 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta
data.metadata, externalKeyword, null, returnType, null, operatorKeyword, name, p
arameters, body); |
| 3234 } | 3482 } |
| 3483 |
| 3235 /** | 3484 /** |
| 3236 * Parse a return type if one is given, otherwise return {@code null} without
advancing. | 3485 * Parse a return type if one is given, otherwise return {@code null} without
advancing. |
| 3237 * @return the return type that was parsed | 3486 * @return the return type that was parsed |
| 3238 */ | 3487 */ |
| 3239 TypeName parseOptionalReturnType() { | 3488 TypeName parseOptionalReturnType() { |
| 3240 if (matches(Keyword.VOID)) { | 3489 if (matches(Keyword.VOID)) { |
| 3241 return parseReturnType(); | 3490 return parseReturnType(); |
| 3242 } else if (matchesIdentifier() && !matches(Keyword.GET) && !matches(Keyword.
SET) && !matches(Keyword.OPERATOR) && (matchesIdentifier2(peek()) || matches4(pe
ek(), TokenType.LT))) { | 3491 } else if (matchesIdentifier() && !matches(Keyword.GET) && !matches(Keyword.
SET) && !matches(Keyword.OPERATOR) && (matchesIdentifier2(peek()) || matches4(pe
ek(), TokenType.LT))) { |
| 3243 return parseReturnType(); | 3492 return parseReturnType(); |
| 3244 } else if (matchesIdentifier() && matches4(peek(), TokenType.PERIOD) && matc
hesIdentifier2(peek2(2)) && (matchesIdentifier2(peek2(3)) || matches4(peek2(3),
TokenType.LT))) { | 3493 } else if (matchesIdentifier() && matches4(peek(), TokenType.PERIOD) && matc
hesIdentifier2(peek2(2)) && (matchesIdentifier2(peek2(3)) || matches4(peek2(3),
TokenType.LT))) { |
| 3245 return parseReturnType(); | 3494 return parseReturnType(); |
| 3246 } | 3495 } |
| 3247 return null; | 3496 return null; |
| 3248 } | 3497 } |
| 3498 |
| 3249 /** | 3499 /** |
| 3250 * Parse a part or part-of directive. | 3500 * Parse a part or part-of directive. |
| 3251 * <pre> | 3501 * <pre> |
| 3252 * partDirective ::= | 3502 * partDirective ::= |
| 3253 * metadata 'part' stringLiteral ';' | 3503 * metadata 'part' stringLiteral ';' |
| 3254 * partOfDirective ::= | 3504 * partOfDirective ::= |
| 3255 * metadata 'part' 'of' identifier ';' | 3505 * metadata 'part' 'of' identifier ';' |
| 3256 * </pre> | 3506 * </pre> |
| 3257 * @param commentAndMetadata the metadata to be associated with the directive | 3507 * @param commentAndMetadata the metadata to be associated with the directive |
| 3258 * @return the part or part-of directive that was parsed | 3508 * @return the part or part-of directive that was parsed |
| 3259 */ | 3509 */ |
| 3260 Directive parsePartDirective(CommentAndMetadata commentAndMetadata) { | 3510 Directive parsePartDirective(CommentAndMetadata commentAndMetadata) { |
| 3261 Token partKeyword = expect(Keyword.PART); | 3511 Token partKeyword = expect(Keyword.PART); |
| 3262 if (matches2(_OF)) { | 3512 if (matches2(_OF)) { |
| 3263 Token ofKeyword = andAdvance; | 3513 Token ofKeyword = andAdvance; |
| 3264 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_N
AME_IN_PART_OF_DIRECTIVE, ofKeyword); | 3514 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_N
AME_IN_PART_OF_DIRECTIVE, ofKeyword); |
| 3265 Token semicolon = expect2(TokenType.SEMICOLON); | 3515 Token semicolon = expect2(TokenType.SEMICOLON); |
| 3266 return new PartOfDirective.full(commentAndMetadata.comment, commentAndMeta
data.metadata, partKeyword, ofKeyword, libraryName, semicolon); | 3516 return new PartOfDirective.full(commentAndMetadata.comment, commentAndMeta
data.metadata, partKeyword, ofKeyword, libraryName, semicolon); |
| 3267 } | 3517 } |
| 3268 StringLiteral partUri = parseStringLiteral(); | 3518 StringLiteral partUri = parseStringLiteral(); |
| 3269 Token semicolon = expect2(TokenType.SEMICOLON); | 3519 Token semicolon = expect2(TokenType.SEMICOLON); |
| 3270 return new PartDirective.full(commentAndMetadata.comment, commentAndMetadata
.metadata, partKeyword, partUri, semicolon); | 3520 return new PartDirective.full(commentAndMetadata.comment, commentAndMetadata
.metadata, partKeyword, partUri, semicolon); |
| 3271 } | 3521 } |
| 3522 |
| 3272 /** | 3523 /** |
| 3273 * Parse a postfix expression. | 3524 * Parse a postfix expression. |
| 3274 * <pre> | 3525 * <pre> |
| 3275 * postfixExpression ::= | 3526 * postfixExpression ::= |
| 3276 * assignableExpression postfixOperator | 3527 * assignableExpression postfixOperator |
| 3277 * | primary selector | 3528 * | primary selector |
| 3278 * selector ::= | 3529 * selector ::= |
| 3279 * assignableSelector | 3530 * assignableSelector |
| 3280 * | argumentList | 3531 * | argumentList |
| 3281 * </pre> | 3532 * </pre> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3296 } else { | 3547 } else { |
| 3297 operand = parseAssignableSelector(operand, true); | 3548 operand = parseAssignableSelector(operand, true); |
| 3298 } | 3549 } |
| 3299 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER
IOD) || matches5(TokenType.OPEN_PAREN)); | 3550 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER
IOD) || matches5(TokenType.OPEN_PAREN)); |
| 3300 return operand; | 3551 return operand; |
| 3301 } | 3552 } |
| 3302 if (!_currentToken.type.isIncrementOperator()) { | 3553 if (!_currentToken.type.isIncrementOperator()) { |
| 3303 return operand; | 3554 return operand; |
| 3304 } | 3555 } |
| 3305 if (operand is FunctionExpressionInvocation) { | 3556 if (operand is FunctionExpressionInvocation) { |
| 3306 reportError4(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); | 3557 reportError7(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); |
| 3307 } | 3558 } |
| 3308 Token operator = andAdvance; | 3559 Token operator = andAdvance; |
| 3309 return new PostfixExpression.full(operand, operator); | 3560 return new PostfixExpression.full(operand, operator); |
| 3310 } | 3561 } |
| 3562 |
| 3311 /** | 3563 /** |
| 3312 * Parse a prefixed identifier. | 3564 * Parse a prefixed identifier. |
| 3313 * <pre> | 3565 * <pre> |
| 3314 * prefixedIdentifier ::= | 3566 * prefixedIdentifier ::= |
| 3315 * identifier ('.' identifier)? | 3567 * identifier ('.' identifier)? |
| 3316 * </pre> | 3568 * </pre> |
| 3317 * @return the prefixed identifier that was parsed | 3569 * @return the prefixed identifier that was parsed |
| 3318 */ | 3570 */ |
| 3319 Identifier parsePrefixedIdentifier() { | 3571 Identifier parsePrefixedIdentifier() { |
| 3320 SimpleIdentifier qualifier = parseSimpleIdentifier(); | 3572 SimpleIdentifier qualifier = parseSimpleIdentifier(); |
| 3321 if (!matches5(TokenType.PERIOD)) { | 3573 if (!matches5(TokenType.PERIOD)) { |
| 3322 return qualifier; | 3574 return qualifier; |
| 3323 } | 3575 } |
| 3324 Token period = andAdvance; | 3576 Token period = andAdvance; |
| 3325 SimpleIdentifier qualified = parseSimpleIdentifier(); | 3577 SimpleIdentifier qualified = parseSimpleIdentifier(); |
| 3326 return new PrefixedIdentifier.full(qualifier, period, qualified); | 3578 return new PrefixedIdentifier.full(qualifier, period, qualified); |
| 3327 } | 3579 } |
| 3580 |
| 3328 /** | 3581 /** |
| 3329 * Parse a primary expression. | 3582 * Parse a primary expression. |
| 3330 * <pre> | 3583 * <pre> |
| 3331 * primary ::= | 3584 * primary ::= |
| 3332 * thisExpression | 3585 * thisExpression |
| 3333 * | 'super' assignableSelector | 3586 * | 'super' assignableSelector |
| 3334 * | functionExpression | 3587 * | functionExpression |
| 3335 * | literal | 3588 * | literal |
| 3336 * | identifier | 3589 * | identifier |
| 3337 * | newExpression | 3590 * | newExpression |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3401 } | 3654 } |
| 3402 Token leftParenthesis = andAdvance; | 3655 Token leftParenthesis = andAdvance; |
| 3403 Expression expression = parseExpression2(); | 3656 Expression expression = parseExpression2(); |
| 3404 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 3657 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 3405 return new ParenthesizedExpression.full(leftParenthesis, expression, right
Parenthesis); | 3658 return new ParenthesizedExpression.full(leftParenthesis, expression, right
Parenthesis); |
| 3406 } else if (matches5(TokenType.LT)) { | 3659 } else if (matches5(TokenType.LT)) { |
| 3407 return parseListOrMapLiteral(null); | 3660 return parseListOrMapLiteral(null); |
| 3408 } else if (matches5(TokenType.QUESTION)) { | 3661 } else if (matches5(TokenType.QUESTION)) { |
| 3409 return parseArgumentDefinitionTest(); | 3662 return parseArgumentDefinitionTest(); |
| 3410 } else if (matches(Keyword.VOID)) { | 3663 } else if (matches(Keyword.VOID)) { |
| 3411 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); | 3664 reportError7(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); |
| 3412 advance(); | 3665 advance(); |
| 3413 return parsePrimaryExpression(); | 3666 return parsePrimaryExpression(); |
| 3414 } else { | 3667 } else { |
| 3668 reportError7(ParserErrorCode.MISSING_IDENTIFIER, []); |
| 3415 return createSyntheticIdentifier(); | 3669 return createSyntheticIdentifier(); |
| 3416 } | 3670 } |
| 3417 } | 3671 } |
| 3672 |
| 3418 /** | 3673 /** |
| 3419 * Parse a redirecting constructor invocation. | 3674 * Parse a redirecting constructor invocation. |
| 3420 * <pre> | 3675 * <pre> |
| 3421 * redirectingConstructorInvocation ::= | 3676 * redirectingConstructorInvocation ::= |
| 3422 * 'this' ('.' identifier)? arguments | 3677 * 'this' ('.' identifier)? arguments |
| 3423 * </pre> | 3678 * </pre> |
| 3424 * @return the redirecting constructor invocation that was parsed | 3679 * @return the redirecting constructor invocation that was parsed |
| 3425 */ | 3680 */ |
| 3426 RedirectingConstructorInvocation parseRedirectingConstructorInvocation() { | 3681 RedirectingConstructorInvocation parseRedirectingConstructorInvocation() { |
| 3427 Token keyword = expect(Keyword.THIS); | 3682 Token keyword = expect(Keyword.THIS); |
| 3428 Token period = null; | 3683 Token period = null; |
| 3429 SimpleIdentifier constructorName = null; | 3684 SimpleIdentifier constructorName = null; |
| 3430 if (matches5(TokenType.PERIOD)) { | 3685 if (matches5(TokenType.PERIOD)) { |
| 3431 period = andAdvance; | 3686 period = andAdvance; |
| 3432 constructorName = parseSimpleIdentifier(); | 3687 constructorName = parseSimpleIdentifier(); |
| 3433 } | 3688 } |
| 3434 ArgumentList argumentList = parseArgumentList(); | 3689 ArgumentList argumentList = parseArgumentList(); |
| 3435 return new RedirectingConstructorInvocation.full(keyword, period, constructo
rName, argumentList); | 3690 return new RedirectingConstructorInvocation.full(keyword, period, constructo
rName, argumentList); |
| 3436 } | 3691 } |
| 3692 |
| 3437 /** | 3693 /** |
| 3438 * Parse a relational expression. | 3694 * Parse a relational expression. |
| 3439 * <pre> | 3695 * <pre> |
| 3440 * relationalExpression ::= | 3696 * relationalExpression ::= |
| 3441 * shiftExpression ('is' '!'? type | 'as' type | relationalOperator shiftExpre
ssion)? | 3697 * shiftExpression ('is' '!'? type | 'as' type | relationalOperator shiftExpre
ssion)? |
| 3442 * | 'super' relationalOperator shiftExpression | 3698 * | 'super' relationalOperator shiftExpression |
| 3443 * </pre> | 3699 * </pre> |
| 3444 * @return the relational expression that was parsed | 3700 * @return the relational expression that was parsed |
| 3445 */ | 3701 */ |
| 3446 Expression parseRelationalExpression() { | 3702 Expression parseRelationalExpression() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3460 if (matches5(TokenType.BANG)) { | 3716 if (matches5(TokenType.BANG)) { |
| 3461 notOperator = andAdvance; | 3717 notOperator = andAdvance; |
| 3462 } | 3718 } |
| 3463 expression = new IsExpression.full(expression, isOperator, notOperator, pa
rseTypeName()); | 3719 expression = new IsExpression.full(expression, isOperator, notOperator, pa
rseTypeName()); |
| 3464 } else if (_currentToken.type.isRelationalOperator()) { | 3720 } else if (_currentToken.type.isRelationalOperator()) { |
| 3465 Token operator = andAdvance; | 3721 Token operator = andAdvance; |
| 3466 expression = new BinaryExpression.full(expression, operator, parseShiftExp
ression()); | 3722 expression = new BinaryExpression.full(expression, operator, parseShiftExp
ression()); |
| 3467 } | 3723 } |
| 3468 return expression; | 3724 return expression; |
| 3469 } | 3725 } |
| 3726 |
| 3470 /** | 3727 /** |
| 3471 * Parse a rethrow expression. | 3728 * Parse a rethrow expression. |
| 3472 * <pre> | 3729 * <pre> |
| 3473 * rethrowExpression ::= | 3730 * rethrowExpression ::= |
| 3474 * 'rethrow' | 3731 * 'rethrow' |
| 3475 * </pre> | 3732 * </pre> |
| 3476 * @return the rethrow expression that was parsed | 3733 * @return the rethrow expression that was parsed |
| 3477 */ | 3734 */ |
| 3478 Expression parseRethrowExpression() => new RethrowExpression.full(expect(Keywo
rd.RETHROW)); | 3735 Expression parseRethrowExpression() => new RethrowExpression.full(expect(Keywo
rd.RETHROW)); |
| 3736 |
| 3479 /** | 3737 /** |
| 3480 * Parse a return statement. | 3738 * Parse a return statement. |
| 3481 * <pre> | 3739 * <pre> |
| 3482 * returnStatement ::= | 3740 * returnStatement ::= |
| 3483 * 'return' expression? ';' | 3741 * 'return' expression? ';' |
| 3484 * </pre> | 3742 * </pre> |
| 3485 * @return the return statement that was parsed | 3743 * @return the return statement that was parsed |
| 3486 */ | 3744 */ |
| 3487 Statement parseReturnStatement() { | 3745 Statement parseReturnStatement() { |
| 3488 Token returnKeyword = expect(Keyword.RETURN); | 3746 Token returnKeyword = expect(Keyword.RETURN); |
| 3489 if (matches5(TokenType.SEMICOLON)) { | 3747 if (matches5(TokenType.SEMICOLON)) { |
| 3490 return new ReturnStatement.full(returnKeyword, null, andAdvance); | 3748 return new ReturnStatement.full(returnKeyword, null, andAdvance); |
| 3491 } | 3749 } |
| 3492 Expression expression = parseExpression2(); | 3750 Expression expression = parseExpression2(); |
| 3493 Token semicolon = expect2(TokenType.SEMICOLON); | 3751 Token semicolon = expect2(TokenType.SEMICOLON); |
| 3494 return new ReturnStatement.full(returnKeyword, expression, semicolon); | 3752 return new ReturnStatement.full(returnKeyword, expression, semicolon); |
| 3495 } | 3753 } |
| 3754 |
| 3496 /** | 3755 /** |
| 3497 * Parse a return type. | 3756 * Parse a return type. |
| 3498 * <pre> | 3757 * <pre> |
| 3499 * returnType ::= | 3758 * returnType ::= |
| 3500 * 'void' | 3759 * 'void' |
| 3501 * | type | 3760 * | type |
| 3502 * </pre> | 3761 * </pre> |
| 3503 * @return the return type that was parsed | 3762 * @return the return type that was parsed |
| 3504 */ | 3763 */ |
| 3505 TypeName parseReturnType() { | 3764 TypeName parseReturnType() { |
| 3506 if (matches(Keyword.VOID)) { | 3765 if (matches(Keyword.VOID)) { |
| 3507 return new TypeName.full(new SimpleIdentifier.full(andAdvance), null); | 3766 return new TypeName.full(new SimpleIdentifier.full(andAdvance), null); |
| 3508 } else { | 3767 } else { |
| 3509 return parseTypeName(); | 3768 return parseTypeName(); |
| 3510 } | 3769 } |
| 3511 } | 3770 } |
| 3771 |
| 3512 /** | 3772 /** |
| 3513 * Parse a setter. | 3773 * Parse a setter. |
| 3514 * <pre> | 3774 * <pre> |
| 3515 * setter ::= | 3775 * setter ::= |
| 3516 * setterSignature functionBody? | 3776 * setterSignature functionBody? |
| 3517 * setterSignature ::= | 3777 * setterSignature ::= |
| 3518 * 'external'? 'static'? returnType? 'set' identifier formalParameterList | 3778 * 'external'? 'static'? returnType? 'set' identifier formalParameterList |
| 3519 * </pre> | 3779 * </pre> |
| 3520 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the | 3780 * @param commentAndMetadata the documentation comment and metadata to be asso
ciated with the |
| 3521 * declaration | 3781 * declaration |
| 3522 * @param externalKeyword the 'external' token | 3782 * @param externalKeyword the 'external' token |
| 3523 * @param staticKeyword the static keyword, or {@code null} if the setter is n
ot static | 3783 * @param staticKeyword the static keyword, or {@code null} if the setter is n
ot static |
| 3524 * @param the return type that has already been parsed, or {@code null} if the
re was no return | 3784 * @param the return type that has already been parsed, or {@code null} if the
re was no return |
| 3525 * type | 3785 * type |
| 3526 * @return the setter that was parsed | 3786 * @return the setter that was parsed |
| 3527 */ | 3787 */ |
| 3528 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext
ernalKeyword, Token staticKeyword, TypeName returnType) { | 3788 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext
ernalKeyword, Token staticKeyword, TypeName returnType) { |
| 3529 Token propertyKeyword = expect(Keyword.SET); | 3789 Token propertyKeyword = expect(Keyword.SET); |
| 3530 SimpleIdentifier name = parseSimpleIdentifier(); | 3790 SimpleIdentifier name = parseSimpleIdentifier(); |
| 3531 FormalParameterList parameters = parseFormalParameterList(); | 3791 FormalParameterList parameters = parseFormalParameterList(); |
| 3532 validateFormalParameterList(parameters); | 3792 validateFormalParameterList(parameters); |
| 3533 FunctionBody body = parseFunctionBody(true, false); | 3793 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo
rd == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false); |
| 3534 if (externalKeyword != null && body is! EmptyFunctionBody) { | 3794 if (externalKeyword != null && body is! EmptyFunctionBody) { |
| 3535 reportError4(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []); | 3795 reportError7(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []); |
| 3536 } | 3796 } |
| 3537 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta
data.metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null
, name, parameters, body); | 3797 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta
data.metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null
, name, parameters, body); |
| 3538 } | 3798 } |
| 3799 |
| 3539 /** | 3800 /** |
| 3540 * Parse a shift expression. | 3801 * Parse a shift expression. |
| 3541 * <pre> | 3802 * <pre> |
| 3542 * shiftExpression ::= | 3803 * shiftExpression ::= |
| 3543 * additiveExpression (shiftOperator additiveExpression) | 3804 * additiveExpression (shiftOperator additiveExpression) |
| 3544 * | 'super' (shiftOperator additiveExpression)+ | 3805 * | 'super' (shiftOperator additiveExpression)+ |
| 3545 * </pre> | 3806 * </pre> |
| 3546 * @return the shift expression that was parsed | 3807 * @return the shift expression that was parsed |
| 3547 */ | 3808 */ |
| 3548 Expression parseShiftExpression() { | 3809 Expression parseShiftExpression() { |
| 3549 Expression expression; | 3810 Expression expression; |
| 3550 if (matches(Keyword.SUPER) && _currentToken.next.type.isShiftOperator()) { | 3811 if (matches(Keyword.SUPER) && _currentToken.next.type.isShiftOperator()) { |
| 3551 expression = new SuperExpression.full(andAdvance); | 3812 expression = new SuperExpression.full(andAdvance); |
| 3552 } else { | 3813 } else { |
| 3553 expression = parseAdditiveExpression(); | 3814 expression = parseAdditiveExpression(); |
| 3554 } | 3815 } |
| 3555 while (_currentToken.type.isShiftOperator()) { | 3816 while (_currentToken.type.isShiftOperator()) { |
| 3556 Token operator = andAdvance; | 3817 Token operator = andAdvance; |
| 3557 expression = new BinaryExpression.full(expression, operator, parseAdditive
Expression()); | 3818 expression = new BinaryExpression.full(expression, operator, parseAdditive
Expression()); |
| 3558 } | 3819 } |
| 3559 return expression; | 3820 return expression; |
| 3560 } | 3821 } |
| 3822 |
| 3561 /** | 3823 /** |
| 3562 * Parse a simple identifier. | 3824 * Parse a simple identifier. |
| 3563 * <pre> | 3825 * <pre> |
| 3564 * identifier ::= | 3826 * identifier ::= |
| 3565 * IDENTIFIER | 3827 * IDENTIFIER |
| 3566 * </pre> | 3828 * </pre> |
| 3567 * @return the simple identifier that was parsed | 3829 * @return the simple identifier that was parsed |
| 3568 */ | 3830 */ |
| 3569 SimpleIdentifier parseSimpleIdentifier() { | 3831 SimpleIdentifier parseSimpleIdentifier() { |
| 3570 if (matchesIdentifier()) { | 3832 if (matchesIdentifier()) { |
| 3571 return new SimpleIdentifier.full(andAdvance); | 3833 return new SimpleIdentifier.full(andAdvance); |
| 3572 } | 3834 } |
| 3573 reportError4(ParserErrorCode.MISSING_IDENTIFIER, []); | 3835 reportError7(ParserErrorCode.MISSING_IDENTIFIER, []); |
| 3574 return createSyntheticIdentifier(); | 3836 return createSyntheticIdentifier(); |
| 3575 } | 3837 } |
| 3838 |
| 3576 /** | 3839 /** |
| 3577 * Parse a statement. | 3840 * Parse a statement. |
| 3578 * <pre> | 3841 * <pre> |
| 3579 * statement ::= | 3842 * statement ::= |
| 3580 * label* nonLabeledStatement | 3843 * label* nonLabeledStatement |
| 3581 * </pre> | 3844 * </pre> |
| 3582 * @return the statement that was parsed | 3845 * @return the statement that was parsed |
| 3583 */ | 3846 */ |
| 3584 Statement parseStatement2() { | 3847 Statement parseStatement2() { |
| 3585 List<Label> labels = new List<Label>(); | 3848 List<Label> labels = new List<Label>(); |
| 3586 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { | 3849 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { |
| 3587 SimpleIdentifier label = parseSimpleIdentifier(); | 3850 SimpleIdentifier label = parseSimpleIdentifier(); |
| 3588 Token colon = expect2(TokenType.COLON); | 3851 Token colon = expect2(TokenType.COLON); |
| 3589 labels.add(new Label.full(label, colon)); | 3852 labels.add(new Label.full(label, colon)); |
| 3590 } | 3853 } |
| 3591 Statement statement = parseNonLabeledStatement(); | 3854 Statement statement = parseNonLabeledStatement(); |
| 3592 if (labels.isEmpty) { | 3855 if (labels.isEmpty) { |
| 3593 return statement; | 3856 return statement; |
| 3594 } | 3857 } |
| 3595 return new LabeledStatement.full(labels, statement); | 3858 return new LabeledStatement.full(labels, statement); |
| 3596 } | 3859 } |
| 3860 |
| 3597 /** | 3861 /** |
| 3598 * Parse a list of statements within a switch statement. | 3862 * Parse a list of statements within a switch statement. |
| 3599 * <pre> | 3863 * <pre> |
| 3600 * statements ::= | 3864 * statements ::= |
| 3601 * statement | 3865 * statement |
| 3602 * </pre> | 3866 * </pre> |
| 3603 * @return the statements that were parsed | 3867 * @return the statements that were parsed |
| 3604 */ | 3868 */ |
| 3605 List<Statement> parseStatements2() { | 3869 List<Statement> parseStatements2() { |
| 3606 List<Statement> statements = new List<Statement>(); | 3870 List<Statement> statements = new List<Statement>(); |
| 3607 Token statementStart = _currentToken; | 3871 Token statementStart = _currentToken; |
| 3608 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)
&& !isSwitchMember()) { | 3872 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)
&& !isSwitchMember()) { |
| 3609 statements.add(parseStatement2()); | 3873 statements.add(parseStatement2()); |
| 3610 if (identical(_currentToken, statementStart)) { | 3874 if (identical(_currentToken, statementStart)) { |
| 3611 reportError5(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); | 3875 reportError8(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT
oken.lexeme]); |
| 3612 advance(); | 3876 advance(); |
| 3613 } | 3877 } |
| 3614 statementStart = _currentToken; | 3878 statementStart = _currentToken; |
| 3615 } | 3879 } |
| 3616 return statements; | 3880 return statements; |
| 3617 } | 3881 } |
| 3882 |
| 3618 /** | 3883 /** |
| 3619 * Parse a string literal that contains interpolations. | 3884 * Parse a string literal that contains interpolations. |
| 3620 * @return the string literal that was parsed | 3885 * @return the string literal that was parsed |
| 3621 */ | 3886 */ |
| 3622 StringInterpolation parseStringInterpolation(Token string) { | 3887 StringInterpolation parseStringInterpolation(Token string) { |
| 3623 List<InterpolationElement> elements = new List<InterpolationElement>(); | 3888 List<InterpolationElement> elements = new List<InterpolationElement>(); |
| 3624 elements.add(new InterpolationString.full(string, computeStringValue(string.
lexeme))); | 3889 elements.add(new InterpolationString.full(string, computeStringValue(string.
lexeme))); |
| 3625 while (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(Token
Type.STRING_INTERPOLATION_IDENTIFIER)) { | 3890 while (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(Token
Type.STRING_INTERPOLATION_IDENTIFIER)) { |
| 3626 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) { | 3891 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) { |
| 3627 Token openToken = andAdvance; | 3892 Token openToken = andAdvance; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3638 } | 3903 } |
| 3639 elements.add(new InterpolationExpression.full(openToken, expression, nul
l)); | 3904 elements.add(new InterpolationExpression.full(openToken, expression, nul
l)); |
| 3640 } | 3905 } |
| 3641 if (matches5(TokenType.STRING)) { | 3906 if (matches5(TokenType.STRING)) { |
| 3642 string = andAdvance; | 3907 string = andAdvance; |
| 3643 elements.add(new InterpolationString.full(string, computeStringValue(str
ing.lexeme))); | 3908 elements.add(new InterpolationString.full(string, computeStringValue(str
ing.lexeme))); |
| 3644 } | 3909 } |
| 3645 } | 3910 } |
| 3646 return new StringInterpolation.full(elements); | 3911 return new StringInterpolation.full(elements); |
| 3647 } | 3912 } |
| 3913 |
| 3648 /** | 3914 /** |
| 3649 * Parse a string literal. | 3915 * Parse a string literal. |
| 3650 * <pre> | 3916 * <pre> |
| 3651 * stringLiteral ::= | 3917 * stringLiteral ::= |
| 3652 * MULTI_LINE_STRING+ | 3918 * MULTI_LINE_STRING+ |
| 3653 * | SINGLE_LINE_STRING+ | 3919 * | SINGLE_LINE_STRING+ |
| 3654 * </pre> | 3920 * </pre> |
| 3655 * @return the string literal that was parsed | 3921 * @return the string literal that was parsed |
| 3656 */ | 3922 */ |
| 3657 StringLiteral parseStringLiteral() { | 3923 StringLiteral parseStringLiteral() { |
| 3658 List<StringLiteral> strings = new List<StringLiteral>(); | 3924 List<StringLiteral> strings = new List<StringLiteral>(); |
| 3659 while (matches5(TokenType.STRING)) { | 3925 while (matches5(TokenType.STRING)) { |
| 3660 Token string = andAdvance; | 3926 Token string = andAdvance; |
| 3661 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT
ype.STRING_INTERPOLATION_IDENTIFIER)) { | 3927 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT
ype.STRING_INTERPOLATION_IDENTIFIER)) { |
| 3662 strings.add(parseStringInterpolation(string)); | 3928 strings.add(parseStringInterpolation(string)); |
| 3663 } else { | 3929 } else { |
| 3664 strings.add(new SimpleStringLiteral.full(string, computeStringValue(stri
ng.lexeme))); | 3930 strings.add(new SimpleStringLiteral.full(string, computeStringValue(stri
ng.lexeme))); |
| 3665 } | 3931 } |
| 3666 } | 3932 } |
| 3667 if (strings.length < 1) { | 3933 if (strings.length < 1) { |
| 3668 reportError4(ParserErrorCode.EXPECTED_STRING_LITERAL, []); | 3934 reportError7(ParserErrorCode.EXPECTED_STRING_LITERAL, []); |
| 3669 return createSyntheticStringLiteral(); | 3935 return createSyntheticStringLiteral(); |
| 3670 } else if (strings.length == 1) { | 3936 } else if (strings.length == 1) { |
| 3671 return strings[0]; | 3937 return strings[0]; |
| 3672 } else { | 3938 } else { |
| 3673 return new AdjacentStrings.full(strings); | 3939 return new AdjacentStrings.full(strings); |
| 3674 } | 3940 } |
| 3675 } | 3941 } |
| 3942 |
| 3676 /** | 3943 /** |
| 3677 * Parse a super constructor invocation. | 3944 * Parse a super constructor invocation. |
| 3678 * <pre> | 3945 * <pre> |
| 3679 * superConstructorInvocation ::= | 3946 * superConstructorInvocation ::= |
| 3680 * 'super' ('.' identifier)? arguments | 3947 * 'super' ('.' identifier)? arguments |
| 3681 * </pre> | 3948 * </pre> |
| 3682 * @return the super constructor invocation that was parsed | 3949 * @return the super constructor invocation that was parsed |
| 3683 */ | 3950 */ |
| 3684 SuperConstructorInvocation parseSuperConstructorInvocation() { | 3951 SuperConstructorInvocation parseSuperConstructorInvocation() { |
| 3685 Token keyword = expect(Keyword.SUPER); | 3952 Token keyword = expect(Keyword.SUPER); |
| 3686 Token period = null; | 3953 Token period = null; |
| 3687 SimpleIdentifier constructorName = null; | 3954 SimpleIdentifier constructorName = null; |
| 3688 if (matches5(TokenType.PERIOD)) { | 3955 if (matches5(TokenType.PERIOD)) { |
| 3689 period = andAdvance; | 3956 period = andAdvance; |
| 3690 constructorName = parseSimpleIdentifier(); | 3957 constructorName = parseSimpleIdentifier(); |
| 3691 } | 3958 } |
| 3692 ArgumentList argumentList = parseArgumentList(); | 3959 ArgumentList argumentList = parseArgumentList(); |
| 3693 return new SuperConstructorInvocation.full(keyword, period, constructorName,
argumentList); | 3960 return new SuperConstructorInvocation.full(keyword, period, constructorName,
argumentList); |
| 3694 } | 3961 } |
| 3962 |
| 3695 /** | 3963 /** |
| 3696 * Parse a switch statement. | 3964 * Parse a switch statement. |
| 3697 * <pre> | 3965 * <pre> |
| 3698 * switchStatement ::= | 3966 * switchStatement ::= |
| 3699 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}' | 3967 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}' |
| 3700 * switchCase ::= | 3968 * switchCase ::= |
| 3701 * label* ('case' expression ':') statements | 3969 * label* ('case' expression ':') statements |
| 3702 * defaultCase ::= | 3970 * defaultCase ::= |
| 3703 * label* 'default' ':' statements | 3971 * label* 'default' ':' statements |
| 3704 * </pre> | 3972 * </pre> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3715 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 3983 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 3716 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); | 3984 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); |
| 3717 Token defaultKeyword = null; | 3985 Token defaultKeyword = null; |
| 3718 List<SwitchMember> members = new List<SwitchMember>(); | 3986 List<SwitchMember> members = new List<SwitchMember>(); |
| 3719 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET
)) { | 3987 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET
)) { |
| 3720 List<Label> labels = new List<Label>(); | 3988 List<Label> labels = new List<Label>(); |
| 3721 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { | 3989 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { |
| 3722 SimpleIdentifier identifier = parseSimpleIdentifier(); | 3990 SimpleIdentifier identifier = parseSimpleIdentifier(); |
| 3723 String label = identifier.token.lexeme; | 3991 String label = identifier.token.lexeme; |
| 3724 if (definedLabels.contains(label)) { | 3992 if (definedLabels.contains(label)) { |
| 3725 reportError5(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, id
entifier.token, [label]); | 3993 reportError8(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, id
entifier.token, [label]); |
| 3726 } else { | 3994 } else { |
| 3727 javaSetAdd(definedLabels, label); | 3995 javaSetAdd(definedLabels, label); |
| 3728 } | 3996 } |
| 3729 Token colon = expect2(TokenType.COLON); | 3997 Token colon = expect2(TokenType.COLON); |
| 3730 labels.add(new Label.full(identifier, colon)); | 3998 labels.add(new Label.full(identifier, colon)); |
| 3731 } | 3999 } |
| 3732 if (matches(Keyword.CASE)) { | 4000 if (matches(Keyword.CASE)) { |
| 3733 Token caseKeyword = andAdvance; | 4001 Token caseKeyword = andAdvance; |
| 3734 Expression caseExpression = parseExpression2(); | 4002 Expression caseExpression = parseExpression2(); |
| 3735 Token colon = expect2(TokenType.COLON); | 4003 Token colon = expect2(TokenType.COLON); |
| 3736 members.add(new SwitchCase.full(labels, caseKeyword, caseExpression, c
olon, parseStatements2())); | 4004 members.add(new SwitchCase.full(labels, caseKeyword, caseExpression, c
olon, parseStatements2())); |
| 3737 if (defaultKeyword != null) { | 4005 if (defaultKeyword != null) { |
| 3738 reportError5(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, cas
eKeyword, []); | 4006 reportError8(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, cas
eKeyword, []); |
| 3739 } | 4007 } |
| 3740 } else if (matches(Keyword.DEFAULT)) { | 4008 } else if (matches(Keyword.DEFAULT)) { |
| 3741 if (defaultKeyword != null) { | 4009 if (defaultKeyword != null) { |
| 3742 reportError5(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, peek
(), []); | 4010 reportError8(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, peek
(), []); |
| 3743 } | 4011 } |
| 3744 defaultKeyword = andAdvance; | 4012 defaultKeyword = andAdvance; |
| 3745 Token colon = expect2(TokenType.COLON); | 4013 Token colon = expect2(TokenType.COLON); |
| 3746 members.add(new SwitchDefault.full(labels, defaultKeyword, colon, pars
eStatements2())); | 4014 members.add(new SwitchDefault.full(labels, defaultKeyword, colon, pars
eStatements2())); |
| 3747 } else { | 4015 } else { |
| 3748 reportError4(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []); | 4016 reportError7(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []); |
| 3749 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA
CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) { | 4017 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA
CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) { |
| 3750 advance(); | 4018 advance(); |
| 3751 } | 4019 } |
| 3752 } | 4020 } |
| 3753 } | 4021 } |
| 3754 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); | 4022 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); |
| 3755 return new SwitchStatement.full(keyword, leftParenthesis, expression, righ
tParenthesis, leftBracket, members, rightBracket); | 4023 return new SwitchStatement.full(keyword, leftParenthesis, expression, righ
tParenthesis, leftBracket, members, rightBracket); |
| 3756 } finally { | 4024 } finally { |
| 3757 _inSwitch = wasInSwitch; | 4025 _inSwitch = wasInSwitch; |
| 3758 } | 4026 } |
| 3759 } | 4027 } |
| 4028 |
| 3760 /** | 4029 /** |
| 3761 * Parse a throw expression. | 4030 * Parse a throw expression. |
| 3762 * <pre> | 4031 * <pre> |
| 3763 * throwExpression ::= | 4032 * throwExpression ::= |
| 3764 * 'throw' expression | 4033 * 'throw' expression |
| 3765 * </pre> | 4034 * </pre> |
| 3766 * @return the throw expression that was parsed | 4035 * @return the throw expression that was parsed |
| 3767 */ | 4036 */ |
| 3768 Expression parseThrowExpression() { | 4037 Expression parseThrowExpression() { |
| 3769 Token keyword = expect(Keyword.THROW); | 4038 Token keyword = expect(Keyword.THROW); |
| 3770 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { | 4039 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { |
| 3771 return new ThrowExpression.full(keyword, null); | 4040 reportError8(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, [
]); |
| 4041 return new ThrowExpression.full(keyword, createSyntheticIdentifier()); |
| 3772 } | 4042 } |
| 3773 Expression expression = parseExpression2(); | 4043 Expression expression = parseExpression2(); |
| 3774 return new ThrowExpression.full(keyword, expression); | 4044 return new ThrowExpression.full(keyword, expression); |
| 3775 } | 4045 } |
| 4046 |
| 3776 /** | 4047 /** |
| 3777 * Parse a throw expression. | 4048 * Parse a throw expression. |
| 3778 * <pre> | 4049 * <pre> |
| 3779 * throwExpressionWithoutCascade ::= | 4050 * throwExpressionWithoutCascade ::= |
| 3780 * 'throw' expressionWithoutCascade | 4051 * 'throw' expressionWithoutCascade |
| 3781 * </pre> | 4052 * </pre> |
| 3782 * @return the throw expression that was parsed | 4053 * @return the throw expression that was parsed |
| 3783 */ | 4054 */ |
| 3784 Expression parseThrowExpressionWithoutCascade() { | 4055 Expression parseThrowExpressionWithoutCascade() { |
| 3785 Token keyword = expect(Keyword.THROW); | 4056 Token keyword = expect(Keyword.THROW); |
| 3786 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { | 4057 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { |
| 3787 return new ThrowExpression.full(keyword, null); | 4058 reportError8(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, [
]); |
| 4059 return new ThrowExpression.full(keyword, createSyntheticIdentifier()); |
| 3788 } | 4060 } |
| 3789 Expression expression = parseExpressionWithoutCascade(); | 4061 Expression expression = parseExpressionWithoutCascade(); |
| 3790 return new ThrowExpression.full(keyword, expression); | 4062 return new ThrowExpression.full(keyword, expression); |
| 3791 } | 4063 } |
| 4064 |
| 3792 /** | 4065 /** |
| 3793 * Parse a try statement. | 4066 * Parse a try statement. |
| 3794 * <pre> | 4067 * <pre> |
| 3795 * tryStatement ::= | 4068 * tryStatement ::= |
| 3796 * 'try' block (onPart+ finallyPart? | finallyPart) | 4069 * 'try' block (onPart+ finallyPart? | finallyPart) |
| 3797 * onPart ::= | 4070 * onPart ::= |
| 3798 * catchPart block | 4071 * catchPart block |
| 3799 * | 'on' type catchPart? block | 4072 * | 'on' type catchPart? block |
| 3800 * catchPart ::= | 4073 * catchPart ::= |
| 3801 * 'catch' '(' identifier (',' identifier)? ')' | 4074 * 'catch' '(' identifier (',' identifier)? ')' |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3834 } | 4107 } |
| 3835 Block catchBody = parseBlock(); | 4108 Block catchBody = parseBlock(); |
| 3836 catchClauses.add(new CatchClause.full(onKeyword, exceptionType, catchKeywo
rd, leftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParent
hesis, catchBody)); | 4109 catchClauses.add(new CatchClause.full(onKeyword, exceptionType, catchKeywo
rd, leftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParent
hesis, catchBody)); |
| 3837 } | 4110 } |
| 3838 Token finallyKeyword = null; | 4111 Token finallyKeyword = null; |
| 3839 if (matches(Keyword.FINALLY)) { | 4112 if (matches(Keyword.FINALLY)) { |
| 3840 finallyKeyword = andAdvance; | 4113 finallyKeyword = andAdvance; |
| 3841 finallyClause = parseBlock(); | 4114 finallyClause = parseBlock(); |
| 3842 } else { | 4115 } else { |
| 3843 if (catchClauses.isEmpty) { | 4116 if (catchClauses.isEmpty) { |
| 3844 reportError4(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []); | 4117 reportError7(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []); |
| 3845 } | 4118 } |
| 3846 } | 4119 } |
| 3847 return new TryStatement.full(tryKeyword, body, catchClauses, finallyKeyword,
finallyClause); | 4120 return new TryStatement.full(tryKeyword, body, catchClauses, finallyKeyword,
finallyClause); |
| 3848 } | 4121 } |
| 4122 |
| 3849 /** | 4123 /** |
| 3850 * Parse a type alias. | 4124 * Parse a type alias. |
| 3851 * <pre> | 4125 * <pre> |
| 3852 * typeAlias ::= | 4126 * typeAlias ::= |
| 3853 * 'typedef' typeAliasBody | 4127 * 'typedef' typeAliasBody |
| 3854 * typeAliasBody ::= | 4128 * typeAliasBody ::= |
| 3855 * classTypeAlias | 4129 * classTypeAlias |
| 3856 * | functionTypeAlias | 4130 * | functionTypeAlias |
| 3857 * classTypeAlias ::= | 4131 * classTypeAlias ::= |
| 3858 * identifier typeParameters? '=' 'abstract'? mixinApplication | 4132 * identifier typeParameters? '=' 'abstract'? mixinApplication |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3874 next = skipTypeParameterList(next); | 4148 next = skipTypeParameterList(next); |
| 3875 if (next != null && matches4(next, TokenType.EQ)) { | 4149 if (next != null && matches4(next, TokenType.EQ)) { |
| 3876 return parseClassTypeAlias(commentAndMetadata, keyword); | 4150 return parseClassTypeAlias(commentAndMetadata, keyword); |
| 3877 } | 4151 } |
| 3878 } else if (matches4(next, TokenType.EQ)) { | 4152 } else if (matches4(next, TokenType.EQ)) { |
| 3879 return parseClassTypeAlias(commentAndMetadata, keyword); | 4153 return parseClassTypeAlias(commentAndMetadata, keyword); |
| 3880 } | 4154 } |
| 3881 } | 4155 } |
| 3882 return parseFunctionTypeAlias(commentAndMetadata, keyword); | 4156 return parseFunctionTypeAlias(commentAndMetadata, keyword); |
| 3883 } | 4157 } |
| 4158 |
| 3884 /** | 4159 /** |
| 3885 * Parse a list of type arguments. | 4160 * Parse a list of type arguments. |
| 3886 * <pre> | 4161 * <pre> |
| 3887 * typeArguments ::= | 4162 * typeArguments ::= |
| 3888 * '<' typeList '>' | 4163 * '<' typeList '>' |
| 3889 * typeList ::= | 4164 * typeList ::= |
| 3890 * type (',' type) | 4165 * type (',' type) |
| 3891 * </pre> | 4166 * </pre> |
| 3892 * @return the type argument list that was parsed | 4167 * @return the type argument list that was parsed |
| 3893 */ | 4168 */ |
| 3894 TypeArgumentList parseTypeArgumentList() { | 4169 TypeArgumentList parseTypeArgumentList() { |
| 3895 Token leftBracket = expect2(TokenType.LT); | 4170 Token leftBracket = expect2(TokenType.LT); |
| 3896 List<TypeName> arguments = new List<TypeName>(); | 4171 List<TypeName> arguments = new List<TypeName>(); |
| 3897 arguments.add(parseTypeName()); | 4172 arguments.add(parseTypeName()); |
| 3898 while (optional(TokenType.COMMA)) { | 4173 while (optional(TokenType.COMMA)) { |
| 3899 arguments.add(parseTypeName()); | 4174 arguments.add(parseTypeName()); |
| 3900 } | 4175 } |
| 3901 Token rightBracket = expect2(TokenType.GT); | 4176 Token rightBracket = expect2(TokenType.GT); |
| 3902 return new TypeArgumentList.full(leftBracket, arguments, rightBracket); | 4177 return new TypeArgumentList.full(leftBracket, arguments, rightBracket); |
| 3903 } | 4178 } |
| 4179 |
| 3904 /** | 4180 /** |
| 3905 * Parse a type name. | 4181 * Parse a type name. |
| 3906 * <pre> | 4182 * <pre> |
| 3907 * type ::= | 4183 * type ::= |
| 3908 * qualified typeArguments? | 4184 * qualified typeArguments? |
| 3909 * </pre> | 4185 * </pre> |
| 3910 * @return the type name that was parsed | 4186 * @return the type name that was parsed |
| 3911 */ | 4187 */ |
| 3912 TypeName parseTypeName() { | 4188 TypeName parseTypeName() { |
| 3913 Identifier typeName = parsePrefixedIdentifier(); | 4189 Identifier typeName; |
| 4190 if (matches(Keyword.VAR)) { |
| 4191 reportError7(ParserErrorCode.VAR_AS_TYPE_NAME, []); |
| 4192 typeName = new SimpleIdentifier.full(andAdvance); |
| 4193 } else if (matchesIdentifier()) { |
| 4194 typeName = parsePrefixedIdentifier(); |
| 4195 } else { |
| 4196 typeName = createSyntheticIdentifier(); |
| 4197 reportError7(ParserErrorCode.EXPECTED_TYPE_NAME, []); |
| 4198 } |
| 3914 TypeArgumentList typeArguments = null; | 4199 TypeArgumentList typeArguments = null; |
| 3915 if (matches5(TokenType.LT)) { | 4200 if (matches5(TokenType.LT)) { |
| 3916 typeArguments = parseTypeArgumentList(); | 4201 typeArguments = parseTypeArgumentList(); |
| 3917 } | 4202 } |
| 3918 return new TypeName.full(typeName, typeArguments); | 4203 return new TypeName.full(typeName, typeArguments); |
| 3919 } | 4204 } |
| 4205 |
| 3920 /** | 4206 /** |
| 3921 * Parse a type parameter. | 4207 * Parse a type parameter. |
| 3922 * <pre> | 4208 * <pre> |
| 3923 * typeParameter ::= | 4209 * typeParameter ::= |
| 3924 * metadata name ('extends' bound)? | 4210 * metadata name ('extends' bound)? |
| 3925 * </pre> | 4211 * </pre> |
| 3926 * @return the type parameter that was parsed | 4212 * @return the type parameter that was parsed |
| 3927 */ | 4213 */ |
| 3928 TypeParameter parseTypeParameter() { | 4214 TypeParameter parseTypeParameter() { |
| 3929 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 4215 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 3930 SimpleIdentifier name = parseSimpleIdentifier(); | 4216 SimpleIdentifier name = parseSimpleIdentifier(); |
| 3931 if (matches(Keyword.EXTENDS)) { | 4217 if (matches(Keyword.EXTENDS)) { |
| 3932 Token keyword = andAdvance; | 4218 Token keyword = andAdvance; |
| 3933 TypeName bound = parseTypeName(); | 4219 TypeName bound = parseTypeName(); |
| 3934 return new TypeParameter.full(commentAndMetadata.comment, commentAndMetada
ta.metadata, name, keyword, bound); | 4220 return new TypeParameter.full(commentAndMetadata.comment, commentAndMetada
ta.metadata, name, keyword, bound); |
| 3935 } | 4221 } |
| 3936 return new TypeParameter.full(commentAndMetadata.comment, commentAndMetadata
.metadata, name, null, null); | 4222 return new TypeParameter.full(commentAndMetadata.comment, commentAndMetadata
.metadata, name, null, null); |
| 3937 } | 4223 } |
| 4224 |
| 3938 /** | 4225 /** |
| 3939 * Parse a list of type parameters. | 4226 * Parse a list of type parameters. |
| 3940 * <pre> | 4227 * <pre> |
| 3941 * typeParameterList ::= | 4228 * typeParameterList ::= |
| 3942 * '<' typeParameter (',' typeParameter)* '>' | 4229 * '<' typeParameter (',' typeParameter)* '>' |
| 3943 * </pre> | 4230 * </pre> |
| 3944 * @return the list of type parameters that were parsed | 4231 * @return the list of type parameters that were parsed |
| 3945 */ | 4232 */ |
| 3946 TypeParameterList parseTypeParameterList() { | 4233 TypeParameterList parseTypeParameterList() { |
| 3947 Token leftBracket = expect2(TokenType.LT); | 4234 Token leftBracket = expect2(TokenType.LT); |
| 3948 List<TypeParameter> typeParameters = new List<TypeParameter>(); | 4235 List<TypeParameter> typeParameters = new List<TypeParameter>(); |
| 3949 typeParameters.add(parseTypeParameter()); | 4236 typeParameters.add(parseTypeParameter()); |
| 3950 while (optional(TokenType.COMMA)) { | 4237 while (optional(TokenType.COMMA)) { |
| 3951 typeParameters.add(parseTypeParameter()); | 4238 typeParameters.add(parseTypeParameter()); |
| 3952 } | 4239 } |
| 3953 Token rightBracket = expect2(TokenType.GT); | 4240 Token rightBracket = expect2(TokenType.GT); |
| 3954 return new TypeParameterList.full(leftBracket, typeParameters, rightBracket)
; | 4241 return new TypeParameterList.full(leftBracket, typeParameters, rightBracket)
; |
| 3955 } | 4242 } |
| 4243 |
| 3956 /** | 4244 /** |
| 3957 * Parse a unary expression. | 4245 * Parse a unary expression. |
| 3958 * <pre> | 4246 * <pre> |
| 3959 * unaryExpression ::= | 4247 * unaryExpression ::= |
| 3960 * prefixOperator unaryExpression | 4248 * prefixOperator unaryExpression |
| 3961 * | postfixExpression | 4249 * | postfixExpression |
| 3962 * | unaryOperator 'super' | 4250 * | unaryOperator 'super' |
| 3963 * | '-' 'super' | 4251 * | '-' 'super' |
| 3964 * | incrementOperator assignableExpression | 4252 * | incrementOperator assignableExpression |
| 3965 * </pre> | 4253 * </pre> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3983 } | 4271 } |
| 3984 if (identical(operator.type, TokenType.MINUS_MINUS)) { | 4272 if (identical(operator.type, TokenType.MINUS_MINUS)) { |
| 3985 int offset2 = operator.offset; | 4273 int offset2 = operator.offset; |
| 3986 Token firstOperator = new Token(TokenType.MINUS, offset2); | 4274 Token firstOperator = new Token(TokenType.MINUS, offset2); |
| 3987 Token secondOperator = new Token(TokenType.MINUS, offset2 + 1); | 4275 Token secondOperator = new Token(TokenType.MINUS, offset2 + 1); |
| 3988 secondOperator.setNext(_currentToken); | 4276 secondOperator.setNext(_currentToken); |
| 3989 firstOperator.setNext(secondOperator); | 4277 firstOperator.setNext(secondOperator); |
| 3990 operator.previous.setNext(firstOperator); | 4278 operator.previous.setNext(firstOperator); |
| 3991 return new PrefixExpression.full(firstOperator, new PrefixExpression.f
ull(secondOperator, new SuperExpression.full(andAdvance))); | 4279 return new PrefixExpression.full(firstOperator, new PrefixExpression.f
ull(secondOperator, new SuperExpression.full(andAdvance))); |
| 3992 } else { | 4280 } else { |
| 3993 reportError4(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lex
eme]); | 4281 reportError7(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lex
eme]); |
| 3994 return new PrefixExpression.full(operator, new SuperExpression.full(an
dAdvance)); | 4282 return new PrefixExpression.full(operator, new SuperExpression.full(an
dAdvance)); |
| 3995 } | 4283 } |
| 3996 } | 4284 } |
| 3997 return new PrefixExpression.full(operator, parseAssignableExpression(false
)); | 4285 return new PrefixExpression.full(operator, parseAssignableExpression(false
)); |
| 3998 } else if (matches5(TokenType.PLUS)) { | 4286 } else if (matches5(TokenType.PLUS)) { |
| 3999 reportError4(ParserErrorCode.USE_OF_UNARY_PLUS_OPERATOR, []); | 4287 reportError7(ParserErrorCode.MISSING_IDENTIFIER, []); |
| 4288 return createSyntheticIdentifier(); |
| 4000 } | 4289 } |
| 4001 return parsePostfixExpression(); | 4290 return parsePostfixExpression(); |
| 4002 } | 4291 } |
| 4292 |
| 4003 /** | 4293 /** |
| 4004 * Parse a variable declaration. | 4294 * Parse a variable declaration. |
| 4005 * <pre> | 4295 * <pre> |
| 4006 * variableDeclaration ::= | 4296 * variableDeclaration ::= |
| 4007 * identifier ('=' expression)? | 4297 * identifier ('=' expression)? |
| 4008 * </pre> | 4298 * </pre> |
| 4009 * @return the variable declaration that was parsed | 4299 * @return the variable declaration that was parsed |
| 4010 */ | 4300 */ |
| 4011 VariableDeclaration parseVariableDeclaration() { | 4301 VariableDeclaration parseVariableDeclaration() { |
| 4012 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 4302 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 4013 SimpleIdentifier name = parseSimpleIdentifier(); | 4303 SimpleIdentifier name = parseSimpleIdentifier(); |
| 4014 Token equals = null; | 4304 Token equals = null; |
| 4015 Expression initializer = null; | 4305 Expression initializer = null; |
| 4016 if (matches5(TokenType.EQ)) { | 4306 if (matches5(TokenType.EQ)) { |
| 4017 equals = andAdvance; | 4307 equals = andAdvance; |
| 4018 initializer = parseExpression2(); | 4308 initializer = parseExpression2(); |
| 4019 } | 4309 } |
| 4020 return new VariableDeclaration.full(commentAndMetadata.comment, commentAndMe
tadata.metadata, name, equals, initializer); | 4310 return new VariableDeclaration.full(commentAndMetadata.comment, commentAndMe
tadata.metadata, name, equals, initializer); |
| 4021 } | 4311 } |
| 4312 |
| 4022 /** | 4313 /** |
| 4023 * Parse a variable declaration list. | 4314 * Parse a variable declaration list. |
| 4024 * <pre> | 4315 * <pre> |
| 4025 * variableDeclarationList ::= | 4316 * variableDeclarationList ::= |
| 4026 * finalConstVarOrType variableDeclaration (',' variableDeclaration) | 4317 * finalConstVarOrType variableDeclaration (',' variableDeclaration) |
| 4027 * </pre> | 4318 * </pre> |
| 4028 * @param commentAndMetadata the metadata to be associated with the variable d
eclaration list | 4319 * @param commentAndMetadata the metadata to be associated with the variable d
eclaration list |
| 4029 * @return the variable declaration list that was parsed | 4320 * @return the variable declaration list that was parsed |
| 4030 */ | 4321 */ |
| 4031 VariableDeclarationList parseVariableDeclarationList(CommentAndMetadata commen
tAndMetadata) { | 4322 VariableDeclarationList parseVariableDeclarationList(CommentAndMetadata commen
tAndMetadata) { |
| 4032 FinalConstVarOrType holder = parseFinalConstVarOrType(false); | 4323 FinalConstVarOrType holder = parseFinalConstVarOrType(false); |
| 4033 return parseVariableDeclarationList2(commentAndMetadata, holder.keyword, hol
der.type); | 4324 return parseVariableDeclarationList2(commentAndMetadata, holder.keyword, hol
der.type); |
| 4034 } | 4325 } |
| 4326 |
| 4035 /** | 4327 /** |
| 4036 * Parse a variable declaration list. | 4328 * Parse a variable declaration list. |
| 4037 * <pre> | 4329 * <pre> |
| 4038 * variableDeclarationList ::= | 4330 * variableDeclarationList ::= |
| 4039 * finalConstVarOrType variableDeclaration (',' variableDeclaration) | 4331 * finalConstVarOrType variableDeclaration (',' variableDeclaration) |
| 4040 * </pre> | 4332 * </pre> |
| 4041 * @param commentAndMetadata the metadata to be associated with the variable d
eclaration list, or{@code null} if there is no attempt at parsing the comment an
d metadata | 4333 * @param commentAndMetadata the metadata to be associated with the variable d
eclaration list, or{@code null} if there is no attempt at parsing the comment an
d metadata |
| 4042 * @param keyword the token representing the 'final', 'const' or 'var' keyword
, or {@code null} if | 4334 * @param keyword the token representing the 'final', 'const' or 'var' keyword
, or {@code null} if |
| 4043 * there is no keyword | 4335 * there is no keyword |
| 4044 * @param type the type of the variables in the list | 4336 * @param type the type of the variables in the list |
| 4045 * @return the variable declaration list that was parsed | 4337 * @return the variable declaration list that was parsed |
| 4046 */ | 4338 */ |
| 4047 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme
ntAndMetadata, Token keyword, TypeName type) { | 4339 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme
ntAndMetadata, Token keyword, TypeName type) { |
| 4048 List<VariableDeclaration> variables = new List<VariableDeclaration>(); | 4340 List<VariableDeclaration> variables = new List<VariableDeclaration>(); |
| 4049 variables.add(parseVariableDeclaration()); | 4341 variables.add(parseVariableDeclaration()); |
| 4050 while (matches5(TokenType.COMMA)) { | 4342 while (matches5(TokenType.COMMA)) { |
| 4051 advance(); | 4343 advance(); |
| 4052 variables.add(parseVariableDeclaration()); | 4344 variables.add(parseVariableDeclaration()); |
| 4053 } | 4345 } |
| 4054 return new VariableDeclarationList.full(commentAndMetadata != null ? comment
AndMetadata.comment : null, commentAndMetadata != null ? commentAndMetadata.meta
data : null, keyword, type, variables); | 4346 return new VariableDeclarationList.full(commentAndMetadata != null ? comment
AndMetadata.comment : null, commentAndMetadata != null ? commentAndMetadata.meta
data : null, keyword, type, variables); |
| 4055 } | 4347 } |
| 4348 |
| 4056 /** | 4349 /** |
| 4057 * Parse a variable declaration statement. | 4350 * Parse a variable declaration statement. |
| 4058 * <pre> | 4351 * <pre> |
| 4059 * variableDeclarationStatement ::= | 4352 * variableDeclarationStatement ::= |
| 4060 * variableDeclarationList ';' | 4353 * variableDeclarationList ';' |
| 4061 * </pre> | 4354 * </pre> |
| 4062 * @param commentAndMetadata the metadata to be associated with the variable d
eclaration | 4355 * @param commentAndMetadata the metadata to be associated with the variable d
eclaration |
| 4063 * statement, or {@code null} if there is no attempt at parsing the comment an
d metadata | 4356 * statement, or {@code null} if there is no attempt at parsing the comment an
d metadata |
| 4064 * @return the variable declaration statement that was parsed | 4357 * @return the variable declaration statement that was parsed |
| 4065 */ | 4358 */ |
| 4066 VariableDeclarationStatement parseVariableDeclarationStatement(CommentAndMetad
ata commentAndMetadata) { | 4359 VariableDeclarationStatement parseVariableDeclarationStatement(CommentAndMetad
ata commentAndMetadata) { |
| 4067 VariableDeclarationList variableList = parseVariableDeclarationList(commentA
ndMetadata); | 4360 VariableDeclarationList variableList = parseVariableDeclarationList(commentA
ndMetadata); |
| 4068 Token semicolon = expect2(TokenType.SEMICOLON); | 4361 Token semicolon = expect2(TokenType.SEMICOLON); |
| 4069 return new VariableDeclarationStatement.full(variableList, semicolon); | 4362 return new VariableDeclarationStatement.full(variableList, semicolon); |
| 4070 } | 4363 } |
| 4364 |
| 4071 /** | 4365 /** |
| 4072 * Parse a variable declaration statement. | 4366 * Parse a variable declaration statement. |
| 4073 * <pre> | 4367 * <pre> |
| 4074 * variableDeclarationStatement ::= | 4368 * variableDeclarationStatement ::= |
| 4075 * variableDeclarationList ';' | 4369 * variableDeclarationList ';' |
| 4076 * </pre> | 4370 * </pre> |
| 4077 * @param commentAndMetadata the metadata to be associated with the variable d
eclaration | 4371 * @param commentAndMetadata the metadata to be associated with the variable d
eclaration |
| 4078 * statement, or {@code null} if there is no attempt at parsing the comment an
d metadata | 4372 * statement, or {@code null} if there is no attempt at parsing the comment an
d metadata |
| 4079 * @param keyword the token representing the 'final', 'const' or 'var' keyword
, or {@code null} if | 4373 * @param keyword the token representing the 'final', 'const' or 'var' keyword
, or {@code null} if |
| 4080 * there is no keyword | 4374 * there is no keyword |
| 4081 * @param type the type of the variables in the list | 4375 * @param type the type of the variables in the list |
| 4082 * @return the variable declaration statement that was parsed | 4376 * @return the variable declaration statement that was parsed |
| 4083 */ | 4377 */ |
| 4084 VariableDeclarationStatement parseVariableDeclarationStatement2(CommentAndMeta
data commentAndMetadata, Token keyword, TypeName type) { | 4378 VariableDeclarationStatement parseVariableDeclarationStatement2(CommentAndMeta
data commentAndMetadata, Token keyword, TypeName type) { |
| 4085 VariableDeclarationList variableList = parseVariableDeclarationList2(comment
AndMetadata, keyword, type); | 4379 VariableDeclarationList variableList = parseVariableDeclarationList2(comment
AndMetadata, keyword, type); |
| 4086 Token semicolon = expect2(TokenType.SEMICOLON); | 4380 Token semicolon = expect2(TokenType.SEMICOLON); |
| 4087 return new VariableDeclarationStatement.full(variableList, semicolon); | 4381 return new VariableDeclarationStatement.full(variableList, semicolon); |
| 4088 } | 4382 } |
| 4383 |
| 4089 /** | 4384 /** |
| 4090 * Parse a while statement. | 4385 * Parse a while statement. |
| 4091 * <pre> | 4386 * <pre> |
| 4092 * whileStatement ::= | 4387 * whileStatement ::= |
| 4093 * 'while' '(' expression ')' statement | 4388 * 'while' '(' expression ')' statement |
| 4094 * </pre> | 4389 * </pre> |
| 4095 * @return the while statement that was parsed | 4390 * @return the while statement that was parsed |
| 4096 */ | 4391 */ |
| 4097 Statement parseWhileStatement() { | 4392 Statement parseWhileStatement() { |
| 4098 bool wasInLoop = _inLoop; | 4393 bool wasInLoop = _inLoop; |
| 4099 _inLoop = true; | 4394 _inLoop = true; |
| 4100 try { | 4395 try { |
| 4101 Token keyword = expect(Keyword.WHILE); | 4396 Token keyword = expect(Keyword.WHILE); |
| 4102 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); | 4397 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); |
| 4103 Expression condition = parseExpression2(); | 4398 Expression condition = parseExpression2(); |
| 4104 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); | 4399 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); |
| 4105 Statement body = parseStatement2(); | 4400 Statement body = parseStatement2(); |
| 4106 return new WhileStatement.full(keyword, leftParenthesis, condition, rightP
arenthesis, body); | 4401 return new WhileStatement.full(keyword, leftParenthesis, condition, rightP
arenthesis, body); |
| 4107 } finally { | 4402 } finally { |
| 4108 _inLoop = wasInLoop; | 4403 _inLoop = wasInLoop; |
| 4109 } | 4404 } |
| 4110 } | 4405 } |
| 4406 |
| 4111 /** | 4407 /** |
| 4112 * Parse a with clause. | 4408 * Parse a with clause. |
| 4113 * <pre> | 4409 * <pre> |
| 4114 * withClause ::= | 4410 * withClause ::= |
| 4115 * 'with' typeName (',' typeName) | 4411 * 'with' typeName (',' typeName) |
| 4116 * </pre> | 4412 * </pre> |
| 4117 * @return the with clause that was parsed | 4413 * @return the with clause that was parsed |
| 4118 */ | 4414 */ |
| 4119 WithClause parseWithClause() { | 4415 WithClause parseWithClause() { |
| 4120 Token with2 = expect(Keyword.WITH); | 4416 Token with2 = expect(Keyword.WITH); |
| 4121 List<TypeName> types = new List<TypeName>(); | 4417 List<TypeName> types = new List<TypeName>(); |
| 4122 types.add(parseTypeName()); | 4418 types.add(parseTypeName()); |
| 4123 while (optional(TokenType.COMMA)) { | 4419 while (optional(TokenType.COMMA)) { |
| 4124 types.add(parseTypeName()); | 4420 types.add(parseTypeName()); |
| 4125 } | 4421 } |
| 4126 return new WithClause.full(with2, types); | 4422 return new WithClause.full(with2, types); |
| 4127 } | 4423 } |
| 4424 |
| 4128 /** | 4425 /** |
| 4129 * Return the token that is immediately after the current token. This is equiv
alent to{@link #peek(int) peek(1)}. | 4426 * Return the token that is immediately after the current token. This is equiv
alent to{@link #peek(int) peek(1)}. |
| 4130 * @return the token that is immediately after the current token | 4427 * @return the token that is immediately after the current token |
| 4131 */ | 4428 */ |
| 4132 Token peek() => _currentToken.next; | 4429 Token peek() => _currentToken.next; |
| 4430 |
| 4133 /** | 4431 /** |
| 4134 * Return the token that is the given distance after the current token. | 4432 * Return the token that is the given distance after the current token. |
| 4135 * @param distance the number of tokens to look ahead, where {@code 0} is the
current token,{@code 1} is the next token, etc. | 4433 * @param distance the number of tokens to look ahead, where {@code 0} is the
current token,{@code 1} is the next token, etc. |
| 4136 * @return the token that is the given distance after the current token | 4434 * @return the token that is the given distance after the current token |
| 4137 */ | 4435 */ |
| 4138 Token peek2(int distance) { | 4436 Token peek2(int distance) { |
| 4139 Token token = _currentToken; | 4437 Token token = _currentToken; |
| 4140 for (int i = 0; i < distance; i++) { | 4438 for (int i = 0; i < distance; i++) { |
| 4141 token = token.next; | 4439 token = token.next; |
| 4142 } | 4440 } |
| 4143 return token; | 4441 return token; |
| 4144 } | 4442 } |
| 4443 |
| 4145 /** | 4444 /** |
| 4146 * Report an error with the given error code and arguments. | 4445 * Report an error with the given error code and arguments. |
| 4147 * @param errorCode the error code of the error to be reported | 4446 * @param errorCode the error code of the error to be reported |
| 4148 * @param node the node specifying the location of the error | 4447 * @param node the node specifying the location of the error |
| 4149 * @param arguments the arguments to the error, used to compose the error mess
age | 4448 * @param arguments the arguments to the error, used to compose the error mess
age |
| 4150 */ | 4449 */ |
| 4151 void reportError(ParserErrorCode errorCode, ASTNode node, List<Object> argumen
ts) { | 4450 void reportError(ParserErrorCode errorCode, ASTNode node, List<Object> argumen
ts) { |
| 4152 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, arguments)); | 4451 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, arguments)); |
| 4153 } | 4452 } |
| 4453 |
| 4154 /** | 4454 /** |
| 4155 * Report an error with the given error code and arguments. | 4455 * Report an error with the given error code and arguments. |
| 4156 * @param errorCode the error code of the error to be reported | 4456 * @param errorCode the error code of the error to be reported |
| 4157 * @param arguments the arguments to the error, used to compose the error mess
age | 4457 * @param arguments the arguments to the error, used to compose the error mess
age |
| 4158 */ | 4458 */ |
| 4159 void reportError4(ParserErrorCode errorCode, List<Object> arguments) { | 4459 void reportError7(ParserErrorCode errorCode, List<Object> arguments) { |
| 4160 reportError5(errorCode, _currentToken, arguments); | 4460 reportError8(errorCode, _currentToken, arguments); |
| 4161 } | 4461 } |
| 4462 |
| 4162 /** | 4463 /** |
| 4163 * Report an error with the given error code and arguments. | 4464 * Report an error with the given error code and arguments. |
| 4164 * @param errorCode the error code of the error to be reported | 4465 * @param errorCode the error code of the error to be reported |
| 4165 * @param token the token specifying the location of the error | 4466 * @param token the token specifying the location of the error |
| 4166 * @param arguments the arguments to the error, used to compose the error mess
age | 4467 * @param arguments the arguments to the error, used to compose the error mess
age |
| 4167 */ | 4468 */ |
| 4168 void reportError5(ParserErrorCode errorCode, Token token, List<Object> argumen
ts) { | 4469 void reportError8(ParserErrorCode errorCode, Token token, List<Object> argumen
ts) { |
| 4169 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, arguments)); | 4470 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, arguments)); |
| 4170 } | 4471 } |
| 4472 |
| 4171 /** | 4473 /** |
| 4172 * Parse the 'final', 'const', 'var' or type preceding a variable declaration,
starting at the | 4474 * Parse the 'final', 'const', 'var' or type preceding a variable declaration,
starting at the |
| 4173 * given token, without actually creating a type or changing the current token
. Return the token | 4475 * given token, without actually creating a type or changing the current token
. Return the token |
| 4174 * following the type that was parsed, or {@code null} if the given token is n
ot the first token | 4476 * following the type that was parsed, or {@code null} if the given token is n
ot the first token |
| 4175 * in a valid type. | 4477 * in a valid type. |
| 4176 * <pre> | 4478 * <pre> |
| 4177 * finalConstVarOrType ::= | 4479 * finalConstVarOrType ::= |
| 4178 * | 'final' type? | 4480 * | 'final' type? |
| 4179 * | 'const' type? | 4481 * | 'const' type? |
| 4180 * | 'var' | 4482 * | 'var' |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4192 } else if (matches3(startToken, Keyword.VAR)) { | 4494 } else if (matches3(startToken, Keyword.VAR)) { |
| 4193 return startToken.next; | 4495 return startToken.next; |
| 4194 } else if (matchesIdentifier2(startToken)) { | 4496 } else if (matchesIdentifier2(startToken)) { |
| 4195 Token next3 = startToken.next; | 4497 Token next3 = startToken.next; |
| 4196 if (matchesIdentifier2(next3) || matches4(next3, TokenType.LT) || matches3
(next3, Keyword.THIS) || (matches4(next3, TokenType.PERIOD) && matchesIdentifier
2(next3.next) && (matchesIdentifier2(next3.next.next) || matches4(next3.next.nex
t, TokenType.LT) || matches3(next3.next.next, Keyword.THIS)))) { | 4498 if (matchesIdentifier2(next3) || matches4(next3, TokenType.LT) || matches3
(next3, Keyword.THIS) || (matches4(next3, TokenType.PERIOD) && matchesIdentifier
2(next3.next) && (matchesIdentifier2(next3.next.next) || matches4(next3.next.nex
t, TokenType.LT) || matches3(next3.next.next, Keyword.THIS)))) { |
| 4197 return skipReturnType(startToken); | 4499 return skipReturnType(startToken); |
| 4198 } | 4500 } |
| 4199 } | 4501 } |
| 4200 return null; | 4502 return null; |
| 4201 } | 4503 } |
| 4504 |
| 4202 /** | 4505 /** |
| 4203 * Parse a list of formal parameters, starting at the given token, without act
ually creating a | 4506 * Parse a list of formal parameters, starting at the given token, without act
ually creating a |
| 4204 * formal parameter list or changing the current token. Return the token follo
wing the formal | 4507 * formal parameter list or changing the current token. Return the token follo
wing the formal |
| 4205 * parameter list that was parsed, or {@code null} if the given token is not t
he first token in a | 4508 * parameter list that was parsed, or {@code null} if the given token is not t
he first token in a |
| 4206 * valid list of formal parameter. | 4509 * valid list of formal parameter. |
| 4207 * <p> | 4510 * <p> |
| 4208 * Note that unlike other skip methods, this method uses a heuristic. In the w
orst case, the | 4511 * Note that unlike other skip methods, this method uses a heuristic. In the w
orst case, the |
| 4209 * parameters could be prefixed by metadata, which would require us to be able
to skip arbitrary | 4512 * parameters could be prefixed by metadata, which would require us to be able
to skip arbitrary |
| 4210 * expressions. Rather than duplicate the logic of most of the parse methods w
e simply look for | 4513 * expressions. Rather than duplicate the logic of most of the parse methods w
e simply look for |
| 4211 * something that is likely to be a list of parameters and then skip to return
ing the token after | 4514 * something that is likely to be a list of parameters and then skip to return
ing the token after |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4249 } | 4552 } |
| 4250 Token afterType = skipFinalConstVarOrType(next2); | 4553 Token afterType = skipFinalConstVarOrType(next2); |
| 4251 if (afterType == null) { | 4554 if (afterType == null) { |
| 4252 return null; | 4555 return null; |
| 4253 } | 4556 } |
| 4254 if (skipSimpleIdentifier(afterType) == null) { | 4557 if (skipSimpleIdentifier(afterType) == null) { |
| 4255 return null; | 4558 return null; |
| 4256 } | 4559 } |
| 4257 return skipPastMatchingToken(startToken); | 4560 return skipPastMatchingToken(startToken); |
| 4258 } | 4561 } |
| 4562 |
| 4259 /** | 4563 /** |
| 4260 * If the given token is a begin token with an associated end token, then retu
rn the token | 4564 * If the given token is a begin token with an associated end token, then retu
rn the token |
| 4261 * following the end token. Otherwise, return {@code null}. | 4565 * following the end token. Otherwise, return {@code null}. |
| 4262 * @param startToken the token that is assumed to be a being token | 4566 * @param startToken the token that is assumed to be a being token |
| 4263 * @return the token following the matching end token | 4567 * @return the token following the matching end token |
| 4264 */ | 4568 */ |
| 4265 Token skipPastMatchingToken(Token startToken) { | 4569 Token skipPastMatchingToken(Token startToken) { |
| 4266 if (startToken is! BeginToken) { | 4570 if (startToken is! BeginToken) { |
| 4267 return null; | 4571 return null; |
| 4268 } | 4572 } |
| 4269 Token closeParen = ((startToken as BeginToken)).endToken; | 4573 Token closeParen = ((startToken as BeginToken)).endToken; |
| 4270 if (closeParen == null) { | 4574 if (closeParen == null) { |
| 4271 return null; | 4575 return null; |
| 4272 } | 4576 } |
| 4273 return closeParen.next; | 4577 return closeParen.next; |
| 4274 } | 4578 } |
| 4579 |
| 4275 /** | 4580 /** |
| 4276 * Parse a prefixed identifier, starting at the given token, without actually
creating a prefixed | 4581 * Parse a prefixed identifier, starting at the given token, without actually
creating a prefixed |
| 4277 * identifier or changing the current token. Return the token following the pr
efixed identifier | 4582 * identifier or changing the current token. Return the token following the pr
efixed identifier |
| 4278 * that was parsed, or {@code null} if the given token is not the first token
in a valid prefixed | 4583 * that was parsed, or {@code null} if the given token is not the first token
in a valid prefixed |
| 4279 * identifier. | 4584 * identifier. |
| 4280 * <p> | 4585 * <p> |
| 4281 * This method must be kept in sync with {@link #parsePrefixedIdentifier()}. | 4586 * This method must be kept in sync with {@link #parsePrefixedIdentifier()}. |
| 4282 * <pre> | 4587 * <pre> |
| 4283 * prefixedIdentifier ::= | 4588 * prefixedIdentifier ::= |
| 4284 * identifier ('.' identifier)? | 4589 * identifier ('.' identifier)? |
| 4285 * </pre> | 4590 * </pre> |
| 4286 * @param startToken the token at which parsing is to begin | 4591 * @param startToken the token at which parsing is to begin |
| 4287 * @return the token following the prefixed identifier that was parsed | 4592 * @return the token following the prefixed identifier that was parsed |
| 4288 */ | 4593 */ |
| 4289 Token skipPrefixedIdentifier(Token startToken) { | 4594 Token skipPrefixedIdentifier(Token startToken) { |
| 4290 Token token = skipSimpleIdentifier(startToken); | 4595 Token token = skipSimpleIdentifier(startToken); |
| 4291 if (token == null) { | 4596 if (token == null) { |
| 4292 return null; | 4597 return null; |
| 4293 } else if (!matches4(token, TokenType.PERIOD)) { | 4598 } else if (!matches4(token, TokenType.PERIOD)) { |
| 4294 return token; | 4599 return token; |
| 4295 } | 4600 } |
| 4296 return skipSimpleIdentifier(token.next); | 4601 return skipSimpleIdentifier(token.next); |
| 4297 } | 4602 } |
| 4603 |
| 4298 /** | 4604 /** |
| 4299 * Parse a return type, starting at the given token, without actually creating
a return type or | 4605 * Parse a return type, starting at the given token, without actually creating
a return type or |
| 4300 * changing the current token. Return the token following the return type that
was parsed, or{@code null} if the given token is not the first token in a valid
return type. | 4606 * changing the current token. Return the token following the return type that
was parsed, or{@code null} if the given token is not the first token in a valid
return type. |
| 4301 * <p> | 4607 * <p> |
| 4302 * This method must be kept in sync with {@link #parseReturnType()}. | 4608 * This method must be kept in sync with {@link #parseReturnType()}. |
| 4303 * <pre> | 4609 * <pre> |
| 4304 * returnType ::= | 4610 * returnType ::= |
| 4305 * 'void' | 4611 * 'void' |
| 4306 * | type | 4612 * | type |
| 4307 * </pre> | 4613 * </pre> |
| 4308 * @param startToken the token at which parsing is to begin | 4614 * @param startToken the token at which parsing is to begin |
| 4309 * @return the token following the return type that was parsed | 4615 * @return the token following the return type that was parsed |
| 4310 */ | 4616 */ |
| 4311 Token skipReturnType(Token startToken) { | 4617 Token skipReturnType(Token startToken) { |
| 4312 if (matches3(startToken, Keyword.VOID)) { | 4618 if (matches3(startToken, Keyword.VOID)) { |
| 4313 return startToken.next; | 4619 return startToken.next; |
| 4314 } else { | 4620 } else { |
| 4315 return skipTypeName(startToken); | 4621 return skipTypeName(startToken); |
| 4316 } | 4622 } |
| 4317 } | 4623 } |
| 4624 |
| 4318 /** | 4625 /** |
| 4319 * Parse a simple identifier, starting at the given token, without actually cr
eating a simple | 4626 * Parse a simple identifier, starting at the given token, without actually cr
eating a simple |
| 4320 * identifier or changing the current token. Return the token following the si
mple identifier that | 4627 * identifier or changing the current token. Return the token following the si
mple identifier that |
| 4321 * was parsed, or {@code null} if the given token is not the first token in a
valid simple | 4628 * was parsed, or {@code null} if the given token is not the first token in a
valid simple |
| 4322 * identifier. | 4629 * identifier. |
| 4323 * <p> | 4630 * <p> |
| 4324 * This method must be kept in sync with {@link #parseSimpleIdentifier()}. | 4631 * This method must be kept in sync with {@link #parseSimpleIdentifier()}. |
| 4325 * <pre> | 4632 * <pre> |
| 4326 * identifier ::= | 4633 * identifier ::= |
| 4327 * IDENTIFIER | 4634 * IDENTIFIER |
| 4328 * </pre> | 4635 * </pre> |
| 4329 * @param startToken the token at which parsing is to begin | 4636 * @param startToken the token at which parsing is to begin |
| 4330 * @return the token following the simple identifier that was parsed | 4637 * @return the token following the simple identifier that was parsed |
| 4331 */ | 4638 */ |
| 4332 Token skipSimpleIdentifier(Token startToken) { | 4639 Token skipSimpleIdentifier(Token startToken) { |
| 4333 if (matches4(startToken, TokenType.IDENTIFIER) || (matches4(startToken, Toke
nType.KEYWORD) && ((startToken as KeywordToken)).keyword.isPseudoKeyword())) { | 4640 if (matches4(startToken, TokenType.IDENTIFIER) || (matches4(startToken, Toke
nType.KEYWORD) && ((startToken as KeywordToken)).keyword.isPseudoKeyword())) { |
| 4334 return startToken.next; | 4641 return startToken.next; |
| 4335 } | 4642 } |
| 4336 return null; | 4643 return null; |
| 4337 } | 4644 } |
| 4645 |
| 4338 /** | 4646 /** |
| 4339 * Parse a string literal that contains interpolations, starting at the given
token, without | 4647 * Parse a string literal that contains interpolations, starting at the given
token, without |
| 4340 * actually creating a string literal or changing the current token. Return th
e token following | 4648 * actually creating a string literal or changing the current token. Return th
e token following |
| 4341 * the string literal that was parsed, or {@code null} if the given token is n
ot the first token | 4649 * the string literal that was parsed, or {@code null} if the given token is n
ot the first token |
| 4342 * in a valid string literal. | 4650 * in a valid string literal. |
| 4343 * <p> | 4651 * <p> |
| 4344 * This method must be kept in sync with {@link #parseStringInterpolation(Toke
n)}. | 4652 * This method must be kept in sync with {@link #parseStringInterpolation(Toke
n)}. |
| 4345 * @param startToken the token at which parsing is to begin | 4653 * @param startToken the token at which parsing is to begin |
| 4346 * @return the string literal that was parsed | 4654 * @return the string literal that was parsed |
| 4347 */ | 4655 */ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4380 token = token.next; | 4688 token = token.next; |
| 4381 } | 4689 } |
| 4382 type2 = token.type; | 4690 type2 = token.type; |
| 4383 if (identical(type2, TokenType.STRING)) { | 4691 if (identical(type2, TokenType.STRING)) { |
| 4384 token = token.next; | 4692 token = token.next; |
| 4385 type2 = token.type; | 4693 type2 = token.type; |
| 4386 } | 4694 } |
| 4387 } | 4695 } |
| 4388 return token; | 4696 return token; |
| 4389 } | 4697 } |
| 4698 |
| 4390 /** | 4699 /** |
| 4391 * Parse a string literal, starting at the given token, without actually creat
ing a string literal | 4700 * Parse a string literal, starting at the given token, without actually creat
ing a string literal |
| 4392 * or changing the current token. Return the token following the string litera
l that was parsed, | 4701 * or changing the current token. Return the token following the string litera
l that was parsed, |
| 4393 * or {@code null} if the given token is not the first token in a valid string
literal. | 4702 * or {@code null} if the given token is not the first token in a valid string
literal. |
| 4394 * <p> | 4703 * <p> |
| 4395 * This method must be kept in sync with {@link #parseStringLiteral()}. | 4704 * This method must be kept in sync with {@link #parseStringLiteral()}. |
| 4396 * <pre> | 4705 * <pre> |
| 4397 * stringLiteral ::= | 4706 * stringLiteral ::= |
| 4398 * MULTI_LINE_STRING+ | 4707 * MULTI_LINE_STRING+ |
| 4399 * | SINGLE_LINE_STRING+ | 4708 * | SINGLE_LINE_STRING+ |
| 4400 * </pre> | 4709 * </pre> |
| 4401 * @param startToken the token at which parsing is to begin | 4710 * @param startToken the token at which parsing is to begin |
| 4402 * @return the token following the string literal that was parsed | 4711 * @return the token following the string literal that was parsed |
| 4403 */ | 4712 */ |
| 4404 Token skipStringLiteral(Token startToken) { | 4713 Token skipStringLiteral(Token startToken) { |
| 4405 Token token = startToken; | 4714 Token token = startToken; |
| 4406 while (token != null && matches4(token, TokenType.STRING)) { | 4715 while (token != null && matches4(token, TokenType.STRING)) { |
| 4407 token = token.next; | 4716 token = token.next; |
| 4408 TokenType type2 = token.type; | 4717 TokenType type2 = token.type; |
| 4409 if (identical(type2, TokenType.STRING_INTERPOLATION_EXPRESSION) || identic
al(type2, TokenType.STRING_INTERPOLATION_IDENTIFIER)) { | 4718 if (identical(type2, TokenType.STRING_INTERPOLATION_EXPRESSION) || identic
al(type2, TokenType.STRING_INTERPOLATION_IDENTIFIER)) { |
| 4410 token = skipStringInterpolation(token); | 4719 token = skipStringInterpolation(token); |
| 4411 } | 4720 } |
| 4412 } | 4721 } |
| 4413 if (identical(token, startToken)) { | 4722 if (identical(token, startToken)) { |
| 4414 return null; | 4723 return null; |
| 4415 } | 4724 } |
| 4416 return token; | 4725 return token; |
| 4417 } | 4726 } |
| 4727 |
| 4418 /** | 4728 /** |
| 4419 * Parse a list of type arguments, starting at the given token, without actual
ly creating a type argument list | 4729 * Parse a list of type arguments, starting at the given token, without actual
ly creating a type argument list |
| 4420 * or changing the current token. Return the token following the type argument
list that was parsed, | 4730 * or changing the current token. Return the token following the type argument
list that was parsed, |
| 4421 * or {@code null} if the given token is not the first token in a valid type a
rgument list. | 4731 * or {@code null} if the given token is not the first token in a valid type a
rgument list. |
| 4422 * <p> | 4732 * <p> |
| 4423 * This method must be kept in sync with {@link #parseTypeArgumentList()}. | 4733 * This method must be kept in sync with {@link #parseTypeArgumentList()}. |
| 4424 * <pre> | 4734 * <pre> |
| 4425 * typeArguments ::= | 4735 * typeArguments ::= |
| 4426 * '<' typeList '>' | 4736 * '<' typeList '>' |
| 4427 * typeList ::= | 4737 * typeList ::= |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4447 } | 4757 } |
| 4448 if (identical(token.type, TokenType.GT)) { | 4758 if (identical(token.type, TokenType.GT)) { |
| 4449 return token.next; | 4759 return token.next; |
| 4450 } else if (identical(token.type, TokenType.GT_GT)) { | 4760 } else if (identical(token.type, TokenType.GT_GT)) { |
| 4451 Token second = new Token(TokenType.GT, token.offset + 1); | 4761 Token second = new Token(TokenType.GT, token.offset + 1); |
| 4452 second.setNextWithoutSettingPrevious(token.next); | 4762 second.setNextWithoutSettingPrevious(token.next); |
| 4453 return second; | 4763 return second; |
| 4454 } | 4764 } |
| 4455 return null; | 4765 return null; |
| 4456 } | 4766 } |
| 4767 |
| 4457 /** | 4768 /** |
| 4458 * Parse a type name, starting at the given token, without actually creating a
type name or | 4769 * Parse a type name, starting at the given token, without actually creating a
type name or |
| 4459 * changing the current token. Return the token following the type name that w
as parsed, or{@code null} if the given token is not the first token in a valid t
ype name. | 4770 * changing the current token. Return the token following the type name that w
as parsed, or{@code null} if the given token is not the first token in a valid t
ype name. |
| 4460 * <p> | 4771 * <p> |
| 4461 * This method must be kept in sync with {@link #parseTypeName()}. | 4772 * This method must be kept in sync with {@link #parseTypeName()}. |
| 4462 * <pre> | 4773 * <pre> |
| 4463 * type ::= | 4774 * type ::= |
| 4464 * qualified typeArguments? | 4775 * qualified typeArguments? |
| 4465 * </pre> | 4776 * </pre> |
| 4466 * @param startToken the token at which parsing is to begin | 4777 * @param startToken the token at which parsing is to begin |
| 4467 * @return the token following the type name that was parsed | 4778 * @return the token following the type name that was parsed |
| 4468 */ | 4779 */ |
| 4469 Token skipTypeName(Token startToken) { | 4780 Token skipTypeName(Token startToken) { |
| 4470 Token token = skipPrefixedIdentifier(startToken); | 4781 Token token = skipPrefixedIdentifier(startToken); |
| 4471 if (token == null) { | 4782 if (token == null) { |
| 4472 return null; | 4783 return null; |
| 4473 } | 4784 } |
| 4474 if (matches4(token, TokenType.LT)) { | 4785 if (matches4(token, TokenType.LT)) { |
| 4475 token = skipTypeArgumentList(token); | 4786 token = skipTypeArgumentList(token); |
| 4476 } | 4787 } |
| 4477 return token; | 4788 return token; |
| 4478 } | 4789 } |
| 4790 |
| 4479 /** | 4791 /** |
| 4480 * Parse a list of type parameters, starting at the given token, without actua
lly creating a type | 4792 * Parse a list of type parameters, starting at the given token, without actua
lly creating a type |
| 4481 * parameter list or changing the current token. Return the token following th
e type parameter | 4793 * parameter list or changing the current token. Return the token following th
e type parameter |
| 4482 * list that was parsed, or {@code null} if the given token is not the first t
oken in a valid type | 4794 * list that was parsed, or {@code null} if the given token is not the first t
oken in a valid type |
| 4483 * parameter list. | 4795 * parameter list. |
| 4484 * <p> | 4796 * <p> |
| 4485 * This method must be kept in sync with {@link #parseTypeParameterList()}. | 4797 * This method must be kept in sync with {@link #parseTypeParameterList()}. |
| 4486 * <pre> | 4798 * <pre> |
| 4487 * typeParameterList ::= | 4799 * typeParameterList ::= |
| 4488 * '<' typeParameter (',' typeParameter)* '>' | 4800 * '<' typeParameter (',' typeParameter)* '>' |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4519 Token fakeEquals = new Token(TokenType.EQ, next2.offset + 2); | 4831 Token fakeEquals = new Token(TokenType.EQ, next2.offset + 2); |
| 4520 fakeEquals.setNextWithoutSettingPrevious(next2.next); | 4832 fakeEquals.setNextWithoutSettingPrevious(next2.next); |
| 4521 return fakeEquals; | 4833 return fakeEquals; |
| 4522 } | 4834 } |
| 4523 depth -= 2; | 4835 depth -= 2; |
| 4524 } | 4836 } |
| 4525 next2 = next2.next; | 4837 next2 = next2.next; |
| 4526 } | 4838 } |
| 4527 return next2; | 4839 return next2; |
| 4528 } | 4840 } |
| 4841 |
| 4529 /** | 4842 /** |
| 4530 * Translate the characters at the given index in the given string, appending
the translated | 4843 * Translate the characters at the given index in the given string, appending
the translated |
| 4531 * character to the given builder. The index is assumed to be valid. | 4844 * character to the given builder. The index is assumed to be valid. |
| 4532 * @param builder the builder to which the translated character is to be appen
ded | 4845 * @param builder the builder to which the translated character is to be appen
ded |
| 4533 * @param lexeme the string containing the character(s) to be translated | 4846 * @param lexeme the string containing the character(s) to be translated |
| 4534 * @param index the index of the character to be translated | 4847 * @param index the index of the character to be translated |
| 4535 * @return the index of the next character to be translated | 4848 * @return the index of the next character to be translated |
| 4536 */ | 4849 */ |
| 4537 int translateCharacter(JavaStringBuilder builder, String lexeme, int index) { | 4850 int translateCharacter(JavaStringBuilder builder, String lexeme, int index) { |
| 4538 int currentChar = lexeme.codeUnitAt(index); | 4851 int currentChar = lexeme.codeUnitAt(index); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4553 } else if (currentChar == 0x66) { | 4866 } else if (currentChar == 0x66) { |
| 4554 builder.appendChar(0xC); | 4867 builder.appendChar(0xC); |
| 4555 } else if (currentChar == 0x62) { | 4868 } else if (currentChar == 0x62) { |
| 4556 builder.appendChar(0x8); | 4869 builder.appendChar(0x8); |
| 4557 } else if (currentChar == 0x74) { | 4870 } else if (currentChar == 0x74) { |
| 4558 builder.appendChar(0x9); | 4871 builder.appendChar(0x9); |
| 4559 } else if (currentChar == 0x76) { | 4872 } else if (currentChar == 0x76) { |
| 4560 builder.appendChar(0xB); | 4873 builder.appendChar(0xB); |
| 4561 } else if (currentChar == 0x78) { | 4874 } else if (currentChar == 0x78) { |
| 4562 if (currentIndex + 2 >= length2) { | 4875 if (currentIndex + 2 >= length2) { |
| 4563 reportError4(ParserErrorCode.INVALID_HEX_ESCAPE, []); | 4876 reportError7(ParserErrorCode.INVALID_HEX_ESCAPE, []); |
| 4564 return length2; | 4877 return length2; |
| 4565 } | 4878 } |
| 4566 int firstDigit = lexeme.codeUnitAt(currentIndex + 1); | 4879 int firstDigit = lexeme.codeUnitAt(currentIndex + 1); |
| 4567 int secondDigit = lexeme.codeUnitAt(currentIndex + 2); | 4880 int secondDigit = lexeme.codeUnitAt(currentIndex + 2); |
| 4568 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) { | 4881 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) { |
| 4569 reportError4(ParserErrorCode.INVALID_HEX_ESCAPE, []); | 4882 reportError7(ParserErrorCode.INVALID_HEX_ESCAPE, []); |
| 4570 } else { | 4883 } else { |
| 4571 builder.appendChar((((Character.digit(firstDigit, 16) << 4) + Character.
digit(secondDigit, 16)) as int)); | 4884 builder.appendChar((((Character.digit(firstDigit, 16) << 4) + Character.
digit(secondDigit, 16)) as int)); |
| 4572 } | 4885 } |
| 4573 return currentIndex + 3; | 4886 return currentIndex + 3; |
| 4574 } else if (currentChar == 0x75) { | 4887 } else if (currentChar == 0x75) { |
| 4575 currentIndex++; | 4888 currentIndex++; |
| 4576 if (currentIndex >= length2) { | 4889 if (currentIndex >= length2) { |
| 4577 reportError4(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); | 4890 reportError7(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); |
| 4578 return length2; | 4891 return length2; |
| 4579 } | 4892 } |
| 4580 currentChar = lexeme.codeUnitAt(currentIndex); | 4893 currentChar = lexeme.codeUnitAt(currentIndex); |
| 4581 if (currentChar == 0x7B) { | 4894 if (currentChar == 0x7B) { |
| 4582 currentIndex++; | 4895 currentIndex++; |
| 4583 if (currentIndex >= length2) { | 4896 if (currentIndex >= length2) { |
| 4584 reportError4(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); | 4897 reportError7(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); |
| 4585 return length2; | 4898 return length2; |
| 4586 } | 4899 } |
| 4587 currentChar = lexeme.codeUnitAt(currentIndex); | 4900 currentChar = lexeme.codeUnitAt(currentIndex); |
| 4588 int digitCount = 0; | 4901 int digitCount = 0; |
| 4589 int value = 0; | 4902 int value = 0; |
| 4590 while (currentChar != 0x7D) { | 4903 while (currentChar != 0x7D) { |
| 4591 if (!isHexDigit(currentChar)) { | 4904 if (!isHexDigit(currentChar)) { |
| 4592 reportError4(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); | 4905 reportError7(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); |
| 4593 currentIndex++; | 4906 currentIndex++; |
| 4594 while (currentIndex < length2 && lexeme.codeUnitAt(currentIndex) !=
0x7D) { | 4907 while (currentIndex < length2 && lexeme.codeUnitAt(currentIndex) !=
0x7D) { |
| 4595 currentIndex++; | 4908 currentIndex++; |
| 4596 } | 4909 } |
| 4597 return currentIndex + 1; | 4910 return currentIndex + 1; |
| 4598 } | 4911 } |
| 4599 digitCount++; | 4912 digitCount++; |
| 4600 value = (value << 4) + Character.digit(currentChar, 16); | 4913 value = (value << 4) + Character.digit(currentChar, 16); |
| 4601 currentIndex++; | 4914 currentIndex++; |
| 4602 if (currentIndex >= length2) { | 4915 if (currentIndex >= length2) { |
| 4603 reportError4(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); | 4916 reportError7(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); |
| 4604 return length2; | 4917 return length2; |
| 4605 } | 4918 } |
| 4606 currentChar = lexeme.codeUnitAt(currentIndex); | 4919 currentChar = lexeme.codeUnitAt(currentIndex); |
| 4607 } | 4920 } |
| 4608 if (digitCount < 1 || digitCount > 6) { | 4921 if (digitCount < 1 || digitCount > 6) { |
| 4609 reportError4(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); | 4922 reportError7(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); |
| 4610 } | 4923 } |
| 4611 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va
lue, index, currentIndex); | 4924 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va
lue, index, currentIndex); |
| 4612 return currentIndex + 1; | 4925 return currentIndex + 1; |
| 4613 } else { | 4926 } else { |
| 4614 if (currentIndex + 3 >= length2) { | 4927 if (currentIndex + 3 >= length2) { |
| 4615 reportError4(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); | 4928 reportError7(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); |
| 4616 return length2; | 4929 return length2; |
| 4617 } | 4930 } |
| 4618 int firstDigit = currentChar; | 4931 int firstDigit = currentChar; |
| 4619 int secondDigit = lexeme.codeUnitAt(currentIndex + 1); | 4932 int secondDigit = lexeme.codeUnitAt(currentIndex + 1); |
| 4620 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2); | 4933 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2); |
| 4621 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3); | 4934 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3); |
| 4622 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t
hirdDigit) || !isHexDigit(fourthDigit)) { | 4935 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t
hirdDigit) || !isHexDigit(fourthDigit)) { |
| 4623 reportError4(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); | 4936 reportError7(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); |
| 4624 } else { | 4937 } else { |
| 4625 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1),
((((((Character.digit(firstDigit, 16) << 4) + Character.digit(secondDigit, 16))
<< 4) + Character.digit(thirdDigit, 16)) << 4) + Character.digit(fourthDigit, 16
)), index, currentIndex + 3); | 4938 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1),
((((((Character.digit(firstDigit, 16) << 4) + Character.digit(secondDigit, 16))
<< 4) + Character.digit(thirdDigit, 16)) << 4) + Character.digit(fourthDigit, 16
)), index, currentIndex + 3); |
| 4626 } | 4939 } |
| 4627 return currentIndex + 4; | 4940 return currentIndex + 4; |
| 4628 } | 4941 } |
| 4629 } else { | 4942 } else { |
| 4630 builder.appendChar(currentChar); | 4943 builder.appendChar(currentChar); |
| 4631 } | 4944 } |
| 4632 return currentIndex + 1; | 4945 return currentIndex + 1; |
| 4633 } | 4946 } |
| 4947 |
| 4634 /** | 4948 /** |
| 4635 * Validate that the given parameter list does not contain any field initializ
ers. | 4949 * Validate that the given parameter list does not contain any field initializ
ers. |
| 4636 * @param parameterList the parameter list to be validated | 4950 * @param parameterList the parameter list to be validated |
| 4637 */ | 4951 */ |
| 4638 void validateFormalParameterList(FormalParameterList parameterList) { | 4952 void validateFormalParameterList(FormalParameterList parameterList) { |
| 4639 for (FormalParameter parameter in parameterList.parameters) { | 4953 for (FormalParameter parameter in parameterList.parameters) { |
| 4640 if (parameter is FieldFormalParameter) { | 4954 if (parameter is FieldFormalParameter) { |
| 4641 reportError(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, ((par
ameter as FieldFormalParameter)).identifier, []); | 4955 reportError(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, ((par
ameter as FieldFormalParameter)).identifier, []); |
| 4642 } | 4956 } |
| 4643 } | 4957 } |
| 4644 } | 4958 } |
| 4959 |
| 4645 /** | 4960 /** |
| 4646 * Validate that the given set of modifiers is appropriate for a class and ret
urn the 'abstract' | 4961 * Validate that the given set of modifiers is appropriate for a class and ret
urn the 'abstract' |
| 4647 * keyword if there is one. | 4962 * keyword if there is one. |
| 4648 * @param modifiers the modifiers being validated | 4963 * @param modifiers the modifiers being validated |
| 4649 */ | 4964 */ |
| 4650 Token validateModifiersForClass(Modifiers modifiers) { | 4965 Token validateModifiersForClass(Modifiers modifiers) { |
| 4651 validateModifiersForTopLevelDeclaration(modifiers); | 4966 validateModifiersForTopLevelDeclaration(modifiers); |
| 4652 if (modifiers.constKeyword != null) { | 4967 if (modifiers.constKeyword != null) { |
| 4653 reportError5(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); | 4968 reportError8(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); |
| 4654 } | 4969 } |
| 4655 if (modifiers.externalKeyword != null) { | 4970 if (modifiers.externalKeyword != null) { |
| 4656 reportError5(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKeyword, []
); | 4971 reportError8(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKeyword, []
); |
| 4657 } | 4972 } |
| 4658 if (modifiers.finalKeyword != null) { | 4973 if (modifiers.finalKeyword != null) { |
| 4659 reportError5(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); | 4974 reportError8(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); |
| 4660 } | 4975 } |
| 4661 if (modifiers.varKeyword != null) { | 4976 if (modifiers.varKeyword != null) { |
| 4662 reportError5(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []); | 4977 reportError8(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []); |
| 4663 } | 4978 } |
| 4664 return modifiers.abstractKeyword; | 4979 return modifiers.abstractKeyword; |
| 4665 } | 4980 } |
| 4981 |
| 4666 /** | 4982 /** |
| 4667 * Validate that the given set of modifiers is appropriate for a constructor a
nd return the | 4983 * Validate that the given set of modifiers is appropriate for a constructor a
nd return the |
| 4668 * 'const' keyword if there is one. | 4984 * 'const' keyword if there is one. |
| 4669 * @param modifiers the modifiers being validated | 4985 * @param modifiers the modifiers being validated |
| 4670 * @return the 'const' or 'final' keyword associated with the constructor | 4986 * @return the 'const' or 'final' keyword associated with the constructor |
| 4671 */ | 4987 */ |
| 4672 Token validateModifiersForConstructor(Modifiers modifiers) { | 4988 Token validateModifiersForConstructor(Modifiers modifiers) { |
| 4673 if (modifiers.abstractKeyword != null) { | 4989 if (modifiers.abstractKeyword != null) { |
| 4674 reportError4(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); | 4990 reportError7(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); |
| 4675 } | 4991 } |
| 4676 if (modifiers.finalKeyword != null) { | 4992 if (modifiers.finalKeyword != null) { |
| 4677 reportError5(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword, []
); | 4993 reportError8(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword, []
); |
| 4678 } | 4994 } |
| 4679 if (modifiers.staticKeyword != null) { | 4995 if (modifiers.staticKeyword != null) { |
| 4680 reportError5(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword,
[]); | 4996 reportError8(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword,
[]); |
| 4681 } | 4997 } |
| 4682 if (modifiers.varKeyword != null) { | 4998 if (modifiers.varKeyword != null) { |
| 4683 reportError5(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifiers.varKe
yword, []); | 4999 reportError8(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifiers.varKe
yword, []); |
| 4684 } | 5000 } |
| 4685 Token externalKeyword2 = modifiers.externalKeyword; | 5001 Token externalKeyword2 = modifiers.externalKeyword; |
| 4686 Token constKeyword2 = modifiers.constKeyword; | 5002 Token constKeyword2 = modifiers.constKeyword; |
| 4687 Token factoryKeyword2 = modifiers.factoryKeyword; | 5003 Token factoryKeyword2 = modifiers.factoryKeyword; |
| 4688 if (externalKeyword2 != null && constKeyword2 != null && constKeyword2.offse
t < externalKeyword2.offset) { | 5004 if (externalKeyword2 != null && constKeyword2 != null && constKeyword2.offse
t < externalKeyword2.offset) { |
| 4689 reportError5(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword2, []); | 5005 reportError8(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword2, []); |
| 4690 } | 5006 } |
| 4691 if (externalKeyword2 != null && factoryKeyword2 != null && factoryKeyword2.o
ffset < externalKeyword2.offset) { | 5007 if (externalKeyword2 != null && factoryKeyword2 != null && factoryKeyword2.o
ffset < externalKeyword2.offset) { |
| 4692 reportError5(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeyword2, [])
; | 5008 reportError8(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeyword2, [])
; |
| 4693 } | 5009 } |
| 4694 return constKeyword2; | 5010 return constKeyword2; |
| 4695 } | 5011 } |
| 5012 |
| 4696 /** | 5013 /** |
| 4697 * Validate that the given set of modifiers is appropriate for a field and ret
urn the 'final', | 5014 * Validate that the given set of modifiers is appropriate for a field and ret
urn the 'final', |
| 4698 * 'const' or 'var' keyword if there is one. | 5015 * 'const' or 'var' keyword if there is one. |
| 4699 * @param modifiers the modifiers being validated | 5016 * @param modifiers the modifiers being validated |
| 4700 * @return the 'final', 'const' or 'var' keyword associated with the field | 5017 * @return the 'final', 'const' or 'var' keyword associated with the field |
| 4701 */ | 5018 */ |
| 4702 Token validateModifiersForField(Modifiers modifiers) { | 5019 Token validateModifiersForField(Modifiers modifiers) { |
| 4703 if (modifiers.abstractKeyword != null) { | 5020 if (modifiers.abstractKeyword != null) { |
| 4704 reportError4(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); | 5021 reportError7(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); |
| 4705 } | 5022 } |
| 4706 if (modifiers.externalKeyword != null) { | 5023 if (modifiers.externalKeyword != null) { |
| 4707 reportError5(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, []
); | 5024 reportError8(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, []
); |
| 4708 } | 5025 } |
| 4709 if (modifiers.factoryKeyword != null) { | 5026 if (modifiers.factoryKeyword != null) { |
| 4710 reportError5(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKey
word, []); | 5027 reportError8(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKey
word, []); |
| 4711 } | 5028 } |
| 4712 Token staticKeyword2 = modifiers.staticKeyword; | 5029 Token staticKeyword2 = modifiers.staticKeyword; |
| 4713 Token constKeyword2 = modifiers.constKeyword; | 5030 Token constKeyword2 = modifiers.constKeyword; |
| 4714 Token finalKeyword2 = modifiers.finalKeyword; | 5031 Token finalKeyword2 = modifiers.finalKeyword; |
| 4715 Token varKeyword2 = modifiers.varKeyword; | 5032 Token varKeyword2 = modifiers.varKeyword; |
| 4716 if (constKeyword2 != null) { | 5033 if (constKeyword2 != null) { |
| 4717 if (finalKeyword2 != null) { | 5034 if (finalKeyword2 != null) { |
| 4718 reportError5(ParserErrorCode.CONST_AND_FINAL, finalKeyword2, []); | 5035 reportError8(ParserErrorCode.CONST_AND_FINAL, finalKeyword2, []); |
| 4719 } | 5036 } |
| 4720 if (varKeyword2 != null) { | 5037 if (varKeyword2 != null) { |
| 4721 reportError5(ParserErrorCode.CONST_AND_VAR, varKeyword2, []); | 5038 reportError8(ParserErrorCode.CONST_AND_VAR, varKeyword2, []); |
| 4722 } | 5039 } |
| 4723 if (staticKeyword2 != null && constKeyword2.offset < staticKeyword2.offset
) { | 5040 if (staticKeyword2 != null && constKeyword2.offset < staticKeyword2.offset
) { |
| 4724 reportError5(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword2, []); | 5041 reportError8(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword2, []); |
| 4725 } | 5042 } |
| 4726 } else if (finalKeyword2 != null) { | 5043 } else if (finalKeyword2 != null) { |
| 4727 if (varKeyword2 != null) { | 5044 if (varKeyword2 != null) { |
| 4728 reportError5(ParserErrorCode.FINAL_AND_VAR, varKeyword2, []); | 5045 reportError8(ParserErrorCode.FINAL_AND_VAR, varKeyword2, []); |
| 4729 } | 5046 } |
| 4730 if (staticKeyword2 != null && finalKeyword2.offset < staticKeyword2.offset
) { | 5047 if (staticKeyword2 != null && finalKeyword2.offset < staticKeyword2.offset
) { |
| 4731 reportError5(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword2, []); | 5048 reportError8(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword2, []); |
| 4732 } | 5049 } |
| 4733 } else if (varKeyword2 != null && staticKeyword2 != null && varKeyword2.offs
et < staticKeyword2.offset) { | 5050 } else if (varKeyword2 != null && staticKeyword2 != null && varKeyword2.offs
et < staticKeyword2.offset) { |
| 4734 reportError5(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword2, []); | 5051 reportError8(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword2, []); |
| 4735 } | 5052 } |
| 4736 return lexicallyFirst([constKeyword2, finalKeyword2, varKeyword2]); | 5053 return lexicallyFirst([constKeyword2, finalKeyword2, varKeyword2]); |
| 4737 } | 5054 } |
| 5055 |
| 4738 /** | 5056 /** |
| 4739 * Validate that the given set of modifiers is appropriate for a getter, sette
r, or method. | 5057 * Validate that the given set of modifiers is appropriate for a getter, sette
r, or method. |
| 4740 * @param modifiers the modifiers being validated | 5058 * @param modifiers the modifiers being validated |
| 4741 */ | 5059 */ |
| 4742 void validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) { | 5060 void validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) { |
| 4743 if (modifiers.abstractKeyword != null) { | 5061 if (modifiers.abstractKeyword != null) { |
| 4744 reportError4(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); | 5062 reportError7(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); |
| 4745 } | 5063 } |
| 4746 if (modifiers.constKeyword != null) { | 5064 if (modifiers.constKeyword != null) { |
| 4747 reportError5(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); | 5065 reportError8(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); |
| 4748 } | 5066 } |
| 4749 if (modifiers.factoryKeyword != null) { | 5067 if (modifiers.factoryKeyword != null) { |
| 4750 reportError5(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKey
word, []); | 5068 reportError8(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKey
word, []); |
| 4751 } | 5069 } |
| 4752 if (modifiers.finalKeyword != null) { | 5070 if (modifiers.finalKeyword != null) { |
| 4753 reportError5(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); | 5071 reportError8(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); |
| 4754 } | 5072 } |
| 4755 if (modifiers.varKeyword != null) { | 5073 if (modifiers.varKeyword != null) { |
| 4756 reportError5(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); | 5074 reportError8(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); |
| 4757 } | 5075 } |
| 4758 Token externalKeyword2 = modifiers.externalKeyword; | 5076 Token externalKeyword2 = modifiers.externalKeyword; |
| 4759 Token staticKeyword2 = modifiers.staticKeyword; | 5077 Token staticKeyword2 = modifiers.staticKeyword; |
| 4760 if (externalKeyword2 != null && staticKeyword2 != null && staticKeyword2.off
set < externalKeyword2.offset) { | 5078 if (externalKeyword2 != null && staticKeyword2 != null && staticKeyword2.off
set < externalKeyword2.offset) { |
| 4761 reportError5(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword2, []); | 5079 reportError8(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword2, []); |
| 4762 } | 5080 } |
| 4763 } | 5081 } |
| 5082 |
| 4764 /** | 5083 /** |
| 4765 * Validate that the given set of modifiers is appropriate for a getter, sette
r, or method. | 5084 * Validate that the given set of modifiers is appropriate for a getter, sette
r, or method. |
| 4766 * @param modifiers the modifiers being validated | 5085 * @param modifiers the modifiers being validated |
| 4767 */ | 5086 */ |
| 4768 void validateModifiersForOperator(Modifiers modifiers) { | 5087 void validateModifiersForOperator(Modifiers modifiers) { |
| 4769 if (modifiers.abstractKeyword != null) { | 5088 if (modifiers.abstractKeyword != null) { |
| 4770 reportError4(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); | 5089 reportError7(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); |
| 4771 } | 5090 } |
| 4772 if (modifiers.constKeyword != null) { | 5091 if (modifiers.constKeyword != null) { |
| 4773 reportError5(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); | 5092 reportError8(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); |
| 4774 } | 5093 } |
| 4775 if (modifiers.factoryKeyword != null) { | 5094 if (modifiers.factoryKeyword != null) { |
| 4776 reportError5(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKey
word, []); | 5095 reportError8(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKey
word, []); |
| 4777 } | 5096 } |
| 4778 if (modifiers.finalKeyword != null) { | 5097 if (modifiers.finalKeyword != null) { |
| 4779 reportError5(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); | 5098 reportError8(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); |
| 4780 } | 5099 } |
| 4781 if (modifiers.staticKeyword != null) { | 5100 if (modifiers.staticKeyword != null) { |
| 4782 reportError5(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyword, [])
; | 5101 reportError8(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyword, [])
; |
| 4783 } | 5102 } |
| 4784 if (modifiers.varKeyword != null) { | 5103 if (modifiers.varKeyword != null) { |
| 4785 reportError5(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); | 5104 reportError8(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); |
| 4786 } | 5105 } |
| 4787 } | 5106 } |
| 5107 |
| 4788 /** | 5108 /** |
| 4789 * Validate that the given set of modifiers is appropriate for a top-level dec
laration. | 5109 * Validate that the given set of modifiers is appropriate for a top-level dec
laration. |
| 4790 * @param modifiers the modifiers being validated | 5110 * @param modifiers the modifiers being validated |
| 4791 */ | 5111 */ |
| 4792 void validateModifiersForTopLevelDeclaration(Modifiers modifiers) { | 5112 void validateModifiersForTopLevelDeclaration(Modifiers modifiers) { |
| 4793 if (modifiers.factoryKeyword != null) { | 5113 if (modifiers.factoryKeyword != null) { |
| 4794 reportError5(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifiers.fact
oryKeyword, []); | 5114 reportError8(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifiers.fact
oryKeyword, []); |
| 4795 } | 5115 } |
| 4796 if (modifiers.staticKeyword != null) { | 5116 if (modifiers.staticKeyword != null) { |
| 4797 reportError5(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifiers.stati
cKeyword, []); | 5117 reportError8(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifiers.stati
cKeyword, []); |
| 4798 } | 5118 } |
| 4799 } | 5119 } |
| 5120 |
| 4800 /** | 5121 /** |
| 4801 * Validate that the given set of modifiers is appropriate for a top-level fun
ction. | 5122 * Validate that the given set of modifiers is appropriate for a top-level fun
ction. |
| 4802 * @param modifiers the modifiers being validated | 5123 * @param modifiers the modifiers being validated |
| 4803 */ | 5124 */ |
| 4804 void validateModifiersForTopLevelFunction(Modifiers modifiers) { | 5125 void validateModifiersForTopLevelFunction(Modifiers modifiers) { |
| 4805 validateModifiersForTopLevelDeclaration(modifiers); | 5126 validateModifiersForTopLevelDeclaration(modifiers); |
| 4806 if (modifiers.abstractKeyword != null) { | 5127 if (modifiers.abstractKeyword != null) { |
| 4807 reportError4(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, []); | 5128 reportError7(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, []); |
| 4808 } | 5129 } |
| 4809 if (modifiers.constKeyword != null) { | 5130 if (modifiers.constKeyword != null) { |
| 4810 reportError5(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); | 5131 reportError8(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); |
| 4811 } | 5132 } |
| 4812 if (modifiers.finalKeyword != null) { | 5133 if (modifiers.finalKeyword != null) { |
| 4813 reportError5(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); | 5134 reportError8(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); |
| 4814 } | 5135 } |
| 4815 if (modifiers.varKeyword != null) { | 5136 if (modifiers.varKeyword != null) { |
| 4816 reportError5(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); | 5137 reportError8(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); |
| 4817 } | 5138 } |
| 4818 } | 5139 } |
| 5140 |
| 4819 /** | 5141 /** |
| 4820 * Validate that the given set of modifiers is appropriate for a field and ret
urn the 'final', | 5142 * Validate that the given set of modifiers is appropriate for a field and ret
urn the 'final', |
| 4821 * 'const' or 'var' keyword if there is one. | 5143 * 'const' or 'var' keyword if there is one. |
| 4822 * @param modifiers the modifiers being validated | 5144 * @param modifiers the modifiers being validated |
| 4823 * @return the 'final', 'const' or 'var' keyword associated with the field | 5145 * @return the 'final', 'const' or 'var' keyword associated with the field |
| 4824 */ | 5146 */ |
| 4825 Token validateModifiersForTopLevelVariable(Modifiers modifiers) { | 5147 Token validateModifiersForTopLevelVariable(Modifiers modifiers) { |
| 4826 validateModifiersForTopLevelDeclaration(modifiers); | 5148 validateModifiersForTopLevelDeclaration(modifiers); |
| 4827 if (modifiers.abstractKeyword != null) { | 5149 if (modifiers.abstractKeyword != null) { |
| 4828 reportError4(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, []); | 5150 reportError7(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, []); |
| 4829 } | 5151 } |
| 4830 if (modifiers.externalKeyword != null) { | 5152 if (modifiers.externalKeyword != null) { |
| 4831 reportError5(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, []
); | 5153 reportError8(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, []
); |
| 4832 } | 5154 } |
| 4833 Token constKeyword2 = modifiers.constKeyword; | 5155 Token constKeyword2 = modifiers.constKeyword; |
| 4834 Token finalKeyword2 = modifiers.finalKeyword; | 5156 Token finalKeyword2 = modifiers.finalKeyword; |
| 4835 Token varKeyword2 = modifiers.varKeyword; | 5157 Token varKeyword2 = modifiers.varKeyword; |
| 4836 if (constKeyword2 != null) { | 5158 if (constKeyword2 != null) { |
| 4837 if (finalKeyword2 != null) { | 5159 if (finalKeyword2 != null) { |
| 4838 reportError5(ParserErrorCode.CONST_AND_FINAL, finalKeyword2, []); | 5160 reportError8(ParserErrorCode.CONST_AND_FINAL, finalKeyword2, []); |
| 4839 } | 5161 } |
| 4840 if (varKeyword2 != null) { | 5162 if (varKeyword2 != null) { |
| 4841 reportError5(ParserErrorCode.CONST_AND_VAR, varKeyword2, []); | 5163 reportError8(ParserErrorCode.CONST_AND_VAR, varKeyword2, []); |
| 4842 } | 5164 } |
| 4843 } else if (finalKeyword2 != null) { | 5165 } else if (finalKeyword2 != null) { |
| 4844 if (varKeyword2 != null) { | 5166 if (varKeyword2 != null) { |
| 4845 reportError5(ParserErrorCode.FINAL_AND_VAR, varKeyword2, []); | 5167 reportError8(ParserErrorCode.FINAL_AND_VAR, varKeyword2, []); |
| 4846 } | 5168 } |
| 4847 } | 5169 } |
| 4848 return lexicallyFirst([constKeyword2, finalKeyword2, varKeyword2]); | 5170 return lexicallyFirst([constKeyword2, finalKeyword2, varKeyword2]); |
| 4849 } | 5171 } |
| 5172 |
| 4850 /** | 5173 /** |
| 4851 * Validate that the given set of modifiers is appropriate for a class and ret
urn the 'abstract' | 5174 * Validate that the given set of modifiers is appropriate for a class and ret
urn the 'abstract' |
| 4852 * keyword if there is one. | 5175 * keyword if there is one. |
| 4853 * @param modifiers the modifiers being validated | 5176 * @param modifiers the modifiers being validated |
| 4854 */ | 5177 */ |
| 4855 void validateModifiersForTypedef(Modifiers modifiers) { | 5178 void validateModifiersForTypedef(Modifiers modifiers) { |
| 4856 validateModifiersForTopLevelDeclaration(modifiers); | 5179 validateModifiersForTopLevelDeclaration(modifiers); |
| 4857 if (modifiers.abstractKeyword != null) { | 5180 if (modifiers.abstractKeyword != null) { |
| 4858 reportError5(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractKeyword,
[]); | 5181 reportError8(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractKeyword,
[]); |
| 4859 } | 5182 } |
| 4860 if (modifiers.constKeyword != null) { | 5183 if (modifiers.constKeyword != null) { |
| 4861 reportError5(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword, []); | 5184 reportError8(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword, []); |
| 4862 } | 5185 } |
| 4863 if (modifiers.externalKeyword != null) { | 5186 if (modifiers.externalKeyword != null) { |
| 4864 reportError5(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword,
[]); | 5187 reportError8(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword,
[]); |
| 4865 } | 5188 } |
| 4866 if (modifiers.finalKeyword != null) { | 5189 if (modifiers.finalKeyword != null) { |
| 4867 reportError5(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []); | 5190 reportError8(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []); |
| 4868 } | 5191 } |
| 4869 if (modifiers.varKeyword != null) { | 5192 if (modifiers.varKeyword != null) { |
| 4870 reportError5(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []); | 5193 reportError8(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []); |
| 4871 } | 5194 } |
| 4872 } | 5195 } |
| 4873 } | 5196 } |
| 4874 class KeywordToken_11 extends KeywordToken { | 5197 class KeywordToken_11 extends KeywordToken { |
| 4875 KeywordToken_11(Keyword arg0, int arg1) : super(arg0, arg1); | 5198 KeywordToken_11(Keyword arg0, int arg1) : super(arg0, arg1); |
| 4876 int get length => 0; | 5199 int get length => 0; |
| 4877 } | 5200 } |
| 4878 class AnalysisErrorListener_12 implements AnalysisErrorListener { | 5201 class AnalysisErrorListener_12 implements AnalysisErrorListener { |
| 4879 List<bool> errorFound; | 5202 List<bool> errorFound; |
| 4880 AnalysisErrorListener_12(this.errorFound); | 5203 AnalysisErrorListener_12(this.errorFound); |
| 4881 void onError(AnalysisError error) { | 5204 void onError(AnalysisError error) { |
| 4882 errorFound[0] = true; | 5205 errorFound[0] = true; |
| 4883 } | 5206 } |
| 4884 } | 5207 } |
| 5208 |
| 4885 /** | 5209 /** |
| 4886 * The enumeration {@code ParserErrorCode} defines the error codes used for erro
rs detected by the | 5210 * The enumeration {@code ParserErrorCode} defines the error codes used for erro
rs detected by the |
| 4887 * parser. The convention for this class is for the name of the error code to in
dicate the problem | 5211 * parser. The convention for this class is for the name of the error code to in
dicate the problem |
| 4888 * that caused the error to be generated and for the error message to explain wh
at is wrong and, | 5212 * that caused the error to be generated and for the error message to explain wh
at is wrong and, |
| 4889 * when appropriate, how the problem can be corrected. | 5213 * when appropriate, how the problem can be corrected. |
| 4890 * @coverage dart.engine.parser | 5214 * @coverage dart.engine.parser |
| 4891 */ | 5215 */ |
| 4892 class ParserErrorCode implements Comparable<ParserErrorCode>, ErrorCode { | 5216 class ParserErrorCode implements Comparable<ParserErrorCode>, ErrorCode { |
| 4893 static final ParserErrorCode ABSTRACT_CLASS_MEMBER = new ParserErrorCode.con2(
'ABSTRACT_CLASS_MEMBER', 0, "Members of classes cannot be declared to be 'abstra
ct'"); | 5217 static final ParserErrorCode ABSTRACT_CLASS_MEMBER = new ParserErrorCode.con2(
'ABSTRACT_CLASS_MEMBER', 0, "Members of classes cannot be declared to be 'abstra
ct'"); |
| 4894 static final ParserErrorCode ABSTRACT_STATIC_METHOD = new ParserErrorCode.con2
('ABSTRACT_STATIC_METHOD', 1, "Static methods cannot be declared to be 'abstract
'"); | 5218 static final ParserErrorCode ABSTRACT_STATIC_METHOD = new ParserErrorCode.con2
('ABSTRACT_STATIC_METHOD', 1, "Static methods cannot be declared to be 'abstract
'"); |
| 4895 static final ParserErrorCode ABSTRACT_TOP_LEVEL_FUNCTION = new ParserErrorCode
.con2('ABSTRACT_TOP_LEVEL_FUNCTION', 2, "Top-level functions cannot be declared
to be 'abstract'"); | 5219 static final ParserErrorCode ABSTRACT_TOP_LEVEL_FUNCTION = new ParserErrorCode
.con2('ABSTRACT_TOP_LEVEL_FUNCTION', 2, "Top-level functions cannot be declared
to be 'abstract'"); |
| 4896 static final ParserErrorCode ABSTRACT_TOP_LEVEL_VARIABLE = new ParserErrorCode
.con2('ABSTRACT_TOP_LEVEL_VARIABLE', 3, "Top-level variables cannot be declared
to be 'abstract'"); | 5220 static final ParserErrorCode ABSTRACT_TOP_LEVEL_VARIABLE = new ParserErrorCode
.con2('ABSTRACT_TOP_LEVEL_VARIABLE', 3, "Top-level variables cannot be declared
to be 'abstract'"); |
| 4897 static final ParserErrorCode ABSTRACT_TYPEDEF = new ParserErrorCode.con2('ABST
RACT_TYPEDEF', 4, "Type aliases cannot be declared to be 'abstract'"); | 5221 static final ParserErrorCode ABSTRACT_TYPEDEF = new ParserErrorCode.con2('ABST
RACT_TYPEDEF', 4, "Type aliases cannot be declared to be 'abstract'"); |
| 4898 static final ParserErrorCode BREAK_OUTSIDE_OF_LOOP = new ParserErrorCode.con2(
'BREAK_OUTSIDE_OF_LOOP', 5, "A break statement cannot be used outside of a loop
or switch statement"); | 5222 static final ParserErrorCode BREAK_OUTSIDE_OF_LOOP = new ParserErrorCode.con2(
'BREAK_OUTSIDE_OF_LOOP', 5, "A break statement cannot be used outside of a loop
or switch statement"); |
| 4899 static final ParserErrorCode CONST_AND_FINAL = new ParserErrorCode.con2('CONST
_AND_FINAL', 6, "Members cannot be declared to be both 'const' and 'final'"); | 5223 static final ParserErrorCode CONST_AND_FINAL = new ParserErrorCode.con2('CONST
_AND_FINAL', 6, "Members cannot be declared to be both 'const' and 'final'"); |
| 4900 static final ParserErrorCode CONST_AND_VAR = new ParserErrorCode.con2('CONST_A
ND_VAR', 7, "Members cannot be declared to be both 'const' and 'var'"); | 5224 static final ParserErrorCode CONST_AND_VAR = new ParserErrorCode.con2('CONST_A
ND_VAR', 7, "Members cannot be declared to be both 'const' and 'var'"); |
| 4901 static final ParserErrorCode CONST_CLASS = new ParserErrorCode.con2('CONST_CLA
SS', 8, "Classes cannot be declared to be 'const'"); | 5225 static final ParserErrorCode CONST_CLASS = new ParserErrorCode.con2('CONST_CLA
SS', 8, "Classes cannot be declared to be 'const'"); |
| 4902 static final ParserErrorCode CONST_METHOD = new ParserErrorCode.con2('CONST_ME
THOD', 9, "Getters, setters and methods cannot be declared to be 'const'"); | 5226 static final ParserErrorCode CONST_CONSTRUCTOR_WITH_BODY = new ParserErrorCode
.con2('CONST_CONSTRUCTOR_WITH_BODY', 9, "'const' constructors cannot have a body
"); |
| 4903 static final ParserErrorCode CONST_TYPEDEF = new ParserErrorCode.con2('CONST_T
YPEDEF', 10, "Type aliases cannot be declared to be 'const'"); | 5227 static final ParserErrorCode CONST_FACTORY = new ParserErrorCode.con2('CONST_F
ACTORY', 10, "Only redirecting factory constructors can be declared to be 'const
'"); |
| 4904 static final ParserErrorCode CONSTRUCTOR_WITH_RETURN_TYPE = new ParserErrorCod
e.con2('CONSTRUCTOR_WITH_RETURN_TYPE', 11, "Constructors cannot have a return ty
pe"); | 5228 static final ParserErrorCode CONST_METHOD = new ParserErrorCode.con2('CONST_ME
THOD', 11, "Getters, setters and methods cannot be declared to be 'const'"); |
| 4905 static final ParserErrorCode CONTINUE_OUTSIDE_OF_LOOP = new ParserErrorCode.co
n2('CONTINUE_OUTSIDE_OF_LOOP', 12, "A continue statement cannot be used outside
of a loop or switch statement"); | 5229 static final ParserErrorCode CONST_TYPEDEF = new ParserErrorCode.con2('CONST_T
YPEDEF', 12, "Type aliases cannot be declared to be 'const'"); |
| 4906 static final ParserErrorCode CONTINUE_WITHOUT_LABEL_IN_CASE = new ParserErrorC
ode.con2('CONTINUE_WITHOUT_LABEL_IN_CASE', 13, "A continue statement in a switch
statement must have a label as a target"); | 5230 static final ParserErrorCode CONSTRUCTOR_WITH_RETURN_TYPE = new ParserErrorCod
e.con2('CONSTRUCTOR_WITH_RETURN_TYPE', 13, "Constructors cannot have a return ty
pe"); |
| 4907 static final ParserErrorCode DIRECTIVE_AFTER_DECLARATION = new ParserErrorCode
.con2('DIRECTIVE_AFTER_DECLARATION', 14, "Directives must appear before any decl
arations"); | 5231 static final ParserErrorCode CONTINUE_OUTSIDE_OF_LOOP = new ParserErrorCode.co
n2('CONTINUE_OUTSIDE_OF_LOOP', 14, "A continue statement cannot be used outside
of a loop or switch statement"); |
| 4908 static final ParserErrorCode DUPLICATE_LABEL_IN_SWITCH_STATEMENT = new ParserE
rrorCode.con2('DUPLICATE_LABEL_IN_SWITCH_STATEMENT', 15, "The label %s was alrea
dy used in this switch statement"); | 5232 static final ParserErrorCode CONTINUE_WITHOUT_LABEL_IN_CASE = new ParserErrorC
ode.con2('CONTINUE_WITHOUT_LABEL_IN_CASE', 15, "A continue statement in a switch
statement must have a label as a target"); |
| 4909 static final ParserErrorCode DUPLICATED_MODIFIER = new ParserErrorCode.con2('D
UPLICATED_MODIFIER', 16, "The modifier '%s' was already specified."); | 5233 static final ParserErrorCode DEPRECATED_ARGUMENT_DEFINITION_TEST = new ParserE
rrorCode.con2('DEPRECATED_ARGUMENT_DEFINITION_TEST', 16, "The argument definitio
n test ('?' operator) has been deprecated"); |
| 4910 static final ParserErrorCode EXPECTED_CASE_OR_DEFAULT = new ParserErrorCode.co
n2('EXPECTED_CASE_OR_DEFAULT', 17, "Expected 'case' or 'default'"); | 5234 static final ParserErrorCode DIRECTIVE_AFTER_DECLARATION = new ParserErrorCode
.con2('DIRECTIVE_AFTER_DECLARATION', 17, "Directives must appear before any decl
arations"); |
| 4911 static final ParserErrorCode EXPECTED_CLASS_MEMBER = new ParserErrorCode.con2(
'EXPECTED_CLASS_MEMBER', 18, "Expected a class member"); | 5235 static final ParserErrorCode DUPLICATE_LABEL_IN_SWITCH_STATEMENT = new ParserE
rrorCode.con2('DUPLICATE_LABEL_IN_SWITCH_STATEMENT', 18, "The label %s was alrea
dy used in this switch statement"); |
| 4912 static final ParserErrorCode EXPECTED_EXECUTABLE = new ParserErrorCode.con2('E
XPECTED_EXECUTABLE', 19, "Expected a method, getter, setter or operator declarat
ion"); | 5236 static final ParserErrorCode DUPLICATED_MODIFIER = new ParserErrorCode.con2('D
UPLICATED_MODIFIER', 19, "The modifier '%s' was already specified."); |
| 4913 static final ParserErrorCode EXPECTED_LIST_OR_MAP_LITERAL = new ParserErrorCod
e.con2('EXPECTED_LIST_OR_MAP_LITERAL', 20, "Expected a list or map literal"); | 5237 static final ParserErrorCode EXPECTED_CASE_OR_DEFAULT = new ParserErrorCode.co
n2('EXPECTED_CASE_OR_DEFAULT', 20, "Expected 'case' or 'default'"); |
| 4914 static final ParserErrorCode EXPECTED_STRING_LITERAL = new ParserErrorCode.con
2('EXPECTED_STRING_LITERAL', 21, "Expected a string literal"); | 5238 static final ParserErrorCode EXPECTED_CLASS_MEMBER = new ParserErrorCode.con2(
'EXPECTED_CLASS_MEMBER', 21, "Expected a class member"); |
| 4915 static final ParserErrorCode EXPECTED_TOKEN = new ParserErrorCode.con2('EXPECT
ED_TOKEN', 22, "Expected to find '%s'"); | 5239 static final ParserErrorCode EXPECTED_EXECUTABLE = new ParserErrorCode.con2('E
XPECTED_EXECUTABLE', 22, "Expected a method, getter, setter or operator declarat
ion"); |
| 4916 static final ParserErrorCode EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE = new Parse
rErrorCode.con2('EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE', 23, "Export directives
must preceed part directives"); | 5240 static final ParserErrorCode EXPECTED_LIST_OR_MAP_LITERAL = new ParserErrorCod
e.con2('EXPECTED_LIST_OR_MAP_LITERAL', 23, "Expected a list or map literal"); |
| 4917 static final ParserErrorCode EXTERNAL_AFTER_CONST = new ParserErrorCode.con2('
EXTERNAL_AFTER_CONST', 24, "The modifier 'external' should be before the modifie
r 'const'"); | 5241 static final ParserErrorCode EXPECTED_STRING_LITERAL = new ParserErrorCode.con
2('EXPECTED_STRING_LITERAL', 24, "Expected a string literal"); |
| 4918 static final ParserErrorCode EXTERNAL_AFTER_FACTORY = new ParserErrorCode.con2
('EXTERNAL_AFTER_FACTORY', 25, "The modifier 'external' should be before the mod
ifier 'factory'"); | 5242 static final ParserErrorCode EXPECTED_TOKEN = new ParserErrorCode.con2('EXPECT
ED_TOKEN', 25, "Expected to find '%s'"); |
| 4919 static final ParserErrorCode EXTERNAL_AFTER_STATIC = new ParserErrorCode.con2(
'EXTERNAL_AFTER_STATIC', 26, "The modifier 'external' should be before the modif
ier 'static'"); | 5243 static final ParserErrorCode EXPECTED_TWO_MAP_TYPE_ARGUMENTS = new ParserError
Code.con2('EXPECTED_TWO_MAP_TYPE_ARGUMENTS', 26, "Map literal requires exactly t
wo type arguments or none, but %d found"); |
| 4920 static final ParserErrorCode EXTERNAL_CLASS = new ParserErrorCode.con2('EXTERN
AL_CLASS', 27, "Classes cannot be declared to be 'external'"); | 5244 static final ParserErrorCode EXPECTED_TYPE_NAME = new ParserErrorCode.con2('EX
PECTED_TYPE_NAME', 27, "Expected a type name"); |
| 4921 static final ParserErrorCode EXTERNAL_CONSTRUCTOR_WITH_BODY = new ParserErrorC
ode.con2('EXTERNAL_CONSTRUCTOR_WITH_BODY', 28, "External constructors cannot hav
e a body"); | 5245 static final ParserErrorCode EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE = new Parse
rErrorCode.con2('EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE', 28, "Export directives
must preceed part directives"); |
| 4922 static final ParserErrorCode EXTERNAL_FIELD = new ParserErrorCode.con2('EXTERN
AL_FIELD', 29, "Fields cannot be declared to be 'external'"); | 5246 static final ParserErrorCode EXTERNAL_AFTER_CONST = new ParserErrorCode.con2('
EXTERNAL_AFTER_CONST', 29, "The modifier 'external' should be before the modifie
r 'const'"); |
| 4923 static final ParserErrorCode EXTERNAL_GETTER_WITH_BODY = new ParserErrorCode.c
on2('EXTERNAL_GETTER_WITH_BODY', 30, "External getters cannot have a body"); | 5247 static final ParserErrorCode EXTERNAL_AFTER_FACTORY = new ParserErrorCode.con2
('EXTERNAL_AFTER_FACTORY', 30, "The modifier 'external' should be before the mod
ifier 'factory'"); |
| 4924 static final ParserErrorCode EXTERNAL_METHOD_WITH_BODY = new ParserErrorCode.c
on2('EXTERNAL_METHOD_WITH_BODY', 31, "External methods cannot have a body"); | 5248 static final ParserErrorCode EXTERNAL_AFTER_STATIC = new ParserErrorCode.con2(
'EXTERNAL_AFTER_STATIC', 31, "The modifier 'external' should be before the modif
ier 'static'"); |
| 4925 static final ParserErrorCode EXTERNAL_OPERATOR_WITH_BODY = new ParserErrorCode
.con2('EXTERNAL_OPERATOR_WITH_BODY', 32, "External operators cannot have a body"
); | 5249 static final ParserErrorCode EXTERNAL_CLASS = new ParserErrorCode.con2('EXTERN
AL_CLASS', 32, "Classes cannot be declared to be 'external'"); |
| 4926 static final ParserErrorCode EXTERNAL_SETTER_WITH_BODY = new ParserErrorCode.c
on2('EXTERNAL_SETTER_WITH_BODY', 33, "External setters cannot have a body"); | 5250 static final ParserErrorCode EXTERNAL_CONSTRUCTOR_WITH_BODY = new ParserErrorC
ode.con2('EXTERNAL_CONSTRUCTOR_WITH_BODY', 33, "External constructors cannot hav
e a body"); |
| 4927 static final ParserErrorCode EXTERNAL_TYPEDEF = new ParserErrorCode.con2('EXTE
RNAL_TYPEDEF', 34, "Type aliases cannot be declared to be 'external'"); | 5251 static final ParserErrorCode EXTERNAL_FIELD = new ParserErrorCode.con2('EXTERN
AL_FIELD', 34, "Fields cannot be declared to be 'external'"); |
| 4928 static final ParserErrorCode FACTORY_TOP_LEVEL_DECLARATION = new ParserErrorCo
de.con2('FACTORY_TOP_LEVEL_DECLARATION', 35, "Top-level declarations cannot be d
eclared to be 'factory'"); | 5252 static final ParserErrorCode EXTERNAL_GETTER_WITH_BODY = new ParserErrorCode.c
on2('EXTERNAL_GETTER_WITH_BODY', 35, "External getters cannot have a body"); |
| 4929 static final ParserErrorCode FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR = new Parse
rErrorCode.con2('FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR', 36, "Field initializers
can only be used in a constructor"); | 5253 static final ParserErrorCode EXTERNAL_METHOD_WITH_BODY = new ParserErrorCode.c
on2('EXTERNAL_METHOD_WITH_BODY', 36, "External methods cannot have a body"); |
| 4930 static final ParserErrorCode FINAL_AND_VAR = new ParserErrorCode.con2('FINAL_A
ND_VAR', 37, "Members cannot be declared to be both 'final' and 'var'"); | 5254 static final ParserErrorCode EXTERNAL_OPERATOR_WITH_BODY = new ParserErrorCode
.con2('EXTERNAL_OPERATOR_WITH_BODY', 37, "External operators cannot have a body"
); |
| 4931 static final ParserErrorCode FINAL_CLASS = new ParserErrorCode.con2('FINAL_CLA
SS', 38, "Classes cannot be declared to be 'final'"); | 5255 static final ParserErrorCode EXTERNAL_SETTER_WITH_BODY = new ParserErrorCode.c
on2('EXTERNAL_SETTER_WITH_BODY', 38, "External setters cannot have a body"); |
| 4932 static final ParserErrorCode FINAL_CONSTRUCTOR = new ParserErrorCode.con2('FIN
AL_CONSTRUCTOR', 39, "A constructor cannot be declared to be 'final'"); | 5256 static final ParserErrorCode EXTERNAL_TYPEDEF = new ParserErrorCode.con2('EXTE
RNAL_TYPEDEF', 39, "Type aliases cannot be declared to be 'external'"); |
| 4933 static final ParserErrorCode FINAL_METHOD = new ParserErrorCode.con2('FINAL_ME
THOD', 40, "Getters, setters and methods cannot be declared to be 'final'"); | 5257 static final ParserErrorCode FACTORY_TOP_LEVEL_DECLARATION = new ParserErrorCo
de.con2('FACTORY_TOP_LEVEL_DECLARATION', 40, "Top-level declarations cannot be d
eclared to be 'factory'"); |
| 4934 static final ParserErrorCode FINAL_TYPEDEF = new ParserErrorCode.con2('FINAL_T
YPEDEF', 41, "Type aliases cannot be declared to be 'final'"); | 5258 static final ParserErrorCode FACTORY_WITHOUT_BODY = new ParserErrorCode.con2('
FACTORY_WITHOUT_BODY', 41, "A non-redirecting 'factory' constructor must have a
body"); |
| 4935 static final ParserErrorCode GETTER_WITH_PARAMETERS = new ParserErrorCode.con2
('GETTER_WITH_PARAMETERS', 42, "Getter should be declared without a parameter li
st"); | 5259 static final ParserErrorCode FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR = new Parse
rErrorCode.con2('FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR', 42, "Field initializers
can only be used in a constructor"); |
| 4936 static final ParserErrorCode ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE = new Parser
ErrorCode.con2('ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE', 43, "Illegal assignment t
o non-assignable expression"); | 5260 static final ParserErrorCode FINAL_AND_VAR = new ParserErrorCode.con2('FINAL_A
ND_VAR', 43, "Members cannot be declared to be both 'final' and 'var'"); |
| 4937 static final ParserErrorCode IMPLEMENTS_BEFORE_EXTENDS = new ParserErrorCode.c
on2('IMPLEMENTS_BEFORE_EXTENDS', 44, "The extends clause must be before the impl
ements clause"); | 5261 static final ParserErrorCode FINAL_CLASS = new ParserErrorCode.con2('FINAL_CLA
SS', 44, "Classes cannot be declared to be 'final'"); |
| 4938 static final ParserErrorCode IMPLEMENTS_BEFORE_WITH = new ParserErrorCode.con2
('IMPLEMENTS_BEFORE_WITH', 45, "The with clause must be before the implements cl
ause"); | 5262 static final ParserErrorCode FINAL_CONSTRUCTOR = new ParserErrorCode.con2('FIN
AL_CONSTRUCTOR', 45, "A constructor cannot be declared to be 'final'"); |
| 4939 static final ParserErrorCode IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE = new Parse
rErrorCode.con2('IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE', 46, "Import directives
must preceed part directives"); | 5263 static final ParserErrorCode FINAL_METHOD = new ParserErrorCode.con2('FINAL_ME
THOD', 46, "Getters, setters and methods cannot be declared to be 'final'"); |
| 4940 static final ParserErrorCode INITIALIZED_VARIABLE_IN_FOR_EACH = new ParserErro
rCode.con2('INITIALIZED_VARIABLE_IN_FOR_EACH', 47, "The loop variable in a for-e
ach loop cannot be initialized"); | 5264 static final ParserErrorCode FINAL_TYPEDEF = new ParserErrorCode.con2('FINAL_T
YPEDEF', 47, "Type aliases cannot be declared to be 'final'"); |
| 4941 static final ParserErrorCode INVALID_CODE_POINT = new ParserErrorCode.con2('IN
VALID_CODE_POINT', 48, "The escape sequence '%s' is not a valid code point"); | 5265 static final ParserErrorCode GETTER_WITH_PARAMETERS = new ParserErrorCode.con2
('GETTER_WITH_PARAMETERS', 48, "Getter should be declared without a parameter li
st"); |
| 4942 static final ParserErrorCode INVALID_COMMENT_REFERENCE = new ParserErrorCode.c
on2('INVALID_COMMENT_REFERENCE', 49, "Comment references should contain a possib
ly prefixed identifier and can start with 'new', but should not contain anything
else"); | 5266 static final ParserErrorCode ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE = new Parser
ErrorCode.con2('ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE', 49, "Illegal assignment t
o non-assignable expression"); |
| 4943 static final ParserErrorCode INVALID_HEX_ESCAPE = new ParserErrorCode.con2('IN
VALID_HEX_ESCAPE', 50, "An escape sequence starting with '\\x' must be followed
by 2 hexidecimal digits"); | 5267 static final ParserErrorCode IMPLEMENTS_BEFORE_EXTENDS = new ParserErrorCode.c
on2('IMPLEMENTS_BEFORE_EXTENDS', 50, "The extends clause must be before the impl
ements clause"); |
| 4944 static final ParserErrorCode INVALID_OPERATOR = new ParserErrorCode.con2('INVA
LID_OPERATOR', 51, "The string '%s' is not a valid operator"); | 5268 static final ParserErrorCode IMPLEMENTS_BEFORE_WITH = new ParserErrorCode.con2
('IMPLEMENTS_BEFORE_WITH', 51, "The with clause must be before the implements cl
ause"); |
| 4945 static final ParserErrorCode INVALID_OPERATOR_FOR_SUPER = new ParserErrorCode.
con2('INVALID_OPERATOR_FOR_SUPER', 52, "The operator '%s' cannot be used with 's
uper'"); | 5269 static final ParserErrorCode IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE = new Parse
rErrorCode.con2('IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE', 52, "Import directives
must preceed part directives"); |
| 4946 static final ParserErrorCode INVALID_UNICODE_ESCAPE = new ParserErrorCode.con2
('INVALID_UNICODE_ESCAPE', 53, "An escape sequence starting with '\\u' must be f
ollowed by 4 hexidecimal digits or from 1 to 6 digits between '{' and '}'"); | 5270 static final ParserErrorCode INITIALIZED_VARIABLE_IN_FOR_EACH = new ParserErro
rCode.con2('INITIALIZED_VARIABLE_IN_FOR_EACH', 53, "The loop variable in a for-e
ach loop cannot be initialized"); |
| 4947 static final ParserErrorCode LIBRARY_DIRECTIVE_NOT_FIRST = new ParserErrorCode
.con2('LIBRARY_DIRECTIVE_NOT_FIRST', 54, "The library directive must appear befo
re all other directives"); | 5271 static final ParserErrorCode INVALID_CODE_POINT = new ParserErrorCode.con2('IN
VALID_CODE_POINT', 54, "The escape sequence '%s' is not a valid code point"); |
| 4948 static final ParserErrorCode MISSING_ASSIGNABLE_SELECTOR = new ParserErrorCode
.con2('MISSING_ASSIGNABLE_SELECTOR', 55, "Missing selector such as \".<identifie
r>\" or \"[0]\""); | 5272 static final ParserErrorCode INVALID_COMMENT_REFERENCE = new ParserErrorCode.c
on2('INVALID_COMMENT_REFERENCE', 55, "Comment references should contain a possib
ly prefixed identifier and can start with 'new', but should not contain anything
else"); |
| 4949 static final ParserErrorCode MISSING_CATCH_OR_FINALLY = new ParserErrorCode.co
n2('MISSING_CATCH_OR_FINALLY', 56, "A try statement must have either a catch or
finally clause"); | 5273 static final ParserErrorCode INVALID_HEX_ESCAPE = new ParserErrorCode.con2('IN
VALID_HEX_ESCAPE', 56, "An escape sequence starting with '\\x' must be followed
by 2 hexidecimal digits"); |
| 4950 static final ParserErrorCode MISSING_CLASS_BODY = new ParserErrorCode.con2('MI
SSING_CLASS_BODY', 57, "A class definition must have a body, even if it is empty
"); | 5274 static final ParserErrorCode INVALID_OPERATOR = new ParserErrorCode.con2('INVA
LID_OPERATOR', 57, "The string '%s' is not a valid operator"); |
| 4951 static final ParserErrorCode MISSING_CLOSING_PARENTHESIS = new ParserErrorCode
.con2('MISSING_CLOSING_PARENTHESIS', 58, "The closing parenthesis is missing"); | 5275 static final ParserErrorCode INVALID_OPERATOR_FOR_SUPER = new ParserErrorCode.
con2('INVALID_OPERATOR_FOR_SUPER', 58, "The operator '%s' cannot be used with 's
uper'"); |
| 4952 static final ParserErrorCode MISSING_CONST_FINAL_VAR_OR_TYPE = new ParserError
Code.con2('MISSING_CONST_FINAL_VAR_OR_TYPE', 59, "Variables must be declared usi
ng the keywords 'const', 'final', 'var' or a type name"); | 5276 static final ParserErrorCode INVALID_UNICODE_ESCAPE = new ParserErrorCode.con2
('INVALID_UNICODE_ESCAPE', 59, "An escape sequence starting with '\\u' must be f
ollowed by 4 hexidecimal digits or from 1 to 6 digits between '{' and '}'"); |
| 4953 static final ParserErrorCode MISSING_EXPRESSION_IN_THROW = new ParserErrorCode
.con2('MISSING_EXPRESSION_IN_THROW', 60, "Throw expressions must compute the obj
ect to be thrown"); | 5277 static final ParserErrorCode LIBRARY_DIRECTIVE_NOT_FIRST = new ParserErrorCode
.con2('LIBRARY_DIRECTIVE_NOT_FIRST', 60, "The library directive must appear befo
re all other directives"); |
| 4954 static final ParserErrorCode MISSING_FUNCTION_BODY = new ParserErrorCode.con2(
'MISSING_FUNCTION_BODY', 61, "A function body must be provided"); | 5278 static final ParserErrorCode MISSING_ASSIGNABLE_SELECTOR = new ParserErrorCode
.con2('MISSING_ASSIGNABLE_SELECTOR', 61, "Missing selector such as \".<identifie
r>\" or \"[0]\""); |
| 4955 static final ParserErrorCode MISSING_FUNCTION_PARAMETERS = new ParserErrorCode
.con2('MISSING_FUNCTION_PARAMETERS', 62, "Functions must have an explicit list o
f parameters"); | 5279 static final ParserErrorCode MISSING_CATCH_OR_FINALLY = new ParserErrorCode.co
n2('MISSING_CATCH_OR_FINALLY', 62, "A try statement must have either a catch or
finally clause"); |
| 4956 static final ParserErrorCode MISSING_IDENTIFIER = new ParserErrorCode.con2('MI
SSING_IDENTIFIER', 63, "Expected an identifier"); | 5280 static final ParserErrorCode MISSING_CLASS_BODY = new ParserErrorCode.con2('MI
SSING_CLASS_BODY', 63, "A class definition must have a body, even if it is empty
"); |
| 4957 static final ParserErrorCode MISSING_KEYWORD_OPERATOR = new ParserErrorCode.co
n2('MISSING_KEYWORD_OPERATOR', 64, "Operator declarations must be preceeded by t
he keyword 'operator'"); | 5281 static final ParserErrorCode MISSING_CLOSING_PARENTHESIS = new ParserErrorCode
.con2('MISSING_CLOSING_PARENTHESIS', 64, "The closing parenthesis is missing"); |
| 4958 static final ParserErrorCode MISSING_NAME_IN_LIBRARY_DIRECTIVE = new ParserErr
orCode.con2('MISSING_NAME_IN_LIBRARY_DIRECTIVE', 65, "Library directives must in
clude a library name"); | 5282 static final ParserErrorCode MISSING_CONST_FINAL_VAR_OR_TYPE = new ParserError
Code.con2('MISSING_CONST_FINAL_VAR_OR_TYPE', 65, "Variables must be declared usi
ng the keywords 'const', 'final', 'var' or a type name"); |
| 4959 static final ParserErrorCode MISSING_NAME_IN_PART_OF_DIRECTIVE = new ParserErr
orCode.con2('MISSING_NAME_IN_PART_OF_DIRECTIVE', 66, "Library directives must in
clude a library name"); | 5283 static final ParserErrorCode MISSING_EXPRESSION_IN_THROW = new ParserErrorCode
.con2('MISSING_EXPRESSION_IN_THROW', 66, "Throw expressions must compute the obj
ect to be thrown"); |
| 4960 static final ParserErrorCode MISSING_STATEMENT = new ParserErrorCode.con2('MIS
SING_STATEMENT', 67, "Expected a statement"); | 5284 static final ParserErrorCode MISSING_FUNCTION_BODY = new ParserErrorCode.con2(
'MISSING_FUNCTION_BODY', 67, "A function body must be provided"); |
| 4961 static final ParserErrorCode MISSING_TERMINATOR_FOR_PARAMETER_GROUP = new Pars
erErrorCode.con2('MISSING_TERMINATOR_FOR_PARAMETER_GROUP', 68, "There is no '%s'
to close the parameter group"); | 5285 static final ParserErrorCode MISSING_FUNCTION_PARAMETERS = new ParserErrorCode
.con2('MISSING_FUNCTION_PARAMETERS', 68, "Functions must have an explicit list o
f parameters"); |
| 4962 static final ParserErrorCode MISSING_TYPEDEF_PARAMETERS = new ParserErrorCode.
con2('MISSING_TYPEDEF_PARAMETERS', 69, "Type aliases for functions must have an
explicit list of parameters"); | 5286 static final ParserErrorCode MISSING_IDENTIFIER = new ParserErrorCode.con2('MI
SSING_IDENTIFIER', 69, "Expected an identifier"); |
| 4963 static final ParserErrorCode MISSING_VARIABLE_IN_FOR_EACH = new ParserErrorCod
e.con2('MISSING_VARIABLE_IN_FOR_EACH', 70, "A loop variable must be declared in
a for-each loop before the 'in', but none were found"); | 5287 static final ParserErrorCode MISSING_KEYWORD_OPERATOR = new ParserErrorCode.co
n2('MISSING_KEYWORD_OPERATOR', 70, "Operator declarations must be preceeded by t
he keyword 'operator'"); |
| 4964 static final ParserErrorCode MIXED_PARAMETER_GROUPS = new ParserErrorCode.con2
('MIXED_PARAMETER_GROUPS', 71, "Cannot have both positional and named parameters
in a single parameter list"); | 5288 static final ParserErrorCode MISSING_NAME_IN_LIBRARY_DIRECTIVE = new ParserErr
orCode.con2('MISSING_NAME_IN_LIBRARY_DIRECTIVE', 71, "Library directives must in
clude a library name"); |
| 4965 static final ParserErrorCode MULTIPLE_EXTENDS_CLAUSES = new ParserErrorCode.co
n2('MULTIPLE_EXTENDS_CLAUSES', 72, "Each class definition can have at most one e
xtends clause"); | 5289 static final ParserErrorCode MISSING_NAME_IN_PART_OF_DIRECTIVE = new ParserErr
orCode.con2('MISSING_NAME_IN_PART_OF_DIRECTIVE', 72, "Library directives must in
clude a library name"); |
| 4966 static final ParserErrorCode MULTIPLE_IMPLEMENTS_CLAUSES = new ParserErrorCode
.con2('MULTIPLE_IMPLEMENTS_CLAUSES', 73, "Each class definition can have at most
one implements clause"); | 5290 static final ParserErrorCode MISSING_STATEMENT = new ParserErrorCode.con2('MIS
SING_STATEMENT', 73, "Expected a statement"); |
| 4967 static final ParserErrorCode MULTIPLE_LIBRARY_DIRECTIVES = new ParserErrorCode
.con2('MULTIPLE_LIBRARY_DIRECTIVES', 74, "Only one library directive may be decl
ared in a file"); | 5291 static final ParserErrorCode MISSING_TERMINATOR_FOR_PARAMETER_GROUP = new Pars
erErrorCode.con2('MISSING_TERMINATOR_FOR_PARAMETER_GROUP', 74, "There is no '%s'
to close the parameter group"); |
| 4968 static final ParserErrorCode MULTIPLE_NAMED_PARAMETER_GROUPS = new ParserError
Code.con2('MULTIPLE_NAMED_PARAMETER_GROUPS', 75, "Cannot have multiple groups of
named parameters in a single parameter list"); | 5292 static final ParserErrorCode MISSING_TYPEDEF_PARAMETERS = new ParserErrorCode.
con2('MISSING_TYPEDEF_PARAMETERS', 75, "Type aliases for functions must have an
explicit list of parameters"); |
| 4969 static final ParserErrorCode MULTIPLE_PART_OF_DIRECTIVES = new ParserErrorCode
.con2('MULTIPLE_PART_OF_DIRECTIVES', 76, "Only one part-of directive may be decl
ared in a file"); | 5293 static final ParserErrorCode MISSING_VARIABLE_IN_FOR_EACH = new ParserErrorCod
e.con2('MISSING_VARIABLE_IN_FOR_EACH', 76, "A loop variable must be declared in
a for-each loop before the 'in', but none were found"); |
| 4970 static final ParserErrorCode MULTIPLE_POSITIONAL_PARAMETER_GROUPS = new Parser
ErrorCode.con2('MULTIPLE_POSITIONAL_PARAMETER_GROUPS', 77, "Cannot have multiple
groups of positional parameters in a single parameter list"); | 5294 static final ParserErrorCode MIXED_PARAMETER_GROUPS = new ParserErrorCode.con2
('MIXED_PARAMETER_GROUPS', 77, "Cannot have both positional and named parameters
in a single parameter list"); |
| 4971 static final ParserErrorCode MULTIPLE_VARIABLES_IN_FOR_EACH = new ParserErrorC
ode.con2('MULTIPLE_VARIABLES_IN_FOR_EACH', 78, "A single loop variable must be d
eclared in a for-each loop before the 'in', but %s were found"); | 5295 static final ParserErrorCode MULTIPLE_EXTENDS_CLAUSES = new ParserErrorCode.co
n2('MULTIPLE_EXTENDS_CLAUSES', 78, "Each class definition can have at most one e
xtends clause"); |
| 4972 static final ParserErrorCode MULTIPLE_WITH_CLAUSES = new ParserErrorCode.con2(
'MULTIPLE_WITH_CLAUSES', 79, "Each class definition can have at most one with cl
ause"); | 5296 static final ParserErrorCode MULTIPLE_IMPLEMENTS_CLAUSES = new ParserErrorCode
.con2('MULTIPLE_IMPLEMENTS_CLAUSES', 79, "Each class definition can have at most
one implements clause"); |
| 4973 static final ParserErrorCode NAMED_FUNCTION_EXPRESSION = new ParserErrorCode.c
on2('NAMED_FUNCTION_EXPRESSION', 80, "Function expressions cannot be named"); | 5297 static final ParserErrorCode MULTIPLE_LIBRARY_DIRECTIVES = new ParserErrorCode
.con2('MULTIPLE_LIBRARY_DIRECTIVES', 80, "Only one library directive may be decl
ared in a file"); |
| 4974 static final ParserErrorCode NAMED_PARAMETER_OUTSIDE_GROUP = new ParserErrorCo
de.con2('NAMED_PARAMETER_OUTSIDE_GROUP', 81, "Named parameters must be enclosed
in curly braces ('{' and '}')"); | 5298 static final ParserErrorCode MULTIPLE_NAMED_PARAMETER_GROUPS = new ParserError
Code.con2('MULTIPLE_NAMED_PARAMETER_GROUPS', 81, "Cannot have multiple groups of
named parameters in a single parameter list"); |
| 4975 static final ParserErrorCode NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE = new Parser
ErrorCode.con2('NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE', 82, "Native functions can
only be declared in the SDK and code that is loaded through native extensions")
; | 5299 static final ParserErrorCode MULTIPLE_PART_OF_DIRECTIVES = new ParserErrorCode
.con2('MULTIPLE_PART_OF_DIRECTIVES', 82, "Only one part-of directive may be decl
ared in a file"); |
| 4976 static final ParserErrorCode NON_CONSTRUCTOR_FACTORY = new ParserErrorCode.con
2('NON_CONSTRUCTOR_FACTORY', 83, "Only constructors can be declared to be a 'fac
tory'"); | 5300 static final ParserErrorCode MULTIPLE_POSITIONAL_PARAMETER_GROUPS = new Parser
ErrorCode.con2('MULTIPLE_POSITIONAL_PARAMETER_GROUPS', 83, "Cannot have multiple
groups of positional parameters in a single parameter list"); |
| 4977 static final ParserErrorCode NON_IDENTIFIER_LIBRARY_NAME = new ParserErrorCode
.con2('NON_IDENTIFIER_LIBRARY_NAME', 84, "The name of a library must be an ident
ifier"); | 5301 static final ParserErrorCode MULTIPLE_VARIABLES_IN_FOR_EACH = new ParserErrorC
ode.con2('MULTIPLE_VARIABLES_IN_FOR_EACH', 84, "A single loop variable must be d
eclared in a for-each loop before the 'in', but %s were found"); |
| 4978 static final ParserErrorCode NON_PART_OF_DIRECTIVE_IN_PART = new ParserErrorCo
de.con2('NON_PART_OF_DIRECTIVE_IN_PART', 85, "The part-of directive must be the
only directive in a part"); | 5302 static final ParserErrorCode MULTIPLE_WITH_CLAUSES = new ParserErrorCode.con2(
'MULTIPLE_WITH_CLAUSES', 85, "Each class definition can have at most one with cl
ause"); |
| 4979 static final ParserErrorCode NON_USER_DEFINABLE_OPERATOR = new ParserErrorCode
.con2('NON_USER_DEFINABLE_OPERATOR', 86, "The operator '%s' is not user definabl
e"); | 5303 static final ParserErrorCode NAMED_FUNCTION_EXPRESSION = new ParserErrorCode.c
on2('NAMED_FUNCTION_EXPRESSION', 86, "Function expressions cannot be named"); |
| 4980 static final ParserErrorCode POSITIONAL_AFTER_NAMED_ARGUMENT = new ParserError
Code.con2('POSITIONAL_AFTER_NAMED_ARGUMENT', 87, "Positional arguments must occu
r before named arguments"); | 5304 static final ParserErrorCode NAMED_PARAMETER_OUTSIDE_GROUP = new ParserErrorCo
de.con2('NAMED_PARAMETER_OUTSIDE_GROUP', 87, "Named parameters must be enclosed
in curly braces ('{' and '}')"); |
| 4981 static final ParserErrorCode POSITIONAL_PARAMETER_OUTSIDE_GROUP = new ParserEr
rorCode.con2('POSITIONAL_PARAMETER_OUTSIDE_GROUP', 88, "Positional parameters mu
st be enclosed in square brackets ('[' and ']')"); | 5305 static final ParserErrorCode NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE = new Parser
ErrorCode.con2('NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE', 88, "Native functions can
only be declared in the SDK and code that is loaded through native extensions")
; |
| 4982 static final ParserErrorCode STATIC_AFTER_CONST = new ParserErrorCode.con2('ST
ATIC_AFTER_CONST', 89, "The modifier 'static' should be before the modifier 'con
st'"); | 5306 static final ParserErrorCode NON_CONSTRUCTOR_FACTORY = new ParserErrorCode.con
2('NON_CONSTRUCTOR_FACTORY', 89, "Only constructors can be declared to be a 'fac
tory'"); |
| 4983 static final ParserErrorCode STATIC_AFTER_FINAL = new ParserErrorCode.con2('ST
ATIC_AFTER_FINAL', 90, "The modifier 'static' should be before the modifier 'fin
al'"); | 5307 static final ParserErrorCode NON_IDENTIFIER_LIBRARY_NAME = new ParserErrorCode
.con2('NON_IDENTIFIER_LIBRARY_NAME', 90, "The name of a library must be an ident
ifier"); |
| 4984 static final ParserErrorCode STATIC_AFTER_VAR = new ParserErrorCode.con2('STAT
IC_AFTER_VAR', 91, "The modifier 'static' should be before the modifier 'var'"); | 5308 static final ParserErrorCode NON_PART_OF_DIRECTIVE_IN_PART = new ParserErrorCo
de.con2('NON_PART_OF_DIRECTIVE_IN_PART', 91, "The part-of directive must be the
only directive in a part"); |
| 4985 static final ParserErrorCode STATIC_CONSTRUCTOR = new ParserErrorCode.con2('ST
ATIC_CONSTRUCTOR', 92, "Constructors cannot be static"); | 5309 static final ParserErrorCode NON_USER_DEFINABLE_OPERATOR = new ParserErrorCode
.con2('NON_USER_DEFINABLE_OPERATOR', 92, "The operator '%s' is not user definabl
e"); |
| 4986 static final ParserErrorCode STATIC_OPERATOR = new ParserErrorCode.con2('STATI
C_OPERATOR', 93, "Operators cannot be static"); | 5310 static final ParserErrorCode POSITIONAL_AFTER_NAMED_ARGUMENT = new ParserError
Code.con2('POSITIONAL_AFTER_NAMED_ARGUMENT', 93, "Positional arguments must occu
r before named arguments"); |
| 4987 static final ParserErrorCode STATIC_TOP_LEVEL_DECLARATION = new ParserErrorCod
e.con2('STATIC_TOP_LEVEL_DECLARATION', 94, "Top-level declarations cannot be dec
lared to be 'static'"); | 5311 static final ParserErrorCode POSITIONAL_PARAMETER_OUTSIDE_GROUP = new ParserEr
rorCode.con2('POSITIONAL_PARAMETER_OUTSIDE_GROUP', 94, "Positional parameters mu
st be enclosed in square brackets ('[' and ']')"); |
| 4988 static final ParserErrorCode SWITCH_HAS_CASE_AFTER_DEFAULT_CASE = new ParserEr
rorCode.con2('SWITCH_HAS_CASE_AFTER_DEFAULT_CASE', 95, "The 'default' case shoul
d be the last case in a switch statement"); | 5312 static final ParserErrorCode STATIC_AFTER_CONST = new ParserErrorCode.con2('ST
ATIC_AFTER_CONST', 95, "The modifier 'static' should be before the modifier 'con
st'"); |
| 4989 static final ParserErrorCode SWITCH_HAS_MULTIPLE_DEFAULT_CASES = new ParserErr
orCode.con2('SWITCH_HAS_MULTIPLE_DEFAULT_CASES', 96, "The 'default' case can onl
y be declared once"); | 5313 static final ParserErrorCode STATIC_AFTER_FINAL = new ParserErrorCode.con2('ST
ATIC_AFTER_FINAL', 96, "The modifier 'static' should be before the modifier 'fin
al'"); |
| 4990 static final ParserErrorCode TOP_LEVEL_OPERATOR = new ParserErrorCode.con2('TO
P_LEVEL_OPERATOR', 97, "Operators must be declared within a class"); | 5314 static final ParserErrorCode STATIC_AFTER_VAR = new ParserErrorCode.con2('STAT
IC_AFTER_VAR', 97, "The modifier 'static' should be before the modifier 'var'"); |
| 4991 static final ParserErrorCode UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP = new P
arserErrorCode.con2('UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP', 98, "There is n
o '%s' to open a parameter group"); | 5315 static final ParserErrorCode STATIC_CONSTRUCTOR = new ParserErrorCode.con2('ST
ATIC_CONSTRUCTOR', 98, "Constructors cannot be static"); |
| 4992 static final ParserErrorCode UNEXPECTED_TOKEN = new ParserErrorCode.con2('UNEX
PECTED_TOKEN', 99, "Unexpected token '%s'"); | 5316 static final ParserErrorCode STATIC_GETTER_WITHOUT_BODY = new ParserErrorCode.
con2('STATIC_GETTER_WITHOUT_BODY', 99, "A 'static' getter must have a body"); |
| 4993 static final ParserErrorCode USE_OF_UNARY_PLUS_OPERATOR = new ParserErrorCode.
con2('USE_OF_UNARY_PLUS_OPERATOR', 100, "There is no unary plus operator in Dart
"); | 5317 static final ParserErrorCode STATIC_OPERATOR = new ParserErrorCode.con2('STATI
C_OPERATOR', 100, "Operators cannot be static"); |
| 4994 static final ParserErrorCode WITH_BEFORE_EXTENDS = new ParserErrorCode.con2('W
ITH_BEFORE_EXTENDS', 101, "The extends clause must be before the with clause"); | 5318 static final ParserErrorCode STATIC_SETTER_WITHOUT_BODY = new ParserErrorCode.
con2('STATIC_SETTER_WITHOUT_BODY', 101, "A 'static' setter must have a body"); |
| 4995 static final ParserErrorCode WITH_WITHOUT_EXTENDS = new ParserErrorCode.con2('
WITH_WITHOUT_EXTENDS', 102, "The with clause cannot be used without an extends c
lause"); | 5319 static final ParserErrorCode STATIC_TOP_LEVEL_DECLARATION = new ParserErrorCod
e.con2('STATIC_TOP_LEVEL_DECLARATION', 102, "Top-level declarations cannot be de
clared to be 'static'"); |
| 4996 static final ParserErrorCode WRONG_SEPARATOR_FOR_NAMED_PARAMETER = new ParserE
rrorCode.con2('WRONG_SEPARATOR_FOR_NAMED_PARAMETER', 103, "The default value of
a named parameter should be preceeded by ':'"); | 5320 static final ParserErrorCode SWITCH_HAS_CASE_AFTER_DEFAULT_CASE = new ParserEr
rorCode.con2('SWITCH_HAS_CASE_AFTER_DEFAULT_CASE', 103, "The 'default' case shou
ld be the last case in a switch statement"); |
| 4997 static final ParserErrorCode WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER = new Pa
rserErrorCode.con2('WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER', 104, "The default
value of a positional parameter should be preceeded by '='"); | 5321 static final ParserErrorCode SWITCH_HAS_MULTIPLE_DEFAULT_CASES = new ParserErr
orCode.con2('SWITCH_HAS_MULTIPLE_DEFAULT_CASES', 104, "The 'default' case can on
ly be declared once"); |
| 4998 static final ParserErrorCode WRONG_TERMINATOR_FOR_PARAMETER_GROUP = new Parser
ErrorCode.con2('WRONG_TERMINATOR_FOR_PARAMETER_GROUP', 105, "Expected '%s' to cl
ose parameter group"); | 5322 static final ParserErrorCode TOP_LEVEL_OPERATOR = new ParserErrorCode.con2('TO
P_LEVEL_OPERATOR', 105, "Operators must be declared within a class"); |
| 4999 static final ParserErrorCode VAR_CLASS = new ParserErrorCode.con2('VAR_CLASS',
106, "Classes cannot be declared to be 'var'"); | 5323 static final ParserErrorCode UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP = new P
arserErrorCode.con2('UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP', 106, "There is
no '%s' to open a parameter group"); |
| 5000 static final ParserErrorCode VAR_RETURN_TYPE = new ParserErrorCode.con2('VAR_R
ETURN_TYPE', 107, "The return type cannot be 'var'"); | 5324 static final ParserErrorCode UNEXPECTED_TOKEN = new ParserErrorCode.con2('UNEX
PECTED_TOKEN', 107, "Unexpected token '%s'"); |
| 5001 static final ParserErrorCode VAR_TYPEDEF = new ParserErrorCode.con2('VAR_TYPED
EF', 108, "Type aliases cannot be declared to be 'var'"); | 5325 static final ParserErrorCode WITH_BEFORE_EXTENDS = new ParserErrorCode.con2('W
ITH_BEFORE_EXTENDS', 108, "The extends clause must be before the with clause"); |
| 5002 static final ParserErrorCode VOID_PARAMETER = new ParserErrorCode.con2('VOID_P
ARAMETER', 109, "Parameters cannot have a type of 'void'"); | 5326 static final ParserErrorCode WITH_WITHOUT_EXTENDS = new ParserErrorCode.con2('
WITH_WITHOUT_EXTENDS', 109, "The with clause cannot be used without an extends c
lause"); |
| 5003 static final ParserErrorCode VOID_VARIABLE = new ParserErrorCode.con2('VOID_VA
RIABLE', 110, "Variables cannot have a type of 'void'"); | 5327 static final ParserErrorCode WRONG_SEPARATOR_FOR_NAMED_PARAMETER = new ParserE
rrorCode.con2('WRONG_SEPARATOR_FOR_NAMED_PARAMETER', 110, "The default value of
a named parameter should be preceeded by ':'"); |
| 5004 static final List<ParserErrorCode> values = [ABSTRACT_CLASS_MEMBER, ABSTRACT_S
TATIC_METHOD, ABSTRACT_TOP_LEVEL_FUNCTION, ABSTRACT_TOP_LEVEL_VARIABLE, ABSTRACT
_TYPEDEF, BREAK_OUTSIDE_OF_LOOP, CONST_AND_FINAL, CONST_AND_VAR, CONST_CLASS, CO
NST_METHOD, CONST_TYPEDEF, CONSTRUCTOR_WITH_RETURN_TYPE, CONTINUE_OUTSIDE_OF_LOO
P, CONTINUE_WITHOUT_LABEL_IN_CASE, DIRECTIVE_AFTER_DECLARATION, DUPLICATE_LABEL_
IN_SWITCH_STATEMENT, DUPLICATED_MODIFIER, EXPECTED_CASE_OR_DEFAULT, EXPECTED_CLA
SS_MEMBER, EXPECTED_EXECUTABLE, EXPECTED_LIST_OR_MAP_LITERAL, EXPECTED_STRING_LI
TERAL, EXPECTED_TOKEN, EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, EXTERNAL_AFTER_CON
ST, EXTERNAL_AFTER_FACTORY, EXTERNAL_AFTER_STATIC, EXTERNAL_CLASS, EXTERNAL_CONS
TRUCTOR_WITH_BODY, EXTERNAL_FIELD, EXTERNAL_GETTER_WITH_BODY, EXTERNAL_METHOD_WI
TH_BODY, EXTERNAL_OPERATOR_WITH_BODY, EXTERNAL_SETTER_WITH_BODY, EXTERNAL_TYPEDE
F, FACTORY_TOP_LEVEL_DECLARATION, FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, FINAL_A
ND_VAR, FINAL_CLASS, FINAL_CONSTRUCTOR, FINAL_METHOD, FINAL_TYPEDEF, GETTER_WITH
_PARAMETERS, ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, IMPLEMENTS_BEFORE_EXTENDS, IM
PLEMENTS_BEFORE_WITH, IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, INITIALIZED_VARIABL
E_IN_FOR_EACH, INVALID_CODE_POINT, INVALID_COMMENT_REFERENCE, INVALID_HEX_ESCAPE
, INVALID_OPERATOR, INVALID_OPERATOR_FOR_SUPER, INVALID_UNICODE_ESCAPE, LIBRARY_
DIRECTIVE_NOT_FIRST, MISSING_ASSIGNABLE_SELECTOR, MISSING_CATCH_OR_FINALLY, MISS
ING_CLASS_BODY, MISSING_CLOSING_PARENTHESIS, MISSING_CONST_FINAL_VAR_OR_TYPE, MI
SSING_EXPRESSION_IN_THROW, MISSING_FUNCTION_BODY, MISSING_FUNCTION_PARAMETERS, M
ISSING_IDENTIFIER, MISSING_KEYWORD_OPERATOR, MISSING_NAME_IN_LIBRARY_DIRECTIVE,
MISSING_NAME_IN_PART_OF_DIRECTIVE, MISSING_STATEMENT, MISSING_TERMINATOR_FOR_PAR
AMETER_GROUP, MISSING_TYPEDEF_PARAMETERS, MISSING_VARIABLE_IN_FOR_EACH, MIXED_PA
RAMETER_GROUPS, MULTIPLE_EXTENDS_CLAUSES, MULTIPLE_IMPLEMENTS_CLAUSES, MULTIPLE_
LIBRARY_DIRECTIVES, MULTIPLE_NAMED_PARAMETER_GROUPS, MULTIPLE_PART_OF_DIRECTIVES
, MULTIPLE_POSITIONAL_PARAMETER_GROUPS, MULTIPLE_VARIABLES_IN_FOR_EACH, MULTIPLE
_WITH_CLAUSES, NAMED_FUNCTION_EXPRESSION, NAMED_PARAMETER_OUTSIDE_GROUP, NATIVE_
FUNCTION_BODY_IN_NON_SDK_CODE, NON_CONSTRUCTOR_FACTORY, NON_IDENTIFIER_LIBRARY_N
AME, NON_PART_OF_DIRECTIVE_IN_PART, NON_USER_DEFINABLE_OPERATOR, POSITIONAL_AFTE
R_NAMED_ARGUMENT, POSITIONAL_PARAMETER_OUTSIDE_GROUP, STATIC_AFTER_CONST, STATIC
_AFTER_FINAL, STATIC_AFTER_VAR, STATIC_CONSTRUCTOR, STATIC_OPERATOR, STATIC_TOP_
LEVEL_DECLARATION, SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, SWITCH_HAS_MULTIPLE_DEFAU
LT_CASES, TOP_LEVEL_OPERATOR, UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP, UNEXPEC
TED_TOKEN, USE_OF_UNARY_PLUS_OPERATOR, WITH_BEFORE_EXTENDS, WITH_WITHOUT_EXTENDS
, WRONG_SEPARATOR_FOR_NAMED_PARAMETER, WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER,
WRONG_TERMINATOR_FOR_PARAMETER_GROUP, VAR_CLASS, VAR_RETURN_TYPE, VAR_TYPEDEF,
VOID_PARAMETER, VOID_VARIABLE]; | 5328 static final ParserErrorCode WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER = new Pa
rserErrorCode.con2('WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER', 111, "The default
value of a positional parameter should be preceeded by '='"); |
| 5005 String __name; | 5329 static final ParserErrorCode WRONG_TERMINATOR_FOR_PARAMETER_GROUP = new Parser
ErrorCode.con2('WRONG_TERMINATOR_FOR_PARAMETER_GROUP', 112, "Expected '%s' to cl
ose parameter group"); |
| 5006 int __ordinal = 0; | 5330 static final ParserErrorCode VAR_AS_TYPE_NAME = new ParserErrorCode.con2('VAR_
AS_TYPE_NAME', 113, "The keyword 'var' cannot be used as a type name"); |
| 5007 int get ordinal => __ordinal; | 5331 static final ParserErrorCode VAR_CLASS = new ParserErrorCode.con2('VAR_CLASS',
114, "Classes cannot be declared to be 'var'"); |
| 5332 static final ParserErrorCode VAR_RETURN_TYPE = new ParserErrorCode.con2('VAR_R
ETURN_TYPE', 115, "The return type cannot be 'var'"); |
| 5333 static final ParserErrorCode VAR_TYPEDEF = new ParserErrorCode.con2('VAR_TYPED
EF', 116, "Type aliases cannot be declared to be 'var'"); |
| 5334 static final ParserErrorCode VOID_PARAMETER = new ParserErrorCode.con2('VOID_P
ARAMETER', 117, "Parameters cannot have a type of 'void'"); |
| 5335 static final ParserErrorCode VOID_VARIABLE = new ParserErrorCode.con2('VOID_VA
RIABLE', 118, "Variables cannot have a type of 'void'"); |
| 5336 static final List<ParserErrorCode> values = [ABSTRACT_CLASS_MEMBER, ABSTRACT_S
TATIC_METHOD, ABSTRACT_TOP_LEVEL_FUNCTION, ABSTRACT_TOP_LEVEL_VARIABLE, ABSTRACT
_TYPEDEF, BREAK_OUTSIDE_OF_LOOP, CONST_AND_FINAL, CONST_AND_VAR, CONST_CLASS, CO
NST_CONSTRUCTOR_WITH_BODY, CONST_FACTORY, CONST_METHOD, CONST_TYPEDEF, CONSTRUCT
OR_WITH_RETURN_TYPE, CONTINUE_OUTSIDE_OF_LOOP, CONTINUE_WITHOUT_LABEL_IN_CASE, D
EPRECATED_ARGUMENT_DEFINITION_TEST, DIRECTIVE_AFTER_DECLARATION, DUPLICATE_LABEL
_IN_SWITCH_STATEMENT, DUPLICATED_MODIFIER, EXPECTED_CASE_OR_DEFAULT, EXPECTED_CL
ASS_MEMBER, EXPECTED_EXECUTABLE, EXPECTED_LIST_OR_MAP_LITERAL, EXPECTED_STRING_L
ITERAL, EXPECTED_TOKEN, EXPECTED_TWO_MAP_TYPE_ARGUMENTS, EXPECTED_TYPE_NAME, EXP
ORT_DIRECTIVE_AFTER_PART_DIRECTIVE, EXTERNAL_AFTER_CONST, EXTERNAL_AFTER_FACTORY
, EXTERNAL_AFTER_STATIC, EXTERNAL_CLASS, EXTERNAL_CONSTRUCTOR_WITH_BODY, EXTERNA
L_FIELD, EXTERNAL_GETTER_WITH_BODY, EXTERNAL_METHOD_WITH_BODY, EXTERNAL_OPERATOR
_WITH_BODY, EXTERNAL_SETTER_WITH_BODY, EXTERNAL_TYPEDEF, FACTORY_TOP_LEVEL_DECLA
RATION, FACTORY_WITHOUT_BODY, FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, FINAL_AND_V
AR, FINAL_CLASS, FINAL_CONSTRUCTOR, FINAL_METHOD, FINAL_TYPEDEF, GETTER_WITH_PAR
AMETERS, ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, IMPLEMENTS_BEFORE_EXTENDS, IMPLEM
ENTS_BEFORE_WITH, IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, INITIALIZED_VARIABLE_IN
_FOR_EACH, INVALID_CODE_POINT, INVALID_COMMENT_REFERENCE, INVALID_HEX_ESCAPE, IN
VALID_OPERATOR, INVALID_OPERATOR_FOR_SUPER, INVALID_UNICODE_ESCAPE, LIBRARY_DIRE
CTIVE_NOT_FIRST, MISSING_ASSIGNABLE_SELECTOR, MISSING_CATCH_OR_FINALLY, MISSING_
CLASS_BODY, MISSING_CLOSING_PARENTHESIS, MISSING_CONST_FINAL_VAR_OR_TYPE, MISSIN
G_EXPRESSION_IN_THROW, MISSING_FUNCTION_BODY, MISSING_FUNCTION_PARAMETERS, MISSI
NG_IDENTIFIER, MISSING_KEYWORD_OPERATOR, MISSING_NAME_IN_LIBRARY_DIRECTIVE, MISS
ING_NAME_IN_PART_OF_DIRECTIVE, MISSING_STATEMENT, MISSING_TERMINATOR_FOR_PARAMET
ER_GROUP, MISSING_TYPEDEF_PARAMETERS, MISSING_VARIABLE_IN_FOR_EACH, MIXED_PARAME
TER_GROUPS, MULTIPLE_EXTENDS_CLAUSES, MULTIPLE_IMPLEMENTS_CLAUSES, MULTIPLE_LIBR
ARY_DIRECTIVES, MULTIPLE_NAMED_PARAMETER_GROUPS, MULTIPLE_PART_OF_DIRECTIVES, MU
LTIPLE_POSITIONAL_PARAMETER_GROUPS, MULTIPLE_VARIABLES_IN_FOR_EACH, MULTIPLE_WIT
H_CLAUSES, NAMED_FUNCTION_EXPRESSION, NAMED_PARAMETER_OUTSIDE_GROUP, NATIVE_FUNC
TION_BODY_IN_NON_SDK_CODE, NON_CONSTRUCTOR_FACTORY, NON_IDENTIFIER_LIBRARY_NAME,
NON_PART_OF_DIRECTIVE_IN_PART, NON_USER_DEFINABLE_OPERATOR, POSITIONAL_AFTER_NA
MED_ARGUMENT, POSITIONAL_PARAMETER_OUTSIDE_GROUP, STATIC_AFTER_CONST, STATIC_AFT
ER_FINAL, STATIC_AFTER_VAR, STATIC_CONSTRUCTOR, STATIC_GETTER_WITHOUT_BODY, STAT
IC_OPERATOR, STATIC_SETTER_WITHOUT_BODY, STATIC_TOP_LEVEL_DECLARATION, SWITCH_HA
S_CASE_AFTER_DEFAULT_CASE, SWITCH_HAS_MULTIPLE_DEFAULT_CASES, TOP_LEVEL_OPERATOR
, UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP, UNEXPECTED_TOKEN, WITH_BEFORE_EXTEN
DS, WITH_WITHOUT_EXTENDS, WRONG_SEPARATOR_FOR_NAMED_PARAMETER, WRONG_SEPARATOR_F
OR_POSITIONAL_PARAMETER, WRONG_TERMINATOR_FOR_PARAMETER_GROUP, VAR_AS_TYPE_NAME,
VAR_CLASS, VAR_RETURN_TYPE, VAR_TYPEDEF, VOID_PARAMETER, VOID_VARIABLE]; |
| 5337 |
| 5338 /// The name of this enum constant, as declared in the enum declaration. |
| 5339 final String name; |
| 5340 |
| 5341 /// The position in the enum declaration. |
| 5342 final int ordinal; |
| 5343 |
| 5008 /** | 5344 /** |
| 5009 * The severity of this error. | 5345 * The severity of this error. |
| 5010 */ | 5346 */ |
| 5011 ErrorSeverity _severity; | 5347 ErrorSeverity _severity; |
| 5348 |
| 5012 /** | 5349 /** |
| 5013 * The message template used to create the message to be displayed for this er
ror. | 5350 * The message template used to create the message to be displayed for this er
ror. |
| 5014 */ | 5351 */ |
| 5015 String _message; | 5352 String _message; |
| 5353 |
| 5016 /** | 5354 /** |
| 5017 * Initialize a newly created error code to have the given severity and messag
e. | 5355 * Initialize a newly created error code to have the given severity and messag
e. |
| 5018 * @param severity the severity of the error | 5356 * @param severity the severity of the error |
| 5019 * @param message the message template used to create the message to be displa
yed for the error | 5357 * @param message the message template used to create the message to be displa
yed for the error |
| 5020 */ | 5358 */ |
| 5021 ParserErrorCode.con1(String ___name, int ___ordinal, ErrorSeverity severity2,
String message2) { | 5359 ParserErrorCode.con1(this.name, this.ordinal, ErrorSeverity severity2, String
message2) { |
| 5022 _jtd_constructor_302_impl(___name, ___ordinal, severity2, message2); | 5360 _jtd_constructor_309_impl(severity2, message2); |
| 5023 } | 5361 } |
| 5024 _jtd_constructor_302_impl(String ___name, int ___ordinal, ErrorSeverity severi
ty2, String message2) { | 5362 _jtd_constructor_309_impl(ErrorSeverity severity2, String message2) { |
| 5025 __name = ___name; | |
| 5026 __ordinal = ___ordinal; | |
| 5027 this._severity = severity2; | 5363 this._severity = severity2; |
| 5028 this._message = message2; | 5364 this._message = message2; |
| 5029 } | 5365 } |
| 5366 |
| 5030 /** | 5367 /** |
| 5031 * Initialize a newly created error code to have the given message and a sever
ity of ERROR. | 5368 * Initialize a newly created error code to have the given message and a sever
ity of ERROR. |
| 5032 * @param message the message template used to create the message to be displa
yed for the error | 5369 * @param message the message template used to create the message to be displa
yed for the error |
| 5033 */ | 5370 */ |
| 5034 ParserErrorCode.con2(String ___name, int ___ordinal, String message) { | 5371 ParserErrorCode.con2(this.name, this.ordinal, String message) { |
| 5035 _jtd_constructor_303_impl(___name, ___ordinal, message); | 5372 _jtd_constructor_310_impl(message); |
| 5036 } | 5373 } |
| 5037 _jtd_constructor_303_impl(String ___name, int ___ordinal, String message) { | 5374 _jtd_constructor_310_impl(String message) { |
| 5038 _jtd_constructor_302_impl(___name, ___ordinal, ErrorSeverity.ERROR, message)
; | 5375 _jtd_constructor_309_impl(ErrorSeverity.ERROR, message); |
| 5039 } | 5376 } |
| 5040 ErrorSeverity get errorSeverity => _severity; | 5377 ErrorSeverity get errorSeverity => _severity; |
| 5041 String get message => _message; | 5378 String get message => _message; |
| 5042 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 5379 ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
| 5043 bool needsRecompilation() => true; | 5380 int compareTo(ParserErrorCode other) => ordinal - other.ordinal; |
| 5044 int compareTo(ParserErrorCode other) => __ordinal - other.__ordinal; | 5381 String toString() => name; |
| 5045 String toString() => __name; | |
| 5046 } | 5382 } |
| 5383 |
| 5047 /** | 5384 /** |
| 5048 * Instances of the class {link ToFormattedSourceVisitor} write a source represe
ntation of a visited | 5385 * Instances of the class {link ToFormattedSourceVisitor} write a source represe
ntation of a visited |
| 5049 * AST node (and all of it's children) to a writer. | 5386 * AST node (and all of it's children) to a writer. |
| 5050 */ | 5387 */ |
| 5051 class ToFormattedSourceVisitor implements ASTVisitor<Object> { | 5388 class ToFormattedSourceVisitor implements ASTVisitor<Object> { |
| 5389 |
| 5052 /** | 5390 /** |
| 5053 * The writer to which the source is to be written. | 5391 * The writer to which the source is to be written. |
| 5054 */ | 5392 */ |
| 5055 PrintWriter _writer; | 5393 PrintWriter _writer; |
| 5056 int _indentLevel = 0; | 5394 int _indentLevel = 0; |
| 5057 String _indentString = ""; | 5395 String _indentString = ""; |
| 5396 |
| 5058 /** | 5397 /** |
| 5059 * Initialize a newly created visitor to write source code representing the vi
sited nodes to the | 5398 * Initialize a newly created visitor to write source code representing the vi
sited nodes to the |
| 5060 * given writer. | 5399 * given writer. |
| 5061 * @param writer the writer to which the source is to be written | 5400 * @param writer the writer to which the source is to be written |
| 5062 */ | 5401 */ |
| 5063 ToFormattedSourceVisitor(PrintWriter writer) { | 5402 ToFormattedSourceVisitor(PrintWriter writer) { |
| 5064 this._writer = writer; | 5403 this._writer = writer; |
| 5065 } | 5404 } |
| 5066 Object visitAdjacentStrings(AdjacentStrings node) { | 5405 Object visitAdjacentStrings(AdjacentStrings node) { |
| 5067 visitList5(node.strings, " "); | 5406 visitList5(node.strings, " "); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5192 _writer.print(";"); | 5531 _writer.print(";"); |
| 5193 return null; | 5532 return null; |
| 5194 } | 5533 } |
| 5195 Object visitComment(Comment node) { | 5534 Object visitComment(Comment node) { |
| 5196 Token token = node.beginToken; | 5535 Token token = node.beginToken; |
| 5197 while (token != null) { | 5536 while (token != null) { |
| 5198 bool firstLine = true; | 5537 bool firstLine = true; |
| 5199 for (String line in StringUtils.split(token.lexeme, "\n")) { | 5538 for (String line in StringUtils.split(token.lexeme, "\n")) { |
| 5200 if (firstLine) { | 5539 if (firstLine) { |
| 5201 firstLine = false; | 5540 firstLine = false; |
| 5541 if (node.isDocumentation()) { |
| 5542 nl2(); |
| 5543 } |
| 5202 } else { | 5544 } else { |
| 5203 line = " ${line.trim()}"; | 5545 line = " ${line.trim()}"; |
| 5204 line = StringUtils.replace(line, "/*", "/ *"); | 5546 line = StringUtils.replace(line, "/*", "/ *"); |
| 5205 } | 5547 } |
| 5206 _writer.print(line); | 5548 _writer.print(line); |
| 5207 nl2(); | 5549 nl2(); |
| 5208 } | 5550 } |
| 5209 if (identical(token, node.endToken)) { | 5551 if (identical(token, node.endToken)) { |
| 5210 break; | 5552 break; |
| 5211 } | 5553 } |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5809 _indentLevel += 2; | 6151 _indentLevel += 2; |
| 5810 _indentString = StringUtils.repeat(" ", _indentLevel); | 6152 _indentString = StringUtils.repeat(" ", _indentLevel); |
| 5811 } | 6153 } |
| 5812 void nl() { | 6154 void nl() { |
| 5813 _writer.print("\n"); | 6155 _writer.print("\n"); |
| 5814 } | 6156 } |
| 5815 void nl2() { | 6157 void nl2() { |
| 5816 nl(); | 6158 nl(); |
| 5817 indent(); | 6159 indent(); |
| 5818 } | 6160 } |
| 6161 |
| 5819 /** | 6162 /** |
| 5820 * Safely visit the given node. | 6163 * Safely visit the given node. |
| 5821 * @param node the node to be visited | 6164 * @param node the node to be visited |
| 5822 */ | 6165 */ |
| 5823 void visit(ASTNode node) { | 6166 void visit(ASTNode node) { |
| 5824 if (node != null) { | 6167 if (node != null) { |
| 5825 node.accept(this); | 6168 node.accept(this); |
| 5826 } | 6169 } |
| 5827 } | 6170 } |
| 6171 |
| 5828 /** | 6172 /** |
| 5829 * Safely visit the given node, printing the suffix after the node if it is no
n-<code>null</code>. | 6173 * Safely visit the given node, printing the suffix after the node if it is no
n-<code>null</code>. |
| 5830 * @param suffix the suffix to be printed if there is a node to visit | 6174 * @param suffix the suffix to be printed if there is a node to visit |
| 5831 * @param node the node to be visited | 6175 * @param node the node to be visited |
| 5832 */ | 6176 */ |
| 5833 void visit6(ASTNode node, String suffix) { | 6177 void visit6(ASTNode node, String suffix) { |
| 5834 if (node != null) { | 6178 if (node != null) { |
| 5835 node.accept(this); | 6179 node.accept(this); |
| 5836 _writer.print(suffix); | 6180 _writer.print(suffix); |
| 5837 } | 6181 } |
| 5838 } | 6182 } |
| 6183 |
| 5839 /** | 6184 /** |
| 5840 * Safely visit the given node, printing the prefix before the node if it is n
on-<code>null</code> | 6185 * Safely visit the given node, printing the prefix before the node if it is n
on-<code>null</code> |
| 5841 * . | 6186 * . |
| 5842 * @param prefix the prefix to be printed if there is a node to visit | 6187 * @param prefix the prefix to be printed if there is a node to visit |
| 5843 * @param node the node to be visited | 6188 * @param node the node to be visited |
| 5844 */ | 6189 */ |
| 5845 void visit7(String prefix, ASTNode node) { | 6190 void visit7(String prefix, ASTNode node) { |
| 5846 if (node != null) { | 6191 if (node != null) { |
| 5847 _writer.print(prefix); | 6192 _writer.print(prefix); |
| 5848 node.accept(this); | 6193 node.accept(this); |
| 5849 } | 6194 } |
| 5850 } | 6195 } |
| 6196 |
| 5851 /** | 6197 /** |
| 5852 * Safely visit the given node, printing the suffix after the node if it is no
n-<code>null</code>. | 6198 * Safely visit the given node, printing the suffix after the node if it is no
n-<code>null</code>. |
| 5853 * @param suffix the suffix to be printed if there is a node to visit | 6199 * @param suffix the suffix to be printed if there is a node to visit |
| 5854 * @param node the node to be visited | 6200 * @param node the node to be visited |
| 5855 */ | 6201 */ |
| 5856 void visit8(Token token, String suffix) { | 6202 void visit8(Token token, String suffix) { |
| 5857 if (token != null) { | 6203 if (token != null) { |
| 5858 _writer.print(token.lexeme); | 6204 _writer.print(token.lexeme); |
| 5859 _writer.print(suffix); | 6205 _writer.print(suffix); |
| 5860 } | 6206 } |
| 5861 } | 6207 } |
| 6208 |
| 5862 /** | 6209 /** |
| 5863 * Print a list of nodes without any separation. | 6210 * Print a list of nodes without any separation. |
| 5864 * @param nodes the nodes to be printed | 6211 * @param nodes the nodes to be printed |
| 5865 * @param separator the separator to be printed between adjacent nodes | 6212 * @param separator the separator to be printed between adjacent nodes |
| 5866 */ | 6213 */ |
| 5867 void visitList(NodeList<ASTNode> nodes) { | 6214 void visitList(NodeList<ASTNode> nodes) { |
| 5868 visitList5(nodes, ""); | 6215 visitList5(nodes, ""); |
| 5869 } | 6216 } |
| 6217 |
| 5870 /** | 6218 /** |
| 5871 * Print a list of nodes, separated by the given separator. | 6219 * Print a list of nodes, separated by the given separator. |
| 5872 * @param nodes the nodes to be printed | 6220 * @param nodes the nodes to be printed |
| 5873 * @param separator the separator to be printed between adjacent nodes | 6221 * @param separator the separator to be printed between adjacent nodes |
| 5874 */ | 6222 */ |
| 5875 void visitList5(NodeList<ASTNode> nodes, String separator) { | 6223 void visitList5(NodeList<ASTNode> nodes, String separator) { |
| 5876 if (nodes != null) { | 6224 if (nodes != null) { |
| 5877 int size2 = nodes.length; | 6225 int size2 = nodes.length; |
| 5878 for (int i = 0; i < size2; i++) { | 6226 for (int i = 0; i < size2; i++) { |
| 5879 if ("\n" == separator) { | 6227 if ("\n" == separator) { |
| 5880 _writer.print("\n"); | 6228 _writer.print("\n"); |
| 5881 indent(); | 6229 indent(); |
| 5882 } else if (i > 0) { | 6230 } else if (i > 0) { |
| 5883 _writer.print(separator); | 6231 _writer.print(separator); |
| 5884 } | 6232 } |
| 5885 nodes[i].accept(this); | 6233 nodes[i].accept(this); |
| 5886 } | 6234 } |
| 5887 } | 6235 } |
| 5888 } | 6236 } |
| 6237 |
| 5889 /** | 6238 /** |
| 5890 * Print a list of nodes, separated by the given separator. | 6239 * Print a list of nodes, separated by the given separator. |
| 5891 * @param nodes the nodes to be printed | 6240 * @param nodes the nodes to be printed |
| 5892 * @param separator the separator to be printed between adjacent nodes | 6241 * @param separator the separator to be printed between adjacent nodes |
| 5893 * @param suffix the suffix to be printed if the list is not empty | 6242 * @param suffix the suffix to be printed if the list is not empty |
| 5894 */ | 6243 */ |
| 5895 void visitList6(NodeList<ASTNode> nodes, String separator, String suffix) { | 6244 void visitList6(NodeList<ASTNode> nodes, String separator, String suffix) { |
| 5896 if (nodes != null) { | 6245 if (nodes != null) { |
| 5897 int size2 = nodes.length; | 6246 int size2 = nodes.length; |
| 5898 if (size2 > 0) { | 6247 if (size2 > 0) { |
| 5899 for (int i = 0; i < size2; i++) { | 6248 for (int i = 0; i < size2; i++) { |
| 5900 if (i > 0) { | 6249 if (i > 0) { |
| 5901 _writer.print(separator); | 6250 _writer.print(separator); |
| 5902 } | 6251 } |
| 5903 nodes[i].accept(this); | 6252 nodes[i].accept(this); |
| 5904 } | 6253 } |
| 5905 _writer.print(suffix); | 6254 _writer.print(suffix); |
| 5906 } | 6255 } |
| 5907 } | 6256 } |
| 5908 } | 6257 } |
| 6258 |
| 5909 /** | 6259 /** |
| 5910 * Print a list of nodes, separated by the given separator. | 6260 * Print a list of nodes, separated by the given separator. |
| 5911 * @param prefix the prefix to be printed if the list is not empty | 6261 * @param prefix the prefix to be printed if the list is not empty |
| 5912 * @param nodes the nodes to be printed | 6262 * @param nodes the nodes to be printed |
| 5913 * @param separator the separator to be printed between adjacent nodes | 6263 * @param separator the separator to be printed between adjacent nodes |
| 5914 */ | 6264 */ |
| 5915 void visitList7(String prefix, NodeList<ASTNode> nodes, String separator) { | 6265 void visitList7(String prefix, NodeList<ASTNode> nodes, String separator) { |
| 5916 if (nodes != null) { | 6266 if (nodes != null) { |
| 5917 int size2 = nodes.length; | 6267 int size2 = nodes.length; |
| 5918 if (size2 > 0) { | 6268 if (size2 > 0) { |
| 5919 _writer.print(prefix); | 6269 _writer.print(prefix); |
| 5920 for (int i = 0; i < size2; i++) { | 6270 for (int i = 0; i < size2; i++) { |
| 5921 if (i > 0) { | 6271 if (i > 0) { |
| 5922 _writer.print(separator); | 6272 _writer.print(separator); |
| 5923 } | 6273 } |
| 5924 nodes[i].accept(this); | 6274 nodes[i].accept(this); |
| 5925 } | 6275 } |
| 5926 } | 6276 } |
| 5927 } | 6277 } |
| 5928 } | 6278 } |
| 5929 } | 6279 } |
| OLD | NEW |