| 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 package com.google.dart.compiler.parser; | 5 package com.google.dart.compiler.parser; |
| 6 | 6 |
| 7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
| 8 import com.google.common.io.CharStreams; | 8 import com.google.common.io.CharStreams; |
| 9 import com.google.dart.compiler.DartCompilationError; | 9 import com.google.dart.compiler.DartCompilationError; |
| 10 import com.google.dart.compiler.DartCompilerListener; | 10 import com.google.dart.compiler.DartCompilerListener; |
| (...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 * </pre> | 1780 * </pre> |
| 1781 * | 1781 * |
| 1782 * @return an expression matching the {@code expression} production above | 1782 * @return an expression matching the {@code expression} production above |
| 1783 */ | 1783 */ |
| 1784 @VisibleForTesting | 1784 @VisibleForTesting |
| 1785 public DartExpression parseExpression() { | 1785 public DartExpression parseExpression() { |
| 1786 beginExpression(); | 1786 beginExpression(); |
| 1787 if (looksLikeTopLevelKeyword() || peek(0).equals(Token.RBRACE)) { | 1787 if (looksLikeTopLevelKeyword() || peek(0).equals(Token.RBRACE)) { |
| 1788 // Allow recovery back to the top level. | 1788 // Allow recovery back to the top level. |
| 1789 reportErrorWithoutAdvancing(ParserErrorCode.UNEXPECTED_TOKEN); | 1789 reportErrorWithoutAdvancing(ParserErrorCode.UNEXPECTED_TOKEN); |
| 1790 return done(DartNullLiteral.get()); | 1790 return done(null); |
| 1791 } | 1791 } |
| 1792 DartExpression result = parseConditionalExpression(); | 1792 DartExpression result = parseConditionalExpression(); |
| 1793 Token token = peek(0); | 1793 Token token = peek(0); |
| 1794 if (token.isAssignmentOperator()) { | 1794 if (token.isAssignmentOperator()) { |
| 1795 ensureAssignable(result); | 1795 ensureAssignable(result); |
| 1796 consume(token); | 1796 consume(token); |
| 1797 result = done(new DartBinaryExpression(token, result, parseExpression())); | 1797 result = done(new DartBinaryExpression(token, result, parseExpression())); |
| 1798 } else { | 1798 } else { |
| 1799 done(null); | 1799 done(null); |
| 1800 } | 1800 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 DartIdentifier name = parseIdentifier(); | 1951 DartIdentifier name = parseIdentifier(); |
| 1952 expect(Token.COLON); | 1952 expect(Token.COLON); |
| 1953 expression = new DartNamedExpression(name, parseExpression()); | 1953 expression = new DartNamedExpression(name, parseExpression()); |
| 1954 namedArgumentParsed = true; | 1954 namedArgumentParsed = true; |
| 1955 } else { | 1955 } else { |
| 1956 expression = parseExpression(); | 1956 expression = parseExpression(); |
| 1957 if (namedArgumentParsed) { | 1957 if (namedArgumentParsed) { |
| 1958 reportError(expression, ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMEN
T); | 1958 reportError(expression, ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMEN
T); |
| 1959 } | 1959 } |
| 1960 } | 1960 } |
| 1961 arguments.add(done(expression)); | 1961 if (expression != null) { |
| 1962 arguments.add(done(expression)); |
| 1963 } |
| 1962 switch(peek(0)) { | 1964 switch(peek(0)) { |
| 1963 // Must keep in sync with @Terminals above | 1965 // Must keep in sync with @Terminals above |
| 1964 case COMMA: | 1966 case COMMA: |
| 1965 consume(Token.COMMA); | 1967 consume(Token.COMMA); |
| 1966 break; | 1968 break; |
| 1967 // Must keep in sync with @Terminals above | 1969 // Must keep in sync with @Terminals above |
| 1968 case RPAREN: | 1970 case RPAREN: |
| 1969 break; | 1971 break; |
| 1970 default: | 1972 default: |
| 1971 Token actual = peek(0); | 1973 Token actual = peek(0); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2239 // Parse the key. | 2241 // Parse the key. |
| 2240 DartExpression keyExpr = parseStringWithPasting(); | 2242 DartExpression keyExpr = parseStringWithPasting(); |
| 2241 if (keyExpr == null) { | 2243 if (keyExpr == null) { |
| 2242 return done(null); | 2244 return done(null); |
| 2243 } | 2245 } |
| 2244 // Parse the value. | 2246 // Parse the value. |
| 2245 DartExpression value; | 2247 DartExpression value; |
| 2246 if (expect(Token.COLON)) { | 2248 if (expect(Token.COLON)) { |
| 2247 value = parseExpression(); | 2249 value = parseExpression(); |
| 2248 } else { | 2250 } else { |
| 2249 value = doneWithoutConsuming(DartNullLiteral.get()); | 2251 value = doneWithoutConsuming(new DartSyntheticErrorExpression()); |
| 2250 } | 2252 } |
| 2251 return done(new DartMapLiteralEntry(keyExpr, value)); | 2253 return done(new DartMapLiteralEntry(keyExpr, value)); |
| 2252 } | 2254 } |
| 2253 private boolean looksLikeString() { | 2255 private boolean looksLikeString() { |
| 2254 switch(peek(0)) { | 2256 switch(peek(0)) { |
| 2255 case STRING: | 2257 case STRING: |
| 2256 case STRING_SEGMENT: | 2258 case STRING_SEGMENT: |
| 2257 case STRING_EMBED_EXP_START: | 2259 case STRING_EMBED_EXP_START: |
| 2258 return true; | 2260 return true; |
| 2259 } | 2261 } |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3083 return emptyBlock; | 3085 return emptyBlock; |
| 3084 } | 3086 } |
| 3085 } | 3087 } |
| 3086 } | 3088 } |
| 3087 // Return an empty block so we don't generate unparseable code. | 3089 // Return an empty block so we don't generate unparseable code. |
| 3088 return emptyBlock; | 3090 return emptyBlock; |
| 3089 } else { | 3091 } else { |
| 3090 beginFunctionStatementBody(); | 3092 beginFunctionStatementBody(); |
| 3091 if (optional(Token.ARROW)) { | 3093 if (optional(Token.ARROW)) { |
| 3092 DartExpression expr = parseExpression(); | 3094 DartExpression expr = parseExpression(); |
| 3095 if (expr == null) { |
| 3096 expr = new DartSyntheticErrorExpression(); |
| 3097 } |
| 3093 if (requireSemicolonForArrow) { | 3098 if (requireSemicolonForArrow) { |
| 3094 expect(Token.SEMICOLON); | 3099 expect(Token.SEMICOLON); |
| 3095 } | 3100 } |
| 3096 return done(makeReturnBlock(expr)); | 3101 return done(makeReturnBlock(expr)); |
| 3097 } else { | 3102 } else { |
| 3098 return done(parseBlock()); | 3103 return done(parseBlock()); |
| 3099 } | 3104 } |
| 3100 } | 3105 } |
| 3101 } | 3106 } |
| 3102 | 3107 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3431 beginExpressionStatement(); | 3436 beginExpressionStatement(); |
| 3432 if (peek(1) == Token.LPAREN && optionalPseudoKeyword(ASSERT_KEYWORD)) { | 3437 if (peek(1) == Token.LPAREN && optionalPseudoKeyword(ASSERT_KEYWORD)) { |
| 3433 consume(Token.LPAREN); | 3438 consume(Token.LPAREN); |
| 3434 DartExpression expression = parseConditionalExpression(); | 3439 DartExpression expression = parseConditionalExpression(); |
| 3435 expectCloseParen(); | 3440 expectCloseParen(); |
| 3436 expectStatmentTerminator(); | 3441 expectStatmentTerminator(); |
| 3437 return done(new DartAssertion(expression)); | 3442 return done(new DartAssertion(expression)); |
| 3438 } | 3443 } |
| 3439 DartExpression expression = parseExpression(); | 3444 DartExpression expression = parseExpression(); |
| 3440 expectStatmentTerminator(); | 3445 expectStatmentTerminator(); |
| 3446 |
| 3441 return done(new DartExprStmt(expression)); | 3447 return done(new DartExprStmt(expression)); |
| 3442 } | 3448 } |
| 3443 | 3449 |
| 3444 /** | 3450 /** |
| 3445 * Expect a close paren, reporting an error and consuming tokens until a | 3451 * Expect a close paren, reporting an error and consuming tokens until a |
| 3446 * plausible continuation is found if it isn't present. | 3452 * plausible continuation is found if it isn't present. |
| 3447 */ | 3453 */ |
| 3448 private void expectCloseParen() { | 3454 private void expectCloseParen() { |
| 3449 int parenCount = 1; | 3455 int parenCount = 1; |
| 3450 Token nextToken = peek(0); | 3456 Token nextToken = peek(0); |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4190 } | 4196 } |
| 4191 | 4197 |
| 4192 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen
ts) { | 4198 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen
ts) { |
| 4193 reportError(new DartCompilationError(node, errorCode, arguments)); | 4199 reportError(new DartCompilationError(node, errorCode, arguments)); |
| 4194 } | 4200 } |
| 4195 | 4201 |
| 4196 private boolean currentlyParsingToplevel() { | 4202 private boolean currentlyParsingToplevel() { |
| 4197 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); | 4203 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); |
| 4198 } | 4204 } |
| 4199 } | 4205 } |
| OLD | NEW |