OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // CHANGES: |
| 6 // |
| 7 // v1.0 First version available in the SDK github repository. Covers the |
| 8 // Dart language as specified in the language specification based on the |
| 9 // many grammar rule snippets. That grammar was then adjusted to remove |
| 10 // known issues (e.g., misplaced metadata) and to resolve ambiguities. |
| 11 // HERE! |
| 12 |
| 13 grammar Dart; |
| 14 |
| 15 /* |
| 16 options { |
| 17 backtrack=true; |
| 18 memoize=true; |
| 19 } |
| 20 */ |
| 21 |
| 22 @parser::header{ |
| 23 import java.util.Stack; |
| 24 } |
| 25 |
| 26 @lexer::header{ |
| 27 import java.util.Stack; |
| 28 } |
| 29 |
| 30 @parser::members { |
| 31 public static String filePath = null; |
| 32 public static boolean filePathHasBeenPrinted = true; |
| 33 |
| 34 // Grammar debugging friendly output, 'The Definitive ANTLR Reference', p247. |
| 35 public String getErrorMessage(RecognitionException e, String[] tokenNames) { |
| 36 List stack = getRuleInvocationStack(e, this.getClass().getName()); |
| 37 String msg = null; |
| 38 if ( e instanceof NoViableAltException ) { |
| 39 NoViableAltException nvae = (NoViableAltException)e; |
| 40 msg = "no viable alt; token=" + e.token + |
| 41 " (decision=" + nvae.decisionNumber + |
| 42 " state " + nvae.stateNumber + ")" + |
| 43 " decision=<<" + nvae.grammarDecisionDescription + ">>"; |
| 44 } |
| 45 else { |
| 46 msg = super.getErrorMessage(e, tokenNames); |
| 47 } |
| 48 if (!filePathHasBeenPrinted) { |
| 49 filePathHasBeenPrinted = true; |
| 50 System.err.println(">>> Parse error in " + filePath + ":"); |
| 51 } |
| 52 return stack + " " + msg; |
| 53 } |
| 54 |
| 55 public String getTokenErrorDisplay(Token t) { |
| 56 return t.toString(); |
| 57 } |
| 58 |
| 59 // Enable the parser to treat ASYNC/AWAIT/YIELD as keywords in the body of an |
| 60 // `async`, `async*`, or `sync*` function. Access via methods below. |
| 61 private Stack<Boolean> asyncEtcAreKeywords = new Stack<Boolean>(); |
| 62 { asyncEtcAreKeywords.push(false); } |
| 63 |
| 64 // Use this to indicate that we are now entering an `async`, `async*`, |
| 65 // or `sync*` function. |
| 66 void startAsyncFunction() { asyncEtcAreKeywords.push(true); } |
| 67 |
| 68 // Use this to indicate that we are now entering a function which is |
| 69 // neither `async`, `async*`, nor `sync*`. |
| 70 void startNonAsyncFunction() { asyncEtcAreKeywords.push(false); } |
| 71 |
| 72 // Use this to indicate that we are now leaving any funciton. |
| 73 void endFunction() { asyncEtcAreKeywords.pop(); } |
| 74 |
| 75 // Whether we can recognize ASYNC/AWAIT/YIELD as an identifier/typeIdentifier. |
| 76 boolean asyncEtcPredicate(int tokenId) { |
| 77 if (tokenId == ASYNC || tokenId == AWAIT || tokenId == YIELD) { |
| 78 return !asyncEtcAreKeywords.peek(); |
| 79 } |
| 80 return false; |
| 81 } |
| 82 |
| 83 // Debugging support methods. |
| 84 void dp(int indent, String method, String sep) { |
| 85 for (int i = 0; i < indent; i++) { |
| 86 System.out.print(" "); |
| 87 } |
| 88 System.out.println(method + sep + " " + input.LT(1) + " " + state.failed); |
| 89 } |
| 90 |
| 91 void dpBegin(int indent, String method) { dp(indent, method, ":"); } |
| 92 void dpEnd(int indent, String method) { dp(indent, method, " END:"); } |
| 93 void dpCall(int indent, String method) { dp(indent, method, "?"); } |
| 94 void dpCalled(int indent, String method) { dp(indent, method, ".."); } |
| 95 void dpResult(int indent, String method) { dp(indent, method, "!"); } |
| 96 } |
| 97 |
| 98 @lexer::members{ |
| 99 public static final int BRACE_NORMAL = 1; |
| 100 public static final int BRACE_SINGLE = 2; |
| 101 public static final int BRACE_DOUBLE = 3; |
| 102 public static final int BRACE_THREE_SINGLE = 4; |
| 103 public static final int BRACE_THREE_DOUBLE = 5; |
| 104 |
| 105 // Enable the parser to handle string interpolations via brace matching. |
| 106 // The top of the `braceLevels` stack describes the most recent unmatched |
| 107 // '{'. This is needed in order to enable/disable certain lexer rules. |
| 108 // |
| 109 // NORMAL: Most recent unmatched '{' was not string literal related. |
| 110 // SINGLE: Most recent unmatched '{' was `'...${`. |
| 111 // DOUBLE: Most recent unmatched '{' was `"...${`. |
| 112 // THREE_SINGLE: Most recent unmatched '{' was `'''...${`. |
| 113 // THREE_DOUBLE: Most recent unmatched '{' was `"""...${`. |
| 114 // |
| 115 // Access via functions below. |
| 116 private Stack<Integer> braceLevels = new Stack<Integer>(); |
| 117 |
| 118 // Whether we are currently in a string literal context, and which one. |
| 119 boolean currentBraceLevel(int braceLevel) { |
| 120 if (braceLevels.empty()) return false; |
| 121 return braceLevels.peek() == braceLevel; |
| 122 } |
| 123 |
| 124 // Use this to indicate that we are now entering a specific '{...}'. |
| 125 // Call it after accepting the '{'. |
| 126 void enterBrace() { |
| 127 braceLevels.push(BRACE_NORMAL); |
| 128 } |
| 129 void enterBraceSingleQuote() { |
| 130 braceLevels.push(BRACE_SINGLE); |
| 131 } |
| 132 void enterBraceDoubleQuote() { |
| 133 braceLevels.push(BRACE_DOUBLE); |
| 134 } |
| 135 void enterBraceThreeSingleQuotes() { |
| 136 braceLevels.push(BRACE_THREE_SINGLE); |
| 137 } |
| 138 void enterBraceThreeDoubleQuotes() { |
| 139 braceLevels.push(BRACE_THREE_DOUBLE); |
| 140 } |
| 141 |
| 142 // Use this to indicate that we are now exiting a specific '{...}', |
| 143 // no matter which kind. Call it before accepting the '}'. |
| 144 void exitBrace() { |
| 145 // We might raise a parse error here if the stack is empty, but the |
| 146 // parsing rules should ensure that we get a parse error anyway, and |
| 147 // it is not a big problem for the spec parser even if it misinterprets |
| 148 // the brace structure of some programs with syntax errors. |
| 149 if (!braceLevels.empty()) braceLevels.pop(); |
| 150 } |
| 151 } |
| 152 |
| 153 // ---------------------------------------- Grammar rules. |
| 154 |
| 155 libraryDefinition |
| 156 : FEFF? SCRIPT_TAG? |
| 157 ((metadata LIBRARY) => libraryName)? |
| 158 ((metadata (IMPORT | EXPORT)) => importOrExport)* |
| 159 ((metadata PART) => partDirective)* |
| 160 (metadata topLevelDefinition)* |
| 161 EOF |
| 162 ; |
| 163 |
| 164 // `functionSignature functionBody` is split into two alternatives because |
| 165 // this eliminates an ambiguity. |
| 166 |
| 167 topLevelDefinition |
| 168 : classDefinition |
| 169 | enumType |
| 170 | (TYPEDEF typeIdentifier typeParameters? '=') => typeAlias |
| 171 | (TYPEDEF functionPrefix ('<' | '(')) => typeAlias |
| 172 | (EXTERNAL functionSignature ';') => EXTERNAL functionSignature ';' |
| 173 | (EXTERNAL getterSignature) => EXTERNAL getterSignature ';' |
| 174 | (EXTERNAL type? SET identifier '(') => |
| 175 EXTERNAL setterSignature ';' |
| 176 | (getterSignature functionBodyPrefix) => getterSignature functionBody |
| 177 | (type? SET identifier '(') => setterSignature functionBody |
| 178 | (identifier typeParameters? '(') => functionSignature functionBody |
| 179 | (type identifier typeParameters? '(') => |
| 180 functionSignature functionBody |
| 181 | ((FINAL | CONST) type? identifier '=') => |
| 182 (FINAL | CONST) type? staticFinalDeclarationList ';' |
| 183 | initializedVariableDeclaration ';' |
| 184 ; |
| 185 |
| 186 declaredIdentifier |
| 187 : COVARIANT? finalConstVarOrType identifier |
| 188 ; |
| 189 |
| 190 finalConstVarOrType |
| 191 : FINAL type? |
| 192 | CONST type? |
| 193 | varOrType |
| 194 ; |
| 195 |
| 196 varOrType |
| 197 : VAR |
| 198 | type |
| 199 ; |
| 200 |
| 201 initializedVariableDeclaration |
| 202 : declaredIdentifier ('=' expression)? (',' initializedIdentifier)* |
| 203 ; |
| 204 |
| 205 initializedIdentifier |
| 206 : identifier ('=' expression)? |
| 207 ; |
| 208 |
| 209 initializedIdentifierList |
| 210 : initializedIdentifier (',' initializedIdentifier)* |
| 211 ; |
| 212 |
| 213 functionSignature |
| 214 : (type identifier typeParameters? '(') => |
| 215 type identifier formalParameterPart |
| 216 | identifier formalParameterPart |
| 217 ; |
| 218 |
| 219 functionBodyPrefix |
| 220 : ASYNC? '=>' |
| 221 | (ASYNC | ASYNC '*' | SYNC '*')? LBRACE |
| 222 ; |
| 223 |
| 224 functionBody |
| 225 : '=>' { startNonAsyncFunction(); } expression { endFunction(); } ';' |
| 226 | { startNonAsyncFunction(); } block { endFunction(); } |
| 227 | ASYNC '=>' |
| 228 { startAsyncFunction(); } expression { endFunction(); } ';' |
| 229 | (ASYNC | ASYNC '*' | SYNC '*') |
| 230 { startAsyncFunction(); } block { endFunction(); } |
| 231 ; |
| 232 |
| 233 block |
| 234 : LBRACE statements RBRACE |
| 235 ; |
| 236 |
| 237 formalParameterPart |
| 238 : typeParameters? formalParameterList |
| 239 ; |
| 240 |
| 241 formalParameterList |
| 242 : '(' ')' |
| 243 | '(' normalFormalParameters (','? | ',' optionalFormalParameters) ')' |
| 244 | '(' optionalFormalParameters ')' |
| 245 ; |
| 246 |
| 247 normalFormalParameters |
| 248 : normalFormalParameter (',' normalFormalParameter)* |
| 249 ; |
| 250 |
| 251 optionalFormalParameters |
| 252 : optionalPositionalFormalParameters |
| 253 | namedFormalParameters |
| 254 ; |
| 255 |
| 256 optionalPositionalFormalParameters |
| 257 : '[' defaultFormalParameter (',' defaultFormalParameter)* ','? ']' |
| 258 ; |
| 259 |
| 260 namedFormalParameters |
| 261 : LBRACE defaultNamedParameter (',' defaultNamedParameter)* ','? RBRACE |
| 262 ; |
| 263 |
| 264 normalFormalParameter |
| 265 : metadata normalFormalParameterNoMetadata |
| 266 ; |
| 267 |
| 268 // `functionFormalParameter` is split into two alternatives because |
| 269 // this eliminates an ambiguity. |
| 270 |
| 271 normalFormalParameterNoMetadata |
| 272 : (COVARIANT? identifier typeParameters? '(') => functionFormalParameter |
| 273 | (COVARIANT? type identifier typeParameters? '(') => |
| 274 functionFormalParameter |
| 275 | (finalConstVarOrType? THIS) => fieldFormalParameter |
| 276 | simpleFormalParameter |
| 277 ; |
| 278 |
| 279 functionFormalParameter |
| 280 : (COVARIANT? type identifier typeParameters? '(') => |
| 281 COVARIANT? type identifier formalParameterPart |
| 282 | COVARIANT? identifier formalParameterPart |
| 283 ; |
| 284 |
| 285 simpleFormalParameter |
| 286 : declaredIdentifier |
| 287 | COVARIANT? identifier |
| 288 ; |
| 289 |
| 290 fieldFormalParameter |
| 291 : finalConstVarOrType? THIS '.' identifier formalParameterPart? |
| 292 ; |
| 293 |
| 294 defaultFormalParameter |
| 295 : normalFormalParameter ('=' expression)? |
| 296 ; |
| 297 |
| 298 defaultNamedParameter |
| 299 : normalFormalParameter ((':' | '=') expression)? |
| 300 ; |
| 301 |
| 302 typeApplication |
| 303 : typeIdentifier typeParameters? |
| 304 ; |
| 305 |
| 306 classDefinition |
| 307 : (ABSTRACT? CLASS typeApplication (EXTENDS|IMPLEMENTS|LBRACE)) => |
| 308 ABSTRACT? CLASS typeApplication (superclass mixins?)? interfaces? |
| 309 LBRACE (metadata classMemberDefinition)* RBRACE |
| 310 | (ABSTRACT? CLASS typeApplication '=') => |
| 311 ABSTRACT? CLASS mixinApplicationClass |
| 312 ; |
| 313 |
| 314 mixins |
| 315 : WITH typeNotVoidNotFunctionList |
| 316 ; |
| 317 |
| 318 classMemberDefinition |
| 319 : (methodSignature functionBodyPrefix) => methodSignature functionBody |
| 320 | declaration ';' |
| 321 ; |
| 322 |
| 323 // `STATIC? functionSignature` is split into two alternatives because this |
| 324 // eliminates an ambiguity. |
| 325 |
| 326 methodSignature |
| 327 : (constructorName '(') => constructorSignature initializers? |
| 328 | (FACTORY constructorName '(') => factoryConstructorSignature |
| 329 | (STATIC? identifier typeParameters? '(') => STATIC? functionSignature |
| 330 | (STATIC? type identifier typeParameters? '(') => |
| 331 STATIC? functionSignature |
| 332 | (STATIC? type? GET) => STATIC? getterSignature |
| 333 | (STATIC? type? SET) => STATIC? setterSignature |
| 334 | operatorSignature |
| 335 ; |
| 336 |
| 337 // https://github.com/dart-lang/sdk/issues/29501 reports on the problem which |
| 338 // was solved by adding a case for redirectingFactoryConstructorSignature. |
| 339 // TODO(eernst): Close that issue when this is integrated into the spec. |
| 340 |
| 341 // https://github.com/dart-lang/sdk/issues/29502 reports on the problem that |
| 342 // than external const factory constructor declaration cannot be derived by |
| 343 // the spec grammar (and also not by this grammar). The following fixes were |
| 344 // introduced for that: Added the 'factoryConstructorSignature' case below in |
| 345 // 'declaration'; also added 'CONST?' in the 'factoryConstructorSignature' |
| 346 // rule, such that const factories in general are allowed. |
| 347 // TODO(eernst): Close that issue when this is integrated into the spec. |
| 348 |
| 349 declaration |
| 350 : (EXTERNAL CONST? FACTORY constructorName '(') => |
| 351 EXTERNAL factoryConstructorSignature |
| 352 | EXTERNAL constantConstructorSignature |
| 353 | (EXTERNAL constructorName '(') => EXTERNAL constructorSignature |
| 354 | ((EXTERNAL STATIC?)? type? GET) => (EXTERNAL STATIC?)? getterSignature |
| 355 | ((EXTERNAL STATIC?)? type? SET) => (EXTERNAL STATIC?)? setterSignature |
| 356 | (EXTERNAL? type? OPERATOR) => EXTERNAL? operatorSignature |
| 357 | (STATIC (FINAL | CONST)) => |
| 358 STATIC (FINAL | CONST) type? staticFinalDeclarationList |
| 359 | FINAL type? initializedIdentifierList |
| 360 | ((STATIC | COVARIANT)? (VAR | type) identifier ('=' | ',' | ';')) => |
| 361 (STATIC | COVARIANT)? (VAR | type) initializedIdentifierList |
| 362 | (EXTERNAL? STATIC? functionSignature ';') => |
| 363 EXTERNAL? STATIC? functionSignature |
| 364 | (CONST? FACTORY constructorName formalParameterList '=') => |
| 365 redirectingFactoryConstructorSignature |
| 366 | constantConstructorSignature (redirection | initializers)? |
| 367 | constructorSignature (redirection | initializers)? |
| 368 ; |
| 369 |
| 370 staticFinalDeclarationList |
| 371 : staticFinalDeclaration (',' staticFinalDeclaration)* |
| 372 ; |
| 373 |
| 374 staticFinalDeclaration |
| 375 : identifier '=' expression |
| 376 ; |
| 377 |
| 378 operatorSignature |
| 379 : type? OPERATOR operator formalParameterList |
| 380 ; |
| 381 |
| 382 operator |
| 383 : '~' |
| 384 | binaryOperator |
| 385 | '[' ']' |
| 386 | '[' ']' '=' |
| 387 ; |
| 388 |
| 389 binaryOperator |
| 390 : multiplicativeOperator |
| 391 | additiveOperator |
| 392 | (shiftOperator) => shiftOperator |
| 393 | relationalOperator |
| 394 | '==' |
| 395 | bitwiseOperator |
| 396 ; |
| 397 |
| 398 getterSignature |
| 399 : type? GET identifier |
| 400 ; |
| 401 |
| 402 setterSignature |
| 403 : type? SET identifier formalParameterList |
| 404 ; |
| 405 |
| 406 constructorSignature |
| 407 : constructorName formalParameterList |
| 408 ; |
| 409 |
| 410 constructorName |
| 411 : typeIdentifier ('.' identifier)? |
| 412 ; |
| 413 |
| 414 redirection |
| 415 : ':' THIS ('.' identifier)? arguments |
| 416 ; |
| 417 |
| 418 initializers |
| 419 : ':' superCallOrFieldInitializer (',' superCallOrFieldInitializer)* |
| 420 ; |
| 421 |
| 422 superCallOrFieldInitializer |
| 423 : SUPER arguments |
| 424 | SUPER '.' identifier arguments |
| 425 | fieldInitializer |
| 426 | assertClause |
| 427 ; |
| 428 |
| 429 fieldInitializer |
| 430 : (THIS '.')? identifier '=' conditionalExpression cascadeSection* |
| 431 ; |
| 432 |
| 433 factoryConstructorSignature |
| 434 : CONST? FACTORY constructorName formalParameterList |
| 435 ; |
| 436 |
| 437 redirectingFactoryConstructorSignature |
| 438 : CONST? FACTORY constructorName formalParameterList '=' |
| 439 constructorDesignation |
| 440 ; |
| 441 |
| 442 constantConstructorSignature |
| 443 : CONST constructorName formalParameterList |
| 444 ; |
| 445 |
| 446 superclass |
| 447 : EXTENDS typeNotVoidNotFunction |
| 448 ; |
| 449 |
| 450 interfaces |
| 451 : IMPLEMENTS typeNotVoidNotFunctionList |
| 452 ; |
| 453 |
| 454 mixinApplicationClass |
| 455 : typeApplication '=' mixinApplication ';' |
| 456 ; |
| 457 |
| 458 mixinApplication |
| 459 : typeNotVoidNotFunction mixins interfaces? |
| 460 ; |
| 461 |
| 462 enumType |
| 463 : ENUM typeIdentifier LBRACE identifier (',' identifier)* (',')? RBRACE |
| 464 ; |
| 465 |
| 466 typeParameter |
| 467 : metadata typeIdentifier (EXTENDS typeNotVoid)? |
| 468 ; |
| 469 |
| 470 typeParameters |
| 471 : '<' typeParameter (',' typeParameter)* '>' |
| 472 ; |
| 473 |
| 474 metadata |
| 475 : ('@' metadatum)* |
| 476 ; |
| 477 |
| 478 metadatum |
| 479 : constructorDesignation arguments |
| 480 | qualified |
| 481 ; |
| 482 |
| 483 expression |
| 484 : (formalParameterPart functionExpressionBodyPrefix) => |
| 485 functionExpression |
| 486 | throwExpression |
| 487 | (assignableExpression assignmentOperator) => |
| 488 assignableExpression assignmentOperator expression |
| 489 | conditionalExpression cascadeSection* |
| 490 ; |
| 491 |
| 492 expressionWithoutCascade |
| 493 : (formalParameterPart functionExpressionBodyPrefix) => |
| 494 functionExpressionWithoutCascade |
| 495 | throwExpressionWithoutCascade |
| 496 | (assignableExpression assignmentOperator) => |
| 497 assignableExpression assignmentOperator expressionWithoutCascade |
| 498 | conditionalExpression |
| 499 ; |
| 500 |
| 501 expressionList |
| 502 : expression (',' expression)* |
| 503 ; |
| 504 |
| 505 primary |
| 506 : thisExpression |
| 507 | SUPER unconditionalAssignableSelector |
| 508 | (CONST constructorDesignation) => constObjectExpression |
| 509 | newExpression |
| 510 | (formalParameterPart functionPrimaryBodyPrefix) => functionPrimary |
| 511 | '(' expression ')' |
| 512 | literal |
| 513 | identifier |
| 514 ; |
| 515 |
| 516 literal |
| 517 : nullLiteral |
| 518 | booleanLiteral |
| 519 | numericLiteral |
| 520 | stringLiteral |
| 521 | symbolLiteral |
| 522 | (CONST? typeArguments? LBRACE) => mapLiteral |
| 523 | listLiteral |
| 524 ; |
| 525 |
| 526 nullLiteral |
| 527 : NULL |
| 528 ; |
| 529 |
| 530 numericLiteral |
| 531 : NUMBER |
| 532 | HEX_NUMBER |
| 533 ; |
| 534 |
| 535 booleanLiteral |
| 536 : TRUE |
| 537 | FALSE |
| 538 ; |
| 539 |
| 540 stringLiteral |
| 541 : (multiLineString | singleLineString)+ |
| 542 ; |
| 543 |
| 544 stringLiteralWithoutInterpolation |
| 545 : singleLineStringWithoutInterpolation+ |
| 546 ; |
| 547 |
| 548 listLiteral |
| 549 : CONST? typeArguments? '[' (expressionList ','?)? ']' |
| 550 ; |
| 551 |
| 552 mapLiteral |
| 553 : CONST? typeArguments? |
| 554 LBRACE (mapLiteralEntry (',' mapLiteralEntry)* ','?)? RBRACE |
| 555 ; |
| 556 |
| 557 mapLiteralEntry |
| 558 : expression ':' expression |
| 559 ; |
| 560 |
| 561 throwExpression |
| 562 : THROW expression |
| 563 ; |
| 564 |
| 565 throwExpressionWithoutCascade |
| 566 : THROW expressionWithoutCascade |
| 567 ; |
| 568 |
| 569 functionExpression |
| 570 : formalParameterPart functionExpressionBody |
| 571 ; |
| 572 |
| 573 functionExpressionBody |
| 574 : '=>' { startNonAsyncFunction(); } expression { endFunction(); } |
| 575 | ASYNC '=>' { startAsyncFunction(); } expression { endFunction(); } |
| 576 ; |
| 577 |
| 578 functionExpressionBodyPrefix |
| 579 : ASYNC? '=>' |
| 580 ; |
| 581 |
| 582 functionExpressionWithoutCascade |
| 583 : formalParameterPart functionExpressionWithoutCascadeBody |
| 584 ; |
| 585 |
| 586 functionExpressionWithoutCascadeBody |
| 587 : '=>' { startNonAsyncFunction(); } |
| 588 expressionWithoutCascade { endFunction(); } |
| 589 | ASYNC '=>' { startAsyncFunction(); } |
| 590 expressionWithoutCascade { endFunction(); } |
| 591 ; |
| 592 |
| 593 functionPrimary |
| 594 : formalParameterPart functionPrimaryBody |
| 595 ; |
| 596 |
| 597 functionPrimaryBody |
| 598 : { startNonAsyncFunction(); } block { endFunction(); } |
| 599 | (ASYNC | ASYNC '*' | SYNC '*') |
| 600 { startAsyncFunction(); } block { endFunction(); } |
| 601 ; |
| 602 |
| 603 functionPrimaryBodyPrefix |
| 604 : (ASYNC | ASYNC '*' | SYNC '*')? LBRACE |
| 605 ; |
| 606 |
| 607 thisExpression |
| 608 : THIS |
| 609 ; |
| 610 |
| 611 newExpression |
| 612 : NEW constructorDesignation arguments |
| 613 ; |
| 614 |
| 615 constObjectExpression |
| 616 : CONST constructorDesignation arguments |
| 617 ; |
| 618 |
| 619 arguments |
| 620 : '(' (argumentList ','?)? ')' |
| 621 ; |
| 622 |
| 623 argumentList |
| 624 : namedArgument (',' namedArgument)* |
| 625 | expressionList (',' namedArgument)* |
| 626 ; |
| 627 |
| 628 namedArgument |
| 629 : label expression |
| 630 ; |
| 631 |
| 632 cascadeSection |
| 633 : '..' |
| 634 (cascadeSelector argumentPart*) |
| 635 (assignableSelector argumentPart*)* |
| 636 (assignmentOperator expressionWithoutCascade)? |
| 637 ; |
| 638 |
| 639 cascadeSelector |
| 640 : '[' expression ']' |
| 641 | identifier |
| 642 ; |
| 643 |
| 644 assignmentOperator |
| 645 : '=' |
| 646 | compoundAssignmentOperator |
| 647 ; |
| 648 |
| 649 compoundAssignmentOperator |
| 650 : '*=' |
| 651 | '/=' |
| 652 | '~/=' |
| 653 | '%=' |
| 654 | '+=' |
| 655 | '-=' |
| 656 | '<<=' |
| 657 | '>' '>' '=' |
| 658 | '&=' |
| 659 | '^=' |
| 660 | '|=' |
| 661 | '??=' |
| 662 ; |
| 663 |
| 664 conditionalExpression |
| 665 : ifNullExpression |
| 666 ('?' expressionWithoutCascade ':' expressionWithoutCascade)? |
| 667 ; |
| 668 |
| 669 ifNullExpression |
| 670 : logicalOrExpression ('??' logicalOrExpression)* |
| 671 ; |
| 672 |
| 673 logicalOrExpression |
| 674 : logicalAndExpression ('||' logicalAndExpression)* |
| 675 ; |
| 676 |
| 677 logicalAndExpression |
| 678 : equalityExpression ('&&' equalityExpression)* |
| 679 ; |
| 680 |
| 681 equalityExpression |
| 682 : relationalExpression (equalityOperator relationalExpression)? |
| 683 | SUPER equalityOperator relationalExpression |
| 684 ; |
| 685 |
| 686 equalityOperator |
| 687 : '==' |
| 688 | '!=' |
| 689 ; |
| 690 |
| 691 relationalExpression |
| 692 : bitwiseOrExpression |
| 693 (typeTest | typeCast | relationalOperator bitwiseOrExpression)? |
| 694 | SUPER relationalOperator bitwiseOrExpression |
| 695 ; |
| 696 |
| 697 relationalOperator |
| 698 : '>' '=' |
| 699 | '>' |
| 700 | '<=' |
| 701 | '<' |
| 702 ; |
| 703 |
| 704 bitwiseOrExpression |
| 705 : bitwiseXorExpression ('|' bitwiseXorExpression)* |
| 706 | SUPER ('|' bitwiseXorExpression)+ |
| 707 ; |
| 708 |
| 709 bitwiseXorExpression |
| 710 : bitwiseAndExpression ('^' bitwiseAndExpression)* |
| 711 | SUPER ('^' bitwiseAndExpression)+ |
| 712 ; |
| 713 |
| 714 bitwiseAndExpression |
| 715 : shiftExpression ('&' shiftExpression)* |
| 716 | SUPER ('&' shiftExpression)+ |
| 717 ; |
| 718 |
| 719 bitwiseOperator |
| 720 : '&' |
| 721 | '^' |
| 722 | '|' |
| 723 ; |
| 724 |
| 725 shiftExpression |
| 726 : additiveExpression (shiftOperator additiveExpression)* |
| 727 | SUPER (shiftOperator additiveExpression)+ |
| 728 ; |
| 729 |
| 730 shiftOperator |
| 731 : '<<' |
| 732 | '>' '>' |
| 733 ; |
| 734 |
| 735 additiveExpression |
| 736 : multiplicativeExpression (additiveOperator multiplicativeExpression)* |
| 737 | SUPER (additiveOperator multiplicativeExpression)+ |
| 738 ; |
| 739 |
| 740 additiveOperator |
| 741 : '+' |
| 742 | '-' |
| 743 ; |
| 744 |
| 745 multiplicativeExpression |
| 746 : unaryExpression (multiplicativeOperator unaryExpression)* |
| 747 | SUPER (multiplicativeOperator unaryExpression)+ |
| 748 ; |
| 749 |
| 750 multiplicativeOperator |
| 751 : '*' |
| 752 | '/' |
| 753 | '%' |
| 754 | '~/' |
| 755 ; |
| 756 |
| 757 unaryExpression |
| 758 : (prefixOperator ~SUPER) => prefixOperator unaryExpression |
| 759 | (awaitExpression) => awaitExpression |
| 760 | postfixExpression |
| 761 | (minusOperator | tildeOperator) SUPER |
| 762 | incrementOperator assignableExpression |
| 763 ; |
| 764 |
| 765 prefixOperator |
| 766 : minusOperator |
| 767 | negationOperator |
| 768 | tildeOperator |
| 769 ; |
| 770 |
| 771 minusOperator |
| 772 : '-' |
| 773 ; |
| 774 |
| 775 negationOperator |
| 776 : '!' |
| 777 ; |
| 778 |
| 779 tildeOperator |
| 780 : '~' |
| 781 ; |
| 782 |
| 783 awaitExpression |
| 784 : AWAIT unaryExpression |
| 785 ; |
| 786 |
| 787 // The `(selector)` predicate ensures that the parser commits to the longest |
| 788 // possible chain of selectors, e.g., `a<b,c>(d)` as a call rather than as a |
| 789 // sequence of two relational expressions. |
| 790 |
| 791 postfixExpression |
| 792 : (assignableExpression postfixOperator) => |
| 793 assignableExpression postfixOperator |
| 794 | primary ((selector) => selector)* |
| 795 ; |
| 796 |
| 797 postfixOperator |
| 798 : incrementOperator |
| 799 ; |
| 800 |
| 801 selector |
| 802 : assignableSelector |
| 803 | argumentPart |
| 804 ; |
| 805 |
| 806 argumentPart |
| 807 : typeArguments? arguments |
| 808 ; |
| 809 |
| 810 incrementOperator |
| 811 : '++' |
| 812 | '--' |
| 813 ; |
| 814 |
| 815 // The `(assignableSelectorPart)` predicate ensures that the parser |
| 816 // commits to the longest possible chain, e.g., `a<b,c>(d).e` as one rather |
| 817 // than two expressions. The first `identifier` alternative handles all |
| 818 // the simple cases; the final `identifier` alternative at the end catches |
| 819 // the case where we have `identifier '<'` and the '<' is used as a |
| 820 // relationalOperator, not the beginning of typeArguments. |
| 821 |
| 822 assignableExpression |
| 823 : (SUPER unconditionalAssignableSelector |
| 824 ~('<' | '(' | '[' | '.' | '?.')) => |
| 825 SUPER unconditionalAssignableSelector |
| 826 | (identifier ~('<' | '(' | '[' | '.' | '?.')) => identifier |
| 827 | (primary argumentPart* assignableSelector) => |
| 828 primary ((assignableSelectorPart) => assignableSelectorPart)+ |
| 829 | identifier |
| 830 ; |
| 831 |
| 832 assignableSelectorPart |
| 833 : argumentPart* assignableSelector |
| 834 ; |
| 835 |
| 836 unconditionalAssignableSelector |
| 837 : '[' expression ']' |
| 838 | '.' identifier |
| 839 ; |
| 840 |
| 841 assignableSelector |
| 842 : unconditionalAssignableSelector |
| 843 | '?.' identifier |
| 844 ; |
| 845 |
| 846 identifier |
| 847 : IDENTIFIER |
| 848 | ABSTRACT |
| 849 | AS |
| 850 | COVARIANT |
| 851 | DEFERRED |
| 852 | DYNAMIC |
| 853 | EXPORT |
| 854 | EXTERNAL |
| 855 | FACTORY |
| 856 | GET |
| 857 | IMPLEMENTS |
| 858 | IMPORT |
| 859 | LIBRARY |
| 860 | OPERATOR |
| 861 | PART |
| 862 | SET |
| 863 | STATIC |
| 864 | TYPEDEF |
| 865 | HIDE // Not a built-in identifier. |
| 866 | OF // Not a built-in identifier. |
| 867 | ON // Not a built-in identifier. |
| 868 | SHOW // Not a built-in identifier. |
| 869 | SYNC // Not a built-in identifier. |
| 870 | FUNCTION // Not a built-in identifier. |
| 871 | { asyncEtcPredicate(input.LA(1)) }? (ASYNC|AWAIT|YIELD) |
| 872 ; |
| 873 |
| 874 qualified |
| 875 : identifier ('.' identifier)? |
| 876 ; |
| 877 |
| 878 typeIdentifier |
| 879 : IDENTIFIER |
| 880 | DYNAMIC // The only built-in identifier that can be used as a type. |
| 881 | HIDE // Not a built-in identifier. |
| 882 | OF // Not a built-in identifier. |
| 883 | ON // Not a built-in identifier. |
| 884 | SHOW // Not a built-in identifier. |
| 885 | SYNC // Not a built-in identifier. |
| 886 | FUNCTION // Not a built-in identifier. |
| 887 | { asyncEtcPredicate(input.LA(1)) }? (ASYNC|AWAIT|YIELD) |
| 888 ; |
| 889 |
| 890 typeTest |
| 891 : isOperator typeNotVoid |
| 892 ; |
| 893 |
| 894 isOperator |
| 895 : IS '!'? |
| 896 ; |
| 897 |
| 898 typeCast |
| 899 : asOperator typeNotVoid |
| 900 ; |
| 901 |
| 902 asOperator |
| 903 : AS |
| 904 ; |
| 905 |
| 906 statements |
| 907 : statement* |
| 908 ; |
| 909 |
| 910 statement |
| 911 : label* nonLabelledStatement |
| 912 ; |
| 913 |
| 914 // Exception in the language specification: An expressionStatement cannot |
| 915 // start with LBRACE. We force anything that starts with LBRACE to be a block, |
| 916 // which will prevent an expressionStatement from starting with LBRACE, and |
| 917 // which will not interfere with the recognition of any other case. If we |
| 918 // add another statement which can start with LBRACE we must adjust this |
| 919 // check. |
| 920 nonLabelledStatement |
| 921 : (LBRACE) => block |
| 922 | (declaredIdentifier ('='|','|';')) => localVariableDeclaration |
| 923 | (AWAIT? FOR) => forStatement |
| 924 | whileStatement |
| 925 | doStatement |
| 926 | switchStatement |
| 927 | ifStatement |
| 928 | rethrowStatement |
| 929 | tryStatement |
| 930 | breakStatement |
| 931 | continueStatement |
| 932 | returnStatement |
| 933 | (functionSignature functionBodyPrefix) => localFunctionDeclaration |
| 934 | assertStatement |
| 935 | (YIELD ~'*') => yieldStatement |
| 936 | yieldEachStatement |
| 937 | expressionStatement |
| 938 ; |
| 939 |
| 940 expressionStatement |
| 941 : expression? ';' |
| 942 ; |
| 943 |
| 944 localVariableDeclaration |
| 945 : initializedVariableDeclaration ';' |
| 946 ; |
| 947 |
| 948 localFunctionDeclaration |
| 949 : functionSignature functionBody |
| 950 ; |
| 951 |
| 952 ifStatement |
| 953 : IF '(' expression ')' statement ((ELSE) => ELSE statement | ()) |
| 954 ; |
| 955 |
| 956 forStatement |
| 957 : AWAIT? FOR '(' forLoopParts ')' statement |
| 958 ; |
| 959 |
| 960 forLoopParts |
| 961 : (declaredIdentifier IN) => declaredIdentifier IN expression |
| 962 | (identifier IN) => identifier IN expression |
| 963 | forInitializerStatement expression? ';' expressionList? |
| 964 ; |
| 965 |
| 966 // The localVariableDeclaration cannot be CONST, but that can |
| 967 // be enforced in a later phase, and the grammar allows it. |
| 968 forInitializerStatement |
| 969 : (localVariableDeclaration) => localVariableDeclaration |
| 970 | expression? ';' |
| 971 ; |
| 972 |
| 973 whileStatement |
| 974 : WHILE '(' expression ')' statement |
| 975 ; |
| 976 |
| 977 doStatement |
| 978 : DO statement WHILE '(' expression ')' ';' |
| 979 ; |
| 980 |
| 981 switchStatement |
| 982 : SWITCH '(' expression ')' LBRACE switchCase* defaultCase? RBRACE |
| 983 ; |
| 984 |
| 985 switchCase |
| 986 : label* CASE expression ':' statements |
| 987 ; |
| 988 |
| 989 defaultCase |
| 990 : label* DEFAULT ':' statements |
| 991 ; |
| 992 |
| 993 rethrowStatement |
| 994 : RETHROW ';' |
| 995 ; |
| 996 |
| 997 tryStatement |
| 998 : TRY block (onParts finallyPart? | finallyPart) |
| 999 ; |
| 1000 |
| 1001 onPart |
| 1002 : catchPart block |
| 1003 | ON typeNotVoid catchPart? block |
| 1004 ; |
| 1005 |
| 1006 onParts |
| 1007 : (onPart (ON|CATCH)) => onPart onParts |
| 1008 | onPart |
| 1009 ; |
| 1010 |
| 1011 catchPart |
| 1012 : CATCH '(' identifier (',' identifier)? ')' |
| 1013 ; |
| 1014 |
| 1015 finallyPart |
| 1016 : FINALLY block |
| 1017 ; |
| 1018 |
| 1019 returnStatement |
| 1020 : RETURN expression? ';' |
| 1021 ; |
| 1022 |
| 1023 label |
| 1024 : identifier ':' |
| 1025 ; |
| 1026 |
| 1027 breakStatement |
| 1028 : BREAK identifier? ';' |
| 1029 ; |
| 1030 |
| 1031 continueStatement |
| 1032 : CONTINUE identifier? ';' |
| 1033 ; |
| 1034 |
| 1035 yieldStatement |
| 1036 : YIELD expression ';' |
| 1037 ; |
| 1038 |
| 1039 yieldEachStatement |
| 1040 : YIELD '*' expression ';' |
| 1041 ; |
| 1042 |
| 1043 assertStatement |
| 1044 : assertClause ';' |
| 1045 ; |
| 1046 |
| 1047 assertClause |
| 1048 : ASSERT '(' expression (',' expression)? ')' |
| 1049 ; |
| 1050 |
| 1051 libraryName |
| 1052 : metadata LIBRARY identifier ('.' identifier)* ';' |
| 1053 ; |
| 1054 |
| 1055 importOrExport |
| 1056 : (metadata IMPORT) => libraryImport |
| 1057 | (metadata EXPORT) => libraryExport |
| 1058 ; |
| 1059 |
| 1060 libraryImport |
| 1061 : metadata importSpecification |
| 1062 ; |
| 1063 |
| 1064 importSpecification |
| 1065 : IMPORT uri (AS identifier)? combinator* ';' |
| 1066 | IMPORT uri DEFERRED AS identifier combinator* ';' |
| 1067 ; |
| 1068 |
| 1069 combinator |
| 1070 : SHOW identifierList |
| 1071 | HIDE identifierList |
| 1072 ; |
| 1073 |
| 1074 identifierList |
| 1075 : identifier (',' identifier)* |
| 1076 ; |
| 1077 |
| 1078 libraryExport |
| 1079 : metadata EXPORT uri combinator* ';' |
| 1080 ; |
| 1081 |
| 1082 partDirective |
| 1083 : metadata PART uri ';' |
| 1084 ; |
| 1085 |
| 1086 partHeader |
| 1087 : metadata PART OF identifier ('.' identifier)* ';' |
| 1088 ; |
| 1089 |
| 1090 partDeclaration |
| 1091 : partHeader topLevelDefinition* EOF |
| 1092 ; |
| 1093 |
| 1094 uri |
| 1095 : stringLiteralWithoutInterpolation |
| 1096 ; |
| 1097 |
| 1098 type |
| 1099 : (FUNCTION ('('|'<')) => functionTypeTails |
| 1100 | (typeNotFunction FUNCTION ('('|'<')) => |
| 1101 typeNotFunction functionTypeTails |
| 1102 | typeNotFunction |
| 1103 ; |
| 1104 |
| 1105 typeNotFunction |
| 1106 : typeNotVoidNotFunction |
| 1107 | VOID |
| 1108 ; |
| 1109 |
| 1110 typeNotVoid |
| 1111 : (typeNotFunction? FUNCTION ('('|'<')) => functionType |
| 1112 | typeNotVoidNotFunction |
| 1113 ; |
| 1114 |
| 1115 typeNotVoidNotFunction |
| 1116 : typeName typeArguments? |
| 1117 ; |
| 1118 |
| 1119 typeName |
| 1120 : typeIdentifier ('.' typeIdentifier)? |
| 1121 ; |
| 1122 |
| 1123 typeArguments |
| 1124 : '<' typeList '>' |
| 1125 ; |
| 1126 |
| 1127 typeList |
| 1128 : type (',' type)* |
| 1129 ; |
| 1130 |
| 1131 typeNotVoidNotFunctionList |
| 1132 : typeNotVoidNotFunction (',' typeNotVoidNotFunction)* |
| 1133 ; |
| 1134 |
| 1135 typeAlias |
| 1136 : (TYPEDEF typeIdentifier typeParameters? '=') => |
| 1137 TYPEDEF typeIdentifier typeParameters? '=' functionType ';' |
| 1138 | TYPEDEF functionTypeAlias |
| 1139 ; |
| 1140 |
| 1141 functionTypeAlias |
| 1142 : functionPrefix formalParameterPart ';' |
| 1143 ; |
| 1144 |
| 1145 functionPrefix |
| 1146 : (type identifier) => type identifier |
| 1147 | identifier |
| 1148 ; |
| 1149 |
| 1150 functionTypeTail |
| 1151 : FUNCTION typeParameters? parameterTypeList |
| 1152 ; |
| 1153 |
| 1154 functionTypeTails |
| 1155 : (functionTypeTail FUNCTION ('<'|'(')) => |
| 1156 functionTypeTail functionTypeTails |
| 1157 | functionTypeTail |
| 1158 ; |
| 1159 |
| 1160 functionType |
| 1161 : (FUNCTION ('<'|'(')) => functionTypeTails |
| 1162 | typeNotFunction functionTypeTails |
| 1163 ; |
| 1164 |
| 1165 parameterTypeList |
| 1166 : ('(' ')') => '(' ')' |
| 1167 | ('(' normalParameterTypes ',' ('['|'{')) => |
| 1168 '(' normalParameterTypes ',' optionalParameterTypes ')' |
| 1169 | ('(' normalParameterTypes ','? ')') => |
| 1170 '(' normalParameterTypes ','? ')' |
| 1171 | '(' optionalParameterTypes ')' |
| 1172 ; |
| 1173 |
| 1174 normalParameterTypes |
| 1175 : normalParameterType (',' normalParameterType)* |
| 1176 ; |
| 1177 |
| 1178 normalParameterType |
| 1179 : (typedIdentifier) => typedIdentifier |
| 1180 | type |
| 1181 ; |
| 1182 |
| 1183 optionalParameterTypes |
| 1184 : optionalPositionalParameterTypes |
| 1185 | namedParameterTypes |
| 1186 ; |
| 1187 |
| 1188 optionalPositionalParameterTypes |
| 1189 : '[' normalParameterTypes ','? ']' |
| 1190 ; |
| 1191 |
| 1192 namedParameterTypes |
| 1193 : '{' typedIdentifier (',' typedIdentifier)* ','? '}' |
| 1194 ; |
| 1195 |
| 1196 typedIdentifier |
| 1197 : type identifier |
| 1198 ; |
| 1199 |
| 1200 constructorDesignation |
| 1201 : typeIdentifier |
| 1202 | identifier '.' identifier |
| 1203 | identifier '.' typeIdentifier '.' identifier |
| 1204 | typeName typeArguments ('.' identifier)? |
| 1205 ; |
| 1206 |
| 1207 // Predicate: Force resolution as composite symbolLiteral as far as possible. |
| 1208 symbolLiteral |
| 1209 : '#' (operator | (identifier (('.' identifier) => '.' identifier)*)) |
| 1210 ; |
| 1211 |
| 1212 singleLineStringWithoutInterpolation |
| 1213 : RAW_SINGLE_LINE_STRING |
| 1214 | SINGLE_LINE_STRING_DQ_BEGIN_END |
| 1215 | SINGLE_LINE_STRING_SQ_BEGIN_END |
| 1216 ; |
| 1217 |
| 1218 singleLineString |
| 1219 : RAW_SINGLE_LINE_STRING |
| 1220 | SINGLE_LINE_STRING_SQ_BEGIN_END |
| 1221 | SINGLE_LINE_STRING_SQ_BEGIN_MID expression |
| 1222 (SINGLE_LINE_STRING_SQ_MID_MID expression)* |
| 1223 SINGLE_LINE_STRING_SQ_MID_END |
| 1224 | SINGLE_LINE_STRING_DQ_BEGIN_END |
| 1225 | SINGLE_LINE_STRING_DQ_BEGIN_MID expression |
| 1226 (SINGLE_LINE_STRING_DQ_MID_MID expression)* |
| 1227 SINGLE_LINE_STRING_DQ_MID_END |
| 1228 ; |
| 1229 |
| 1230 multiLineString |
| 1231 : RAW_MULTI_LINE_STRING |
| 1232 | MULTI_LINE_STRING_SQ_BEGIN_END |
| 1233 | MULTI_LINE_STRING_SQ_BEGIN_MID expression |
| 1234 (MULTI_LINE_STRING_SQ_MID_MID expression)* |
| 1235 MULTI_LINE_STRING_SQ_MID_END |
| 1236 | MULTI_LINE_STRING_DQ_BEGIN_END |
| 1237 | MULTI_LINE_STRING_DQ_BEGIN_MID expression |
| 1238 (MULTI_LINE_STRING_DQ_MID_MID expression)* |
| 1239 MULTI_LINE_STRING_DQ_MID_END |
| 1240 ; |
| 1241 |
| 1242 // ---------------------------------------- Lexer rules. |
| 1243 |
| 1244 fragment |
| 1245 LETTER |
| 1246 : 'a' .. 'z' |
| 1247 | 'A' .. 'Z' |
| 1248 ; |
| 1249 |
| 1250 fragment |
| 1251 DIGIT |
| 1252 : '0' .. '9' |
| 1253 ; |
| 1254 |
| 1255 fragment |
| 1256 EXPONENT |
| 1257 : ('e' | 'E') ('+' | '-')? DIGIT+ |
| 1258 ; |
| 1259 |
| 1260 fragment |
| 1261 HEX_DIGIT |
| 1262 : ('a' | 'b' | 'c' | 'd' | 'e' | 'f') |
| 1263 | ('A' | 'B' | 'C' | 'D' | 'E' | 'F') |
| 1264 | DIGIT |
| 1265 ; |
| 1266 |
| 1267 FINAL |
| 1268 : 'final' |
| 1269 ; |
| 1270 |
| 1271 CONST |
| 1272 : 'const' |
| 1273 ; |
| 1274 |
| 1275 VAR |
| 1276 : 'var' |
| 1277 ; |
| 1278 |
| 1279 VOID |
| 1280 : 'void' |
| 1281 ; |
| 1282 |
| 1283 ASYNC |
| 1284 : 'async' |
| 1285 ; |
| 1286 |
| 1287 THIS |
| 1288 : 'this' |
| 1289 ; |
| 1290 |
| 1291 ABSTRACT |
| 1292 : 'abstract' |
| 1293 ; |
| 1294 |
| 1295 AS |
| 1296 : 'as' |
| 1297 ; |
| 1298 |
| 1299 SYNC |
| 1300 : 'sync' |
| 1301 ; |
| 1302 |
| 1303 CLASS |
| 1304 : 'class' |
| 1305 ; |
| 1306 |
| 1307 WITH |
| 1308 : 'with' |
| 1309 ; |
| 1310 |
| 1311 STATIC |
| 1312 : 'static' |
| 1313 ; |
| 1314 |
| 1315 DYNAMIC |
| 1316 : 'dynamic' |
| 1317 ; |
| 1318 |
| 1319 EXTERNAL |
| 1320 : 'external' |
| 1321 ; |
| 1322 |
| 1323 GET |
| 1324 : 'get' |
| 1325 ; |
| 1326 |
| 1327 SET |
| 1328 : 'set' |
| 1329 ; |
| 1330 |
| 1331 OPERATOR |
| 1332 : 'operator' |
| 1333 ; |
| 1334 |
| 1335 SUPER |
| 1336 : 'super' |
| 1337 ; |
| 1338 |
| 1339 FACTORY |
| 1340 : 'factory' |
| 1341 ; |
| 1342 |
| 1343 EXTENDS |
| 1344 : 'extends' |
| 1345 ; |
| 1346 |
| 1347 IMPLEMENTS |
| 1348 : 'implements' |
| 1349 ; |
| 1350 |
| 1351 ENUM |
| 1352 : 'enum' |
| 1353 ; |
| 1354 |
| 1355 NULL |
| 1356 : 'null' |
| 1357 ; |
| 1358 |
| 1359 TRUE |
| 1360 : 'true' |
| 1361 ; |
| 1362 |
| 1363 FALSE |
| 1364 : 'false' |
| 1365 ; |
| 1366 |
| 1367 THROW |
| 1368 : 'throw' |
| 1369 ; |
| 1370 |
| 1371 NEW |
| 1372 : 'new' |
| 1373 ; |
| 1374 |
| 1375 AWAIT |
| 1376 : 'await' |
| 1377 ; |
| 1378 |
| 1379 DEFERRED |
| 1380 : 'deferred' |
| 1381 ; |
| 1382 |
| 1383 EXPORT |
| 1384 : 'export' |
| 1385 ; |
| 1386 |
| 1387 IMPORT |
| 1388 : 'import' |
| 1389 ; |
| 1390 |
| 1391 LIBRARY |
| 1392 : 'library' |
| 1393 ; |
| 1394 |
| 1395 PART |
| 1396 : 'part' |
| 1397 ; |
| 1398 |
| 1399 TYPEDEF |
| 1400 : 'typedef' |
| 1401 ; |
| 1402 |
| 1403 IS |
| 1404 : 'is' |
| 1405 ; |
| 1406 |
| 1407 IF |
| 1408 : 'if' |
| 1409 ; |
| 1410 |
| 1411 ELSE |
| 1412 : 'else' |
| 1413 ; |
| 1414 |
| 1415 WHILE |
| 1416 : 'while' |
| 1417 ; |
| 1418 |
| 1419 FOR |
| 1420 : 'for' |
| 1421 ; |
| 1422 |
| 1423 IN |
| 1424 : 'in' |
| 1425 ; |
| 1426 |
| 1427 DO |
| 1428 : 'do' |
| 1429 ; |
| 1430 |
| 1431 SWITCH |
| 1432 : 'switch' |
| 1433 ; |
| 1434 |
| 1435 CASE |
| 1436 : 'case' |
| 1437 ; |
| 1438 |
| 1439 DEFAULT |
| 1440 : 'default' |
| 1441 ; |
| 1442 |
| 1443 RETHROW |
| 1444 : 'rethrow' |
| 1445 ; |
| 1446 |
| 1447 TRY |
| 1448 : 'try' |
| 1449 ; |
| 1450 |
| 1451 ON |
| 1452 : 'on' |
| 1453 ; |
| 1454 |
| 1455 CATCH |
| 1456 : 'catch' |
| 1457 ; |
| 1458 |
| 1459 FINALLY |
| 1460 : 'finally' |
| 1461 ; |
| 1462 |
| 1463 RETURN |
| 1464 : 'return' |
| 1465 ; |
| 1466 |
| 1467 BREAK |
| 1468 : 'break' |
| 1469 ; |
| 1470 |
| 1471 CONTINUE |
| 1472 : 'continue' |
| 1473 ; |
| 1474 |
| 1475 YIELD |
| 1476 : 'yield' |
| 1477 ; |
| 1478 |
| 1479 SHOW |
| 1480 : 'show' |
| 1481 ; |
| 1482 |
| 1483 HIDE |
| 1484 : 'hide' |
| 1485 ; |
| 1486 |
| 1487 OF |
| 1488 : 'of' |
| 1489 ; |
| 1490 |
| 1491 ASSERT |
| 1492 : 'assert' |
| 1493 ; |
| 1494 |
| 1495 COVARIANT |
| 1496 : 'covariant' |
| 1497 ; |
| 1498 |
| 1499 FUNCTION |
| 1500 : 'Function' |
| 1501 ; |
| 1502 |
| 1503 NUMBER |
| 1504 : (DIGIT+ '.' DIGIT) => DIGIT+ '.' DIGIT+ EXPONENT? |
| 1505 | DIGIT+ EXPONENT? |
| 1506 | '.' DIGIT+ EXPONENT? |
| 1507 ; |
| 1508 |
| 1509 HEX_NUMBER |
| 1510 : '0x' HEX_DIGIT+ |
| 1511 | '0X' HEX_DIGIT+ |
| 1512 ; |
| 1513 |
| 1514 RAW_SINGLE_LINE_STRING |
| 1515 : 'r' '\'' (~('\'' | '\r' | '\n'))* '\'' |
| 1516 | 'r' '"' (~('"' | '\r' | '\n'))* '"' |
| 1517 ; |
| 1518 |
| 1519 RAW_MULTI_LINE_STRING |
| 1520 : 'r' '"""' (options {greedy=false;} : .)* '"""' |
| 1521 | 'r' '\'\'\'' (options {greedy=false;} : .)* '\'\'\'' |
| 1522 ; |
| 1523 |
| 1524 fragment |
| 1525 SIMPLE_STRING_INTERPOLATION |
| 1526 : '$' IDENTIFIER_NO_DOLLAR |
| 1527 ; |
| 1528 |
| 1529 fragment |
| 1530 STRING_CONTENT_SQ |
| 1531 : ~('\\' | '\'' | '$' | '\r' | '\n') |
| 1532 | '\\' ~( '\r' | '\n') |
| 1533 | SIMPLE_STRING_INTERPOLATION |
| 1534 ; |
| 1535 |
| 1536 SINGLE_LINE_STRING_SQ_BEGIN_END |
| 1537 : '\'' STRING_CONTENT_SQ* '\'' |
| 1538 ; |
| 1539 |
| 1540 SINGLE_LINE_STRING_SQ_BEGIN_MID |
| 1541 : '\'' STRING_CONTENT_SQ* '${' { enterBraceSingleQuote(); } |
| 1542 ; |
| 1543 |
| 1544 SINGLE_LINE_STRING_SQ_MID_MID |
| 1545 : { currentBraceLevel(BRACE_SINGLE) }? => |
| 1546 ('}' STRING_CONTENT_SQ* '${') => |
| 1547 { exitBrace(); } '}' STRING_CONTENT_SQ* '${' |
| 1548 { enterBraceSingleQuote(); } |
| 1549 ; |
| 1550 |
| 1551 SINGLE_LINE_STRING_SQ_MID_END |
| 1552 : { currentBraceLevel(BRACE_SINGLE) }? => |
| 1553 ('}' STRING_CONTENT_SQ* '\'') => |
| 1554 { exitBrace(); } '}' STRING_CONTENT_SQ* '\'' |
| 1555 ; |
| 1556 |
| 1557 fragment |
| 1558 STRING_CONTENT_DQ |
| 1559 : ~('\\' | '"' | '$' | '\r' | '\n') |
| 1560 | '\\' ~('\r' | '\n') |
| 1561 | SIMPLE_STRING_INTERPOLATION |
| 1562 ; |
| 1563 |
| 1564 SINGLE_LINE_STRING_DQ_BEGIN_END |
| 1565 : '"' STRING_CONTENT_DQ* '"' |
| 1566 ; |
| 1567 |
| 1568 SINGLE_LINE_STRING_DQ_BEGIN_MID |
| 1569 : '"' STRING_CONTENT_DQ* '${' { enterBraceDoubleQuote(); } |
| 1570 ; |
| 1571 |
| 1572 SINGLE_LINE_STRING_DQ_MID_MID |
| 1573 : { currentBraceLevel(BRACE_DOUBLE) }? => |
| 1574 ('}' STRING_CONTENT_DQ* '${') => |
| 1575 { exitBrace(); } '}' STRING_CONTENT_DQ* '${' |
| 1576 { enterBraceDoubleQuote(); } |
| 1577 ; |
| 1578 |
| 1579 SINGLE_LINE_STRING_DQ_MID_END |
| 1580 : { currentBraceLevel(BRACE_DOUBLE) }? => |
| 1581 ('}' STRING_CONTENT_DQ* '"') => |
| 1582 { exitBrace(); } '}' STRING_CONTENT_DQ* '"' |
| 1583 ; |
| 1584 |
| 1585 fragment |
| 1586 QUOTES_SQ |
| 1587 : |
| 1588 | '\'' |
| 1589 | '\'\'' |
| 1590 ; |
| 1591 |
| 1592 // Read string contents, which may be almost anything, but stop when seeing |
| 1593 // '\'\'\'' and when seeing '${'. We do this by allowing all other |
| 1594 // possibilities including escapes, simple interpolation, and fewer than |
| 1595 // three '\''. |
| 1596 fragment |
| 1597 STRING_CONTENT_TSQ |
| 1598 : QUOTES_SQ |
| 1599 (~('\\' | '$' | '\'') | '\\' . | SIMPLE_STRING_INTERPOLATION) |
| 1600 ; |
| 1601 |
| 1602 MULTI_LINE_STRING_SQ_BEGIN_END |
| 1603 : '\'\'\'' STRING_CONTENT_TSQ* '\'\'\'' |
| 1604 ; |
| 1605 |
| 1606 MULTI_LINE_STRING_SQ_BEGIN_MID |
| 1607 : '\'\'\'' STRING_CONTENT_TSQ* QUOTES_SQ '${' |
| 1608 { enterBraceThreeSingleQuotes(); } |
| 1609 ; |
| 1610 |
| 1611 MULTI_LINE_STRING_SQ_MID_MID |
| 1612 : { currentBraceLevel(BRACE_THREE_SINGLE) }? => |
| 1613 ('}' STRING_CONTENT_TSQ* QUOTES_SQ '${') => |
| 1614 { exitBrace(); } '}' STRING_CONTENT_TSQ* QUOTES_SQ '${' |
| 1615 { enterBraceThreeSingleQuotes(); } |
| 1616 ; |
| 1617 |
| 1618 MULTI_LINE_STRING_SQ_MID_END |
| 1619 : { currentBraceLevel(BRACE_THREE_SINGLE) }? => |
| 1620 ('}' STRING_CONTENT_TSQ* '\'\'\'') => |
| 1621 { exitBrace(); } '}' STRING_CONTENT_TSQ* '\'\'\'' |
| 1622 ; |
| 1623 |
| 1624 fragment |
| 1625 QUOTES_DQ |
| 1626 : |
| 1627 | '"' |
| 1628 | '""' |
| 1629 ; |
| 1630 |
| 1631 // Read string contents, which may be almost anything, but stop when seeing |
| 1632 // '"""' and when seeing '${'. We do this by allowing all other possibilities |
| 1633 // including escapes, simple interpolation, and fewer-than-three '"'. |
| 1634 fragment |
| 1635 STRING_CONTENT_TDQ |
| 1636 : QUOTES_DQ |
| 1637 (~('\\' | '$' | '"') | '\\' . | SIMPLE_STRING_INTERPOLATION) |
| 1638 ; |
| 1639 |
| 1640 MULTI_LINE_STRING_DQ_BEGIN_END |
| 1641 : '"""' STRING_CONTENT_TDQ* '"""' |
| 1642 ; |
| 1643 |
| 1644 MULTI_LINE_STRING_DQ_BEGIN_MID |
| 1645 : '"""' STRING_CONTENT_TDQ* QUOTES_DQ '${' |
| 1646 { enterBraceThreeDoubleQuotes(); } |
| 1647 ; |
| 1648 |
| 1649 MULTI_LINE_STRING_DQ_MID_MID |
| 1650 : { currentBraceLevel(BRACE_THREE_DOUBLE) }? => |
| 1651 ('}' STRING_CONTENT_TDQ* QUOTES_DQ '${') => |
| 1652 { exitBrace(); } '}' STRING_CONTENT_TDQ* QUOTES_DQ '${' |
| 1653 { enterBraceThreeDoubleQuotes(); } |
| 1654 ; |
| 1655 |
| 1656 MULTI_LINE_STRING_DQ_MID_END |
| 1657 : { currentBraceLevel(BRACE_THREE_DOUBLE) }? => |
| 1658 ('}' STRING_CONTENT_TDQ* '"""') => |
| 1659 { exitBrace(); } '}' STRING_CONTENT_TDQ* '"""' |
| 1660 ; |
| 1661 |
| 1662 LBRACE |
| 1663 : '{' { enterBrace(); } |
| 1664 ; |
| 1665 |
| 1666 RBRACE |
| 1667 : { currentBraceLevel(BRACE_NORMAL) }? => ('}') => { exitBrace(); } '}' |
| 1668 ; |
| 1669 |
| 1670 fragment |
| 1671 IDENTIFIER_START_NO_DOLLAR |
| 1672 : LETTER |
| 1673 | '_' |
| 1674 ; |
| 1675 |
| 1676 fragment |
| 1677 IDENTIFIER_PART_NO_DOLLAR |
| 1678 : IDENTIFIER_START_NO_DOLLAR |
| 1679 | DIGIT |
| 1680 ; |
| 1681 |
| 1682 fragment |
| 1683 IDENTIFIER_NO_DOLLAR |
| 1684 : IDENTIFIER_START_NO_DOLLAR IDENTIFIER_PART_NO_DOLLAR* |
| 1685 ; |
| 1686 |
| 1687 fragment |
| 1688 IDENTIFIER_START |
| 1689 : IDENTIFIER_START_NO_DOLLAR |
| 1690 | '$' |
| 1691 ; |
| 1692 |
| 1693 fragment |
| 1694 IDENTIFIER_PART |
| 1695 : IDENTIFIER_START |
| 1696 | DIGIT |
| 1697 ; |
| 1698 |
| 1699 SCRIPT_TAG |
| 1700 : '#!' (~('\r' | '\n'))* NEWLINE |
| 1701 ; |
| 1702 |
| 1703 IDENTIFIER |
| 1704 : IDENTIFIER_START IDENTIFIER_PART* |
| 1705 ; |
| 1706 |
| 1707 SINGLE_LINE_COMMENT |
| 1708 : '//' (~('\r' | '\n'))* NEWLINE? |
| 1709 { skip(); } |
| 1710 ; |
| 1711 |
| 1712 MULTI_LINE_COMMENT |
| 1713 : '/*' (options {greedy=false;} : (MULTI_LINE_COMMENT | .))* '*/' |
| 1714 { skip(); } |
| 1715 ; |
| 1716 |
| 1717 fragment |
| 1718 NEWLINE |
| 1719 : ('\r' | '\n' | '\r\n') |
| 1720 ; |
| 1721 |
| 1722 FEFF |
| 1723 : '\uFEFF' |
| 1724 ; |
| 1725 |
| 1726 WS |
| 1727 : (' ' | '\t' | '\r' | '\n')+ |
| 1728 { skip(); } |
| 1729 ; |
OLD | NEW |