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

Unified Diff: compiler/java/com/google/dart/compiler/parser/DartParser.java

Issue 10536223: Fix for issue 3756 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/parser/DartParser.java
===================================================================
--- compiler/java/com/google/dart/compiler/parser/DartParser.java (revision 8906)
+++ compiler/java/com/google/dart/compiler/parser/DartParser.java (working copy)
@@ -141,6 +141,7 @@
private static final String INTERFACE_KEYWORD = "interface";
private static final String NATIVE_KEYWORD = "native";
private static final String NEGATE_KEYWORD = "negate";
+ private static final String ON_KEYWORD = "on";
private static final String OPERATOR_KEYWORD = "operator";
private static final String PREFIX_KEYWORD = "prefix";
private static final String SETTER_KEYWORD = "set";
@@ -4113,6 +4114,7 @@
}
/**
+ * Parse either the old try statement syntax:
* <pre>
* tryStatement
* : TRY block (catchPart+ finallyPart? | finallyPart)
@@ -4126,6 +4128,24 @@
* : FINALLY block
* ;
* </pre>
+ * or the new syntax:
+ * <pre>
+ * tryStatement
+ * : TRY block (onPart+ finallyPart? | finallyPart)
+ * ;
+ *
+ * onPart
+ * : catchPart block
+ * | ON qualified catchPart? block
+ *
+ * catchPart
+ * : CATCH '(' identifier (',' identifier)? ')'
+ * ;
+ *
+ * finallyPart
+ * : FINALLY block
+ * ;
+ * </pre>
*/
private DartTryStatement parseTryStatement() {
beginTryStatement();
@@ -4135,18 +4155,62 @@
DartBlock tryBlock = parseBlock();
List<DartCatchBlock> catches = new ArrayList<DartCatchBlock>();
- while (optional(Token.CATCH)) {
+ while (peekPseudoKeyword(0, ON_KEYWORD) || match(Token.CATCH)) {
// TODO(zundel): It would be nice here to setup 'FINALLY' as token for recovery
- beginCatchClause();
- expect(Token.LPAREN);
- DartParameter exception = parseCatchParameter();
- DartParameter stackTrace = null;
- if (optional(Token.COMMA)) {
- stackTrace = parseCatchParameter();
+ if (peekPseudoKeyword(0, ON_KEYWORD)) {
+ beginCatchClause();
+ next();
+ DartTypeNode exceptionType = new DartTypeNode(parseQualified());
+ DartParameter exception = null;
+ DartParameter stackTrace = null;
+ if (optional(Token.CATCH)) {
+ expect(Token.LPAREN);
+ beginCatchParameter();
+ DartIdentifier exceptionName = parseIdentifier();
+ exception = done(new DartParameter(exceptionName, exceptionType, null, null, Modifiers.NONE));
+ if (optional(Token.COMMA)) {
+ beginCatchParameter();
+ DartIdentifier stackName = parseIdentifier();
+ stackTrace = done(new DartParameter(stackName, null, null, null, Modifiers.NONE));
+ }
+ expectCloseParen();
+ } else {
+ // Create a dummy identifier that the user cannot reliably reference.
+ DartIdentifier exceptionName = new DartIdentifier("e" + Long.toHexString(System.currentTimeMillis()));
+ exception = new DartParameter(exceptionName, exceptionType, null, null, Modifiers.NONE);
+ }
+ DartBlock block = parseBlock();
+ catches.add(done(new DartCatchBlock(block, exception, stackTrace)));
+ } else {
+ beginCatchClause();
+ next();
+ expect(Token.LPAREN);
+ if (match(Token.IDENTIFIER) && (peek(1) == Token.COMMA || peek(1) == Token.RPAREN)) {
+ beginCatchParameter();
+ DartIdentifier exceptionName = parseIdentifier();
+ // Create a dummy type with the right semantics.
+ DartTypeNode exceptionType = new DartTypeNode(new DartIdentifier("Object"));
+ DartParameter exception = done(new DartParameter(exceptionName, exceptionType, null, null, Modifiers.NONE));
+ DartParameter stackTrace = null;
+ if (optional(Token.COMMA)) {
+ beginCatchParameter();
+ DartIdentifier stackName = parseIdentifier();
+ stackTrace = done(new DartParameter(stackName, null, null, null, Modifiers.NONE));
+ }
+ expectCloseParen();
+ DartBlock block = parseBlock();
+ catches.add(done(new DartCatchBlock(block, exception, stackTrace)));
+ } else {
+ DartParameter exception = parseCatchParameter();
+ DartParameter stackTrace = null;
+ if (optional(Token.COMMA)) {
+ stackTrace = parseCatchParameter();
+ }
+ expectCloseParen();
+ DartBlock block = parseBlock();
+ catches.add(done(new DartCatchBlock(block, exception, stackTrace)));
+ }
}
- expectCloseParen();
- DartBlock block = parseBlock();
- catches.add(done(new DartCatchBlock(block, exception, stackTrace)));
}
// Finally.
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698