Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1134)

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 712083003: Create fewer unnecessary lists (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 arguments.add(argument); 1769 arguments.add(argument);
1770 bool foundNamedArgument = argument is NamedExpression; 1770 bool foundNamedArgument = argument is NamedExpression;
1771 bool generatedError = false; 1771 bool generatedError = false;
1772 while (_optional(TokenType.COMMA)) { 1772 while (_optional(TokenType.COMMA)) {
1773 argument = parseArgument(); 1773 argument = parseArgument();
1774 arguments.add(argument); 1774 arguments.add(argument);
1775 if (foundNamedArgument) { 1775 if (foundNamedArgument) {
1776 bool blankArgument = argument is SimpleIdentifier && (argument as Simp leIdentifier).name.isEmpty; 1776 bool blankArgument = argument is SimpleIdentifier && (argument as Simp leIdentifier).name.isEmpty;
1777 if (!generatedError && !(argument is NamedExpression && !blankArgument )) { 1777 if (!generatedError && !(argument is NamedExpression && !blankArgument )) {
1778 // Report the error, once, but allow the arguments to be in any orde r in the AST. 1778 // Report the error, once, but allow the arguments to be in any orde r in the AST.
1779 _reportErrorForCurrentToken(ParserErrorCode.POSITIONAL_AFTER_NAMED_A RGUMENT, []); 1779 _reportErrorForCurrentToken(ParserErrorCode.POSITIONAL_AFTER_NAMED_A RGUMENT);
1780 generatedError = true; 1780 generatedError = true;
1781 } 1781 }
1782 } else if (argument is NamedExpression) { 1782 } else if (argument is NamedExpression) {
1783 foundNamedArgument = true; 1783 foundNamedArgument = true;
1784 } 1784 }
1785 } 1785 }
1786 // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whet her there is a 1786 // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whet her there is a
1787 // matching right parenthesis. If there is, then we're more likely missing a comma and should 1787 // matching right parenthesis. If there is, then we're more likely missing a comma and should
1788 // go back to parsing arguments. 1788 // go back to parsing arguments.
1789 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); 1789 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 return _parseMethodDeclarationAfterReturnType(commentAndMetadata, modifi ers.externalKeyword, modifiers.staticKeyword, returnType); 1883 return _parseMethodDeclarationAfterReturnType(commentAndMetadata, modifi ers.externalKeyword, modifiers.staticKeyword, returnType);
1884 } else { 1884 } else {
1885 // 1885 //
1886 // We have found an error of some kind. Try to recover. 1886 // We have found an error of some kind. Try to recover.
1887 // 1887 //
1888 if (_matchesIdentifier()) { 1888 if (_matchesIdentifier()) {
1889 if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 1889 if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
1890 // 1890 //
1891 // We appear to have a variable declaration with a type of "void". 1891 // We appear to have a variable declaration with a type of "void".
1892 // 1892 //
1893 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType, []); 1893 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
1894 return _parseInitializedIdentifierList(commentAndMetadata, modifiers .staticKeyword, _validateModifiersForField(modifiers), returnType); 1894 return _parseInitializedIdentifierList(commentAndMetadata, modifiers .staticKeyword, _validateModifiersForField(modifiers), returnType);
1895 } 1895 }
1896 } 1896 }
1897 if (_isOperator(_currentToken)) { 1897 if (_isOperator(_currentToken)) {
1898 // 1898 //
1899 // We appear to have found an operator declaration without the 'operat or' keyword. 1899 // We appear to have found an operator declaration without the 'operat or' keyword.
1900 // 1900 //
1901 _validateModifiersForOperator(modifiers); 1901 _validateModifiersForOperator(modifiers);
1902 return _parseOperator(commentAndMetadata, modifiers.externalKeyword, r eturnType); 1902 return _parseOperator(commentAndMetadata, modifiers.externalKeyword, r eturnType);
1903 } 1903 }
1904 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 1904 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken) ;
1905 return null; 1905 return null;
1906 } 1906 }
1907 } else if (_matchesKeyword(Keyword.GET) && _tokenMatchesIdentifier(_peek())) { 1907 } else if (_matchesKeyword(Keyword.GET) && _tokenMatchesIdentifier(_peek())) {
1908 _validateModifiersForGetterOrSetterOrMethod(modifiers); 1908 _validateModifiersForGetterOrSetterOrMethod(modifiers);
1909 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, null); 1909 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, null);
1910 } else if (_matchesKeyword(Keyword.SET) && _tokenMatchesIdentifier(_peek())) { 1910 } else if (_matchesKeyword(Keyword.SET) && _tokenMatchesIdentifier(_peek())) {
1911 _validateModifiersForGetterOrSetterOrMethod(modifiers); 1911 _validateModifiersForGetterOrSetterOrMethod(modifiers);
1912 return _parseSetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, null); 1912 return _parseSetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, null);
1913 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) { 1913 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) {
1914 _validateModifiersForOperator(modifiers); 1914 _validateModifiersForOperator(modifiers);
(...skipping 10 matching lines...) Expand all
1925 if (keyword == null) { 1925 if (keyword == null) {
1926 keyword = modifiers.finalKeyword; 1926 keyword = modifiers.finalKeyword;
1927 } 1927 }
1928 if (keyword == null) { 1928 if (keyword == null) {
1929 keyword = modifiers.constKeyword; 1929 keyword = modifiers.constKeyword;
1930 } 1930 }
1931 if (keyword != null) { 1931 if (keyword != null) {
1932 // 1932 //
1933 // We appear to have found an incomplete field declaration. 1933 // We appear to have found an incomplete field declaration.
1934 // 1934 //
1935 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); 1935 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
1936 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 1936 List<VariableDeclaration> variables = new List<VariableDeclaration>();
1937 variables.add(new VariableDeclaration(null, null, _createSyntheticIdenti fier(), null, null)); 1937 variables.add(new VariableDeclaration(null, null, _createSyntheticIdenti fier(), null, null));
1938 return new FieldDeclaration(commentAndMetadata.comment, commentAndMetada ta.metadata, null, new VariableDeclarationList(null, null, keyword, null, variab les), _expectSemicolon()); 1938 return new FieldDeclaration(commentAndMetadata.comment, commentAndMetada ta.metadata, null, new VariableDeclarationList(null, null, keyword, null, variab les), _expectSemicolon());
1939 } 1939 }
1940 _reportErrorForToken(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); 1940 _reportErrorForToken(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken) ;
1941 if (commentAndMetadata.comment != null || !commentAndMetadata.metadata.isE mpty) { 1941 if (commentAndMetadata.comment != null || !commentAndMetadata.metadata.isE mpty) {
1942 // 1942 //
1943 // We appear to have found an incomplete declaration at the end of the c lass. At this point 1943 // We appear to have found an incomplete declaration at the end of the c lass. At this point
1944 // it consists of a metadata, which we don't want to loose, so we'll tre at it as a method 1944 // it consists of a metadata, which we don't want to loose, so we'll tre at it as a method
1945 // declaration with a missing name, parameters and empty body. 1945 // declaration with a missing name, parameters and empty body.
1946 // 1946 //
1947 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetad ata.metadata, null, null, null, null, null, _createSyntheticIdentifier(), new Fo rmalParameterList(null, new List<FormalParameter>(), null, null, null), new Empt yFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))); 1947 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetad ata.metadata, null, null, null, null, null, _createSyntheticIdentifier(), new Fo rmalParameterList(null, new List<FormalParameter>(), null, null, null), new Empt yFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)));
1948 } 1948 }
1949 return null; 1949 return null;
1950 } else if (_tokenMatches(_peek(), TokenType.PERIOD) && _tokenMatchesIdentifi er(_peekAt(2)) && _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { 1950 } else if (_tokenMatches(_peek(), TokenType.PERIOD) && _tokenMatchesIdentifi er(_peekAt(2)) && _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) {
1951 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, _v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, parseSimple Identifier(), andAdvance, parseSimpleIdentifier(), parseFormalParameterList()); 1951 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, _v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, parseSimple Identifier(), andAdvance, parseSimpleIdentifier(), parseFormalParameterList());
1952 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 1952 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
1953 SimpleIdentifier methodName = parseSimpleIdentifier(); 1953 SimpleIdentifier methodName = parseSimpleIdentifier();
1954 FormalParameterList parameters = parseFormalParameterList(); 1954 FormalParameterList parameters = parseFormalParameterList();
1955 if (_matches(TokenType.COLON) || modifiers.factoryKeyword != null || metho dName.name == className) { 1955 if (_matches(TokenType.COLON) || modifiers.factoryKeyword != null || metho dName.name == className) {
1956 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, _validateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodNam e, null, null, parameters); 1956 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, _validateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodNam e, null, null, parameters);
1957 } 1957 }
1958 _validateModifiersForGetterOrSetterOrMethod(modifiers); 1958 _validateModifiersForGetterOrSetterOrMethod(modifiers);
1959 _validateFormalParameterList(parameters); 1959 _validateFormalParameterList(parameters);
1960 return _parseMethodDeclarationAfterParameters(commentAndMetadata, modifier s.externalKeyword, modifiers.staticKeyword, null, methodName, parameters); 1960 return _parseMethodDeclarationAfterParameters(commentAndMetadata, modifier s.externalKeyword, modifiers.staticKeyword, null, methodName, parameters);
1961 } else if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 1961 } else if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
1962 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 1962 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
1963 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_T YPE, []); 1963 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_T YPE);
1964 } 1964 }
1965 return _parseInitializedIdentifierList(commentAndMetadata, modifiers.stati cKeyword, _validateModifiersForField(modifiers), null); 1965 return _parseInitializedIdentifierList(commentAndMetadata, modifiers.stati cKeyword, _validateModifiersForField(modifiers), null);
1966 } 1966 }
1967 TypeName type = parseTypeName(); 1967 TypeName type = parseTypeName();
1968 if (_matchesKeyword(Keyword.GET) && _tokenMatchesIdentifier(_peek())) { 1968 if (_matchesKeyword(Keyword.GET) && _tokenMatchesIdentifier(_peek())) {
1969 _validateModifiersForGetterOrSetterOrMethod(modifiers); 1969 _validateModifiersForGetterOrSetterOrMethod(modifiers);
1970 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, type); 1970 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, type);
1971 } else if (_matchesKeyword(Keyword.SET) && _tokenMatchesIdentifier(_peek())) { 1971 } else if (_matchesKeyword(Keyword.SET) && _tokenMatchesIdentifier(_peek())) {
1972 _validateModifiersForGetterOrSetterOrMethod(modifiers); 1972 _validateModifiersForGetterOrSetterOrMethod(modifiers);
1973 return _parseSetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, type); 1973 return _parseSetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, type);
(...skipping 14 matching lines...) Expand all
1988 // We appear to have found an operator declaration without the 'operator ' keyword. 1988 // We appear to have found an operator declaration without the 'operator ' keyword.
1989 // 1989 //
1990 _validateModifiersForOperator(modifiers); 1990 _validateModifiersForOperator(modifiers);
1991 return _parseOperator(commentAndMetadata, modifiers.externalKeyword, typ e); 1991 return _parseOperator(commentAndMetadata, modifiers.externalKeyword, typ e);
1992 } 1992 }
1993 // 1993 //
1994 // We appear to have found an incomplete declaration before another declar ation. 1994 // We appear to have found an incomplete declaration before another declar ation.
1995 // At this point it consists of a type name, so we'll treat it as a field declaration 1995 // At this point it consists of a type name, so we'll treat it as a field declaration
1996 // with a missing field name and semicolon. 1996 // with a missing field name and semicolon.
1997 // 1997 //
1998 _reportErrorForToken(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); 1998 _reportErrorForToken(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken) ;
1999 try { 1999 try {
2000 _lockErrorListener(); 2000 _lockErrorListener();
2001 return _parseInitializedIdentifierList(commentAndMetadata, modifiers.sta ticKeyword, _validateModifiersForField(modifiers), type); 2001 return _parseInitializedIdentifierList(commentAndMetadata, modifiers.sta ticKeyword, _validateModifiersForField(modifiers), type);
2002 } finally { 2002 } finally {
2003 _unlockErrorListener(); 2003 _unlockErrorListener();
2004 } 2004 }
2005 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 2005 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
2006 SimpleIdentifier methodName = parseSimpleIdentifier(); 2006 SimpleIdentifier methodName = parseSimpleIdentifier();
2007 FormalParameterList parameters = parseFormalParameterList(); 2007 FormalParameterList parameters = parseFormalParameterList();
2008 if (methodName.name == className) { 2008 if (methodName.name == className) {
2009 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type, []); 2009 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type);
2010 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, _validateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodNam e, null, null, parameters); 2010 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, _validateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodNam e, null, null, parameters);
2011 } 2011 }
2012 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2012 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2013 _validateFormalParameterList(parameters); 2013 _validateFormalParameterList(parameters);
2014 return _parseMethodDeclarationAfterParameters(commentAndMetadata, modifier s.externalKeyword, modifiers.staticKeyword, type, methodName, parameters); 2014 return _parseMethodDeclarationAfterParameters(commentAndMetadata, modifier s.externalKeyword, modifiers.staticKeyword, type, methodName, parameters);
2015 } else if (_tokenMatches(_peek(), TokenType.OPEN_CURLY_BRACKET)) { 2015 } else if (_tokenMatches(_peek(), TokenType.OPEN_CURLY_BRACKET)) {
2016 // We have found "TypeName identifier {", and are guessing that this is a getter without the 2016 // We have found "TypeName identifier {", and are guessing that this is a getter without the
2017 // keyword 'get'. 2017 // keyword 'get'.
2018 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2018 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2019 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET, []); 2019 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET);
2020 _currentToken = _injectToken(new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset)); 2020 _currentToken = _injectToken(new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset));
2021 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, type); 2021 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, modifie rs.staticKeyword, type);
2022 } 2022 }
2023 return _parseInitializedIdentifierList(commentAndMetadata, modifiers.staticK eyword, _validateModifiersForField(modifiers), type); 2023 return _parseInitializedIdentifierList(commentAndMetadata, modifiers.staticK eyword, _validateModifiersForField(modifiers), type);
2024 } 2024 }
2025 2025
2026 /** 2026 /**
2027 * Parse a compilation unit. 2027 * Parse a compilation unit.
2028 * 2028 *
2029 * Specified: 2029 * Specified:
(...skipping 30 matching lines...) Expand all
2060 bool partDirectiveFound = false; 2060 bool partDirectiveFound = false;
2061 bool directiveFoundAfterDeclaration = false; 2061 bool directiveFoundAfterDeclaration = false;
2062 List<Directive> directives = new List<Directive>(); 2062 List<Directive> directives = new List<Directive>();
2063 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ; 2063 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ;
2064 Token memberStart = _currentToken; 2064 Token memberStart = _currentToken;
2065 while (!_matches(TokenType.EOF)) { 2065 while (!_matches(TokenType.EOF)) {
2066 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 2066 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
2067 if ((_matchesKeyword(Keyword.IMPORT) || _matchesKeyword(Keyword.EXPORT) || _matchesKeyword(Keyword.LIBRARY) || _matchesKeyword(Keyword.PART)) && !_tokenMa tches(_peek(), TokenType.PERIOD) && !_tokenMatches(_peek(), TokenType.LT) && !_t okenMatches(_peek(), TokenType.OPEN_PAREN)) { 2067 if ((_matchesKeyword(Keyword.IMPORT) || _matchesKeyword(Keyword.EXPORT) || _matchesKeyword(Keyword.LIBRARY) || _matchesKeyword(Keyword.PART)) && !_tokenMa tches(_peek(), TokenType.PERIOD) && !_tokenMatches(_peek(), TokenType.LT) && !_t okenMatches(_peek(), TokenType.OPEN_PAREN)) {
2068 Directive directive = _parseDirective(commentAndMetadata); 2068 Directive directive = _parseDirective(commentAndMetadata);
2069 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { 2069 if (declarations.length > 0 && !directiveFoundAfterDeclaration) {
2070 _reportErrorForCurrentToken(ParserErrorCode.DIRECTIVE_AFTER_DECLARATIO N, []); 2070 _reportErrorForCurrentToken(ParserErrorCode.DIRECTIVE_AFTER_DECLARATIO N);
2071 directiveFoundAfterDeclaration = true; 2071 directiveFoundAfterDeclaration = true;
2072 } 2072 }
2073 if (directive is LibraryDirective) { 2073 if (directive is LibraryDirective) {
2074 if (libraryDirectiveFound) { 2074 if (libraryDirectiveFound) {
2075 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTI VES, []); 2075 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTI VES);
2076 } else { 2076 } else {
2077 if (directives.length > 0) { 2077 if (directives.length > 0) {
2078 _reportErrorForToken(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, directive.libraryToken, []); 2078 _reportErrorForToken(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, directive.libraryToken);
2079 } 2079 }
2080 libraryDirectiveFound = true; 2080 libraryDirectiveFound = true;
2081 } 2081 }
2082 } else if (directive is PartDirective) { 2082 } else if (directive is PartDirective) {
2083 partDirectiveFound = true; 2083 partDirectiveFound = true;
2084 } else if (partDirectiveFound) { 2084 } else if (partDirectiveFound) {
2085 if (directive is ExportDirective) { 2085 if (directive is ExportDirective) {
2086 _reportErrorForToken(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIR ECTIVE, directive.keyword, []); 2086 _reportErrorForToken(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIR ECTIVE, directive.keyword);
2087 } else if (directive is ImportDirective) { 2087 } else if (directive is ImportDirective) {
2088 _reportErrorForToken(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIR ECTIVE, directive.keyword, []); 2088 _reportErrorForToken(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIR ECTIVE, directive.keyword);
2089 } 2089 }
2090 } 2090 }
2091 if (directive is PartOfDirective) { 2091 if (directive is PartOfDirective) {
2092 if (partOfDirectiveFound) { 2092 if (partOfDirectiveFound) {
2093 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_PART_OF_DIRECTI VES, []); 2093 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_PART_OF_DIRECTI VES);
2094 } else { 2094 } else {
2095 int directiveCount = directives.length; 2095 int directiveCount = directives.length;
2096 for (int i = 0; i < directiveCount; i++) { 2096 for (int i = 0; i < directiveCount; i++) {
2097 _reportErrorForToken(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART , directives[i].keyword, []); 2097 _reportErrorForToken(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART , directives[i].keyword);
2098 } 2098 }
2099 partOfDirectiveFound = true; 2099 partOfDirectiveFound = true;
2100 } 2100 }
2101 } else { 2101 } else {
2102 if (partOfDirectiveFound) { 2102 if (partOfDirectiveFound) {
2103 _reportErrorForToken(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directive.keyword, []); 2103 _reportErrorForToken(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directive.keyword);
2104 } 2104 }
2105 } 2105 }
2106 directives.add(directive); 2106 directives.add(directive);
2107 } else if (_matches(TokenType.SEMICOLON)) { 2107 } else if (_matches(TokenType.SEMICOLON)) {
2108 _reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_ currentToken.lexeme]); 2108 _reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_ currentToken.lexeme]);
2109 _advance(); 2109 _advance();
2110 } else { 2110 } else {
2111 CompilationUnitMember member = _parseCompilationUnitMember(commentAndMet adata); 2111 CompilationUnitMember member = _parseCompilationUnitMember(commentAndMet adata);
2112 if (member != null) { 2112 if (member != null) {
2113 declarations.add(member); 2113 declarations.add(member);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2313 bool wasOptionalParameter = false; 2313 bool wasOptionalParameter = false;
2314 Token initialToken = null; 2314 Token initialToken = null;
2315 do { 2315 do {
2316 if (firstParameter) { 2316 if (firstParameter) {
2317 firstParameter = false; 2317 firstParameter = false;
2318 } else if (!_optional(TokenType.COMMA)) { 2318 } else if (!_optional(TokenType.COMMA)) {
2319 // TODO(brianwilkerson) The token is wrong, we need to recover from this case. 2319 // TODO(brianwilkerson) The token is wrong, we need to recover from this case.
2320 if (_getEndToken(leftParenthesis) != null) { 2320 if (_getEndToken(leftParenthesis) != null) {
2321 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TOKEN, [TokenType .COMMA.lexeme]); 2321 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TOKEN, [TokenType .COMMA.lexeme]);
2322 } else { 2322 } else {
2323 _reportErrorForToken(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _cur rentToken.previous, []); 2323 _reportErrorForToken(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _cur rentToken.previous);
2324 break; 2324 break;
2325 } 2325 }
2326 } 2326 }
2327 initialToken = _currentToken; 2327 initialToken = _currentToken;
2328 // 2328 //
2329 // Handle the beginning of parameter groups. 2329 // Handle the beginning of parameter groups.
2330 // 2330 //
2331 if (_matches(TokenType.OPEN_SQUARE_BRACKET)) { 2331 if (_matches(TokenType.OPEN_SQUARE_BRACKET)) {
2332 wasOptionalParameter = true; 2332 wasOptionalParameter = true;
2333 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) { 2333 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) {
2334 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_POSITIONAL_PARAME TER_GROUPS, []); 2334 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_POSITIONAL_PARAME TER_GROUPS);
2335 reportedMuliplePositionalGroups = true; 2335 reportedMuliplePositionalGroups = true;
2336 } 2336 }
2337 if (leftCurlyBracket != null && !reportedMixedGroups) { 2337 if (leftCurlyBracket != null && !reportedMixedGroups) {
2338 _reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS, [] ); 2338 _reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS);
2339 reportedMixedGroups = true; 2339 reportedMixedGroups = true;
2340 } 2340 }
2341 leftSquareBracket = andAdvance; 2341 leftSquareBracket = andAdvance;
2342 currentParameters = positionalParameters; 2342 currentParameters = positionalParameters;
2343 kind = ParameterKind.POSITIONAL; 2343 kind = ParameterKind.POSITIONAL;
2344 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 2344 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
2345 wasOptionalParameter = true; 2345 wasOptionalParameter = true;
2346 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) { 2346 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) {
2347 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_G ROUPS, []); 2347 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_G ROUPS);
2348 reportedMulipleNamedGroups = true; 2348 reportedMulipleNamedGroups = true;
2349 } 2349 }
2350 if (leftSquareBracket != null && !reportedMixedGroups) { 2350 if (leftSquareBracket != null && !reportedMixedGroups) {
2351 _reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS, [] ); 2351 _reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS);
2352 reportedMixedGroups = true; 2352 reportedMixedGroups = true;
2353 } 2353 }
2354 leftCurlyBracket = andAdvance; 2354 leftCurlyBracket = andAdvance;
2355 currentParameters = namedParameters; 2355 currentParameters = namedParameters;
2356 kind = ParameterKind.NAMED; 2356 kind = ParameterKind.NAMED;
2357 } 2357 }
2358 // 2358 //
2359 // Parse and record the parameter. 2359 // Parse and record the parameter.
2360 // 2360 //
2361 FormalParameter parameter = _parseFormalParameter(kind); 2361 FormalParameter parameter = _parseFormalParameter(kind);
2362 parameters.add(parameter); 2362 parameters.add(parameter);
2363 currentParameters.add(parameter); 2363 currentParameters.add(parameter);
2364 if (kind == ParameterKind.REQUIRED && wasOptionalParameter) { 2364 if (kind == ParameterKind.REQUIRED && wasOptionalParameter) {
2365 _reportErrorForNode(ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, p arameter, []); 2365 _reportErrorForNode(ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, p arameter);
2366 } 2366 }
2367 // 2367 //
2368 // Handle the end of parameter groups. 2368 // Handle the end of parameter groups.
2369 // 2369 //
2370 // TODO(brianwilkerson) Improve the detection and reporting of missing and mismatched delimiters. 2370 // TODO(brianwilkerson) Improve the detection and reporting of missing and mismatched delimiters.
2371 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { 2371 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) {
2372 rightSquareBracket = andAdvance; 2372 rightSquareBracket = andAdvance;
2373 currentParameters = normalParameters; 2373 currentParameters = normalParameters;
2374 if (leftSquareBracket == null) { 2374 if (leftSquareBracket == null) {
2375 if (leftCurlyBracket != null) { 2375 if (leftCurlyBracket != null) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2555 Token period = null; 2555 Token period = null;
2556 if (_matchesKeyword(Keyword.THIS)) { 2556 if (_matchesKeyword(Keyword.THIS)) {
2557 thisKeyword = andAdvance; 2557 thisKeyword = andAdvance;
2558 period = _expect(TokenType.PERIOD); 2558 period = _expect(TokenType.PERIOD);
2559 } 2559 }
2560 SimpleIdentifier identifier = parseSimpleIdentifier(); 2560 SimpleIdentifier identifier = parseSimpleIdentifier();
2561 if (_matches(TokenType.OPEN_PAREN)) { 2561 if (_matches(TokenType.OPEN_PAREN)) {
2562 FormalParameterList parameters = parseFormalParameterList(); 2562 FormalParameterList parameters = parseFormalParameterList();
2563 if (thisKeyword == null) { 2563 if (thisKeyword == null) {
2564 if (holder.keyword != null) { 2564 if (holder.keyword != null) {
2565 _reportErrorForToken(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, hol der.keyword, []); 2565 _reportErrorForToken(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, hol der.keyword);
2566 } 2566 }
2567 return new FunctionTypedFormalParameter(commentAndMetadata.comment, comm entAndMetadata.metadata, holder.type, identifier, parameters); 2567 return new FunctionTypedFormalParameter(commentAndMetadata.comment, comm entAndMetadata.metadata, holder.type, identifier, parameters);
2568 } else { 2568 } else {
2569 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMe tadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, p arameters); 2569 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMe tadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, p arameters);
2570 } 2570 }
2571 } 2571 }
2572 TypeName type = holder.type; 2572 TypeName type = holder.type;
2573 if (type != null) { 2573 if (type != null) {
2574 if (_tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) { 2574 if (_tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) {
2575 _reportErrorForToken(ParserErrorCode.VOID_PARAMETER, type.name.beginToke n, []); 2575 _reportErrorForToken(ParserErrorCode.VOID_PARAMETER, type.name.beginToke n);
2576 } else if (holder.keyword != null && _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) { 2576 } else if (holder.keyword != null && _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) {
2577 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []); 2577 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword);
2578 } 2578 }
2579 } 2579 }
2580 if (thisKeyword != null) { 2580 if (thisKeyword != null) {
2581 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMeta data.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, nul l); 2581 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMeta data.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, nul l);
2582 } 2582 }
2583 return new SimpleFormalParameter(commentAndMetadata.comment, commentAndMetad ata.metadata, holder.keyword, holder.type, identifier); 2583 return new SimpleFormalParameter(commentAndMetadata.comment, commentAndMetad ata.metadata, holder.keyword, holder.type, identifier);
2584 } 2584 }
2585 2585
2586 /** 2586 /**
2587 * Parse a prefixed identifier. 2587 * Parse a prefixed identifier.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2629 * identifier ::= 2629 * identifier ::=
2630 * IDENTIFIER 2630 * IDENTIFIER
2631 * </pre> 2631 * </pre>
2632 * 2632 *
2633 * @return the simple identifier that was parsed 2633 * @return the simple identifier that was parsed
2634 */ 2634 */
2635 SimpleIdentifier parseSimpleIdentifier() { 2635 SimpleIdentifier parseSimpleIdentifier() {
2636 if (_matchesIdentifier()) { 2636 if (_matchesIdentifier()) {
2637 return new SimpleIdentifier(andAdvance); 2637 return new SimpleIdentifier(andAdvance);
2638 } 2638 }
2639 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); 2639 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
2640 return _createSyntheticIdentifier(); 2640 return _createSyntheticIdentifier();
2641 } 2641 }
2642 2642
2643 /** 2643 /**
2644 * Parse a statement. 2644 * Parse a statement.
2645 * 2645 *
2646 * <pre> 2646 * <pre>
2647 * statement ::= 2647 * statement ::=
2648 * label* nonLabeledStatement 2648 * label* nonLabeledStatement
2649 * </pre> 2649 * </pre>
(...skipping 27 matching lines...) Expand all
2677 List<StringLiteral> strings = new List<StringLiteral>(); 2677 List<StringLiteral> strings = new List<StringLiteral>();
2678 while (_matches(TokenType.STRING)) { 2678 while (_matches(TokenType.STRING)) {
2679 Token string = andAdvance; 2679 Token string = andAdvance;
2680 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || _matches(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) { 2680 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || _matches(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) {
2681 strings.add(_parseStringInterpolation(string)); 2681 strings.add(_parseStringInterpolation(string));
2682 } else { 2682 } else {
2683 strings.add(new SimpleStringLiteral(string, _computeStringValue(string.l exeme, true, true))); 2683 strings.add(new SimpleStringLiteral(string, _computeStringValue(string.l exeme, true, true)));
2684 } 2684 }
2685 } 2685 }
2686 if (strings.length < 1) { 2686 if (strings.length < 1) {
2687 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_STRING_LITERAL, []); 2687 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_STRING_LITERAL);
2688 return _createSyntheticStringLiteral(); 2688 return _createSyntheticStringLiteral();
2689 } else if (strings.length == 1) { 2689 } else if (strings.length == 1) {
2690 return strings[0]; 2690 return strings[0];
2691 } else { 2691 } else {
2692 return new AdjacentStrings(strings); 2692 return new AdjacentStrings(strings);
2693 } 2693 }
2694 } 2694 }
2695 2695
2696 /** 2696 /**
2697 * Parse a list of type arguments. 2697 * Parse a list of type arguments.
(...skipping 25 matching lines...) Expand all
2723 * <pre> 2723 * <pre>
2724 * type ::= 2724 * type ::=
2725 * qualified typeArguments? 2725 * qualified typeArguments?
2726 * </pre> 2726 * </pre>
2727 * 2727 *
2728 * @return the type name that was parsed 2728 * @return the type name that was parsed
2729 */ 2729 */
2730 TypeName parseTypeName() { 2730 TypeName parseTypeName() {
2731 Identifier typeName; 2731 Identifier typeName;
2732 if (_matchesKeyword(Keyword.VAR)) { 2732 if (_matchesKeyword(Keyword.VAR)) {
2733 _reportErrorForCurrentToken(ParserErrorCode.VAR_AS_TYPE_NAME, []); 2733 _reportErrorForCurrentToken(ParserErrorCode.VAR_AS_TYPE_NAME);
2734 typeName = new SimpleIdentifier(andAdvance); 2734 typeName = new SimpleIdentifier(andAdvance);
2735 } else if (_matchesIdentifier()) { 2735 } else if (_matchesIdentifier()) {
2736 typeName = parsePrefixedIdentifier(); 2736 typeName = parsePrefixedIdentifier();
2737 } else { 2737 } else {
2738 typeName = _createSyntheticIdentifier(); 2738 typeName = _createSyntheticIdentifier();
2739 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TYPE_NAME, []); 2739 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TYPE_NAME);
2740 } 2740 }
2741 TypeArgumentList typeArguments = null; 2741 TypeArgumentList typeArguments = null;
2742 if (_matches(TokenType.LT)) { 2742 if (_matches(TokenType.LT)) {
2743 typeArguments = parseTypeArgumentList(); 2743 typeArguments = parseTypeArgumentList();
2744 } 2744 }
2745 return new TypeName(typeName, typeArguments); 2745 return new TypeName(typeName, typeArguments);
2746 } 2746 }
2747 2747
2748 /** 2748 /**
2749 * Parse a type parameter. 2749 * Parse a type parameter.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2984 * 2984 *
2985 * assignableSelector ::= 2985 * assignableSelector ::=
2986 * '[' expression ']' 2986 * '[' expression ']'
2987 * | '.' identifier 2987 * | '.' identifier
2988 * </pre> 2988 * </pre>
2989 * 2989 *
2990 * @param expression the expression being checked 2990 * @param expression the expression being checked
2991 */ 2991 */
2992 void _ensureAssignable(Expression expression) { 2992 void _ensureAssignable(Expression expression) {
2993 if (expression != null && !expression.isAssignable) { 2993 if (expression != null && !expression.isAssignable) {
2994 _reportErrorForCurrentToken(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSI GNABLE, []); 2994 _reportErrorForCurrentToken(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSI GNABLE);
2995 } 2995 }
2996 } 2996 }
2997 2997
2998 /** 2998 /**
2999 * If the current token has the expected type, return it after advancing to th e next token. 2999 * If the current token has the expected type, return it after advancing to th e next token.
3000 * Otherwise report an error and return the current token without advancing. N ote that the method 3000 * Otherwise report an error and return the current token without advancing. N ote that the method
3001 * [_expectGt] should be used if the argument to this method would be [TokenTy pe.GT]. 3001 * [_expectGt] should be used if the argument to this method would be [TokenTy pe.GT].
3002 * 3002 *
3003 * @param type the type of token that is expected 3003 * @param type the type of token that is expected
3004 * @return the token that matched the given type 3004 * @return the token that matched the given type
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
3584 * 'assert' '(' conditionalExpression ')' ';' 3584 * 'assert' '(' conditionalExpression ')' ';'
3585 * </pre> 3585 * </pre>
3586 * 3586 *
3587 * @return the assert statement 3587 * @return the assert statement
3588 */ 3588 */
3589 AssertStatement _parseAssertStatement() { 3589 AssertStatement _parseAssertStatement() {
3590 Token keyword = _expectKeyword(Keyword.ASSERT); 3590 Token keyword = _expectKeyword(Keyword.ASSERT);
3591 Token leftParen = _expect(TokenType.OPEN_PAREN); 3591 Token leftParen = _expect(TokenType.OPEN_PAREN);
3592 Expression expression = parseExpression2(); 3592 Expression expression = parseExpression2();
3593 if (expression is AssignmentExpression) { 3593 if (expression is AssignmentExpression) {
3594 _reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expre ssion, []); 3594 _reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expre ssion);
3595 } else if (expression is CascadeExpression) { 3595 } else if (expression is CascadeExpression) {
3596 _reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expressi on, []); 3596 _reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expressi on);
3597 } else if (expression is ThrowExpression) { 3597 } else if (expression is ThrowExpression) {
3598 _reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression , []); 3598 _reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression );
3599 } else if (expression is RethrowExpression) { 3599 } else if (expression is RethrowExpression) {
3600 _reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expressi on, []); 3600 _reportErrorForNode(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expressi on);
3601 } 3601 }
3602 Token rightParen = _expect(TokenType.CLOSE_PAREN); 3602 Token rightParen = _expect(TokenType.CLOSE_PAREN);
3603 Token semicolon = _expect(TokenType.SEMICOLON); 3603 Token semicolon = _expect(TokenType.SEMICOLON);
3604 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon); 3604 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon);
3605 } 3605 }
3606 3606
3607 /** 3607 /**
3608 * Parse an assignable expression. 3608 * Parse an assignable expression.
3609 * 3609 *
3610 * <pre> 3610 * <pre>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3685 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBr acket); 3685 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBr acket);
3686 } finally { 3686 } finally {
3687 _inInitializer = wasInInitializer; 3687 _inInitializer = wasInInitializer;
3688 } 3688 }
3689 } else if (_matches(TokenType.PERIOD)) { 3689 } else if (_matches(TokenType.PERIOD)) {
3690 Token period = andAdvance; 3690 Token period = andAdvance;
3691 return new PropertyAccess(prefix, period, parseSimpleIdentifier()); 3691 return new PropertyAccess(prefix, period, parseSimpleIdentifier());
3692 } else { 3692 } else {
3693 if (!optional) { 3693 if (!optional) {
3694 // Report the missing selector. 3694 // Report the missing selector.
3695 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 3695 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR) ;
3696 } 3696 }
3697 return prefix; 3697 return prefix;
3698 } 3698 }
3699 } 3699 }
3700 3700
3701 /** 3701 /**
3702 * Parse a await expression. 3702 * Parse a await expression.
3703 * 3703 *
3704 * <pre> 3704 * <pre>
3705 * awaitExpression ::= 3705 * awaitExpression ::=
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3774 * 3774 *
3775 * @return the break statement that was parsed 3775 * @return the break statement that was parsed
3776 */ 3776 */
3777 Statement _parseBreakStatement() { 3777 Statement _parseBreakStatement() {
3778 Token breakKeyword = _expectKeyword(Keyword.BREAK); 3778 Token breakKeyword = _expectKeyword(Keyword.BREAK);
3779 SimpleIdentifier label = null; 3779 SimpleIdentifier label = null;
3780 if (_matchesIdentifier()) { 3780 if (_matchesIdentifier()) {
3781 label = parseSimpleIdentifier(); 3781 label = parseSimpleIdentifier();
3782 } 3782 }
3783 if (!_inLoop && !_inSwitch && label == null) { 3783 if (!_inLoop && !_inSwitch && label == null) {
3784 _reportErrorForToken(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []); 3784 _reportErrorForToken(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword);
3785 } 3785 }
3786 Token semicolon = _expect(TokenType.SEMICOLON); 3786 Token semicolon = _expect(TokenType.SEMICOLON);
3787 return new BreakStatement(breakKeyword, label, semicolon); 3787 return new BreakStatement(breakKeyword, label, semicolon);
3788 } 3788 }
3789 3789
3790 /** 3790 /**
3791 * Parse a cascade section. 3791 * Parse a cascade section.
3792 * 3792 *
3793 * <pre> 3793 * <pre>
3794 * cascadeSection ::= 3794 * cascadeSection ::=
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3909 // 3909 //
3910 ExtendsClause extendsClause = null; 3910 ExtendsClause extendsClause = null;
3911 WithClause withClause = null; 3911 WithClause withClause = null;
3912 ImplementsClause implementsClause = null; 3912 ImplementsClause implementsClause = null;
3913 bool foundClause = true; 3913 bool foundClause = true;
3914 while (foundClause) { 3914 while (foundClause) {
3915 if (_matchesKeyword(Keyword.EXTENDS)) { 3915 if (_matchesKeyword(Keyword.EXTENDS)) {
3916 if (extendsClause == null) { 3916 if (extendsClause == null) {
3917 extendsClause = parseExtendsClause(); 3917 extendsClause = parseExtendsClause();
3918 if (withClause != null) { 3918 if (withClause != null) {
3919 _reportErrorForToken(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause .withKeyword, []); 3919 _reportErrorForToken(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause .withKeyword);
3920 } else if (implementsClause != null) { 3920 } else if (implementsClause != null) {
3921 _reportErrorForToken(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, impl ementsClause.keyword, []); 3921 _reportErrorForToken(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, impl ementsClause.keyword);
3922 } 3922 }
3923 } else { 3923 } else {
3924 _reportErrorForToken(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extends Clause.keyword, []); 3924 _reportErrorForToken(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extends Clause.keyword);
3925 parseExtendsClause(); 3925 parseExtendsClause();
3926 } 3926 }
3927 } else if (_matchesKeyword(Keyword.WITH)) { 3927 } else if (_matchesKeyword(Keyword.WITH)) {
3928 if (withClause == null) { 3928 if (withClause == null) {
3929 withClause = parseWithClause(); 3929 withClause = parseWithClause();
3930 if (implementsClause != null) { 3930 if (implementsClause != null) {
3931 _reportErrorForToken(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, impleme ntsClause.keyword, []); 3931 _reportErrorForToken(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, impleme ntsClause.keyword);
3932 } 3932 }
3933 } else { 3933 } else {
3934 _reportErrorForToken(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause .withKeyword, []); 3934 _reportErrorForToken(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause .withKeyword);
3935 parseWithClause(); 3935 parseWithClause();
3936 // TODO(brianwilkerson) Should we merge the list of applied mixins int o a single list? 3936 // TODO(brianwilkerson) Should we merge the list of applied mixins int o a single list?
3937 } 3937 }
3938 } else if (_matchesKeyword(Keyword.IMPLEMENTS)) { 3938 } else if (_matchesKeyword(Keyword.IMPLEMENTS)) {
3939 if (implementsClause == null) { 3939 if (implementsClause == null) {
3940 implementsClause = parseImplementsClause(); 3940 implementsClause = parseImplementsClause();
3941 } else { 3941 } else {
3942 _reportErrorForToken(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, impl ementsClause.keyword, []); 3942 _reportErrorForToken(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, impl ementsClause.keyword);
3943 parseImplementsClause(); 3943 parseImplementsClause();
3944 // TODO(brianwilkerson) Should we merge the list of implemented classe s into a single list? 3944 // TODO(brianwilkerson) Should we merge the list of implemented classe s into a single list?
3945 } 3945 }
3946 } else { 3946 } else {
3947 foundClause = false; 3947 foundClause = false;
3948 } 3948 }
3949 } 3949 }
3950 if (withClause != null && extendsClause == null) { 3950 if (withClause != null && extendsClause == null) {
3951 _reportErrorForToken(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.with Keyword, []); 3951 _reportErrorForToken(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.with Keyword);
3952 } 3952 }
3953 // 3953 //
3954 // Look for and skip over the extra-lingual 'native' specification. 3954 // Look for and skip over the extra-lingual 'native' specification.
3955 // 3955 //
3956 NativeClause nativeClause = null; 3956 NativeClause nativeClause = null;
3957 if (_matchesString(_NATIVE) && _tokenMatches(_peek(), TokenType.STRING)) { 3957 if (_matchesString(_NATIVE) && _tokenMatches(_peek(), TokenType.STRING)) {
3958 nativeClause = _parseNativeClause(); 3958 nativeClause = _parseNativeClause();
3959 } 3959 }
3960 // 3960 //
3961 // Parse the body of the class. 3961 // Parse the body of the class.
3962 // 3962 //
3963 Token leftBracket = null; 3963 Token leftBracket = null;
3964 List<ClassMember> members = null; 3964 List<ClassMember> members = null;
3965 Token rightBracket = null; 3965 Token rightBracket = null;
3966 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 3966 if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
3967 leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET); 3967 leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET);
3968 members = _parseClassMembers(className, _getEndToken(leftBracket)); 3968 members = _parseClassMembers(className, _getEndToken(leftBracket));
3969 rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); 3969 rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
3970 } else { 3970 } else {
3971 leftBracket = _createSyntheticToken(TokenType.OPEN_CURLY_BRACKET); 3971 leftBracket = _createSyntheticToken(TokenType.OPEN_CURLY_BRACKET);
3972 rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET); 3972 rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET);
3973 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CLASS_BODY, []); 3973 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CLASS_BODY);
3974 } 3974 }
3975 ClassDeclaration classDeclaration = new ClassDeclaration(commentAndMetadata. comment, commentAndMetadata.metadata, abstractKeyword, keyword, name, typeParame ters, extendsClause, withClause, implementsClause, leftBracket, members, rightBr acket); 3975 ClassDeclaration classDeclaration = new ClassDeclaration(commentAndMetadata. comment, commentAndMetadata.metadata, abstractKeyword, keyword, name, typeParame ters, extendsClause, withClause, implementsClause, leftBracket, members, rightBr acket);
3976 classDeclaration.nativeClause = nativeClause; 3976 classDeclaration.nativeClause = nativeClause;
3977 return classDeclaration; 3977 return classDeclaration;
3978 } 3978 }
3979 3979
3980 /** 3980 /**
3981 * Parse a list of class members. 3981 * Parse a list of class members.
3982 * 3982 *
3983 * <pre> 3983 * <pre>
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
4267 } else if (_parseEnum && _matchesKeyword(Keyword.ENUM)) { 4267 } else if (_parseEnum && _matchesKeyword(Keyword.ENUM)) {
4268 _validateModifiersForEnum(modifiers); 4268 _validateModifiersForEnum(modifiers);
4269 return _parseEnumDeclaration(commentAndMetadata); 4269 return _parseEnumDeclaration(commentAndMetadata);
4270 } 4270 }
4271 if (_matchesKeyword(Keyword.VOID)) { 4271 if (_matchesKeyword(Keyword.VOID)) {
4272 TypeName returnType = parseReturnType(); 4272 TypeName returnType = parseReturnType();
4273 if ((_matchesKeyword(Keyword.GET) || _matchesKeyword(Keyword.SET)) && _tok enMatchesIdentifier(_peek())) { 4273 if ((_matchesKeyword(Keyword.GET) || _matchesKeyword(Keyword.SET)) && _tok enMatchesIdentifier(_peek())) {
4274 _validateModifiersForTopLevelFunction(modifiers); 4274 _validateModifiersForTopLevelFunction(modifiers);
4275 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalK eyword, returnType); 4275 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalK eyword, returnType);
4276 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) { 4276 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) {
4277 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 4277 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken);
4278 return _convertToFunctionDeclaration(_parseOperator(commentAndMetadata, modifiers.externalKeyword, returnType)); 4278 return _convertToFunctionDeclaration(_parseOperator(commentAndMetadata, modifiers.externalKeyword, returnType));
4279 } else if (_matchesIdentifier() && _peek().matchesAny([ 4279 } else if (_matchesIdentifier() && _peek().matchesAny([
4280 TokenType.OPEN_PAREN, 4280 TokenType.OPEN_PAREN,
4281 TokenType.OPEN_CURLY_BRACKET, 4281 TokenType.OPEN_CURLY_BRACKET,
4282 TokenType.FUNCTION])) { 4282 TokenType.FUNCTION])) {
4283 _validateModifiersForTopLevelFunction(modifiers); 4283 _validateModifiersForTopLevelFunction(modifiers);
4284 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalK eyword, returnType); 4284 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalK eyword, returnType);
4285 } else { 4285 } else {
4286 // 4286 //
4287 // We have found an error of some kind. Try to recover. 4287 // We have found an error of some kind. Try to recover.
4288 // 4288 //
4289 if (_matchesIdentifier()) { 4289 if (_matchesIdentifier()) {
4290 if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 4290 if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
4291 // 4291 //
4292 // We appear to have a variable declaration with a type of "void". 4292 // We appear to have a variable declaration with a type of "void".
4293 // 4293 //
4294 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType, []); 4294 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
4295 return new TopLevelVariableDeclaration(commentAndMetadata.comment, c ommentAndMetadata.metadata, _parseVariableDeclarationListAfterType(null, _valida teModifiersForTopLevelVariable(modifiers), null), _expect(TokenType.SEMICOLON)); 4295 return new TopLevelVariableDeclaration(commentAndMetadata.comment, c ommentAndMetadata.metadata, _parseVariableDeclarationListAfterType(null, _valida teModifiersForTopLevelVariable(modifiers), null), _expect(TokenType.SEMICOLON));
4296 } 4296 }
4297 } 4297 }
4298 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 4298 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken) ;
4299 return null; 4299 return null;
4300 } 4300 }
4301 } else if ((_matchesKeyword(Keyword.GET) || _matchesKeyword(Keyword.SET)) && _tokenMatchesIdentifier(_peek())) { 4301 } else if ((_matchesKeyword(Keyword.GET) || _matchesKeyword(Keyword.SET)) && _tokenMatchesIdentifier(_peek())) {
4302 _validateModifiersForTopLevelFunction(modifiers); 4302 _validateModifiersForTopLevelFunction(modifiers);
4303 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalKey word, null); 4303 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalKey word, null);
4304 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) { 4304 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) {
4305 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, [] ); 4305 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken);
4306 return _convertToFunctionDeclaration(_parseOperator(commentAndMetadata, mo difiers.externalKeyword, null)); 4306 return _convertToFunctionDeclaration(_parseOperator(commentAndMetadata, mo difiers.externalKeyword, null));
4307 } else if (!_matchesIdentifier()) { 4307 } else if (!_matchesIdentifier()) {
4308 Token keyword = modifiers.varKeyword; 4308 Token keyword = modifiers.varKeyword;
4309 if (keyword == null) { 4309 if (keyword == null) {
4310 keyword = modifiers.finalKeyword; 4310 keyword = modifiers.finalKeyword;
4311 } 4311 }
4312 if (keyword == null) { 4312 if (keyword == null) {
4313 keyword = modifiers.constKeyword; 4313 keyword = modifiers.constKeyword;
4314 } 4314 }
4315 if (keyword != null) { 4315 if (keyword != null) {
4316 // 4316 //
4317 // We appear to have found an incomplete top-level variable declaration. 4317 // We appear to have found an incomplete top-level variable declaration.
4318 // 4318 //
4319 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); 4319 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
4320 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4320 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4321 variables.add(new VariableDeclaration(null, null, _createSyntheticIdenti fier(), null, null)); 4321 variables.add(new VariableDeclaration(null, null, _createSyntheticIdenti fier(), null, null));
4322 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comme ntAndMetadata.metadata, new VariableDeclarationList(null, null, keyword, null, v ariables), _expectSemicolon()); 4322 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comme ntAndMetadata.metadata, new VariableDeclarationList(null, null, keyword, null, v ariables), _expectSemicolon());
4323 } 4323 }
4324 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, [ ]); 4324 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken);
4325 return null; 4325 return null;
4326 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 4326 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
4327 _validateModifiersForTopLevelFunction(modifiers); 4327 _validateModifiersForTopLevelFunction(modifiers);
4328 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalKey word, null); 4328 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalKey word, null);
4329 } else if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 4329 } else if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
4330 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 4330 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
4331 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_T YPE, []); 4331 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_T YPE);
4332 } 4332 }
4333 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, _parseVariableDeclarationListAfterType(null, _validateModi fiersForTopLevelVariable(modifiers), null), _expect(TokenType.SEMICOLON)); 4333 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, _parseVariableDeclarationListAfterType(null, _validateModi fiersForTopLevelVariable(modifiers), null), _expect(TokenType.SEMICOLON));
4334 } 4334 }
4335 TypeName returnType = parseReturnType(); 4335 TypeName returnType = parseReturnType();
4336 if ((_matchesKeyword(Keyword.GET) || _matchesKeyword(Keyword.SET)) && _token MatchesIdentifier(_peek())) { 4336 if ((_matchesKeyword(Keyword.GET) || _matchesKeyword(Keyword.SET)) && _token MatchesIdentifier(_peek())) {
4337 _validateModifiersForTopLevelFunction(modifiers); 4337 _validateModifiersForTopLevelFunction(modifiers);
4338 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalKey word, returnType); 4338 return _parseFunctionDeclaration(commentAndMetadata, modifiers.externalKey word, returnType);
4339 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) { 4339 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) {
4340 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, [] ); 4340 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken);
4341 return _convertToFunctionDeclaration(_parseOperator(commentAndMetadata, mo difiers.externalKeyword, returnType)); 4341 return _convertToFunctionDeclaration(_parseOperator(commentAndMetadata, mo difiers.externalKeyword, returnType));
4342 } else if (_matches(TokenType.AT)) { 4342 } else if (_matches(TokenType.AT)) {
4343 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, _parseVariableDeclarationListAfterType(null, _validateModi fiersForTopLevelVariable(modifiers), returnType), _expect(TokenType.SEMICOLON)); 4343 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, _parseVariableDeclarationListAfterType(null, _validateModi fiersForTopLevelVariable(modifiers), returnType), _expect(TokenType.SEMICOLON));
4344 } else if (!_matchesIdentifier()) { 4344 } else if (!_matchesIdentifier()) {
4345 // TODO(brianwilkerson) Generalize this error. We could also be parsing a top-level variable at this point. 4345 // TODO(brianwilkerson) Generalize this error. We could also be parsing a top-level variable at this point.
4346 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, [ ]); 4346 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken);
4347 Token semicolon; 4347 Token semicolon;
4348 if (_matches(TokenType.SEMICOLON)) { 4348 if (_matches(TokenType.SEMICOLON)) {
4349 semicolon = andAdvance; 4349 semicolon = andAdvance;
4350 } else { 4350 } else {
4351 semicolon = _createSyntheticToken(TokenType.SEMICOLON); 4351 semicolon = _createSyntheticToken(TokenType.SEMICOLON);
4352 } 4352 }
4353 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4353 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4354 variables.add(new VariableDeclaration(null, null, _createSyntheticIdentifi er(), null, null)); 4354 variables.add(new VariableDeclaration(null, null, _createSyntheticIdentifi er(), null, null));
4355 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, new VariableDeclarationList(null, null, null, returnType, variables), semicolon); 4355 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, new VariableDeclarationList(null, null, null, returnType, variables), semicolon);
4356 } 4356 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4403 } else if (_tokenMatches(_peek(), TokenType.PERIOD) && _tokenMatches(_ peekAt(3), TokenType.OPEN_PAREN)) { 4403 } else if (_tokenMatches(_peek(), TokenType.PERIOD) && _tokenMatches(_ peekAt(3), TokenType.OPEN_PAREN)) {
4404 bodyAllowed = false; 4404 bodyAllowed = false;
4405 initializers.add(_parseRedirectingConstructorInvocation()); 4405 initializers.add(_parseRedirectingConstructorInvocation());
4406 } else { 4406 } else {
4407 initializers.add(_parseConstructorFieldInitializer()); 4407 initializers.add(_parseConstructorFieldInitializer());
4408 } 4408 }
4409 } else if (_matchesKeyword(Keyword.SUPER)) { 4409 } else if (_matchesKeyword(Keyword.SUPER)) {
4410 initializers.add(_parseSuperConstructorInvocation()); 4410 initializers.add(_parseSuperConstructorInvocation());
4411 } else if (_matches(TokenType.OPEN_CURLY_BRACKET) 4411 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)
4412 || _matches(TokenType.FUNCTION)) { 4412 || _matches(TokenType.FUNCTION)) {
4413 _reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER, []); 4413 _reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER);
4414 } else { 4414 } else {
4415 initializers.add(_parseConstructorFieldInitializer()); 4415 initializers.add(_parseConstructorFieldInitializer());
4416 } 4416 }
4417 } while (_optional(TokenType.COMMA)); 4417 } while (_optional(TokenType.COMMA));
4418 if (factoryKeyword != null) { 4418 if (factoryKeyword != null) {
4419 _reportErrorForToken(ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryK eyword, []); 4419 _reportErrorForToken(ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryK eyword);
4420 } 4420 }
4421 } 4421 }
4422 ConstructorName redirectedConstructor = null; 4422 ConstructorName redirectedConstructor = null;
4423 FunctionBody body; 4423 FunctionBody body;
4424 if (_matches(TokenType.EQ)) { 4424 if (_matches(TokenType.EQ)) {
4425 separator = andAdvance; 4425 separator = andAdvance;
4426 redirectedConstructor = parseConstructorName(); 4426 redirectedConstructor = parseConstructorName();
4427 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON)); 4427 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON));
4428 if (factoryKeyword == null) { 4428 if (factoryKeyword == null) {
4429 _reportErrorForNode(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCT OR, redirectedConstructor, []); 4429 _reportErrorForNode(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCT OR, redirectedConstructor);
4430 } 4430 }
4431 } else { 4431 } else {
4432 body = _parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fal se); 4432 body = _parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fal se);
4433 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) { 4433 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) {
4434 _reportErrorForToken(ParserErrorCode.CONST_FACTORY, factoryKeyword, []); 4434 _reportErrorForToken(ParserErrorCode.CONST_FACTORY, factoryKeyword);
4435 } else if (body is EmptyFunctionBody) { 4435 } else if (body is EmptyFunctionBody) {
4436 if (factoryKeyword != null && externalKeyword == null) { 4436 if (factoryKeyword != null && externalKeyword == null) {
4437 _reportErrorForToken(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyw ord, []); 4437 _reportErrorForToken(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyw ord);
4438 } 4438 }
4439 } else { 4439 } else {
4440 if (constKeyword != null) { 4440 if (constKeyword != null) {
4441 _reportErrorForNode(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []); 4441 _reportErrorForNode(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body) ;
4442 } else if (!bodyAllowed) { 4442 } else if (!bodyAllowed) {
4443 _reportErrorForNode(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, bo dy, []); 4443 _reportErrorForNode(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, bo dy);
4444 } 4444 }
4445 } 4445 }
4446 } 4446 }
4447 return new ConstructorDeclaration(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, period , name, parameters, separator, initializers, redirectedConstructor, body); 4447 return new ConstructorDeclaration(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, period , name, parameters, separator, initializers, redirectedConstructor, body);
4448 } 4448 }
4449 4449
4450 /** 4450 /**
4451 * Parse a field initializer within a constructor. 4451 * Parse a field initializer within a constructor.
4452 * 4452 *
4453 * <pre> 4453 * <pre>
4454 * fieldInitializer: 4454 * fieldInitializer:
4455 * ('this' '.')? identifier '=' conditionalExpression cascadeSection* 4455 * ('this' '.')? identifier '=' conditionalExpression cascadeSection*
4456 * </pre> 4456 * </pre>
4457 * 4457 *
4458 * @return the field initializer that was parsed 4458 * @return the field initializer that was parsed
4459 */ 4459 */
4460 ConstructorFieldInitializer _parseConstructorFieldInitializer() { 4460 ConstructorFieldInitializer _parseConstructorFieldInitializer() {
4461 Token keyword = null; 4461 Token keyword = null;
4462 Token period = null; 4462 Token period = null;
4463 if (_matchesKeyword(Keyword.THIS)) { 4463 if (_matchesKeyword(Keyword.THIS)) {
4464 keyword = andAdvance; 4464 keyword = andAdvance;
4465 period = _expect(TokenType.PERIOD); 4465 period = _expect(TokenType.PERIOD);
4466 } 4466 }
4467 SimpleIdentifier fieldName = parseSimpleIdentifier(); 4467 SimpleIdentifier fieldName = parseSimpleIdentifier();
4468 if (!_matches(TokenType.EQ)) { 4468 if (!_matches(TokenType.EQ)) {
4469 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALI ZER, []); 4469 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALI ZER);
4470 return new ConstructorFieldInitializer( 4470 return new ConstructorFieldInitializer(
4471 keyword, 4471 keyword,
4472 period, 4472 period,
4473 fieldName, 4473 fieldName,
4474 _createSyntheticToken(TokenType.EQ), 4474 _createSyntheticToken(TokenType.EQ),
4475 _createSyntheticIdentifier()); 4475 _createSyntheticIdentifier());
4476 } 4476 }
4477 Token equals = _expect(TokenType.EQ); 4477 Token equals = _expect(TokenType.EQ);
4478 bool wasInInitializer = _inInitializer; 4478 bool wasInInitializer = _inInitializer;
4479 _inInitializer = true; 4479 _inInitializer = true;
(...skipping 23 matching lines...) Expand all
4503 * <pre> 4503 * <pre>
4504 * continueStatement ::= 4504 * continueStatement ::=
4505 * 'continue' identifier? ';' 4505 * 'continue' identifier? ';'
4506 * </pre> 4506 * </pre>
4507 * 4507 *
4508 * @return the continue statement that was parsed 4508 * @return the continue statement that was parsed
4509 */ 4509 */
4510 Statement _parseContinueStatement() { 4510 Statement _parseContinueStatement() {
4511 Token continueKeyword = _expectKeyword(Keyword.CONTINUE); 4511 Token continueKeyword = _expectKeyword(Keyword.CONTINUE);
4512 if (!_inLoop && !_inSwitch) { 4512 if (!_inLoop && !_inSwitch) {
4513 _reportErrorForToken(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKey word, []); 4513 _reportErrorForToken(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKey word);
4514 } 4514 }
4515 SimpleIdentifier label = null; 4515 SimpleIdentifier label = null;
4516 if (_matchesIdentifier()) { 4516 if (_matchesIdentifier()) {
4517 label = parseSimpleIdentifier(); 4517 label = parseSimpleIdentifier();
4518 } 4518 }
4519 if (_inSwitch && !_inLoop && label == null) { 4519 if (_inSwitch && !_inLoop && label == null) {
4520 _reportErrorForToken(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, conti nueKeyword, []); 4520 _reportErrorForToken(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, conti nueKeyword);
4521 } 4521 }
4522 Token semicolon = _expect(TokenType.SEMICOLON); 4522 Token semicolon = _expect(TokenType.SEMICOLON);
4523 return new ContinueStatement(continueKeyword, label, semicolon); 4523 return new ContinueStatement(continueKeyword, label, semicolon);
4524 } 4524 }
4525 4525
4526 /** 4526 /**
4527 * Parse a directive. 4527 * Parse a directive.
4528 * 4528 *
4529 * <pre> 4529 * <pre>
4530 * directive ::= 4530 * directive ::=
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
4691 SimpleIdentifier name = parseSimpleIdentifier(); 4691 SimpleIdentifier name = parseSimpleIdentifier();
4692 Token leftBracket = null; 4692 Token leftBracket = null;
4693 List<EnumConstantDeclaration> constants = new List<EnumConstantDeclaration>( ); 4693 List<EnumConstantDeclaration> constants = new List<EnumConstantDeclaration>( );
4694 Token rightBracket = null; 4694 Token rightBracket = null;
4695 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 4695 if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
4696 leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET); 4696 leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET);
4697 if (_matchesIdentifier()) { 4697 if (_matchesIdentifier()) {
4698 constants.add(_parseEnumConstantDeclaration()); 4698 constants.add(_parseEnumConstantDeclaration());
4699 } else if (_matches(TokenType.COMMA) && _tokenMatchesIdentifier(_peek())) { 4699 } else if (_matches(TokenType.COMMA) && _tokenMatchesIdentifier(_peek())) {
4700 constants.add(_parseEnumConstantDeclaration()); 4700 constants.add(_parseEnumConstantDeclaration());
4701 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); 4701 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
4702 } else { 4702 } else {
4703 constants.add(_parseEnumConstantDeclaration()); 4703 constants.add(_parseEnumConstantDeclaration());
4704 _reportErrorForCurrentToken(ParserErrorCode.EMPTY_ENUM_BODY, []); 4704 _reportErrorForCurrentToken(ParserErrorCode.EMPTY_ENUM_BODY);
4705 } 4705 }
4706 while (_optional(TokenType.COMMA)) { 4706 while (_optional(TokenType.COMMA)) {
4707 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { 4707 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
4708 break; 4708 break;
4709 } 4709 }
4710 constants.add(_parseEnumConstantDeclaration()); 4710 constants.add(_parseEnumConstantDeclaration());
4711 } 4711 }
4712 rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); 4712 rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
4713 } else { 4713 } else {
4714 leftBracket = _createSyntheticToken(TokenType.OPEN_CURLY_BRACKET); 4714 leftBracket = _createSyntheticToken(TokenType.OPEN_CURLY_BRACKET);
4715 rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET); 4715 rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET);
4716 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ENUM_BODY, []); 4716 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ENUM_BODY);
4717 } 4717 }
4718 return new EnumDeclaration(commentAndMetadata.comment, commentAndMetadata.me tadata, keyword, name, leftBracket, constants, rightBracket); 4718 return new EnumDeclaration(commentAndMetadata.comment, commentAndMetadata.me tadata, keyword, name, leftBracket, constants, rightBracket);
4719 } 4719 }
4720 4720
4721 /** 4721 /**
4722 * Parse an equality expression. 4722 * Parse an equality expression.
4723 * 4723 *
4724 * <pre> 4724 * <pre>
4725 * equalityExpression ::= 4725 * equalityExpression ::=
4726 * relationalExpression (equalityOperator relationalExpression)? 4726 * relationalExpression (equalityOperator relationalExpression)?
4727 * | 'super' equalityOperator relationalExpression 4727 * | 'super' equalityOperator relationalExpression
4728 * </pre> 4728 * </pre>
4729 * 4729 *
4730 * @return the equality expression that was parsed 4730 * @return the equality expression that was parsed
4731 */ 4731 */
4732 Expression _parseEqualityExpression() { 4732 Expression _parseEqualityExpression() {
4733 Expression expression; 4733 Expression expression;
4734 if (_matchesKeyword(Keyword.SUPER) && _currentToken.next.type.isEqualityOper ator) { 4734 if (_matchesKeyword(Keyword.SUPER) && _currentToken.next.type.isEqualityOper ator) {
4735 expression = new SuperExpression(andAdvance); 4735 expression = new SuperExpression(andAdvance);
4736 } else { 4736 } else {
4737 expression = _parseRelationalExpression(); 4737 expression = _parseRelationalExpression();
4738 } 4738 }
4739 bool leftEqualityExpression = false; 4739 bool leftEqualityExpression = false;
4740 while (_currentToken.type.isEqualityOperator) { 4740 while (_currentToken.type.isEqualityOperator) {
4741 Token operator = andAdvance; 4741 Token operator = andAdvance;
4742 if (leftEqualityExpression) { 4742 if (leftEqualityExpression) {
4743 _reportErrorForNode(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expression, []); 4743 _reportErrorForNode(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expression);
4744 } 4744 }
4745 expression = new BinaryExpression(expression, operator, _parseRelationalEx pression()); 4745 expression = new BinaryExpression(expression, operator, _parseRelationalEx pression());
4746 leftEqualityExpression = true; 4746 leftEqualityExpression = true;
4747 } 4747 }
4748 return expression; 4748 return expression;
4749 } 4749 }
4750 4750
4751 /** 4751 /**
4752 * Parse an export directive. 4752 * Parse an export directive.
4753 * 4753 *
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4807 keyword = andAdvance; 4807 keyword = andAdvance;
4808 if (_isTypedIdentifier(_currentToken)) { 4808 if (_isTypedIdentifier(_currentToken)) {
4809 type = parseTypeName(); 4809 type = parseTypeName();
4810 } 4810 }
4811 } else if (_matchesKeyword(Keyword.VAR)) { 4811 } else if (_matchesKeyword(Keyword.VAR)) {
4812 keyword = andAdvance; 4812 keyword = andAdvance;
4813 } else { 4813 } else {
4814 if (_isTypedIdentifier(_currentToken)) { 4814 if (_isTypedIdentifier(_currentToken)) {
4815 type = parseReturnType(); 4815 type = parseReturnType();
4816 } else if (!optional) { 4816 } else if (!optional) {
4817 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_T YPE, []); 4817 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_T YPE);
4818 } 4818 }
4819 } 4819 }
4820 return new FinalConstVarOrType(keyword, type); 4820 return new FinalConstVarOrType(keyword, type);
4821 } 4821 }
4822 4822
4823 /** 4823 /**
4824 * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be 4824 * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be
4825 * `true`. 4825 * `true`.
4826 * 4826 *
4827 * <pre> 4827 * <pre>
4828 * defaultFormalParameter ::= 4828 * defaultFormalParameter ::=
4829 * normalFormalParameter ('=' expression)? 4829 * normalFormalParameter ('=' expression)?
4830 * 4830 *
4831 * defaultNamedParameter ::= 4831 * defaultNamedParameter ::=
4832 * normalFormalParameter (':' expression)? 4832 * normalFormalParameter (':' expression)?
4833 * </pre> 4833 * </pre>
4834 * 4834 *
4835 * @param kind the kind of parameter being expected based on the presence or a bsence of group 4835 * @param kind the kind of parameter being expected based on the presence or a bsence of group
4836 * delimiters 4836 * delimiters
4837 * @return the formal parameter that was parsed 4837 * @return the formal parameter that was parsed
4838 */ 4838 */
4839 FormalParameter _parseFormalParameter(ParameterKind kind) { 4839 FormalParameter _parseFormalParameter(ParameterKind kind) {
4840 NormalFormalParameter parameter = parseNormalFormalParameter(); 4840 NormalFormalParameter parameter = parseNormalFormalParameter();
4841 if (_matches(TokenType.EQ)) { 4841 if (_matches(TokenType.EQ)) {
4842 Token seperator = andAdvance; 4842 Token seperator = andAdvance;
4843 Expression defaultValue = parseExpression2(); 4843 Expression defaultValue = parseExpression2();
4844 if (kind == ParameterKind.NAMED) { 4844 if (kind == ParameterKind.NAMED) {
4845 _reportErrorForToken(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER , seperator, []); 4845 _reportErrorForToken(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER , seperator);
4846 } else if (kind == ParameterKind.REQUIRED) { 4846 } else if (kind == ParameterKind.REQUIRED) {
4847 _reportErrorForNode(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parameter, []); 4847 _reportErrorForNode(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parameter);
4848 } 4848 }
4849 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 4849 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4850 } else if (_matches(TokenType.COLON)) { 4850 } else if (_matches(TokenType.COLON)) {
4851 Token seperator = andAdvance; 4851 Token seperator = andAdvance;
4852 Expression defaultValue = parseExpression2(); 4852 Expression defaultValue = parseExpression2();
4853 if (kind == ParameterKind.POSITIONAL) { 4853 if (kind == ParameterKind.POSITIONAL) {
4854 _reportErrorForToken(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARA METER, seperator, []); 4854 _reportErrorForToken(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARA METER, seperator);
4855 } else if (kind == ParameterKind.REQUIRED) { 4855 } else if (kind == ParameterKind.REQUIRED) {
4856 _reportErrorForNode(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, param eter, []); 4856 _reportErrorForNode(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, param eter);
4857 } 4857 }
4858 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 4858 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4859 } else if (kind != ParameterKind.REQUIRED) { 4859 } else if (kind != ParameterKind.REQUIRED) {
4860 return new DefaultFormalParameter(parameter, kind, null, null); 4860 return new DefaultFormalParameter(parameter, kind, null, null);
4861 } 4861 }
4862 return parameter; 4862 return parameter;
4863 } 4863 }
4864 4864
4865 /** 4865 /**
4866 * Parse a for statement. 4866 * Parse a for statement.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4903 } else if (_isInitializedVariableDeclaration()) { 4903 } else if (_isInitializedVariableDeclaration()) {
4904 variableList = _parseVariableDeclarationListAfterMetadata(commentAndMe tadata); 4904 variableList = _parseVariableDeclarationListAfterMetadata(commentAndMe tadata);
4905 } else { 4905 } else {
4906 initialization = parseExpression2(); 4906 initialization = parseExpression2();
4907 } 4907 }
4908 if (_matchesKeyword(Keyword.IN)) { 4908 if (_matchesKeyword(Keyword.IN)) {
4909 DeclaredIdentifier loopVariable = null; 4909 DeclaredIdentifier loopVariable = null;
4910 SimpleIdentifier identifier = null; 4910 SimpleIdentifier identifier = null;
4911 if (variableList == null) { 4911 if (variableList == null) {
4912 // We found: <expression> 'in' 4912 // We found: <expression> 'in'
4913 _reportErrorForCurrentToken(ParserErrorCode.MISSING_VARIABLE_IN_FOR_ EACH, []); 4913 _reportErrorForCurrentToken(ParserErrorCode.MISSING_VARIABLE_IN_FOR_ EACH);
4914 } else { 4914 } else {
4915 NodeList<VariableDeclaration> variables = variableList.variables; 4915 NodeList<VariableDeclaration> variables = variableList.variables;
4916 if (variables.length > 1) { 4916 if (variables.length > 1) {
4917 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_VARIABLES_IN_ FOR_EACH, [variables.length.toString()]); 4917 _reportErrorForCurrentToken(ParserErrorCode.MULTIPLE_VARIABLES_IN_ FOR_EACH, [variables.length.toString()]);
4918 } 4918 }
4919 VariableDeclaration variable = variables[0]; 4919 VariableDeclaration variable = variables[0];
4920 if (variable.initializer != null) { 4920 if (variable.initializer != null) {
4921 _reportErrorForCurrentToken(ParserErrorCode.INITIALIZED_VARIABLE_I N_FOR_EACH, []); 4921 _reportErrorForCurrentToken(ParserErrorCode.INITIALIZED_VARIABLE_I N_FOR_EACH);
4922 } 4922 }
4923 Token keyword = variableList.keyword; 4923 Token keyword = variableList.keyword;
4924 TypeName type = variableList.type; 4924 TypeName type = variableList.type;
4925 if (keyword != null || type != null) { 4925 if (keyword != null || type != null) {
4926 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name); 4926 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name);
4927 } else { 4927 } else {
4928 if (!commentAndMetadata.metadata.isEmpty) { 4928 if (!commentAndMetadata.metadata.isEmpty) {
4929 // TODO(jwren) metadata isn't allowed before the identifier in " identifier in expression", 4929 // TODO(jwren) metadata isn't allowed before the identifier in " identifier in expression",
4930 // add warning if commentAndMetadata has content 4930 // add warning if commentAndMetadata has content
4931 } 4931 }
4932 identifier = variable.name; 4932 identifier = variable.name;
4933 } 4933 }
4934 } 4934 }
4935 Token inKeyword = _expectKeyword(Keyword.IN); 4935 Token inKeyword = _expectKeyword(Keyword.IN);
4936 Expression iterator = parseExpression2(); 4936 Expression iterator = parseExpression2();
4937 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); 4937 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
4938 Statement body = parseStatement2(); 4938 Statement body = parseStatement2();
4939 if (loopVariable == null) { 4939 if (loopVariable == null) {
4940 return new ForEachStatement.con2(awaitKeyword, forKeyword, leftParen thesis, identifier, inKeyword, iterator, rightParenthesis, body); 4940 return new ForEachStatement.con2(awaitKeyword, forKeyword, leftParen thesis, identifier, inKeyword, iterator, rightParenthesis, body);
4941 } 4941 }
4942 return new ForEachStatement.con1(awaitKeyword, forKeyword, leftParenth esis, loopVariable, inKeyword, iterator, rightParenthesis, body); 4942 return new ForEachStatement.con1(awaitKeyword, forKeyword, leftParenth esis, loopVariable, inKeyword, iterator, rightParenthesis, body);
4943 } 4943 }
4944 } 4944 }
4945 if (awaitKeyword != null) { 4945 if (awaitKeyword != null) {
4946 _reportErrorForToken(ParserErrorCode.INVALID_AWAIT_IN_FOR, awaitKeyword, []); 4946 _reportErrorForToken(ParserErrorCode.INVALID_AWAIT_IN_FOR, awaitKeyword) ;
4947 } 4947 }
4948 Token leftSeparator = _expect(TokenType.SEMICOLON); 4948 Token leftSeparator = _expect(TokenType.SEMICOLON);
4949 Expression condition = null; 4949 Expression condition = null;
4950 if (!_matches(TokenType.SEMICOLON)) { 4950 if (!_matches(TokenType.SEMICOLON)) {
4951 condition = parseExpression2(); 4951 condition = parseExpression2();
4952 } 4952 }
4953 Token rightSeparator = _expect(TokenType.SEMICOLON); 4953 Token rightSeparator = _expect(TokenType.SEMICOLON);
4954 List<Expression> updaters = null; 4954 List<Expression> updaters = null;
4955 if (!_matches(TokenType.CLOSE_PAREN)) { 4955 if (!_matches(TokenType.CLOSE_PAREN)) {
4956 updaters = _parseExpressionList(); 4956 updaters = _parseExpressionList();
(...skipping 30 matching lines...) Expand all
4987 bool wasInGenerator = _inGenerator; 4987 bool wasInGenerator = _inGenerator;
4988 bool wasInLoop = _inLoop; 4988 bool wasInLoop = _inLoop;
4989 bool wasInSwitch = _inSwitch; 4989 bool wasInSwitch = _inSwitch;
4990 _inAsync = false; 4990 _inAsync = false;
4991 _inGenerator = false; 4991 _inGenerator = false;
4992 _inLoop = false; 4992 _inLoop = false;
4993 _inSwitch = false; 4993 _inSwitch = false;
4994 try { 4994 try {
4995 if (_matches(TokenType.SEMICOLON)) { 4995 if (_matches(TokenType.SEMICOLON)) {
4996 if (!mayBeEmpty) { 4996 if (!mayBeEmpty) {
4997 _reportErrorForCurrentToken(emptyErrorCode, []); 4997 _reportErrorForCurrentToken(emptyErrorCode);
4998 } 4998 }
4999 return new EmptyFunctionBody(andAdvance); 4999 return new EmptyFunctionBody(andAdvance);
5000 } else if (_matchesString(_NATIVE)) { 5000 } else if (_matchesString(_NATIVE)) {
5001 Token nativeToken = andAdvance; 5001 Token nativeToken = andAdvance;
5002 StringLiteral stringLiteral = null; 5002 StringLiteral stringLiteral = null;
5003 if (_matches(TokenType.STRING)) { 5003 if (_matches(TokenType.STRING)) {
5004 stringLiteral = parseStringLiteral(); 5004 stringLiteral = parseStringLiteral();
5005 } 5005 }
5006 return new NativeFunctionBody(nativeToken, stringLiteral, _expect(TokenT ype.SEMICOLON)); 5006 return new NativeFunctionBody(nativeToken, stringLiteral, _expect(TokenT ype.SEMICOLON));
5007 } 5007 }
(...skipping 11 matching lines...) Expand all
5019 keyword = andAdvance; 5019 keyword = andAdvance;
5020 if (_matches(TokenType.STAR)) { 5020 if (_matches(TokenType.STAR)) {
5021 star = andAdvance; 5021 star = andAdvance;
5022 _inGenerator = true; 5022 _inGenerator = true;
5023 } 5023 }
5024 } 5024 }
5025 } 5025 }
5026 if (_matches(TokenType.FUNCTION)) { 5026 if (_matches(TokenType.FUNCTION)) {
5027 if (keyword != null) { 5027 if (keyword != null) {
5028 if (!_tokenMatchesString(keyword, ASYNC)) { 5028 if (!_tokenMatchesString(keyword, ASYNC)) {
5029 _reportErrorForToken(ParserErrorCode.INVALID_SYNC, keyword, []); 5029 _reportErrorForToken(ParserErrorCode.INVALID_SYNC, keyword);
5030 keyword = null; 5030 keyword = null;
5031 } else if (star != null) { 5031 } else if (star != null) {
5032 _reportErrorForToken(ParserErrorCode.INVALID_STAR_AFTER_ASYNC, star, []); 5032 _reportErrorForToken(ParserErrorCode.INVALID_STAR_AFTER_ASYNC, star) ;
5033 } 5033 }
5034 } 5034 }
5035 Token functionDefinition = andAdvance; 5035 Token functionDefinition = andAdvance;
5036 Expression expression = parseExpression2(); 5036 Expression expression = parseExpression2();
5037 Token semicolon = null; 5037 Token semicolon = null;
5038 if (!inExpression) { 5038 if (!inExpression) {
5039 semicolon = _expect(TokenType.SEMICOLON); 5039 semicolon = _expect(TokenType.SEMICOLON);
5040 } 5040 }
5041 if (!_parseFunctionBodies) { 5041 if (!_parseFunctionBodies) {
5042 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON )); 5042 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON ));
5043 } 5043 }
5044 return new ExpressionFunctionBody(keyword, functionDefinition, expressio n, semicolon); 5044 return new ExpressionFunctionBody(keyword, functionDefinition, expressio n, semicolon);
5045 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 5045 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
5046 if (keyword != null) { 5046 if (keyword != null) {
5047 if (_tokenMatchesString(keyword, SYNC) && star == null) { 5047 if (_tokenMatchesString(keyword, SYNC) && star == null) {
5048 _reportErrorForToken(ParserErrorCode.MISSING_STAR_AFTER_SYNC, keywor d, []); 5048 _reportErrorForToken(ParserErrorCode.MISSING_STAR_AFTER_SYNC, keywor d);
5049 } 5049 }
5050 } 5050 }
5051 if (!_parseFunctionBodies) { 5051 if (!_parseFunctionBodies) {
5052 _skipBlock(); 5052 _skipBlock();
5053 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON )); 5053 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON ));
5054 } 5054 }
5055 return new BlockFunctionBody(keyword, star, parseBlock()); 5055 return new BlockFunctionBody(keyword, star, parseBlock());
5056 } else { 5056 } else {
5057 // Invalid function body 5057 // Invalid function body
5058 _reportErrorForCurrentToken(emptyErrorCode, []); 5058 _reportErrorForCurrentToken(emptyErrorCode);
5059 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)) ; 5059 return new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)) ;
5060 } 5060 }
5061 } finally { 5061 } finally {
5062 _inAsync = wasInAsync; 5062 _inAsync = wasInAsync;
5063 _inGenerator = wasInGenerator; 5063 _inGenerator = wasInGenerator;
5064 _inLoop = wasInLoop; 5064 _inLoop = wasInLoop;
5065 _inSwitch = wasInSwitch; 5065 _inSwitch = wasInSwitch;
5066 } 5066 }
5067 } 5067 }
5068 5068
(...skipping 22 matching lines...) Expand all
5091 } else if (_matchesKeyword(Keyword.SET) && !_tokenMatches(_peek(), TokenType .OPEN_PAREN)) { 5091 } else if (_matchesKeyword(Keyword.SET) && !_tokenMatches(_peek(), TokenType .OPEN_PAREN)) {
5092 keyword = andAdvance; 5092 keyword = andAdvance;
5093 } 5093 }
5094 SimpleIdentifier name = parseSimpleIdentifier(); 5094 SimpleIdentifier name = parseSimpleIdentifier();
5095 FormalParameterList parameters = null; 5095 FormalParameterList parameters = null;
5096 if (!isGetter) { 5096 if (!isGetter) {
5097 if (_matches(TokenType.OPEN_PAREN)) { 5097 if (_matches(TokenType.OPEN_PAREN)) {
5098 parameters = parseFormalParameterList(); 5098 parameters = parseFormalParameterList();
5099 _validateFormalParameterList(parameters); 5099 _validateFormalParameterList(parameters);
5100 } else { 5100 } else {
5101 _reportErrorForCurrentToken(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []); 5101 _reportErrorForCurrentToken(ParserErrorCode.MISSING_FUNCTION_PARAMETERS) ;
5102 } 5102 }
5103 } else if (_matches(TokenType.OPEN_PAREN)) { 5103 } else if (_matches(TokenType.OPEN_PAREN)) {
5104 _reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 5104 _reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS);
5105 parseFormalParameterList(); 5105 parseFormalParameterList();
5106 } 5106 }
5107 FunctionBody body; 5107 FunctionBody body;
5108 if (externalKeyword == null) { 5108 if (externalKeyword == null) {
5109 body = _parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fa lse); 5109 body = _parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fa lse);
5110 } else { 5110 } else {
5111 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON)); 5111 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON));
5112 } 5112 }
5113 // if (!isStatement && matches(TokenType.SEMICOLON)) { 5113 // if (!isStatement && matches(TokenType.SEMICOLON)) {
5114 // // TODO(brianwilkerson) Improve this error message. 5114 // // TODO(brianwilkerson) Improve this error message.
(...skipping 30 matching lines...) Expand all
5145 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 5145 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
5146 * declaration 5146 * declaration
5147 * @param returnType the return type, or `null` if there is no return type 5147 * @param returnType the return type, or `null` if there is no return type
5148 * @return the function declaration statement that was parsed 5148 * @return the function declaration statement that was parsed
5149 */ 5149 */
5150 Statement _parseFunctionDeclarationStatementAfterReturnType(CommentAndMetadata commentAndMetadata, TypeName returnType) { 5150 Statement _parseFunctionDeclarationStatementAfterReturnType(CommentAndMetadata commentAndMetadata, TypeName returnType) {
5151 FunctionDeclaration declaration = _parseFunctionDeclaration(commentAndMetada ta, null, returnType); 5151 FunctionDeclaration declaration = _parseFunctionDeclaration(commentAndMetada ta, null, returnType);
5152 Token propertyKeyword = declaration.propertyKeyword; 5152 Token propertyKeyword = declaration.propertyKeyword;
5153 if (propertyKeyword != null) { 5153 if (propertyKeyword != null) {
5154 if ((propertyKeyword as KeywordToken).keyword == Keyword.GET) { 5154 if ((propertyKeyword as KeywordToken).keyword == Keyword.GET) {
5155 _reportErrorForToken(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword , []); 5155 _reportErrorForToken(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword );
5156 } else { 5156 } else {
5157 _reportErrorForToken(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword , []); 5157 _reportErrorForToken(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword );
5158 } 5158 }
5159 } 5159 }
5160 return new FunctionDeclarationStatement(declaration); 5160 return new FunctionDeclarationStatement(declaration);
5161 } 5161 }
5162 5162
5163 /** 5163 /**
5164 * Parse a function type alias. 5164 * Parse a function type alias.
5165 * 5165 *
5166 * <pre> 5166 * <pre>
5167 * functionTypeAlias ::= 5167 * functionTypeAlias ::=
(...skipping 11 matching lines...) Expand all
5179 TypeName returnType = null; 5179 TypeName returnType = null;
5180 if (hasReturnTypeInTypeAlias) { 5180 if (hasReturnTypeInTypeAlias) {
5181 returnType = parseReturnType(); 5181 returnType = parseReturnType();
5182 } 5182 }
5183 SimpleIdentifier name = parseSimpleIdentifier(); 5183 SimpleIdentifier name = parseSimpleIdentifier();
5184 TypeParameterList typeParameters = null; 5184 TypeParameterList typeParameters = null;
5185 if (_matches(TokenType.LT)) { 5185 if (_matches(TokenType.LT)) {
5186 typeParameters = parseTypeParameterList(); 5186 typeParameters = parseTypeParameterList();
5187 } 5187 }
5188 if (_matches(TokenType.SEMICOLON) || _matches(TokenType.EOF)) { 5188 if (_matches(TokenType.SEMICOLON) || _matches(TokenType.EOF)) {
5189 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, [] ); 5189 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS);
5190 FormalParameterList parameters = new FormalParameterList(_createSyntheticT oken(TokenType.OPEN_PAREN), null, null, null, _createSyntheticToken(TokenType.CL OSE_PAREN)); 5190 FormalParameterList parameters = new FormalParameterList(_createSyntheticT oken(TokenType.OPEN_PAREN), null, null, null, _createSyntheticToken(TokenType.CL OSE_PAREN));
5191 Token semicolon = _expect(TokenType.SEMICOLON); 5191 Token semicolon = _expect(TokenType.SEMICOLON);
5192 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, parameters, semicolon); 5192 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, parameters, semicolon);
5193 } else if (!_matches(TokenType.OPEN_PAREN)) { 5193 } else if (!_matches(TokenType.OPEN_PAREN)) {
5194 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, [] ); 5194 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS);
5195 // TODO(brianwilkerson) Recover from this error. At the very least we shou ld skip to the start 5195 // TODO(brianwilkerson) Recover from this error. At the very least we shou ld skip to the start
5196 // of the next valid compilation unit member, allowing for the possibility of finding the 5196 // of the next valid compilation unit member, allowing for the possibility of finding the
5197 // typedef parameters before that point. 5197 // typedef parameters before that point.
5198 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, new FormalParameterList(_ createSyntheticToken(TokenType.OPEN_PAREN), null, null, null, _createSyntheticTo ken(TokenType.CLOSE_PAREN)), _createSyntheticToken(TokenType.SEMICOLON)); 5198 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, new FormalParameterList(_ createSyntheticToken(TokenType.OPEN_PAREN), null, null, null, _createSyntheticTo ken(TokenType.CLOSE_PAREN)), _createSyntheticToken(TokenType.SEMICOLON));
5199 } 5199 }
5200 FormalParameterList parameters = parseFormalParameterList(); 5200 FormalParameterList parameters = parseFormalParameterList();
5201 _validateFormalParameterList(parameters); 5201 _validateFormalParameterList(parameters);
5202 Token semicolon = _expect(TokenType.SEMICOLON); 5202 Token semicolon = _expect(TokenType.SEMICOLON);
5203 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadata. metadata, keyword, returnType, name, typeParameters, parameters, semicolon); 5203 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadata. metadata, keyword, returnType, name, typeParameters, parameters, semicolon);
5204 } 5204 }
(...skipping 14 matching lines...) Expand all
5219 * @param externalKeyword the 'external' token 5219 * @param externalKeyword the 'external' token
5220 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 5220 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
5221 * @param the return type that has already been parsed, or `null` if there was no return 5221 * @param the return type that has already been parsed, or `null` if there was no return
5222 * type 5222 * type
5223 * @return the getter that was parsed 5223 * @return the getter that was parsed
5224 */ 5224 */
5225 MethodDeclaration _parseGetter(CommentAndMetadata commentAndMetadata, Token ex ternalKeyword, Token staticKeyword, TypeName returnType) { 5225 MethodDeclaration _parseGetter(CommentAndMetadata commentAndMetadata, Token ex ternalKeyword, Token staticKeyword, TypeName returnType) {
5226 Token propertyKeyword = _expectKeyword(Keyword.GET); 5226 Token propertyKeyword = _expectKeyword(Keyword.GET);
5227 SimpleIdentifier name = parseSimpleIdentifier(); 5227 SimpleIdentifier name = parseSimpleIdentifier();
5228 if (_matches(TokenType.OPEN_PAREN) && _tokenMatches(_peek(), TokenType.CLOSE _PAREN)) { 5228 if (_matches(TokenType.OPEN_PAREN) && _tokenMatches(_peek(), TokenType.CLOSE _PAREN)) {
5229 _reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 5229 _reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS);
5230 _advance(); 5230 _advance();
5231 _advance(); 5231 _advance();
5232 } 5232 }
5233 FunctionBody body = _parseFunctionBody(externalKeyword != null || staticKeyw ord == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false); 5233 FunctionBody body = _parseFunctionBody(externalKeyword != null || staticKeyw ord == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false);
5234 if (externalKeyword != null && body is! EmptyFunctionBody) { 5234 if (externalKeyword != null && body is! EmptyFunctionBody) {
5235 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []) ; 5235 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY);
5236 } 5236 }
5237 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, null, body); 5237 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, null, body);
5238 } 5238 }
5239 5239
5240 /** 5240 /**
5241 * Parse a list of identifiers. 5241 * Parse a list of identifiers.
5242 * 5242 *
5243 * <pre> 5243 * <pre>
5244 * identifierList ::= 5244 * identifierList ::=
5245 * identifier (',' identifier)* 5245 * identifier (',' identifier)*
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
5296 ImportDirective _parseImportDirective(CommentAndMetadata commentAndMetadata) { 5296 ImportDirective _parseImportDirective(CommentAndMetadata commentAndMetadata) {
5297 Token importKeyword = _expectKeyword(Keyword.IMPORT); 5297 Token importKeyword = _expectKeyword(Keyword.IMPORT);
5298 StringLiteral libraryUri = parseStringLiteral(); 5298 StringLiteral libraryUri = parseStringLiteral();
5299 Token deferredToken = null; 5299 Token deferredToken = null;
5300 Token asToken = null; 5300 Token asToken = null;
5301 SimpleIdentifier prefix = null; 5301 SimpleIdentifier prefix = null;
5302 if (_matchesKeyword(Keyword.DEFERRED)) { 5302 if (_matchesKeyword(Keyword.DEFERRED)) {
5303 if (_parseDeferredLibraries) { 5303 if (_parseDeferredLibraries) {
5304 deferredToken = andAdvance; 5304 deferredToken = andAdvance;
5305 } else { 5305 } else {
5306 _reportErrorForCurrentToken(ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORT ED, []); 5306 _reportErrorForCurrentToken(ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORT ED);
5307 _advance(); 5307 _advance();
5308 } 5308 }
5309 } 5309 }
5310 if (_matchesKeyword(Keyword.AS)) { 5310 if (_matchesKeyword(Keyword.AS)) {
5311 asToken = andAdvance; 5311 asToken = andAdvance;
5312 prefix = parseSimpleIdentifier(); 5312 prefix = parseSimpleIdentifier();
5313 } else if (deferredToken != null) { 5313 } else if (deferredToken != null) {
5314 _reportErrorForCurrentToken(ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMP ORT, []); 5314 _reportErrorForCurrentToken(ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMP ORT);
5315 } 5315 }
5316 List<Combinator> combinators = _parseCombinators(); 5316 List<Combinator> combinators = _parseCombinators();
5317 Token semicolon = _expectSemicolon(); 5317 Token semicolon = _expectSemicolon();
5318 return new ImportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, importKeyword, libraryUri, deferredToken, asToken, prefix, combinators, semicolon); 5318 return new ImportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, importKeyword, libraryUri, deferredToken, asToken, prefix, combinators, semicolon);
5319 } 5319 }
5320 5320
5321 /** 5321 /**
5322 * Parse a list of initialized identifiers. 5322 * Parse a list of initialized identifiers.
5323 * 5323 *
5324 * <pre> 5324 * <pre>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5394 * missing 5394 * missing
5395 * @return the library name that was parsed 5395 * @return the library name that was parsed
5396 */ 5396 */
5397 LibraryIdentifier _parseLibraryName(ParserErrorCode missingNameError, Token mi ssingNameToken) { 5397 LibraryIdentifier _parseLibraryName(ParserErrorCode missingNameError, Token mi ssingNameToken) {
5398 if (_matchesIdentifier()) { 5398 if (_matchesIdentifier()) {
5399 return parseLibraryIdentifier(); 5399 return parseLibraryIdentifier();
5400 } else if (_matches(TokenType.STRING)) { 5400 } else if (_matches(TokenType.STRING)) {
5401 // TODO(brianwilkerson) Recovery: This should be extended to handle arbitr ary tokens until we 5401 // TODO(brianwilkerson) Recovery: This should be extended to handle arbitr ary tokens until we
5402 // can find a token that can start a compilation unit member. 5402 // can find a token that can start a compilation unit member.
5403 StringLiteral string = parseStringLiteral(); 5403 StringLiteral string = parseStringLiteral();
5404 _reportErrorForNode(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, [ ]); 5404 _reportErrorForNode(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string);
5405 } else { 5405 } else {
5406 _reportErrorForToken(missingNameError, missingNameToken, []); 5406 _reportErrorForToken(missingNameError, missingNameToken);
5407 } 5407 }
5408 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 5408 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
5409 components.add(_createSyntheticIdentifier()); 5409 components.add(_createSyntheticIdentifier());
5410 return new LibraryIdentifier(components); 5410 return new LibraryIdentifier(components);
5411 } 5411 }
5412 5412
5413 /** 5413 /**
5414 * Parse a list literal. 5414 * Parse a list literal.
5415 * 5415 *
5416 * <pre> 5416 * <pre>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
5475 TypedLiteral _parseListOrMapLiteral(Token modifier) { 5475 TypedLiteral _parseListOrMapLiteral(Token modifier) {
5476 TypeArgumentList typeArguments = null; 5476 TypeArgumentList typeArguments = null;
5477 if (_matches(TokenType.LT)) { 5477 if (_matches(TokenType.LT)) {
5478 typeArguments = parseTypeArgumentList(); 5478 typeArguments = parseTypeArgumentList();
5479 } 5479 }
5480 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 5480 if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
5481 return _parseMapLiteral(modifier, typeArguments); 5481 return _parseMapLiteral(modifier, typeArguments);
5482 } else if (_matches(TokenType.OPEN_SQUARE_BRACKET) || _matches(TokenType.IND EX)) { 5482 } else if (_matches(TokenType.OPEN_SQUARE_BRACKET) || _matches(TokenType.IND EX)) {
5483 return _parseListLiteral(modifier, typeArguments); 5483 return _parseListLiteral(modifier, typeArguments);
5484 } 5484 }
5485 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, [] ); 5485 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL);
5486 return new ListLiteral(modifier, typeArguments, _createSyntheticToken(TokenT ype.OPEN_SQUARE_BRACKET), null, _createSyntheticToken(TokenType.CLOSE_SQUARE_BRA CKET)); 5486 return new ListLiteral(modifier, typeArguments, _createSyntheticToken(TokenT ype.OPEN_SQUARE_BRACKET), null, _createSyntheticToken(TokenType.CLOSE_SQUARE_BRA CKET));
5487 } 5487 }
5488 5488
5489 /** 5489 /**
5490 * Parse a logical and expression. 5490 * Parse a logical and expression.
5491 * 5491 *
5492 * <pre> 5492 * <pre>
5493 * logicalAndExpression ::= 5493 * logicalAndExpression ::=
5494 * equalityExpression ('&&' equalityExpression)* 5494 * equalityExpression ('&&' equalityExpression)*
5495 * </pre> 5495 * </pre>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
5557 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 5557 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
5558 * @param returnType the return type of the method 5558 * @param returnType the return type of the method
5559 * @param name the name of the method 5559 * @param name the name of the method
5560 * @param parameters the parameters to the method 5560 * @param parameters the parameters to the method
5561 * @return the method declaration that was parsed 5561 * @return the method declaration that was parsed
5562 */ 5562 */
5563 MethodDeclaration _parseMethodDeclarationAfterParameters(CommentAndMetadata co mmentAndMetadata, Token externalKeyword, Token staticKeyword, TypeName returnTyp e, SimpleIdentifier name, FormalParameterList parameters) { 5563 MethodDeclaration _parseMethodDeclarationAfterParameters(CommentAndMetadata co mmentAndMetadata, Token externalKeyword, Token staticKeyword, TypeName returnTyp e, SimpleIdentifier name, FormalParameterList parameters) {
5564 FunctionBody body = _parseFunctionBody(externalKeyword != null || staticKeyw ord == null, ParserErrorCode.MISSING_FUNCTION_BODY, false); 5564 FunctionBody body = _parseFunctionBody(externalKeyword != null || staticKeyw ord == null, ParserErrorCode.MISSING_FUNCTION_BODY, false);
5565 if (externalKeyword != null) { 5565 if (externalKeyword != null) {
5566 if (body is! EmptyFunctionBody) { 5566 if (body is! EmptyFunctionBody) {
5567 _reportErrorForNode(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []) ; 5567 _reportErrorForNode(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body);
5568 } 5568 }
5569 } else if (staticKeyword != null) { 5569 } else if (staticKeyword != null) {
5570 if (body is EmptyFunctionBody) { 5570 if (body is EmptyFunctionBody) {
5571 _reportErrorForNode(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []); 5571 _reportErrorForNode(ParserErrorCode.ABSTRACT_STATIC_METHOD, body);
5572 } 5572 }
5573 } 5573 }
5574 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, null, null, name, paramete rs, body); 5574 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, null, null, name, paramete rs, body);
5575 } 5575 }
5576 5576
5577 /** 5577 /**
5578 * Parse a method declaration. 5578 * Parse a method declaration.
5579 * 5579 *
5580 * <pre> 5580 * <pre>
5581 * functionDeclaration ::= 5581 * functionDeclaration ::=
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
5798 return _parseFunctionDeclarationStatementAfterReturnType(commentAndMet adata, returnType); 5798 return _parseFunctionDeclarationStatementAfterReturnType(commentAndMet adata, returnType);
5799 } else { 5799 } else {
5800 // 5800 //
5801 // We have found an error of some kind. Try to recover. 5801 // We have found an error of some kind. Try to recover.
5802 // 5802 //
5803 if (_matchesIdentifier()) { 5803 if (_matchesIdentifier()) {
5804 if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) { 5804 if (_peek().matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) {
5805 // 5805 //
5806 // We appear to have a variable declaration with a type of "void". 5806 // We appear to have a variable declaration with a type of "void".
5807 // 5807 //
5808 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType, []) ; 5808 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
5809 return _parseVariableDeclarationStatementAfterMetadata(commentAndM etadata); 5809 return _parseVariableDeclarationStatementAfterMetadata(commentAndM etadata);
5810 } 5810 }
5811 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { 5811 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
5812 // 5812 //
5813 // We appear to have found an incomplete statement at the end of a b lock. Parse it as a 5813 // We appear to have found an incomplete statement at the end of a b lock. Parse it as a
5814 // variable declaration. 5814 // variable declaration.
5815 // 5815 //
5816 return _parseVariableDeclarationStatementAfterType(commentAndMetadat a, null, returnType); 5816 return _parseVariableDeclarationStatementAfterType(commentAndMetadat a, null, returnType);
5817 } 5817 }
5818 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []); 5818 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT);
5819 // TODO(brianwilkerson) Recover from this error. 5819 // TODO(brianwilkerson) Recover from this error.
5820 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); 5820 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
5821 } 5821 }
5822 } else if (keyword == Keyword.CONST) { 5822 } else if (keyword == Keyword.CONST) {
5823 if (_peek().matchesAny([ 5823 if (_peek().matchesAny([
5824 TokenType.LT, 5824 TokenType.LT,
5825 TokenType.OPEN_CURLY_BRACKET, 5825 TokenType.OPEN_CURLY_BRACKET,
5826 TokenType.OPEN_SQUARE_BRACKET, 5826 TokenType.OPEN_SQUARE_BRACKET,
5827 TokenType.INDEX])) { 5827 TokenType.INDEX])) {
5828 return new ExpressionStatement(parseExpression2(), _expect(TokenType.S EMICOLON)); 5828 return new ExpressionStatement(parseExpression2(), _expect(TokenType.S EMICOLON));
5829 } else if (_tokenMatches(_peek(), TokenType.IDENTIFIER)) { 5829 } else if (_tokenMatches(_peek(), TokenType.IDENTIFIER)) {
5830 Token afterType = _skipTypeName(_peek()); 5830 Token afterType = _skipTypeName(_peek());
5831 if (afterType != null) { 5831 if (afterType != null) {
5832 if (_tokenMatches(afterType, TokenType.OPEN_PAREN) || (_tokenMatches (afterType, TokenType.PERIOD) && _tokenMatches(afterType.next, TokenType.IDENTIF IER) && _tokenMatches(afterType.next.next, TokenType.OPEN_PAREN))) { 5832 if (_tokenMatches(afterType, TokenType.OPEN_PAREN) || (_tokenMatches (afterType, TokenType.PERIOD) && _tokenMatches(afterType.next, TokenType.IDENTIF IER) && _tokenMatches(afterType.next.next, TokenType.OPEN_PAREN))) {
5833 return new ExpressionStatement(parseExpression2(), _expect(TokenTy pe.SEMICOLON)); 5833 return new ExpressionStatement(parseExpression2(), _expect(TokenTy pe.SEMICOLON));
5834 } 5834 }
5835 } 5835 }
5836 } 5836 }
5837 return _parseVariableDeclarationStatementAfterMetadata(commentAndMetadat a); 5837 return _parseVariableDeclarationStatementAfterMetadata(commentAndMetadat a);
5838 } else if (keyword == Keyword.NEW || keyword == Keyword.TRUE || keyword == Keyword.FALSE || keyword == Keyword.NULL || keyword == Keyword.SUPER || keyword == Keyword.THIS) { 5838 } else if (keyword == Keyword.NEW || keyword == Keyword.TRUE || keyword == Keyword.FALSE || keyword == Keyword.NULL || keyword == Keyword.SUPER || keyword == Keyword.THIS) {
5839 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEM ICOLON)); 5839 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEM ICOLON));
5840 } else { 5840 } else {
5841 // 5841 //
5842 // We have found an error of some kind. Try to recover. 5842 // We have found an error of some kind. Try to recover.
5843 // 5843 //
5844 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []); 5844 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT);
5845 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); 5845 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
5846 } 5846 }
5847 } else if (_inGenerator && _matchesString(_YIELD)) { 5847 } else if (_inGenerator && _matchesString(_YIELD)) {
5848 return _parseYieldStatement(); 5848 return _parseYieldStatement();
5849 } else if (_inAsync && _matchesString(_AWAIT)) { 5849 } else if (_inAsync && _matchesString(_AWAIT)) {
5850 if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) { 5850 if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) {
5851 return _parseForStatement(); 5851 return _parseForStatement();
5852 } 5852 }
5853 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEMIC OLON)); 5853 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEMIC OLON));
5854 } else if (_matchesString(_AWAIT) && _tokenMatchesKeyword(_peek(), Keyword.F OR)) { 5854 } else if (_matchesString(_AWAIT) && _tokenMatchesKeyword(_peek(), Keyword.F OR)) {
5855 Token awaitToken = _currentToken; 5855 Token awaitToken = _currentToken;
5856 Statement statement = _parseForStatement(); 5856 Statement statement = _parseForStatement();
5857 if (statement is! ForStatement) { 5857 if (statement is! ForStatement) {
5858 _reportErrorForToken(CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, aw aitToken, []); 5858 _reportErrorForToken(CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, aw aitToken);
5859 } 5859 }
5860 return statement; 5860 return statement;
5861 } else if (_matches(TokenType.SEMICOLON)) { 5861 } else if (_matches(TokenType.SEMICOLON)) {
5862 return _parseEmptyStatement(); 5862 return _parseEmptyStatement();
5863 } else if (_isInitializedVariableDeclaration()) { 5863 } else if (_isInitializedVariableDeclaration()) {
5864 return _parseVariableDeclarationStatementAfterMetadata(commentAndMetadata) ; 5864 return _parseVariableDeclarationStatementAfterMetadata(commentAndMetadata) ;
5865 } else if (_isFunctionDeclaration()) { 5865 } else if (_isFunctionDeclaration()) {
5866 return _parseFunctionDeclarationStatement(); 5866 return _parseFunctionDeclarationStatement();
5867 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { 5867 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
5868 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT, []); 5868 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT);
5869 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); 5869 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON));
5870 } else { 5870 } else {
5871 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEMIC OLON)); 5871 return new ExpressionStatement(parseExpression2(), _expect(TokenType.SEMIC OLON));
5872 } 5872 }
5873 } 5873 }
5874 5874
5875 /** 5875 /**
5876 * Parse an operator declaration. 5876 * Parse an operator declaration.
5877 * 5877 *
5878 * <pre> 5878 * <pre>
5879 * operatorDeclaration ::= 5879 * operatorDeclaration ::=
5880 * operatorSignature (';' | functionBody) 5880 * operatorSignature (';' | functionBody)
5881 * 5881 *
5882 * operatorSignature ::= 5882 * operatorSignature ::=
5883 * 'external'? returnType? 'operator' operator formalParameterList 5883 * 'external'? returnType? 'operator' operator formalParameterList
5884 * </pre> 5884 * </pre>
5885 * 5885 *
5886 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 5886 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
5887 * declaration 5887 * declaration
5888 * @param externalKeyword the 'external' token 5888 * @param externalKeyword the 'external' token
5889 * @param the return type that has already been parsed, or `null` if there was no return 5889 * @param the return type that has already been parsed, or `null` if there was no return
5890 * type 5890 * type
5891 * @return the operator declaration that was parsed 5891 * @return the operator declaration that was parsed
5892 */ 5892 */
5893 MethodDeclaration _parseOperator(CommentAndMetadata commentAndMetadata, Token externalKeyword, TypeName returnType) { 5893 MethodDeclaration _parseOperator(CommentAndMetadata commentAndMetadata, Token externalKeyword, TypeName returnType) {
5894 Token operatorKeyword; 5894 Token operatorKeyword;
5895 if (_matchesKeyword(Keyword.OPERATOR)) { 5895 if (_matchesKeyword(Keyword.OPERATOR)) {
5896 operatorKeyword = andAdvance; 5896 operatorKeyword = andAdvance;
5897 } else { 5897 } else {
5898 _reportErrorForToken(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentTok en, []); 5898 _reportErrorForToken(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentTok en);
5899 operatorKeyword = _createSyntheticKeyword(Keyword.OPERATOR); 5899 operatorKeyword = _createSyntheticKeyword(Keyword.OPERATOR);
5900 } 5900 }
5901 if (!_currentToken.isUserDefinableOperator) { 5901 if (!_currentToken.isUserDefinableOperator) {
5902 _reportErrorForCurrentToken(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [ _currentToken.lexeme]); 5902 _reportErrorForCurrentToken(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [ _currentToken.lexeme]);
5903 } 5903 }
5904 SimpleIdentifier name = new SimpleIdentifier(andAdvance); 5904 SimpleIdentifier name = new SimpleIdentifier(andAdvance);
5905 if (_matches(TokenType.EQ)) { 5905 if (_matches(TokenType.EQ)) {
5906 Token previous = _currentToken.previous; 5906 Token previous = _currentToken.previous;
5907 if ((_tokenMatches(previous, TokenType.EQ_EQ) || _tokenMatches(previous, T okenType.BANG_EQ)) && _currentToken.offset == previous.offset + 2) { 5907 if ((_tokenMatches(previous, TokenType.EQ_EQ) || _tokenMatches(previous, T okenType.BANG_EQ)) && _currentToken.offset == previous.offset + 2) {
5908 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR, ["${previo us.lexeme}${_currentToken.lexeme}"]); 5908 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR, ["${previo us.lexeme}${_currentToken.lexeme}"]);
5909 _advance(); 5909 _advance();
5910 } 5910 }
5911 } 5911 }
5912 FormalParameterList parameters = parseFormalParameterList(); 5912 FormalParameterList parameters = parseFormalParameterList();
5913 _validateFormalParameterList(parameters); 5913 _validateFormalParameterList(parameters);
5914 FunctionBody body = _parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTIO N_BODY, false); 5914 FunctionBody body = _parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTIO N_BODY, false);
5915 if (externalKeyword != null && body is! EmptyFunctionBody) { 5915 if (externalKeyword != null && body is! EmptyFunctionBody) {
5916 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, [ ]); 5916 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY);
5917 } 5917 }
5918 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, null, returnType, null, operatorKeyword, name, parame ters, body); 5918 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, null, returnType, null, operatorKeyword, name, parame ters, body);
5919 } 5919 }
5920 5920
5921 /** 5921 /**
5922 * Parse a return type if one is given, otherwise return `null` without advanc ing. 5922 * Parse a return type if one is given, otherwise return `null` without advanc ing.
5923 * 5923 *
5924 * @return the return type that was parsed 5924 * @return the return type that was parsed
5925 */ 5925 */
5926 TypeName _parseOptionalReturnType() { 5926 TypeName _parseOptionalReturnType() {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
6113 // 6113 //
6114 // Recover from having a return type of "void" where a return type is not expected. 6114 // Recover from having a return type of "void" where a return type is not expected.
6115 // 6115 //
6116 // TODO(brianwilkerson) Improve this error message. 6116 // TODO(brianwilkerson) Improve this error message.
6117 _reportErrorForCurrentToken(ParserErrorCode.UNEXPECTED_TOKEN, [_currentTok en.lexeme]); 6117 _reportErrorForCurrentToken(ParserErrorCode.UNEXPECTED_TOKEN, [_currentTok en.lexeme]);
6118 _advance(); 6118 _advance();
6119 return _parsePrimaryExpression(); 6119 return _parsePrimaryExpression();
6120 } else if (_matches(TokenType.HASH)) { 6120 } else if (_matches(TokenType.HASH)) {
6121 return _parseSymbolLiteral(); 6121 return _parseSymbolLiteral();
6122 } else { 6122 } else {
6123 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); 6123 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
6124 return _createSyntheticIdentifier(); 6124 return _createSyntheticIdentifier();
6125 } 6125 }
6126 } 6126 }
6127 6127
6128 /** 6128 /**
6129 * Parse a redirecting constructor invocation. 6129 * Parse a redirecting constructor invocation.
6130 * 6130 *
6131 * <pre> 6131 * <pre>
6132 * redirectingConstructorInvocation ::= 6132 * redirectingConstructorInvocation ::=
6133 * 'this' ('.' identifier)? arguments 6133 * 'this' ('.' identifier)? arguments
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
6234 * type 6234 * type
6235 * @return the setter that was parsed 6235 * @return the setter that was parsed
6236 */ 6236 */
6237 MethodDeclaration _parseSetter(CommentAndMetadata commentAndMetadata, Token ex ternalKeyword, Token staticKeyword, TypeName returnType) { 6237 MethodDeclaration _parseSetter(CommentAndMetadata commentAndMetadata, Token ex ternalKeyword, Token staticKeyword, TypeName returnType) {
6238 Token propertyKeyword = _expectKeyword(Keyword.SET); 6238 Token propertyKeyword = _expectKeyword(Keyword.SET);
6239 SimpleIdentifier name = parseSimpleIdentifier(); 6239 SimpleIdentifier name = parseSimpleIdentifier();
6240 FormalParameterList parameters = parseFormalParameterList(); 6240 FormalParameterList parameters = parseFormalParameterList();
6241 _validateFormalParameterList(parameters); 6241 _validateFormalParameterList(parameters);
6242 FunctionBody body = _parseFunctionBody(externalKeyword != null || staticKeyw ord == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false); 6242 FunctionBody body = _parseFunctionBody(externalKeyword != null || staticKeyw ord == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false);
6243 if (externalKeyword != null && body is! EmptyFunctionBody) { 6243 if (externalKeyword != null && body is! EmptyFunctionBody) {
6244 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []) ; 6244 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY);
6245 } 6245 }
6246 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, parameters, body); 6246 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, parameters, body);
6247 } 6247 }
6248 6248
6249 /** 6249 /**
6250 * Parse a shift expression. 6250 * Parse a shift expression.
6251 * 6251 *
6252 * <pre> 6252 * <pre>
6253 * shiftExpression ::= 6253 * shiftExpression ::=
6254 * additiveExpression (shiftOperator additiveExpression)* 6254 * additiveExpression (shiftOperator additiveExpression)*
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
6399 } 6399 }
6400 Token colon = _expect(TokenType.COLON); 6400 Token colon = _expect(TokenType.COLON);
6401 labels.add(new Label(identifier, colon)); 6401 labels.add(new Label(identifier, colon));
6402 } 6402 }
6403 if (_matchesKeyword(Keyword.CASE)) { 6403 if (_matchesKeyword(Keyword.CASE)) {
6404 Token caseKeyword = andAdvance; 6404 Token caseKeyword = andAdvance;
6405 Expression caseExpression = parseExpression2(); 6405 Expression caseExpression = parseExpression2();
6406 Token colon = _expect(TokenType.COLON); 6406 Token colon = _expect(TokenType.COLON);
6407 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, _parseStatementList())); 6407 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, _parseStatementList()));
6408 if (defaultKeyword != null) { 6408 if (defaultKeyword != null) {
6409 _reportErrorForToken(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_C ASE, caseKeyword, []); 6409 _reportErrorForToken(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_C ASE, caseKeyword);
6410 } 6410 }
6411 } else if (_matchesKeyword(Keyword.DEFAULT)) { 6411 } else if (_matchesKeyword(Keyword.DEFAULT)) {
6412 if (defaultKeyword != null) { 6412 if (defaultKeyword != null) {
6413 _reportErrorForToken(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CAS ES, _peek(), []); 6413 _reportErrorForToken(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CAS ES, _peek());
6414 } 6414 }
6415 defaultKeyword = andAdvance; 6415 defaultKeyword = andAdvance;
6416 Token colon = _expect(TokenType.COLON); 6416 Token colon = _expect(TokenType.COLON);
6417 members.add(new SwitchDefault(labels, defaultKeyword, colon, _parseSta tementList())); 6417 members.add(new SwitchDefault(labels, defaultKeyword, colon, _parseSta tementList()));
6418 } else { 6418 } else {
6419 // We need to advance, otherwise we could end up in an infinite loop, but this could be a 6419 // We need to advance, otherwise we could end up in an infinite loop, but this could be a
6420 // lot smarter about recovering from the error. 6420 // lot smarter about recovering from the error.
6421 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []); 6421 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT);
6422 while (!_matches(TokenType.EOF) && !_matches(TokenType.CLOSE_CURLY_BRA CKET) && !_matchesKeyword(Keyword.CASE) && !_matchesKeyword(Keyword.DEFAULT)) { 6422 while (!_matches(TokenType.EOF) && !_matches(TokenType.CLOSE_CURLY_BRA CKET) && !_matchesKeyword(Keyword.CASE) && !_matchesKeyword(Keyword.DEFAULT)) {
6423 _advance(); 6423 _advance();
6424 } 6424 }
6425 } 6425 }
6426 } 6426 }
6427 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); 6427 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
6428 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket); 6428 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket);
6429 } finally { 6429 } finally {
6430 _inSwitch = wasInSwitch; 6430 _inSwitch = wasInSwitch;
6431 } 6431 }
(...skipping 12 matching lines...) Expand all
6444 SymbolLiteral _parseSymbolLiteral() { 6444 SymbolLiteral _parseSymbolLiteral() {
6445 Token poundSign = andAdvance; 6445 Token poundSign = andAdvance;
6446 List<Token> components = new List<Token>(); 6446 List<Token> components = new List<Token>();
6447 if (_matchesIdentifier()) { 6447 if (_matchesIdentifier()) {
6448 components.add(andAdvance); 6448 components.add(andAdvance);
6449 while (_matches(TokenType.PERIOD)) { 6449 while (_matches(TokenType.PERIOD)) {
6450 _advance(); 6450 _advance();
6451 if (_matchesIdentifier()) { 6451 if (_matchesIdentifier()) {
6452 components.add(andAdvance); 6452 components.add(andAdvance);
6453 } else { 6453 } else {
6454 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); 6454 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
6455 components.add(_createSyntheticToken(TokenType.IDENTIFIER)); 6455 components.add(_createSyntheticToken(TokenType.IDENTIFIER));
6456 break; 6456 break;
6457 } 6457 }
6458 } 6458 }
6459 } else if (_currentToken.isOperator) { 6459 } else if (_currentToken.isOperator) {
6460 components.add(andAdvance); 6460 components.add(andAdvance);
6461 } else if (_tokenMatchesKeyword(_currentToken, Keyword.VOID)) { 6461 } else if (_tokenMatchesKeyword(_currentToken, Keyword.VOID)) {
6462 components.add(andAdvance); 6462 components.add(andAdvance);
6463 } else { 6463 } else {
6464 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); 6464 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
6465 components.add(_createSyntheticToken(TokenType.IDENTIFIER)); 6465 components.add(_createSyntheticToken(TokenType.IDENTIFIER));
6466 } 6466 }
6467 return new SymbolLiteral(poundSign, components); 6467 return new SymbolLiteral(poundSign, components);
6468 } 6468 }
6469 6469
6470 /** 6470 /**
6471 * Parse a throw expression. 6471 * Parse a throw expression.
6472 * 6472 *
6473 * <pre> 6473 * <pre>
6474 * throwExpression ::= 6474 * throwExpression ::=
6475 * 'throw' expression 6475 * 'throw' expression
6476 * </pre> 6476 * </pre>
6477 * 6477 *
6478 * @return the throw expression that was parsed 6478 * @return the throw expression that was parsed
6479 */ 6479 */
6480 Expression _parseThrowExpression() { 6480 Expression _parseThrowExpression() {
6481 Token keyword = _expectKeyword(Keyword.THROW); 6481 Token keyword = _expectKeyword(Keyword.THROW);
6482 if (_matches(TokenType.SEMICOLON) || _matches(TokenType.CLOSE_PAREN)) { 6482 if (_matches(TokenType.SEMICOLON) || _matches(TokenType.CLOSE_PAREN)) {
6483 _reportErrorForToken(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _current Token, []); 6483 _reportErrorForToken(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _current Token);
6484 return new ThrowExpression(keyword, _createSyntheticIdentifier()); 6484 return new ThrowExpression(keyword, _createSyntheticIdentifier());
6485 } 6485 }
6486 Expression expression = parseExpression2(); 6486 Expression expression = parseExpression2();
6487 return new ThrowExpression(keyword, expression); 6487 return new ThrowExpression(keyword, expression);
6488 } 6488 }
6489 6489
6490 /** 6490 /**
6491 * Parse a throw expression. 6491 * Parse a throw expression.
6492 * 6492 *
6493 * <pre> 6493 * <pre>
6494 * throwExpressionWithoutCascade ::= 6494 * throwExpressionWithoutCascade ::=
6495 * 'throw' expressionWithoutCascade 6495 * 'throw' expressionWithoutCascade
6496 * </pre> 6496 * </pre>
6497 * 6497 *
6498 * @return the throw expression that was parsed 6498 * @return the throw expression that was parsed
6499 */ 6499 */
6500 Expression _parseThrowExpressionWithoutCascade() { 6500 Expression _parseThrowExpressionWithoutCascade() {
6501 Token keyword = _expectKeyword(Keyword.THROW); 6501 Token keyword = _expectKeyword(Keyword.THROW);
6502 if (_matches(TokenType.SEMICOLON) || _matches(TokenType.CLOSE_PAREN)) { 6502 if (_matches(TokenType.SEMICOLON) || _matches(TokenType.CLOSE_PAREN)) {
6503 _reportErrorForToken(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _current Token, []); 6503 _reportErrorForToken(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _current Token);
6504 return new ThrowExpression(keyword, _createSyntheticIdentifier()); 6504 return new ThrowExpression(keyword, _createSyntheticIdentifier());
6505 } 6505 }
6506 Expression expression = parseExpressionWithoutCascade(); 6506 Expression expression = parseExpressionWithoutCascade();
6507 return new ThrowExpression(keyword, expression); 6507 return new ThrowExpression(keyword, expression);
6508 } 6508 }
6509 6509
6510 /** 6510 /**
6511 * Parse a try statement. 6511 * Parse a try statement.
6512 * 6512 *
6513 * <pre> 6513 * <pre>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
6557 } 6557 }
6558 Block catchBody = parseBlock(); 6558 Block catchBody = parseBlock();
6559 catchClauses.add(new CatchClause(onKeyword, exceptionType, catchKeyword, l eftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParenthesis , catchBody)); 6559 catchClauses.add(new CatchClause(onKeyword, exceptionType, catchKeyword, l eftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParenthesis , catchBody));
6560 } 6560 }
6561 Token finallyKeyword = null; 6561 Token finallyKeyword = null;
6562 if (_matchesKeyword(Keyword.FINALLY)) { 6562 if (_matchesKeyword(Keyword.FINALLY)) {
6563 finallyKeyword = andAdvance; 6563 finallyKeyword = andAdvance;
6564 finallyClause = parseBlock(); 6564 finallyClause = parseBlock();
6565 } else { 6565 } else {
6566 if (catchClauses.isEmpty) { 6566 if (catchClauses.isEmpty) {
6567 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CATCH_OR_FINALLY, [] ); 6567 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CATCH_OR_FINALLY);
6568 } 6568 }
6569 } 6569 }
6570 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause); 6570 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause);
6571 } 6571 }
6572 6572
6573 /** 6573 /**
6574 * Parse a type alias. 6574 * Parse a type alias.
6575 * 6575 *
6576 * <pre> 6576 * <pre>
6577 * typeAlias ::= 6577 * typeAlias ::=
(...skipping 20 matching lines...) Expand all
6598 * @return the type alias that was parsed 6598 * @return the type alias that was parsed
6599 */ 6599 */
6600 TypeAlias _parseTypeAlias(CommentAndMetadata commentAndMetadata) { 6600 TypeAlias _parseTypeAlias(CommentAndMetadata commentAndMetadata) {
6601 Token keyword = _expectKeyword(Keyword.TYPEDEF); 6601 Token keyword = _expectKeyword(Keyword.TYPEDEF);
6602 if (_matchesIdentifier()) { 6602 if (_matchesIdentifier()) {
6603 Token next = _peek(); 6603 Token next = _peek();
6604 if (_tokenMatches(next, TokenType.LT)) { 6604 if (_tokenMatches(next, TokenType.LT)) {
6605 next = _skipTypeParameterList(next); 6605 next = _skipTypeParameterList(next);
6606 if (next != null && _tokenMatches(next, TokenType.EQ)) { 6606 if (next != null && _tokenMatches(next, TokenType.EQ)) {
6607 TypeAlias typeAlias = _parseClassTypeAlias(commentAndMetadata, null, k eyword); 6607 TypeAlias typeAlias = _parseClassTypeAlias(commentAndMetadata, null, k eyword);
6608 _reportErrorForToken(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyw ord, []); 6608 _reportErrorForToken(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyw ord);
6609 return typeAlias; 6609 return typeAlias;
6610 } 6610 }
6611 } else if (_tokenMatches(next, TokenType.EQ)) { 6611 } else if (_tokenMatches(next, TokenType.EQ)) {
6612 TypeAlias typeAlias = _parseClassTypeAlias(commentAndMetadata, null, key word); 6612 TypeAlias typeAlias = _parseClassTypeAlias(commentAndMetadata, null, key word);
6613 _reportErrorForToken(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keywor d, []); 6613 _reportErrorForToken(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keywor d);
6614 return typeAlias; 6614 return typeAlias;
6615 } 6615 }
6616 } 6616 }
6617 return _parseFunctionTypeAlias(commentAndMetadata, keyword); 6617 return _parseFunctionTypeAlias(commentAndMetadata, keyword);
6618 } 6618 }
6619 6619
6620 /** 6620 /**
6621 * Parse a unary expression. 6621 * Parse a unary expression.
6622 * 6622 *
6623 * <pre> 6623 * <pre>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
6667 operator.previous.setNext(firstOperator); 6667 operator.previous.setNext(firstOperator);
6668 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance))); 6668 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance)));
6669 } else { 6669 } else {
6670 // Invalid operator before 'super' 6670 // Invalid operator before 'super'
6671 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER , [operator.lexeme]); 6671 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER , [operator.lexeme]);
6672 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ; 6672 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ;
6673 } 6673 }
6674 } 6674 }
6675 return new PrefixExpression(operator, _parseAssignableExpression(false)); 6675 return new PrefixExpression(operator, _parseAssignableExpression(false));
6676 } else if (_matches(TokenType.PLUS)) { 6676 } else if (_matches(TokenType.PLUS)) {
6677 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER, []); 6677 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
6678 return _createSyntheticIdentifier(); 6678 return _createSyntheticIdentifier();
6679 } else if (_matchesString(_AWAIT)) { 6679 } else if (_matchesString(_AWAIT)) {
6680 return _parseAwaitExpression(); 6680 return _parseAwaitExpression();
6681 } 6681 }
6682 return _parsePostfixExpression(); 6682 return _parsePostfixExpression();
6683 } 6683 }
6684 6684
6685 /** 6685 /**
6686 * Parse a variable declaration. 6686 * Parse a variable declaration.
6687 * 6687 *
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6730 * 6730 *
6731 * @param commentAndMetadata the metadata to be associated with the variable d eclaration list, or 6731 * @param commentAndMetadata the metadata to be associated with the variable d eclaration list, or
6732 * `null` if there is no attempt at parsing the comment and metadata 6732 * `null` if there is no attempt at parsing the comment and metadata
6733 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if 6733 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if
6734 * there is no keyword 6734 * there is no keyword
6735 * @param type the type of the variables in the list 6735 * @param type the type of the variables in the list
6736 * @return the variable declaration list that was parsed 6736 * @return the variable declaration list that was parsed
6737 */ 6737 */
6738 VariableDeclarationList _parseVariableDeclarationListAfterType(CommentAndMetad ata commentAndMetadata, Token keyword, TypeName type) { 6738 VariableDeclarationList _parseVariableDeclarationListAfterType(CommentAndMetad ata commentAndMetadata, Token keyword, TypeName type) {
6739 if (type != null && keyword != null && _tokenMatchesKeyword(keyword, Keyword .VAR)) { 6739 if (type != null && keyword != null && _tokenMatchesKeyword(keyword, Keyword .VAR)) {
6740 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, keyword, []); 6740 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, keyword);
6741 } 6741 }
6742 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 6742 List<VariableDeclaration> variables = new List<VariableDeclaration>();
6743 variables.add(_parseVariableDeclaration()); 6743 variables.add(_parseVariableDeclaration());
6744 while (_matches(TokenType.COMMA)) { 6744 while (_matches(TokenType.COMMA)) {
6745 _advance(); 6745 _advance();
6746 variables.add(_parseVariableDeclaration()); 6746 variables.add(_parseVariableDeclaration());
6747 } 6747 }
6748 return new VariableDeclarationList(commentAndMetadata != null ? commentAndMe tadata.comment : null, commentAndMetadata != null ? commentAndMetadata.metadata : null, keyword, type, variables); 6748 return new VariableDeclarationList(commentAndMetadata != null ? commentAndMe tadata.comment : null, commentAndMetadata != null ? commentAndMetadata.metadata : null, keyword, type, variables);
6749 } 6749 }
6750 6750
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
6874 } 6874 }
6875 _errorListener.onError(error); 6875 _errorListener.onError(error);
6876 } 6876 }
6877 6877
6878 /** 6878 /**
6879 * Report an error with the given error code and arguments. 6879 * Report an error with the given error code and arguments.
6880 * 6880 *
6881 * @param errorCode the error code of the error to be reported 6881 * @param errorCode the error code of the error to be reported
6882 * @param arguments the arguments to the error, used to compose the error mess age 6882 * @param arguments the arguments to the error, used to compose the error mess age
6883 */ 6883 */
6884 void _reportErrorForCurrentToken(ParserErrorCode errorCode, List<Object> argum ents) { 6884 void _reportErrorForCurrentToken(ParserErrorCode errorCode, [List<Object> argu ments]) {
6885 _reportErrorForToken(errorCode, _currentToken, arguments); 6885 _reportErrorForToken(errorCode, _currentToken, arguments);
6886 } 6886 }
6887 6887
6888 /** 6888 /**
6889 * Report an error with the given error code and arguments. 6889 * Report an error with the given error code and arguments.
6890 * 6890 *
6891 * @param errorCode the error code of the error to be reported 6891 * @param errorCode the error code of the error to be reported
6892 * @param node the node specifying the location of the error 6892 * @param node the node specifying the location of the error
6893 * @param arguments the arguments to the error, used to compose the error mess age 6893 * @param arguments the arguments to the error, used to compose the error mess age
6894 */ 6894 */
6895 void _reportErrorForNode(ParserErrorCode errorCode, AstNode node, List<Object> arguments) { 6895 void _reportErrorForNode(ParserErrorCode errorCode, AstNode node, [List<Object > arguments]) {
6896 _reportError(new AnalysisError.con2(_source, node.offset, node.length, error Code, arguments)); 6896 _reportError(new AnalysisError.con2(_source, node.offset, node.length, error Code, arguments));
6897 } 6897 }
6898 6898
6899 /** 6899 /**
6900 * Report an error with the given error code and arguments. 6900 * Report an error with the given error code and arguments.
6901 * 6901 *
6902 * @param errorCode the error code of the error to be reported 6902 * @param errorCode the error code of the error to be reported
6903 * @param token the token specifying the location of the error 6903 * @param token the token specifying the location of the error
6904 * @param arguments the arguments to the error, used to compose the error mess age 6904 * @param arguments the arguments to the error, used to compose the error mess age
6905 */ 6905 */
6906 void _reportErrorForToken(ErrorCode errorCode, Token token, List<Object> argum ents) { 6906 void _reportErrorForToken(ErrorCode errorCode, Token token, [List<Object> argu ments]) {
6907 if (token.type == TokenType.EOF) { 6907 if (token.type == TokenType.EOF) {
6908 token = token.previous; 6908 token = token.previous;
6909 } 6909 }
6910 _reportError(new AnalysisError.con2(_source, token.offset, math.max(token.le ngth, 1), errorCode, arguments)); 6910 _reportError(new AnalysisError.con2(_source, token.offset, math.max(token.le ngth, 1), errorCode, arguments));
6911 } 6911 }
6912 6912
6913 /** 6913 /**
6914 * Skips a block with all containing blocks. 6914 * Skips a block with all containing blocks.
6915 */ 6915 */
6916 void _skipBlock() { 6916 void _skipBlock() {
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
7427 // backspace 7427 // backspace
7428 } else if (currentChar == 0x74) { 7428 } else if (currentChar == 0x74) {
7429 buffer.writeCharCode(0x9); 7429 buffer.writeCharCode(0x9);
7430 // tab 7430 // tab
7431 } else if (currentChar == 0x76) { 7431 } else if (currentChar == 0x76) {
7432 buffer.writeCharCode(0xB); 7432 buffer.writeCharCode(0xB);
7433 // vertical tab 7433 // vertical tab
7434 } else if (currentChar == 0x78) { 7434 } else if (currentChar == 0x78) {
7435 if (currentIndex + 2 >= length) { 7435 if (currentIndex + 2 >= length) {
7436 // Illegal escape sequence: not enough hex digits 7436 // Illegal escape sequence: not enough hex digits
7437 _reportErrorForCurrentToken(ParserErrorCode.INVALID_HEX_ESCAPE, []); 7437 _reportErrorForCurrentToken(ParserErrorCode.INVALID_HEX_ESCAPE);
7438 return length; 7438 return length;
7439 } 7439 }
7440 int firstDigit = lexeme.codeUnitAt(currentIndex + 1); 7440 int firstDigit = lexeme.codeUnitAt(currentIndex + 1);
7441 int secondDigit = lexeme.codeUnitAt(currentIndex + 2); 7441 int secondDigit = lexeme.codeUnitAt(currentIndex + 2);
7442 if (!_isHexDigit(firstDigit) || !_isHexDigit(secondDigit)) { 7442 if (!_isHexDigit(firstDigit) || !_isHexDigit(secondDigit)) {
7443 // Illegal escape sequence: invalid hex digit 7443 // Illegal escape sequence: invalid hex digit
7444 _reportErrorForCurrentToken(ParserErrorCode.INVALID_HEX_ESCAPE, []); 7444 _reportErrorForCurrentToken(ParserErrorCode.INVALID_HEX_ESCAPE);
7445 } else { 7445 } else {
7446 int charCode = (Character.digit(firstDigit, 16) << 4) 7446 int charCode = (Character.digit(firstDigit, 16) << 4)
7447 + Character.digit(secondDigit, 16); 7447 + Character.digit(secondDigit, 16);
7448 buffer.writeCharCode(charCode); 7448 buffer.writeCharCode(charCode);
7449 } 7449 }
7450 return currentIndex + 3; 7450 return currentIndex + 3;
7451 } else if (currentChar == 0x75) { 7451 } else if (currentChar == 0x75) {
7452 currentIndex++; 7452 currentIndex++;
7453 if (currentIndex >= length) { 7453 if (currentIndex >= length) {
7454 // Illegal escape sequence: not enough hex digits 7454 // Illegal escape sequence: not enough hex digits
7455 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 7455 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE);
7456 return length; 7456 return length;
7457 } 7457 }
7458 currentChar = lexeme.codeUnitAt(currentIndex); 7458 currentChar = lexeme.codeUnitAt(currentIndex);
7459 if (currentChar == 0x7B) { 7459 if (currentChar == 0x7B) {
7460 currentIndex++; 7460 currentIndex++;
7461 if (currentIndex >= length) { 7461 if (currentIndex >= length) {
7462 // Illegal escape sequence: incomplete escape 7462 // Illegal escape sequence: incomplete escape
7463 _reportErrorForCurrentToken( 7463 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE);
7464 ParserErrorCode.INVALID_UNICODE_ESCAPE,
7465 []);
7466 return length; 7464 return length;
7467 } 7465 }
7468 currentChar = lexeme.codeUnitAt(currentIndex); 7466 currentChar = lexeme.codeUnitAt(currentIndex);
7469 int digitCount = 0; 7467 int digitCount = 0;
7470 int value = 0; 7468 int value = 0;
7471 while (currentChar != 0x7D) { 7469 while (currentChar != 0x7D) {
7472 if (!_isHexDigit(currentChar)) { 7470 if (!_isHexDigit(currentChar)) {
7473 // Illegal escape sequence: invalid hex digit 7471 // Illegal escape sequence: invalid hex digit
7474 _reportErrorForCurrentToken( 7472 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE);
7475 ParserErrorCode.INVALID_UNICODE_ESCAPE,
7476 []);
7477 currentIndex++; 7473 currentIndex++;
7478 while (currentIndex < length 7474 while (currentIndex < length
7479 && lexeme.codeUnitAt(currentIndex) != 0x7D) { 7475 && lexeme.codeUnitAt(currentIndex) != 0x7D) {
7480 currentIndex++; 7476 currentIndex++;
7481 } 7477 }
7482 return currentIndex + 1; 7478 return currentIndex + 1;
7483 } 7479 }
7484 digitCount++; 7480 digitCount++;
7485 value = (value << 4) + Character.digit(currentChar, 16); 7481 value = (value << 4) + Character.digit(currentChar, 16);
7486 currentIndex++; 7482 currentIndex++;
7487 if (currentIndex >= length) { 7483 if (currentIndex >= length) {
7488 // Illegal escape sequence: incomplete escape 7484 // Illegal escape sequence: incomplete escape
7489 _reportErrorForCurrentToken( 7485 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE);
7490 ParserErrorCode.INVALID_UNICODE_ESCAPE,
7491 []);
7492 return length; 7486 return length;
7493 } 7487 }
7494 currentChar = lexeme.codeUnitAt(currentIndex); 7488 currentChar = lexeme.codeUnitAt(currentIndex);
7495 } 7489 }
7496 if (digitCount < 1 || digitCount > 6) { 7490 if (digitCount < 1 || digitCount > 6) {
7497 // Illegal escape sequence: not enough or too many hex digits 7491 // Illegal escape sequence: not enough or too many hex digits
7498 _reportErrorForCurrentToken( 7492 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE);
7499 ParserErrorCode.INVALID_UNICODE_ESCAPE,
7500 []);
7501 } 7493 }
7502 _appendScalarValue( 7494 _appendScalarValue(
7503 buffer, 7495 buffer,
7504 lexeme.substring(index, currentIndex + 1), 7496 lexeme.substring(index, currentIndex + 1),
7505 value, 7497 value,
7506 index, 7498 index,
7507 currentIndex); 7499 currentIndex);
7508 return currentIndex + 1; 7500 return currentIndex + 1;
7509 } else { 7501 } else {
7510 if (currentIndex + 3 >= length) { 7502 if (currentIndex + 3 >= length) {
7511 // Illegal escape sequence: not enough hex digits 7503 // Illegal escape sequence: not enough hex digits
7512 _reportErrorForCurrentToken( 7504 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE);
7513 ParserErrorCode.INVALID_UNICODE_ESCAPE,
7514 []);
7515 return length; 7505 return length;
7516 } 7506 }
7517 int firstDigit = currentChar; 7507 int firstDigit = currentChar;
7518 int secondDigit = lexeme.codeUnitAt(currentIndex + 1); 7508 int secondDigit = lexeme.codeUnitAt(currentIndex + 1);
7519 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2); 7509 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2);
7520 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3); 7510 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3);
7521 if (!_isHexDigit(firstDigit) 7511 if (!_isHexDigit(firstDigit)
7522 || !_isHexDigit(secondDigit) 7512 || !_isHexDigit(secondDigit)
7523 || !_isHexDigit(thirdDigit) 7513 || !_isHexDigit(thirdDigit)
7524 || !_isHexDigit(fourthDigit)) { 7514 || !_isHexDigit(fourthDigit)) {
7525 // Illegal escape sequence: invalid hex digits 7515 // Illegal escape sequence: invalid hex digits
7526 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE, [] ); 7516 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE);
7527 } else { 7517 } else {
7528 _appendScalarValue( 7518 _appendScalarValue(
7529 buffer, 7519 buffer,
7530 lexeme.substring(index, currentIndex + 1), 7520 lexeme.substring(index, currentIndex + 1),
7531 (((((Character.digit(firstDigit, 16) << 4) 7521 (((((Character.digit(firstDigit, 16) << 4)
7532 + Character.digit(secondDigit, 16)) << 4) 7522 + Character.digit(secondDigit, 16)) << 4)
7533 + Character.digit(thirdDigit, 16)) << 4) 7523 + Character.digit(thirdDigit, 16)) << 4)
7534 + Character.digit(fourthDigit, 16), 7524 + Character.digit(fourthDigit, 16),
7535 index, 7525 index,
7536 currentIndex + 3); 7526 currentIndex + 3);
(...skipping 18 matching lines...) Expand all
7555 } 7545 }
7556 7546
7557 /** 7547 /**
7558 * Validate that the given parameter list does not contain any field initializ ers. 7548 * Validate that the given parameter list does not contain any field initializ ers.
7559 * 7549 *
7560 * @param parameterList the parameter list to be validated 7550 * @param parameterList the parameter list to be validated
7561 */ 7551 */
7562 void _validateFormalParameterList(FormalParameterList parameterList) { 7552 void _validateFormalParameterList(FormalParameterList parameterList) {
7563 for (FormalParameter parameter in parameterList.parameters) { 7553 for (FormalParameter parameter in parameterList.parameters) {
7564 if (parameter is FieldFormalParameter) { 7554 if (parameter is FieldFormalParameter) {
7565 _reportErrorForNode(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTO R, parameter.identifier, []); 7555 _reportErrorForNode(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTO R, parameter.identifier);
7566 } 7556 }
7567 } 7557 }
7568 } 7558 }
7569 7559
7570 /** 7560 /**
7571 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract' 7561 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract'
7572 * keyword if there is one. 7562 * keyword if there is one.
7573 * 7563 *
7574 * @param modifiers the modifiers being validated 7564 * @param modifiers the modifiers being validated
7575 */ 7565 */
7576 Token _validateModifiersForClass(Modifiers modifiers) { 7566 Token _validateModifiersForClass(Modifiers modifiers) {
7577 _validateModifiersForTopLevelDeclaration(modifiers); 7567 _validateModifiersForTopLevelDeclaration(modifiers);
7578 if (modifiers.constKeyword != null) { 7568 if (modifiers.constKeyword != null) {
7579 _reportErrorForToken(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); 7569 _reportErrorForToken(ParserErrorCode.CONST_CLASS, modifiers.constKeyword);
7580 } 7570 }
7581 if (modifiers.externalKeyword != null) { 7571 if (modifiers.externalKeyword != null) {
7582 _reportErrorForToken(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKey word, []); 7572 _reportErrorForToken(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKey word);
7583 } 7573 }
7584 if (modifiers.finalKeyword != null) { 7574 if (modifiers.finalKeyword != null) {
7585 _reportErrorForToken(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); 7575 _reportErrorForToken(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword);
7586 } 7576 }
7587 if (modifiers.varKeyword != null) { 7577 if (modifiers.varKeyword != null) {
7588 _reportErrorForToken(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []); 7578 _reportErrorForToken(ParserErrorCode.VAR_CLASS, modifiers.varKeyword);
7589 } 7579 }
7590 return modifiers.abstractKeyword; 7580 return modifiers.abstractKeyword;
7591 } 7581 }
7592 7582
7593 /** 7583 /**
7594 * Validate that the given set of modifiers is appropriate for a constructor a nd return the 7584 * Validate that the given set of modifiers is appropriate for a constructor a nd return the
7595 * 'const' keyword if there is one. 7585 * 'const' keyword if there is one.
7596 * 7586 *
7597 * @param modifiers the modifiers being validated 7587 * @param modifiers the modifiers being validated
7598 * @return the 'const' or 'final' keyword associated with the constructor 7588 * @return the 'const' or 'final' keyword associated with the constructor
7599 */ 7589 */
7600 Token _validateModifiersForConstructor(Modifiers modifiers) { 7590 Token _validateModifiersForConstructor(Modifiers modifiers) {
7601 if (modifiers.abstractKeyword != null) { 7591 if (modifiers.abstractKeyword != null) {
7602 _reportErrorForToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, modifiers.abst ractKeyword, []); 7592 _reportErrorForToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, modifiers.abst ractKeyword);
7603 } 7593 }
7604 if (modifiers.finalKeyword != null) { 7594 if (modifiers.finalKeyword != null) {
7605 _reportErrorForToken(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKey word, []); 7595 _reportErrorForToken(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKey word);
7606 } 7596 }
7607 if (modifiers.staticKeyword != null) { 7597 if (modifiers.staticKeyword != null) {
7608 _reportErrorForToken(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticK eyword, []); 7598 _reportErrorForToken(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticK eyword);
7609 } 7599 }
7610 if (modifiers.varKeyword != null) { 7600 if (modifiers.varKeyword != null) {
7611 _reportErrorForToken(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifie rs.varKeyword, []); 7601 _reportErrorForToken(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifie rs.varKeyword);
7612 } 7602 }
7613 Token externalKeyword = modifiers.externalKeyword; 7603 Token externalKeyword = modifiers.externalKeyword;
7614 Token constKeyword = modifiers.constKeyword; 7604 Token constKeyword = modifiers.constKeyword;
7615 Token factoryKeyword = modifiers.factoryKeyword; 7605 Token factoryKeyword = modifiers.factoryKeyword;
7616 if (externalKeyword != null && constKeyword != null && constKeyword.offset < externalKeyword.offset) { 7606 if (externalKeyword != null && constKeyword != null && constKeyword.offset < externalKeyword.offset) {
7617 _reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword , []); 7607 _reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword );
7618 } 7608 }
7619 if (externalKeyword != null && factoryKeyword != null && factoryKeyword.offs et < externalKeyword.offset) { 7609 if (externalKeyword != null && factoryKeyword != null && factoryKeyword.offs et < externalKeyword.offset) {
7620 _reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeywo rd, []); 7610 _reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeywo rd);
7621 } 7611 }
7622 return constKeyword; 7612 return constKeyword;
7623 } 7613 }
7624 7614
7625 /** 7615 /**
7626 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract' 7616 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract'
7627 * keyword if there is one. 7617 * keyword if there is one.
7628 * 7618 *
7629 * @param modifiers the modifiers being validated 7619 * @param modifiers the modifiers being validated
7630 */ 7620 */
7631 void _validateModifiersForEnum(Modifiers modifiers) { 7621 void _validateModifiersForEnum(Modifiers modifiers) {
7632 _validateModifiersForTopLevelDeclaration(modifiers); 7622 _validateModifiersForTopLevelDeclaration(modifiers);
7633 if (modifiers.abstractKeyword != null) { 7623 if (modifiers.abstractKeyword != null) {
7634 _reportErrorForToken(ParserErrorCode.ABSTRACT_ENUM, modifiers.abstractKeyw ord, []); 7624 _reportErrorForToken(ParserErrorCode.ABSTRACT_ENUM, modifiers.abstractKeyw ord);
7635 } 7625 }
7636 if (modifiers.constKeyword != null) { 7626 if (modifiers.constKeyword != null) {
7637 _reportErrorForToken(ParserErrorCode.CONST_ENUM, modifiers.constKeyword, [ ]); 7627 _reportErrorForToken(ParserErrorCode.CONST_ENUM, modifiers.constKeyword);
7638 } 7628 }
7639 if (modifiers.externalKeyword != null) { 7629 if (modifiers.externalKeyword != null) {
7640 _reportErrorForToken(ParserErrorCode.EXTERNAL_ENUM, modifiers.externalKeyw ord, []); 7630 _reportErrorForToken(ParserErrorCode.EXTERNAL_ENUM, modifiers.externalKeyw ord);
7641 } 7631 }
7642 if (modifiers.finalKeyword != null) { 7632 if (modifiers.finalKeyword != null) {
7643 _reportErrorForToken(ParserErrorCode.FINAL_ENUM, modifiers.finalKeyword, [ ]); 7633 _reportErrorForToken(ParserErrorCode.FINAL_ENUM, modifiers.finalKeyword);
7644 } 7634 }
7645 if (modifiers.varKeyword != null) { 7635 if (modifiers.varKeyword != null) {
7646 _reportErrorForToken(ParserErrorCode.VAR_ENUM, modifiers.varKeyword, []); 7636 _reportErrorForToken(ParserErrorCode.VAR_ENUM, modifiers.varKeyword);
7647 } 7637 }
7648 } 7638 }
7649 7639
7650 /** 7640 /**
7651 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final', 7641 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final',
7652 * 'const' or 'var' keyword if there is one. 7642 * 'const' or 'var' keyword if there is one.
7653 * 7643 *
7654 * @param modifiers the modifiers being validated 7644 * @param modifiers the modifiers being validated
7655 * @return the 'final', 'const' or 'var' keyword associated with the field 7645 * @return the 'final', 'const' or 'var' keyword associated with the field
7656 */ 7646 */
7657 Token _validateModifiersForField(Modifiers modifiers) { 7647 Token _validateModifiersForField(Modifiers modifiers) {
7658 if (modifiers.abstractKeyword != null) { 7648 if (modifiers.abstractKeyword != null) {
7659 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7649 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER);
7660 } 7650 }
7661 if (modifiers.externalKeyword != null) { 7651 if (modifiers.externalKeyword != null) {
7662 _reportErrorForToken(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKey word, []); 7652 _reportErrorForToken(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKey word);
7663 } 7653 }
7664 if (modifiers.factoryKeyword != null) { 7654 if (modifiers.factoryKeyword != null) {
7665 _reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fa ctoryKeyword, []); 7655 _reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fa ctoryKeyword);
7666 } 7656 }
7667 Token staticKeyword = modifiers.staticKeyword; 7657 Token staticKeyword = modifiers.staticKeyword;
7668 Token constKeyword = modifiers.constKeyword; 7658 Token constKeyword = modifiers.constKeyword;
7669 Token finalKeyword = modifiers.finalKeyword; 7659 Token finalKeyword = modifiers.finalKeyword;
7670 Token varKeyword = modifiers.varKeyword; 7660 Token varKeyword = modifiers.varKeyword;
7671 if (constKeyword != null) { 7661 if (constKeyword != null) {
7672 if (finalKeyword != null) { 7662 if (finalKeyword != null) {
7673 _reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []); 7663 _reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword);
7674 } 7664 }
7675 if (varKeyword != null) { 7665 if (varKeyword != null) {
7676 _reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword, []); 7666 _reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword);
7677 } 7667 }
7678 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) { 7668 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) {
7679 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword, []); 7669 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword);
7680 } 7670 }
7681 } else if (finalKeyword != null) { 7671 } else if (finalKeyword != null) {
7682 if (varKeyword != null) { 7672 if (varKeyword != null) {
7683 _reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword, []); 7673 _reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword);
7684 } 7674 }
7685 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) { 7675 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) {
7686 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword, []); 7676 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword);
7687 } 7677 }
7688 } else if (varKeyword != null && staticKeyword != null && varKeyword.offset < staticKeyword.offset) { 7678 } else if (varKeyword != null && staticKeyword != null && varKeyword.offset < staticKeyword.offset) {
7689 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword, []); 7679 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword);
7690 } 7680 }
7691 return _lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 7681 return _lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
7692 } 7682 }
7693 7683
7694 /** 7684 /**
7695 * Validate that the given set of modifiers is appropriate for a local functio n. 7685 * Validate that the given set of modifiers is appropriate for a local functio n.
7696 * 7686 *
7697 * @param modifiers the modifiers being validated 7687 * @param modifiers the modifiers being validated
7698 */ 7688 */
7699 void _validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) { 7689 void _validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) {
7700 if (modifiers.abstractKeyword != null || modifiers.constKeyword != null || m odifiers.externalKeyword != null || modifiers.factoryKeyword != null || modifier s.finalKeyword != null || modifiers.staticKeyword != null || modifiers.varKeywor d != null) { 7690 if (modifiers.abstractKeyword != null || modifiers.constKeyword != null || m odifiers.externalKeyword != null || modifiers.factoryKeyword != null || modifier s.finalKeyword != null || modifiers.staticKeyword != null || modifiers.varKeywor d != null) {
7701 _reportErrorForCurrentToken(ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MOD IFIER, []); 7691 _reportErrorForCurrentToken(ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MOD IFIER);
7702 } 7692 }
7703 } 7693 }
7704 7694
7705 /** 7695 /**
7706 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method. 7696 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method.
7707 * 7697 *
7708 * @param modifiers the modifiers being validated 7698 * @param modifiers the modifiers being validated
7709 */ 7699 */
7710 void _validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) { 7700 void _validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) {
7711 if (modifiers.abstractKeyword != null) { 7701 if (modifiers.abstractKeyword != null) {
7712 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7702 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER);
7713 } 7703 }
7714 if (modifiers.constKeyword != null) { 7704 if (modifiers.constKeyword != null) {
7715 _reportErrorForToken(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); 7705 _reportErrorForToken(ParserErrorCode.CONST_METHOD, modifiers.constKeyword) ;
7716 } 7706 }
7717 if (modifiers.factoryKeyword != null) { 7707 if (modifiers.factoryKeyword != null) {
7718 _reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fa ctoryKeyword, []); 7708 _reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fa ctoryKeyword);
7719 } 7709 }
7720 if (modifiers.finalKeyword != null) { 7710 if (modifiers.finalKeyword != null) {
7721 _reportErrorForToken(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); 7711 _reportErrorForToken(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword) ;
7722 } 7712 }
7723 if (modifiers.varKeyword != null) { 7713 if (modifiers.varKeyword != null) {
7724 _reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword , []); 7714 _reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword );
7725 } 7715 }
7726 Token externalKeyword = modifiers.externalKeyword; 7716 Token externalKeyword = modifiers.externalKeyword;
7727 Token staticKeyword = modifiers.staticKeyword; 7717 Token staticKeyword = modifiers.staticKeyword;
7728 if (externalKeyword != null && staticKeyword != null && staticKeyword.offset < externalKeyword.offset) { 7718 if (externalKeyword != null && staticKeyword != null && staticKeyword.offset < externalKeyword.offset) {
7729 _reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeywor d, []); 7719 _reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeywor d);
7730 } 7720 }
7731 } 7721 }
7732 7722
7733 /** 7723 /**
7734 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method. 7724 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method.
7735 * 7725 *
7736 * @param modifiers the modifiers being validated 7726 * @param modifiers the modifiers being validated
7737 */ 7727 */
7738 void _validateModifiersForOperator(Modifiers modifiers) { 7728 void _validateModifiersForOperator(Modifiers modifiers) {
7739 if (modifiers.abstractKeyword != null) { 7729 if (modifiers.abstractKeyword != null) {
7740 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7730 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_CLASS_MEMBER);
7741 } 7731 }
7742 if (modifiers.constKeyword != null) { 7732 if (modifiers.constKeyword != null) {
7743 _reportErrorForToken(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); 7733 _reportErrorForToken(ParserErrorCode.CONST_METHOD, modifiers.constKeyword) ;
7744 } 7734 }
7745 if (modifiers.factoryKeyword != null) { 7735 if (modifiers.factoryKeyword != null) {
7746 _reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fa ctoryKeyword, []); 7736 _reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.fa ctoryKeyword);
7747 } 7737 }
7748 if (modifiers.finalKeyword != null) { 7738 if (modifiers.finalKeyword != null) {
7749 _reportErrorForToken(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); 7739 _reportErrorForToken(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword) ;
7750 } 7740 }
7751 if (modifiers.staticKeyword != null) { 7741 if (modifiers.staticKeyword != null) {
7752 _reportErrorForToken(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyw ord, []); 7742 _reportErrorForToken(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyw ord);
7753 } 7743 }
7754 if (modifiers.varKeyword != null) { 7744 if (modifiers.varKeyword != null) {
7755 _reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword , []); 7745 _reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword );
7756 } 7746 }
7757 } 7747 }
7758 7748
7759 /** 7749 /**
7760 * Validate that the given set of modifiers is appropriate for a top-level dec laration. 7750 * Validate that the given set of modifiers is appropriate for a top-level dec laration.
7761 * 7751 *
7762 * @param modifiers the modifiers being validated 7752 * @param modifiers the modifiers being validated
7763 */ 7753 */
7764 void _validateModifiersForTopLevelDeclaration(Modifiers modifiers) { 7754 void _validateModifiersForTopLevelDeclaration(Modifiers modifiers) {
7765 if (modifiers.factoryKeyword != null) { 7755 if (modifiers.factoryKeyword != null) {
7766 _reportErrorForToken(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifi ers.factoryKeyword, []); 7756 _reportErrorForToken(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifi ers.factoryKeyword);
7767 } 7757 }
7768 if (modifiers.staticKeyword != null) { 7758 if (modifiers.staticKeyword != null) {
7769 _reportErrorForToken(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifie rs.staticKeyword, []); 7759 _reportErrorForToken(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifie rs.staticKeyword);
7770 } 7760 }
7771 } 7761 }
7772 7762
7773 /** 7763 /**
7774 * Validate that the given set of modifiers is appropriate for a top-level fun ction. 7764 * Validate that the given set of modifiers is appropriate for a top-level fun ction.
7775 * 7765 *
7776 * @param modifiers the modifiers being validated 7766 * @param modifiers the modifiers being validated
7777 */ 7767 */
7778 void _validateModifiersForTopLevelFunction(Modifiers modifiers) { 7768 void _validateModifiersForTopLevelFunction(Modifiers modifiers) {
7779 _validateModifiersForTopLevelDeclaration(modifiers); 7769 _validateModifiersForTopLevelDeclaration(modifiers);
7780 if (modifiers.abstractKeyword != null) { 7770 if (modifiers.abstractKeyword != null) {
7781 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, [ ]); 7771 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION);
7782 } 7772 }
7783 if (modifiers.constKeyword != null) { 7773 if (modifiers.constKeyword != null) {
7784 _reportErrorForToken(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); 7774 _reportErrorForToken(ParserErrorCode.CONST_CLASS, modifiers.constKeyword);
7785 } 7775 }
7786 if (modifiers.finalKeyword != null) { 7776 if (modifiers.finalKeyword != null) {
7787 _reportErrorForToken(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); 7777 _reportErrorForToken(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword);
7788 } 7778 }
7789 if (modifiers.varKeyword != null) { 7779 if (modifiers.varKeyword != null) {
7790 _reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword , []); 7780 _reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword );
7791 } 7781 }
7792 } 7782 }
7793 7783
7794 /** 7784 /**
7795 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final', 7785 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final',
7796 * 'const' or 'var' keyword if there is one. 7786 * 'const' or 'var' keyword if there is one.
7797 * 7787 *
7798 * @param modifiers the modifiers being validated 7788 * @param modifiers the modifiers being validated
7799 * @return the 'final', 'const' or 'var' keyword associated with the field 7789 * @return the 'final', 'const' or 'var' keyword associated with the field
7800 */ 7790 */
7801 Token _validateModifiersForTopLevelVariable(Modifiers modifiers) { 7791 Token _validateModifiersForTopLevelVariable(Modifiers modifiers) {
7802 _validateModifiersForTopLevelDeclaration(modifiers); 7792 _validateModifiersForTopLevelDeclaration(modifiers);
7803 if (modifiers.abstractKeyword != null) { 7793 if (modifiers.abstractKeyword != null) {
7804 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, [ ]); 7794 _reportErrorForCurrentToken(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE);
7805 } 7795 }
7806 if (modifiers.externalKeyword != null) { 7796 if (modifiers.externalKeyword != null) {
7807 _reportErrorForToken(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKey word, []); 7797 _reportErrorForToken(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKey word);
7808 } 7798 }
7809 Token constKeyword = modifiers.constKeyword; 7799 Token constKeyword = modifiers.constKeyword;
7810 Token finalKeyword = modifiers.finalKeyword; 7800 Token finalKeyword = modifiers.finalKeyword;
7811 Token varKeyword = modifiers.varKeyword; 7801 Token varKeyword = modifiers.varKeyword;
7812 if (constKeyword != null) { 7802 if (constKeyword != null) {
7813 if (finalKeyword != null) { 7803 if (finalKeyword != null) {
7814 _reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []); 7804 _reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword);
7815 } 7805 }
7816 if (varKeyword != null) { 7806 if (varKeyword != null) {
7817 _reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword, []); 7807 _reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword);
7818 } 7808 }
7819 } else if (finalKeyword != null) { 7809 } else if (finalKeyword != null) {
7820 if (varKeyword != null) { 7810 if (varKeyword != null) {
7821 _reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword, []); 7811 _reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword);
7822 } 7812 }
7823 } 7813 }
7824 return _lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 7814 return _lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
7825 } 7815 }
7826 7816
7827 /** 7817 /**
7828 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract' 7818 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract'
7829 * keyword if there is one. 7819 * keyword if there is one.
7830 * 7820 *
7831 * @param modifiers the modifiers being validated 7821 * @param modifiers the modifiers being validated
7832 */ 7822 */
7833 void _validateModifiersForTypedef(Modifiers modifiers) { 7823 void _validateModifiersForTypedef(Modifiers modifiers) {
7834 _validateModifiersForTopLevelDeclaration(modifiers); 7824 _validateModifiersForTopLevelDeclaration(modifiers);
7835 if (modifiers.abstractKeyword != null) { 7825 if (modifiers.abstractKeyword != null) {
7836 _reportErrorForToken(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractK eyword, []); 7826 _reportErrorForToken(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractK eyword);
7837 } 7827 }
7838 if (modifiers.constKeyword != null) { 7828 if (modifiers.constKeyword != null) {
7839 _reportErrorForToken(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword , []); 7829 _reportErrorForToken(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword );
7840 } 7830 }
7841 if (modifiers.externalKeyword != null) { 7831 if (modifiers.externalKeyword != null) {
7842 _reportErrorForToken(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalK eyword, []); 7832 _reportErrorForToken(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalK eyword);
7843 } 7833 }
7844 if (modifiers.finalKeyword != null) { 7834 if (modifiers.finalKeyword != null) {
7845 _reportErrorForToken(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword , []); 7835 _reportErrorForToken(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword );
7846 } 7836 }
7847 if (modifiers.varKeyword != null) { 7837 if (modifiers.varKeyword != null) {
7848 _reportErrorForToken(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, [] ); 7838 _reportErrorForToken(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword);
7849 } 7839 }
7850 } 7840 }
7851 } 7841 }
7852 7842
7853 /** 7843 /**
7854 * The enumeration `ParserErrorCode` defines the error codes used for errors 7844 * The enumeration `ParserErrorCode` defines the error codes used for errors
7855 * detected by the parser. The convention for this class is for the name of the 7845 * detected by the parser. The convention for this class is for the name of the
7856 * error code to indicate the problem that caused the error to be generated and 7846 * error code to indicate the problem that caused the error to be generated and
7857 * for the error message to explain what is wrong and, when appropriate, how the 7847 * for the error message to explain what is wrong and, when appropriate, how the
7858 * problem can be corrected. 7848 * problem can be corrected.
(...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after
9806 return trampoline(target, arguments[0], arguments[1]); 9796 return trampoline(target, arguments[0], arguments[1]);
9807 case 3: 9797 case 3:
9808 return trampoline(target, arguments[0], arguments[1], arguments[2]); 9798 return trampoline(target, arguments[0], arguments[1], arguments[2]);
9809 case 4: 9799 case 4:
9810 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]); 9800 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]);
9811 default: 9801 default:
9812 throw new IllegalArgumentException("Not implemented for > 4 arguments"); 9802 throw new IllegalArgumentException("Not implemented for > 4 arguments");
9813 } 9803 }
9814 } 9804 }
9815 } 9805 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/java_core.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698