From a670d7d2b0ddfdaf866b6d7fa071260f04494279 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 22 Apr 2013 17:23:54 -0500 Subject: [PATCH] Support Java 7 "try with resources" and "multi-catch" --- tool/test/org/antlr/v4/test/Java-LR.g4 | 35 +++++++++++++++++++------- tool/test/org/antlr/v4/test/Java.g4 | 33 ++++++++++++++++++------ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/tool/test/org/antlr/v4/test/Java-LR.g4 b/tool/test/org/antlr/v4/test/Java-LR.g4 index 5d97bd432..a29027a49 100644 --- a/tool/test/org/antlr/v4/test/Java-LR.g4 +++ b/tool/test/org/antlr/v4/test/Java-LR.g4 @@ -628,11 +628,8 @@ statement | 'for' '(' forControl ')' statement | 'while' parExpression statement | 'do' statement 'while' parExpression ';' - | 'try' block - ( catches 'finally' block - | catches - | 'finally' block - ) + | 'try' block (catches finallyBlock? | finallyBlock) + | 'try' resourceSpecification block catches? finallyBlock? | 'switch' parExpression '{' switchBlockStatementGroups '}' | 'synchronized' parExpression block | 'return' expression? ';' @@ -643,15 +640,35 @@ statement | statementExpression ';' | Identifier ':' statement ; - + catches - : catchClause (catchClause)* + : catchClause+ ; - + catchClause - : 'catch' '(' formalParameter ')' block + : 'catch' '(' variableModifiers catchType Identifier ')' block ; +catchType + : qualifiedName ('|' qualifiedName)* + ; + +finallyBlock + : 'finally' block + ; + +resourceSpecification + : '(' resources ';'? ')' + ; + +resources + : resource (';' resource)* + ; + +resource + : variableModifiers classOrInterfaceType variableDeclaratorId '=' expression + ; + formalParameter : variableModifiers type variableDeclaratorId ; diff --git a/tool/test/org/antlr/v4/test/Java.g4 b/tool/test/org/antlr/v4/test/Java.g4 index ccf221cb1..22d326953 100644 --- a/tool/test/org/antlr/v4/test/Java.g4 +++ b/tool/test/org/antlr/v4/test/Java.g4 @@ -625,11 +625,8 @@ statement | 'for' '(' forControl ')' statement | 'while' parExpression statement | 'do' statement 'while' parExpression ';' - | 'try' block - ( catches 'finally' block - | catches - | 'finally' block - ) + | 'try' block (catches finallyBlock? | finallyBlock) + | 'try' resourceSpecification block catches? finallyBlock? | 'switch' parExpression '{' switchBlockStatementGroups '}' | 'synchronized' parExpression block | 'return' expression? ';' @@ -640,15 +637,35 @@ statement | statementExpression ';' | Identifier ':' statement ; - + catches - : catchClause (catchClause)* + : catchClause+ ; catchClause - : 'catch' '(' formalParameter ')' block + : 'catch' '(' variableModifiers catchType Identifier ')' block ; +catchType + : qualifiedName ('|' qualifiedName)* + ; + +finallyBlock + : 'finally' block + ; + +resourceSpecification + : '(' resources ';'? ')' + ; + +resources + : resource (';' resource)* + ; + +resource + : variableModifiers classOrInterfaceType variableDeclaratorId '=' expression + ; + formalParameter : variableModifiers type variableDeclaratorId ;