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

Side by Side Diff: compiler/java/com/google/dart/compiler/parser/DartParser.java

Issue 10854097: Fix for issue 3756 - support new catch syntax (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months 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
« no previous file with comments | « no previous file | tests/co19/co19-compiler.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.collect.ImmutableSet; 8 import com.google.common.collect.ImmutableSet;
9 import com.google.common.io.CharStreams; 9 import com.google.common.io.CharStreams;
10 import com.google.dart.compiler.DartCompilationError; 10 import com.google.dart.compiler.DartCompilationError;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 private static final String EQUALS_KEYWORD = "equals"; 141 private static final String EQUALS_KEYWORD = "equals";
142 //private static final String EXPORT_KEYWORD = "export"; 142 //private static final String EXPORT_KEYWORD = "export";
143 private static final String EXTERNAL_KEYWORD = "external"; 143 private static final String EXTERNAL_KEYWORD = "external";
144 private static final String FACTORY_KEYWORD = "factory"; 144 private static final String FACTORY_KEYWORD = "factory";
145 private static final String GETTER_KEYWORD = "get"; 145 private static final String GETTER_KEYWORD = "get";
146 //private static final String HIDE_KEYWORD = "hide"; 146 //private static final String HIDE_KEYWORD = "hide";
147 private static final String IMPLEMENTS_KEYWORD = "implements"; 147 private static final String IMPLEMENTS_KEYWORD = "implements";
148 private static final String INTERFACE_KEYWORD = "interface"; 148 private static final String INTERFACE_KEYWORD = "interface";
149 private static final String NATIVE_KEYWORD = "native"; 149 private static final String NATIVE_KEYWORD = "native";
150 private static final String NEGATE_KEYWORD = "negate"; 150 private static final String NEGATE_KEYWORD = "negate";
151 //private static final String ON_KEYWORD = "on"; 151 private static final String ON_KEYWORD = "on";
152 private static final String OPERATOR_KEYWORD = "operator"; 152 private static final String OPERATOR_KEYWORD = "operator";
153 private static final String PREFIX_KEYWORD = "prefix"; 153 private static final String PREFIX_KEYWORD = "prefix";
154 private static final String SETTER_KEYWORD = "set"; 154 private static final String SETTER_KEYWORD = "set";
155 //private static final String SHOW_KEYWORD = "show"; 155 //private static final String SHOW_KEYWORD = "show";
156 private static final String STATIC_KEYWORD = "static"; 156 private static final String STATIC_KEYWORD = "static";
157 private static final String TYPEDEF_KEYWORD = "typedef"; 157 private static final String TYPEDEF_KEYWORD = "typedef";
158 158
159 159
160 public static final String[] PSEUDO_KEYWORDS = { 160 public static final String[] PSEUDO_KEYWORDS = {
161 ABSTRACT_KEYWORD, 161 ABSTRACT_KEYWORD,
(...skipping 4235 matching lines...) Expand 10 before | Expand all | Expand 10 after
4397 * 4397 *
4398 * finallyPart 4398 * finallyPart
4399 * : FINALLY block 4399 * : FINALLY block
4400 * ; 4400 * ;
4401 * </pre> 4401 * </pre>
4402 */ 4402 */
4403 private DartTryStatement parseTryStatement() { 4403 private DartTryStatement parseTryStatement() {
4404 beginTryStatement(); 4404 beginTryStatement();
4405 // Try. 4405 // Try.
4406 expect(Token.TRY); 4406 expect(Token.TRY);
4407 // TODO(zundel): It would be nice here to setup 'CATCH' and 'FINALLY' as tok ens for recovery 4407 // TODO(zundel): It would be nice here to setup 'ON', 'CATCH' and 'FINALLY' as tokens for recovery
4408 DartBlock tryBlock = parseBlock(); 4408 DartBlock tryBlock = parseBlock();
4409 4409
4410 List<DartCatchBlock> catches = new ArrayList<DartCatchBlock>(); 4410 List<DartCatchBlock> catches = new ArrayList<DartCatchBlock>();
4411 while (/*peekPseudoKeyword(0, ON_KEYWORD) ||*/ match(Token.CATCH)) { 4411 while (peekPseudoKeyword(0, ON_KEYWORD) || match(Token.CATCH)) {
4412 // TODO(zundel): It would be nice here to setup 'FINALLY' as token for rec overy 4412 // TODO(zundel): It would be nice here to setup 'FINALLY' as token for rec overy
4413 // if (peekPseudoKeyword(0, ON_KEYWORD)) { 4413 if (peekPseudoKeyword(0, ON_KEYWORD)) {
4414 // beginCatchClause(); 4414 beginCatchClause();
4415 // next(); 4415 next();
4416 // DartTypeNode exceptionType = new DartTypeNode(parseQualified()); 4416 DartTypeNode exceptionType = new DartTypeNode(parseQualified());
4417 // DartParameter exception = null; 4417 DartParameter exception = null;
4418 // DartParameter stackTrace = null; 4418 DartParameter stackTrace = null;
4419 // if (optional(Token.CATCH)) { 4419 if (optional(Token.CATCH)) {
4420 // expect(Token.LPAREN); 4420 expect(Token.LPAREN);
4421 // beginCatchParameter(); 4421 beginCatchParameter();
4422 // DartIdentifier exceptionName = parseIdentifier(); 4422 DartIdentifier exceptionName = parseIdentifier();
4423 // exception = done(new DartParameter(exceptionName, exceptionType, nul l, null, Modifiers.NONE)); 4423 exception = done(new DartParameter(exceptionName, exceptionType, null, null, Modifiers.NONE));
4424 // if (optional(Token.COMMA)) { 4424 if (optional(Token.COMMA)) {
4425 // beginCatchParameter(); 4425 beginCatchParameter();
4426 // DartIdentifier stackName = parseIdentifier(); 4426 DartIdentifier stackName = parseIdentifier();
4427 // stackTrace = done(new DartParameter(stackName, null, null, null, M odifiers.NONE)); 4427 stackTrace = done(new DartParameter(stackName, null, null, null, Mod ifiers.NONE));
4428 // } 4428 }
4429 // expectCloseParen(); 4429 expectCloseParen();
4430 // } else { 4430 } else {
4431 // // Create a dummy identifier that the user cannot reliably reference . 4431 // Create a dummy identifier that the user cannot reliably reference.
4432 // DartIdentifier exceptionName = new DartIdentifier("e" + Long.toHexSt ring(System.currentTimeMillis())); 4432 DartIdentifier exceptionName = new DartIdentifier("e" + Long.toHexStri ng(System.currentTimeMillis()));
4433 // exception = new DartParameter(exceptionName, exceptionType, null, nu ll, Modifiers.NONE); 4433 exception = new DartParameter(exceptionName, exceptionType, null, null , Modifiers.NONE);
4434 // } 4434 }
4435 // DartBlock block = parseBlock(); 4435 DartBlock block = parseBlock();
4436 // catches.add(done(new DartCatchBlock(block, exception, stackTrace))); 4436 catches.add(done(new DartCatchBlock(block, exception, stackTrace)));
4437 // } else { 4437 } else {
4438 beginCatchClause(); 4438 beginCatchClause();
4439 next(); 4439 next();
4440 expect(Token.LPAREN); 4440 expect(Token.LPAREN);
4441 // if (match(Token.IDENTIFIER) && (peek(1) == Token.COMMA || peek(1) == T oken.RPAREN)) { 4441 DartParameter exception;
4442 // beginCatchParameter(); 4442 if (match(Token.IDENTIFIER) && (peek(1) == Token.COMMA || peek(1) == Tok en.RPAREN)) {
4443 // DartIdentifier exceptionName = parseIdentifier(); 4443 beginCatchParameter();
4444 // // Create a dummy type with the right semantics. 4444 DartIdentifier exceptionName = parseIdentifier();
4445 // DartTypeNode exceptionType = new DartTypeNode(new DartIdentifier("Ob ject")); 4445 exception = done(new DartParameter(exceptionName, null , null, null, M odifiers.NONE));
4446 // DartParameter exception = done(new DartParameter(exceptionName, exce ptionType, null, null, Modifiers.NONE)); 4446 } else {
4447 // DartParameter stackTrace = null; 4447 // Old-style parameter
4448 // if (optional(Token.COMMA)) { 4448 exception = parseCatchParameter();
4449 // beginCatchParameter(); 4449 }
4450 // DartIdentifier stackName = parseIdentifier(); 4450 DartParameter stackTrace = null;
4451 // stackTrace = done(new DartParameter(stackName, null, null, null, M odifiers.NONE)); 4451 if (optional(Token.COMMA)) {
4452 // } 4452 if (match(Token.IDENTIFIER) && peek(1) == Token.RPAREN) {
4453 // expectCloseParen(); 4453 beginCatchParameter();
4454 // DartBlock block = parseBlock(); 4454 DartIdentifier stackName = parseIdentifier();
4455 // catches.add(done(new DartCatchBlock(block, exception, stackTrace))); 4455 stackTrace = done(new DartParameter(stackName, null, null, null, Mod ifiers.NONE));
4456 // } else { 4456 } else {
4457 DartParameter exception = parseCatchParameter(); 4457 // Old-style parameter
4458 DartParameter stackTrace = null;
4459 if (optional(Token.COMMA)) {
4460 stackTrace = parseCatchParameter(); 4458 stackTrace = parseCatchParameter();
4461 } 4459 }
4462 expectCloseParen();
4463 DartBlock block = parseBlock();
4464 catches.add(done(new DartCatchBlock(block, exception, stackTrace)));
4465 } 4460 }
4466 // } 4461 expectCloseParen();
4467 // } 4462 DartBlock block = parseBlock();
4463 catches.add(done(new DartCatchBlock(block, exception, stackTrace)));
4464 }
4465 }
4468 4466
4469 // Finally. 4467 // Finally.
4470 DartBlock finallyBlock = null; 4468 DartBlock finallyBlock = null;
4471 if (optional(Token.FINALLY)) { 4469 if (optional(Token.FINALLY)) {
4472 finallyBlock = parseBlock(); 4470 finallyBlock = parseBlock();
4473 } 4471 }
4474 4472
4475 if ( catches.size() == 0 && finallyBlock == null) { 4473 if ( catches.size() == 0 && finallyBlock == null) {
4476 reportError(new DartCompilationError(tryBlock.getSourceInfo().getSource(), new Location(position()), 4474 reportError(new DartCompilationError(tryBlock.getSourceInfo().getSource(), new Location(position()),
4477 ParserErrorCode.CATCH_OR_FINALLY_EXPECTED)); 4475 ParserErrorCode.CATCH_OR_FINALLY_EXPECTED));
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
4744 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen ts) { 4742 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen ts) {
4745 if (node != null) { 4743 if (node != null) {
4746 reportError(new DartCompilationError(node, errorCode, arguments)); 4744 reportError(new DartCompilationError(node, errorCode, arguments));
4747 } 4745 }
4748 } 4746 }
4749 4747
4750 private boolean currentlyParsingToplevel() { 4748 private boolean currentlyParsingToplevel() {
4751 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); 4749 return !(isParsingInterface || isTopLevelAbstract || isParsingClass);
4752 } 4750 }
4753 } 4751 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698