| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.parser; | 8 library engine.parser; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 * The next token to be parsed. | 1498 * The next token to be parsed. |
| 1499 */ | 1499 */ |
| 1500 Token _currentToken; | 1500 Token _currentToken; |
| 1501 | 1501 |
| 1502 /** | 1502 /** |
| 1503 * A flag indicating whether the parser is currently in a function body marked
as being 'async'. | 1503 * A flag indicating whether the parser is currently in a function body marked
as being 'async'. |
| 1504 */ | 1504 */ |
| 1505 bool _inAsync = false; | 1505 bool _inAsync = false; |
| 1506 | 1506 |
| 1507 /** | 1507 /** |
| 1508 * A flag indicating whether the parser is currently in a function body marked
as being 'async'. |
| 1509 */ |
| 1510 bool _inGenerator = false; |
| 1511 |
| 1512 /** |
| 1508 * A flag indicating whether the parser is currently in the body of a loop. | 1513 * A flag indicating whether the parser is currently in the body of a loop. |
| 1509 */ | 1514 */ |
| 1510 bool _inLoop = false; | 1515 bool _inLoop = false; |
| 1511 | 1516 |
| 1512 /** | 1517 /** |
| 1513 * A flag indicating whether the parser is currently in a switch statement. | 1518 * A flag indicating whether the parser is currently in a switch statement. |
| 1514 */ | 1519 */ |
| 1515 bool _inSwitch = false; | 1520 bool _inSwitch = false; |
| 1516 | 1521 |
| 1517 /** | 1522 /** |
| (...skipping 3406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4924 * </pre> | 4929 * </pre> |
| 4925 * | 4930 * |
| 4926 * @param mayBeEmpty `true` if the function body is allowed to be empty | 4931 * @param mayBeEmpty `true` if the function body is allowed to be empty |
| 4927 * @param emptyErrorCode the error code to report if function body expected, b
ut not found | 4932 * @param emptyErrorCode the error code to report if function body expected, b
ut not found |
| 4928 * @param inExpression `true` if the function body is being parsed as part of
an expression | 4933 * @param inExpression `true` if the function body is being parsed as part of
an expression |
| 4929 * and therefore does not have a terminating semicolon | 4934 * and therefore does not have a terminating semicolon |
| 4930 * @return the function body that was parsed | 4935 * @return the function body that was parsed |
| 4931 */ | 4936 */ |
| 4932 FunctionBody _parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCod
e, bool inExpression) { | 4937 FunctionBody _parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCod
e, bool inExpression) { |
| 4933 bool wasInAsync = _inAsync; | 4938 bool wasInAsync = _inAsync; |
| 4939 bool wasInGenerator = _inGenerator; |
| 4934 bool wasInLoop = _inLoop; | 4940 bool wasInLoop = _inLoop; |
| 4935 bool wasInSwitch = _inSwitch; | 4941 bool wasInSwitch = _inSwitch; |
| 4936 _inAsync = false; | 4942 _inAsync = false; |
| 4943 _inGenerator = false; |
| 4937 _inLoop = false; | 4944 _inLoop = false; |
| 4938 _inSwitch = false; | 4945 _inSwitch = false; |
| 4939 try { | 4946 try { |
| 4940 if (_matches(TokenType.SEMICOLON)) { | 4947 if (_matches(TokenType.SEMICOLON)) { |
| 4941 if (!mayBeEmpty) { | 4948 if (!mayBeEmpty) { |
| 4942 _reportErrorForCurrentToken(emptyErrorCode, []); | 4949 _reportErrorForCurrentToken(emptyErrorCode, []); |
| 4943 } | 4950 } |
| 4944 return new EmptyFunctionBody(andAdvance); | 4951 return new EmptyFunctionBody(andAdvance); |
| 4945 } else if (_matchesString(_NATIVE)) { | 4952 } else if (_matchesString(_NATIVE)) { |
| 4946 Token nativeToken = andAdvance; | 4953 Token nativeToken = andAdvance; |
| 4947 StringLiteral stringLiteral = null; | 4954 StringLiteral stringLiteral = null; |
| 4948 if (_matches(TokenType.STRING)) { | 4955 if (_matches(TokenType.STRING)) { |
| 4949 stringLiteral = parseStringLiteral(); | 4956 stringLiteral = parseStringLiteral(); |
| 4950 } | 4957 } |
| 4951 return new NativeFunctionBody(nativeToken, stringLiteral, _expect(TokenT
ype.SEMICOLON)); | 4958 return new NativeFunctionBody(nativeToken, stringLiteral, _expect(TokenT
ype.SEMICOLON)); |
| 4952 } | 4959 } |
| 4953 Token keyword = null; | 4960 Token keyword = null; |
| 4954 Token star = null; | 4961 Token star = null; |
| 4955 if (_parseAsync) { | 4962 if (_parseAsync) { |
| 4956 if (_matchesString(ASYNC)) { | 4963 if (_matchesString(ASYNC)) { |
| 4957 keyword = andAdvance; | 4964 keyword = andAdvance; |
| 4958 if (_matches(TokenType.STAR)) { | 4965 if (_matches(TokenType.STAR)) { |
| 4959 star = andAdvance; | 4966 star = andAdvance; |
| 4967 _inGenerator = true; |
| 4960 } | 4968 } |
| 4961 _inAsync = true; | 4969 _inAsync = true; |
| 4962 } else if (_matchesString(SYNC)) { | 4970 } else if (_matchesString(SYNC)) { |
| 4963 keyword = andAdvance; | 4971 keyword = andAdvance; |
| 4964 if (_matches(TokenType.STAR)) { | 4972 if (_matches(TokenType.STAR)) { |
| 4965 star = andAdvance; | 4973 star = andAdvance; |
| 4974 _inGenerator = true; |
| 4966 } | 4975 } |
| 4967 } | 4976 } |
| 4968 } | 4977 } |
| 4969 if (_matches(TokenType.FUNCTION)) { | 4978 if (_matches(TokenType.FUNCTION)) { |
| 4970 if (keyword != null) { | 4979 if (keyword != null) { |
| 4971 if (!_tokenMatchesString(keyword, ASYNC)) { | 4980 if (!_tokenMatchesString(keyword, ASYNC)) { |
| 4972 _reportErrorForToken(ParserErrorCode.INVALID_SYNC, keyword, []); | 4981 _reportErrorForToken(ParserErrorCode.INVALID_SYNC, keyword, []); |
| 4973 keyword = null; | 4982 keyword = null; |
| 4974 } else if (star != null) { | 4983 } else if (star != null) { |
| 4975 _reportErrorForToken(ParserErrorCode.INVALID_STAR_AFTER_ASYNC, star,
[]); | 4984 _reportErrorForToken(ParserErrorCode.INVALID_STAR_AFTER_ASYNC, star,
[]); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4996 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON
)); | 5005 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON
)); |
| 4997 } | 5006 } |
| 4998 return new BlockFunctionBody(keyword, star, parseBlock()); | 5007 return new BlockFunctionBody(keyword, star, parseBlock()); |
| 4999 } else { | 5008 } else { |
| 5000 // Invalid function body | 5009 // Invalid function body |
| 5001 _reportErrorForCurrentToken(emptyErrorCode, []); | 5010 _reportErrorForCurrentToken(emptyErrorCode, []); |
| 5002 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))
; | 5011 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))
; |
| 5003 } | 5012 } |
| 5004 } finally { | 5013 } finally { |
| 5005 _inAsync = wasInAsync; | 5014 _inAsync = wasInAsync; |
| 5015 _inGenerator = wasInGenerator; |
| 5006 _inLoop = wasInLoop; | 5016 _inLoop = wasInLoop; |
| 5007 _inSwitch = wasInSwitch; | 5017 _inSwitch = wasInSwitch; |
| 5008 } | 5018 } |
| 5009 } | 5019 } |
| 5010 | 5020 |
| 5011 /** | 5021 /** |
| 5012 * Parse a function declaration. | 5022 * Parse a function declaration. |
| 5013 * | 5023 * |
| 5014 * <pre> | 5024 * <pre> |
| 5015 * functionDeclaration ::= | 5025 * functionDeclaration ::= |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5779 return _parseVariableDeclarationStatementAfterMetadata(commentAndMetadat
a); | 5789 return _parseVariableDeclarationStatementAfterMetadata(commentAndMetadat
a); |
| 5780 } else if (keyword == Keyword.NEW || keyword == Keyword.TRUE || keyword ==
Keyword.FALSE || keyword == Keyword.NULL || keyword == Keyword.SUPER || keyword
== Keyword.THIS) { | 5790 } else if (keyword == Keyword.NEW || keyword == Keyword.TRUE || keyword ==
Keyword.FALSE || keyword == Keyword.NULL || keyword == Keyword.SUPER || keyword
== Keyword.THIS) { |
| 5781 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEM
ICOLON)); | 5791 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEM
ICOLON)); |
| 5782 } else { | 5792 } else { |
| 5783 // | 5793 // |
| 5784 // We have found an error of some kind. Try to recover. | 5794 // We have found an error of some kind. Try to recover. |
| 5785 // | 5795 // |
| 5786 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []); | 5796 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []); |
| 5787 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); | 5797 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); |
| 5788 } | 5798 } |
| 5789 } else if (_inAsync && _matchesString(_YIELD)) { | 5799 } else if (_inGenerator && _matchesString(_YIELD)) { |
| 5790 return _parseYieldStatement(); | 5800 return _parseYieldStatement(); |
| 5791 } else if (_inAsync && _matchesString(_AWAIT)) { | 5801 } else if (_inAsync && _matchesString(_AWAIT)) { |
| 5792 if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) { | 5802 if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) { |
| 5793 return _parseForStatement(); | 5803 return _parseForStatement(); |
| 5794 } | 5804 } |
| 5795 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEMIC
OLON)); | 5805 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEMIC
OLON)); |
| 5806 } else if (_matchesString(_AWAIT) && _tokenMatchesKeyword(_peek(), Keyword.F
OR)) { |
| 5807 Token awaitToken = _currentToken; |
| 5808 Statement statement = _parseForStatement(); |
| 5809 if (statement is! ForStatement) { |
| 5810 _reportErrorForToken(CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, aw
aitToken, []); |
| 5811 } |
| 5812 return statement; |
| 5796 } else if (_matches(TokenType.SEMICOLON)) { | 5813 } else if (_matches(TokenType.SEMICOLON)) { |
| 5797 return _parseEmptyStatement(); | 5814 return _parseEmptyStatement(); |
| 5798 } else if (_isInitializedVariableDeclaration()) { | 5815 } else if (_isInitializedVariableDeclaration()) { |
| 5799 return _parseVariableDeclarationStatementAfterMetadata(commentAndMetadata)
; | 5816 return _parseVariableDeclarationStatementAfterMetadata(commentAndMetadata)
; |
| 5800 } else if (_isFunctionDeclaration()) { | 5817 } else if (_isFunctionDeclaration()) { |
| 5801 return _parseFunctionDeclarationStatement(); | 5818 return _parseFunctionDeclarationStatement(); |
| 5802 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { | 5819 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { |
| 5803 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []); | 5820 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []); |
| 5804 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); | 5821 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); |
| 5805 } else { | 5822 } else { |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6601 } else { | 6618 } else { |
| 6602 // Invalid operator before 'super' | 6619 // Invalid operator before 'super' |
| 6603 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER
, [operator.lexeme]); | 6620 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER
, [operator.lexeme]); |
| 6604 return new PrefixExpression(operator, new SuperExpression(andAdvance))
; | 6621 return new PrefixExpression(operator, new SuperExpression(andAdvance))
; |
| 6605 } | 6622 } |
| 6606 } | 6623 } |
| 6607 return new PrefixExpression(operator, _parseAssignableExpression(false)); | 6624 return new PrefixExpression(operator, _parseAssignableExpression(false)); |
| 6608 } else if (_matches(TokenType.PLUS)) { | 6625 } else if (_matches(TokenType.PLUS)) { |
| 6609 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); | 6626 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); |
| 6610 return _createSyntheticIdentifier(); | 6627 return _createSyntheticIdentifier(); |
| 6611 } else if (_inAsync && _matchesString(_AWAIT)) { | 6628 } else if (_matchesString(_AWAIT)) { |
| 6612 return _parseAwaitExpression(); | 6629 return _parseAwaitExpression(); |
| 6613 } | 6630 } |
| 6614 return _parsePostfixExpression(); | 6631 return _parsePostfixExpression(); |
| 6615 } | 6632 } |
| 6616 | 6633 |
| 6617 /** | 6634 /** |
| 6618 * Parse a variable declaration. | 6635 * Parse a variable declaration. |
| 6619 * | 6636 * |
| 6620 * <pre> | 6637 * <pre> |
| 6621 * variableDeclaration ::= | 6638 * variableDeclaration ::= |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6828 _reportError(new AnalysisError.con2(_source, node.offset, node.length, error
Code, arguments)); | 6845 _reportError(new AnalysisError.con2(_source, node.offset, node.length, error
Code, arguments)); |
| 6829 } | 6846 } |
| 6830 | 6847 |
| 6831 /** | 6848 /** |
| 6832 * Report an error with the given error code and arguments. | 6849 * Report an error with the given error code and arguments. |
| 6833 * | 6850 * |
| 6834 * @param errorCode the error code of the error to be reported | 6851 * @param errorCode the error code of the error to be reported |
| 6835 * @param token the token specifying the location of the error | 6852 * @param token the token specifying the location of the error |
| 6836 * @param arguments the arguments to the error, used to compose the error mess
age | 6853 * @param arguments the arguments to the error, used to compose the error mess
age |
| 6837 */ | 6854 */ |
| 6838 void _reportErrorForToken(ParserErrorCode errorCode, Token token, List<Object>
arguments) { | 6855 void _reportErrorForToken(ErrorCode errorCode, Token token, List<Object> argum
ents) { |
| 6839 if (token.type == TokenType.EOF) { | 6856 if (token.type == TokenType.EOF) { |
| 6840 token = token.previous; | 6857 token = token.previous; |
| 6841 } | 6858 } |
| 6842 _reportError(new AnalysisError.con2(_source, token.offset, Math.max(token.le
ngth, 1), errorCode, arguments)); | 6859 _reportError(new AnalysisError.con2(_source, token.offset, Math.max(token.le
ngth, 1), errorCode, arguments)); |
| 6843 } | 6860 } |
| 6844 | 6861 |
| 6845 /** | 6862 /** |
| 6846 * Skips a block with all containing blocks. | 6863 * Skips a block with all containing blocks. |
| 6847 */ | 6864 */ |
| 6848 void _skipBlock() { | 6865 void _skipBlock() { |
| (...skipping 2625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9474 return trampoline(target, arguments[0], arguments[1]); | 9491 return trampoline(target, arguments[0], arguments[1]); |
| 9475 case 3: | 9492 case 3: |
| 9476 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 9493 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 9477 case 4: | 9494 case 4: |
| 9478 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 9495 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 9479 default: | 9496 default: |
| 9480 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 9497 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 9481 } | 9498 } |
| 9482 } | 9499 } |
| 9483 } | 9500 } |
| OLD | NEW |