| 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 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 } | 2034 } |
| 2035 } | 2035 } |
| 2036 return token; | 2036 return token; |
| 2037 } | 2037 } |
| 2038 | 2038 |
| 2039 Token parseFunctionBody(Token token, bool isExpression, bool allowAbstract) { | 2039 Token parseFunctionBody(Token token, bool isExpression, bool allowAbstract) { |
| 2040 if (optional(';', token)) { | 2040 if (optional(';', token)) { |
| 2041 if (!allowAbstract) { | 2041 if (!allowAbstract) { |
| 2042 reportRecoverableError(token, ErrorKind.ExpectedBody); | 2042 reportRecoverableError(token, ErrorKind.ExpectedBody); |
| 2043 } | 2043 } |
| 2044 listener.endEmptyFunctionBody(token); | 2044 listener.handleEmptyFunctionBody(token); |
| 2045 return token; | 2045 return token; |
| 2046 } else if (optional('=>', token)) { | 2046 } else if (optional('=>', token)) { |
| 2047 Token begin = token; | 2047 Token begin = token; |
| 2048 token = parseExpression(token.next); | 2048 token = parseExpression(token.next); |
| 2049 if (!isExpression) { | 2049 if (!isExpression) { |
| 2050 expectSemicolon(token); | 2050 expectSemicolon(token); |
| 2051 listener.endExpressionFunctionBody(begin, token); | 2051 listener.handleExpressionFunctionBody(begin, token); |
| 2052 } else { | 2052 } else { |
| 2053 listener.endExpressionFunctionBody(begin, null); | 2053 listener.handleExpressionFunctionBody(begin, null); |
| 2054 } | 2054 } |
| 2055 return token; | 2055 return token; |
| 2056 } else if (optional('=', token)) { | 2056 } else if (optional('=', token)) { |
| 2057 Token begin = token; | 2057 Token begin = token; |
| 2058 // Recover from a bad factory method. | 2058 // Recover from a bad factory method. |
| 2059 reportRecoverableError(token, ErrorKind.ExpectedBody); | 2059 reportRecoverableError(token, ErrorKind.ExpectedBody); |
| 2060 token = parseExpression(token.next); | 2060 token = parseExpression(token.next); |
| 2061 if (!isExpression) { | 2061 if (!isExpression) { |
| 2062 expectSemicolon(token); | 2062 expectSemicolon(token); |
| 2063 listener.endExpressionFunctionBody(begin, token); | 2063 listener.handleExpressionFunctionBody(begin, token); |
| 2064 } else { | 2064 } else { |
| 2065 listener.endExpressionFunctionBody(begin, null); | 2065 listener.handleExpressionFunctionBody(begin, null); |
| 2066 } | 2066 } |
| 2067 return token; | 2067 return token; |
| 2068 } | 2068 } |
| 2069 Token begin = token; | 2069 Token begin = token; |
| 2070 int statementCount = 0; | 2070 int statementCount = 0; |
| 2071 if (!optional('{', token)) { | 2071 if (!optional('{', token)) { |
| 2072 token = | 2072 token = |
| 2073 reportUnrecoverableError(token, ErrorKind.ExpectedFunctionBody)?.next; | 2073 reportUnrecoverableError(token, ErrorKind.ExpectedFunctionBody)?.next; |
| 2074 listener.handleInvalidFunctionBody(token); | 2074 listener.handleInvalidFunctionBody(token); |
| 2075 return token; | 2075 return token; |
| 2076 } | 2076 } |
| 2077 | 2077 |
| 2078 listener.beginFunctionBody(begin); | 2078 listener.beginBlockFunctionBody(begin); |
| 2079 token = token.next; | 2079 token = token.next; |
| 2080 while (notEofOrValue('}', token)) { | 2080 while (notEofOrValue('}', token)) { |
| 2081 token = parseStatement(token); | 2081 token = parseStatement(token); |
| 2082 ++statementCount; | 2082 ++statementCount; |
| 2083 } | 2083 } |
| 2084 listener.endFunctionBody(statementCount, begin, token); | 2084 listener.endBlockFunctionBody(statementCount, begin, token); |
| 2085 expect('}', token); | 2085 expect('}', token); |
| 2086 return token; | 2086 return token; |
| 2087 } | 2087 } |
| 2088 | 2088 |
| 2089 Token skipAsyncModifier(Token token) { | 2089 Token skipAsyncModifier(Token token) { |
| 2090 String value = token.stringValue; | 2090 String value = token.stringValue; |
| 2091 if (identical(value, 'async')) { | 2091 if (identical(value, 'async')) { |
| 2092 token = token.next; | 2092 token = token.next; |
| 2093 value = token.stringValue; | 2093 value = token.stringValue; |
| 2094 | 2094 |
| (...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3597 break; | 3597 break; |
| 3598 } | 3598 } |
| 3599 if (isRecoverable) { | 3599 if (isRecoverable) { |
| 3600 listener.handleRecoverableError(token, kind, arguments); | 3600 listener.handleRecoverableError(token, kind, arguments); |
| 3601 return null; | 3601 return null; |
| 3602 } else { | 3602 } else { |
| 3603 return listener.handleUnrecoverableError(token, kind, arguments); | 3603 return listener.handleUnrecoverableError(token, kind, arguments); |
| 3604 } | 3604 } |
| 3605 } | 3605 } |
| 3606 } | 3606 } |
| OLD | NEW |