| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library fasta.parser.parser; | 5 library fasta.parser.parser; |
| 6 | 6 |
| 7 import '../scanner.dart' show ErrorToken; | 7 import '../scanner.dart' show ErrorToken; |
| 8 | 8 |
| 9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; | 9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; |
| 10 | 10 |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 Token covariantKeyword; | 535 Token covariantKeyword; |
| 536 if (identical(token.stringValue, 'covariant') && | 536 if (identical(token.stringValue, 'covariant') && |
| 537 (token.next.isIdentifier() || isModifier(token.next))) { | 537 (token.next.isIdentifier() || isModifier(token.next))) { |
| 538 covariantKeyword = token; | 538 covariantKeyword = token; |
| 539 token = token.next; | 539 token = token.next; |
| 540 } | 540 } |
| 541 token = parseModifiers(token); | 541 token = parseModifiers(token); |
| 542 bool isNamedParameter = kind == FormalParameterType.NAMED; | 542 bool isNamedParameter = kind == FormalParameterType.NAMED; |
| 543 | 543 |
| 544 Token thisKeyword = null; | 544 Token thisKeyword = null; |
| 545 Token nameToken; |
| 545 if (inFunctionType && isNamedParameter) { | 546 if (inFunctionType && isNamedParameter) { |
| 546 token = parseType(token); | 547 token = parseType(token); |
| 547 token = | 548 token = |
| 548 parseIdentifier(token, IdentifierContext.formalParameterDeclaration); | 549 parseIdentifier(token, IdentifierContext.formalParameterDeclaration); |
| 549 } else if (inFunctionType) { | 550 } else if (inFunctionType) { |
| 550 token = parseType(token); | 551 token = parseType(token); |
| 551 if (token.isIdentifier()) { | 552 if (token.isIdentifier()) { |
| 552 token = parseIdentifier( | 553 token = parseIdentifier( |
| 553 token, IdentifierContext.formalParameterDeclaration); | 554 token, IdentifierContext.formalParameterDeclaration); |
| 554 } else { | 555 } else { |
| 555 listener.handleNoName(token); | 556 listener.handleNoName(token); |
| 556 } | 557 } |
| 557 } else { | 558 } else { |
| 558 token = parseReturnTypeOpt(token); | 559 token = parseReturnTypeOpt(token); |
| 559 if (optional('this', token)) { | 560 if (optional('this', token)) { |
| 560 thisKeyword = token; | 561 thisKeyword = token; |
| 561 token = expect('.', token.next); | 562 token = expect('.', token.next); |
| 563 nameToken = token; |
| 562 token = parseIdentifier(token, IdentifierContext.fieldInitializer); | 564 token = parseIdentifier(token, IdentifierContext.fieldInitializer); |
| 563 } else { | 565 } else { |
| 566 nameToken = token; |
| 564 token = parseIdentifier( | 567 token = parseIdentifier( |
| 565 token, IdentifierContext.formalParameterDeclaration); | 568 token, IdentifierContext.formalParameterDeclaration); |
| 566 } | 569 } |
| 567 } | 570 } |
| 568 | 571 |
| 569 if (optional('(', token)) { | 572 if (optional('(', token)) { |
| 570 Token inlineFunctionTypeStart = token; | 573 Token inlineFunctionTypeStart = token; |
| 571 listener.beginFunctionTypedFormalParameter(token); | 574 listener.beginFunctionTypedFormalParameter(token); |
| 572 listener.handleNoTypeVariables(token); | 575 listener.handleNoTypeVariables(token); |
| 573 token = parseFormalParameters(token); | 576 token = parseFormalParameters(token); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 602 token = parseExpression(token.next); | 605 token = parseExpression(token.next); |
| 603 listener.handleValuedFormalParameter(equal, token); | 606 listener.handleValuedFormalParameter(equal, token); |
| 604 if (kind.isRequired) { | 607 if (kind.isRequired) { |
| 605 reportRecoverableError(equal, ErrorKind.RequiredParameterWithDefault); | 608 reportRecoverableError(equal, ErrorKind.RequiredParameterWithDefault); |
| 606 } else if (kind.isPositional && identical(':', value)) { | 609 } else if (kind.isPositional && identical(':', value)) { |
| 607 reportRecoverableError(equal, ErrorKind.PositionalParameterWithEquals); | 610 reportRecoverableError(equal, ErrorKind.PositionalParameterWithEquals); |
| 608 } | 611 } |
| 609 } else { | 612 } else { |
| 610 listener.handleFormalParameterWithoutValue(token); | 613 listener.handleFormalParameterWithoutValue(token); |
| 611 } | 614 } |
| 612 listener.endFormalParameter(covariantKeyword, thisKeyword, kind); | 615 listener.endFormalParameter(covariantKeyword, thisKeyword, nameToken, kind); |
| 613 return token; | 616 return token; |
| 614 } | 617 } |
| 615 | 618 |
| 616 Token parseOptionalFormalParameters(Token token, bool isNamed, | 619 Token parseOptionalFormalParameters(Token token, bool isNamed, |
| 617 {bool inFunctionType: false}) { | 620 {bool inFunctionType: false}) { |
| 618 Token begin = token; | 621 Token begin = token; |
| 619 listener.beginOptionalFormalParameters(begin); | 622 listener.beginOptionalFormalParameters(begin); |
| 620 assert((isNamed && optional('{', token)) || optional('[', token)); | 623 assert((isNamed && optional('{', token)) || optional('[', token)); |
| 621 int parameterCount = 0; | 624 int parameterCount = 0; |
| 622 do { | 625 do { |
| (...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 Token operator = token; | 1944 Token operator = token; |
| 1942 token = token.next; | 1945 token = token.next; |
| 1943 listener.handleOperatorName(operator, token); | 1946 listener.handleOperatorName(operator, token); |
| 1944 return token.next; | 1947 return token.next; |
| 1945 } else { | 1948 } else { |
| 1946 return parseIdentifier(token, IdentifierContext.operatorName); | 1949 return parseIdentifier(token, IdentifierContext.operatorName); |
| 1947 } | 1950 } |
| 1948 } | 1951 } |
| 1949 | 1952 |
| 1950 Token parseFunction(Token token, Token getOrSet) { | 1953 Token parseFunction(Token token, Token getOrSet) { |
| 1954 Token beginToken = token; |
| 1951 listener.beginFunction(token); | 1955 listener.beginFunction(token); |
| 1952 token = parseModifiers(token); | 1956 token = parseModifiers(token); |
| 1953 if (identical(getOrSet, token)) { | 1957 if (identical(getOrSet, token)) { |
| 1954 // get <name> => ... | 1958 // get <name> => ... |
| 1955 token = token.next; | 1959 token = token.next; |
| 1956 listener.handleNoType(token); | 1960 listener.handleNoType(token); |
| 1957 listener.beginFunctionName(token); | 1961 listener.beginFunctionName(token); |
| 1958 if (optional('operator', token)) { | 1962 if (optional('operator', token)) { |
| 1959 token = parseOperatorName(token); | 1963 token = parseOperatorName(token); |
| 1960 } else { | 1964 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1975 listener.beginFunctionName(token); | 1979 listener.beginFunctionName(token); |
| 1976 if (optional('operator', token)) { | 1980 if (optional('operator', token)) { |
| 1977 token = parseOperatorName(token); | 1981 token = parseOperatorName(token); |
| 1978 } else { | 1982 } else { |
| 1979 token = | 1983 token = |
| 1980 parseIdentifier(token, IdentifierContext.localFunctionDeclaration); | 1984 parseIdentifier(token, IdentifierContext.localFunctionDeclaration); |
| 1981 } | 1985 } |
| 1982 } | 1986 } |
| 1983 token = parseQualifiedRestOpt( | 1987 token = parseQualifiedRestOpt( |
| 1984 token, IdentifierContext.localFunctionDeclarationContinuation); | 1988 token, IdentifierContext.localFunctionDeclarationContinuation); |
| 1985 listener.endFunctionName(token); | 1989 listener.endFunctionName(beginToken, token); |
| 1986 if (getOrSet == null) { | 1990 if (getOrSet == null) { |
| 1987 token = parseTypeVariablesOpt(token); | 1991 token = parseTypeVariablesOpt(token); |
| 1988 } else { | 1992 } else { |
| 1989 listener.handleNoTypeVariables(token); | 1993 listener.handleNoTypeVariables(token); |
| 1990 } | 1994 } |
| 1991 token = parseFormalParametersOpt(token); | 1995 token = parseFormalParametersOpt(token); |
| 1992 token = parseInitializersOpt(token); | 1996 token = parseInitializersOpt(token); |
| 1993 AsyncModifier savedAsyncModifier = asyncState; | 1997 AsyncModifier savedAsyncModifier = asyncState; |
| 1994 token = parseAsyncModifier(token); | 1998 token = parseAsyncModifier(token); |
| 1995 token = parseFunctionBody(token, false, true); | 1999 token = parseFunctionBody(token, false, true); |
| 1996 asyncState = savedAsyncModifier; | 2000 asyncState = savedAsyncModifier; |
| 1997 listener.endFunction(getOrSet, token); | 2001 listener.endFunction(getOrSet, token); |
| 1998 return token.next; | 2002 return token.next; |
| 1999 } | 2003 } |
| 2000 | 2004 |
| 2001 Token parseUnnamedFunction(Token token) { | 2005 Token parseUnnamedFunction(Token token) { |
| 2006 Token beginToken = token; |
| 2002 listener.beginUnnamedFunction(token); | 2007 listener.beginUnnamedFunction(token); |
| 2003 token = parseFormalParameters(token); | 2008 token = parseFormalParameters(token); |
| 2004 AsyncModifier savedAsyncModifier = asyncState; | 2009 AsyncModifier savedAsyncModifier = asyncState; |
| 2005 token = parseAsyncModifier(token); | 2010 token = parseAsyncModifier(token); |
| 2006 bool isBlock = optional('{', token); | 2011 bool isBlock = optional('{', token); |
| 2007 token = parseFunctionBody(token, true, false); | 2012 token = parseFunctionBody(token, true, false); |
| 2008 asyncState = savedAsyncModifier; | 2013 asyncState = savedAsyncModifier; |
| 2009 listener.endUnnamedFunction(token); | 2014 listener.endUnnamedFunction(beginToken, token); |
| 2010 return isBlock ? token.next : token; | 2015 return isBlock ? token.next : token; |
| 2011 } | 2016 } |
| 2012 | 2017 |
| 2013 Token parseFunctionDeclaration(Token token) { | 2018 Token parseFunctionDeclaration(Token token) { |
| 2014 listener.beginFunctionDeclaration(token); | 2019 listener.beginFunctionDeclaration(token); |
| 2015 token = parseFunction(token, null); | 2020 token = parseFunction(token, null); |
| 2016 listener.endFunctionDeclaration(token); | 2021 listener.endFunctionDeclaration(token); |
| 2017 return token; | 2022 return token; |
| 2018 } | 2023 } |
| 2019 | 2024 |
| 2020 Token parseFunctionExpression(Token token) { | 2025 Token parseFunctionExpression(Token token) { |
| 2026 Token beginToken = token; |
| 2021 listener.beginFunction(token); | 2027 listener.beginFunction(token); |
| 2022 listener.handleModifiers(0); | 2028 listener.handleModifiers(0); |
| 2023 token = parseReturnTypeOpt(token); | 2029 token = parseReturnTypeOpt(token); |
| 2024 listener.beginFunctionName(token); | 2030 listener.beginFunctionName(token); |
| 2025 token = parseIdentifier(token, IdentifierContext.functionExpressionName); | 2031 token = parseIdentifier(token, IdentifierContext.functionExpressionName); |
| 2026 listener.endFunctionName(token); | 2032 listener.endFunctionName(beginToken, token); |
| 2027 token = parseTypeVariablesOpt(token); | 2033 token = parseTypeVariablesOpt(token); |
| 2028 token = parseFormalParameters(token); | 2034 token = parseFormalParameters(token); |
| 2029 listener.handleNoInitializers(); | 2035 listener.handleNoInitializers(); |
| 2030 AsyncModifier savedAsyncModifier = asyncState; | 2036 AsyncModifier savedAsyncModifier = asyncState; |
| 2031 token = parseAsyncModifier(token); | 2037 token = parseAsyncModifier(token); |
| 2032 bool isBlock = optional('{', token); | 2038 bool isBlock = optional('{', token); |
| 2033 token = parseFunctionBody(token, true, false); | 2039 token = parseFunctionBody(token, true, false); |
| 2034 asyncState = savedAsyncModifier; | 2040 asyncState = savedAsyncModifier; |
| 2035 listener.endFunction(null, token); | 2041 listener.endFunction(null, token); |
| 2036 return isBlock ? token.next : token; | 2042 return isBlock ? token.next : token; |
| (...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3696 break; | 3702 break; |
| 3697 } | 3703 } |
| 3698 if (isRecoverable) { | 3704 if (isRecoverable) { |
| 3699 listener.handleRecoverableError(token, kind, arguments); | 3705 listener.handleRecoverableError(token, kind, arguments); |
| 3700 return null; | 3706 return null; |
| 3701 } else { | 3707 } else { |
| 3702 return listener.handleUnrecoverableError(token, kind, arguments); | 3708 return listener.handleUnrecoverableError(token, kind, arguments); |
| 3703 } | 3709 } |
| 3704 } | 3710 } |
| 3705 } | 3711 } |
| OLD | NEW |