Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions src/main/java/org/rumbledb/compiler/TranslationVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2734,14 +2734,14 @@ public Node visitTryCatchExpr(JsoniqParser.TryCatchExprContext ctx) {
Expression catchExpression = catchCtx.catch_expression == null
? new CommaExpression(createMetadataFromContext(catchCtx))
: (Expression) this.visitExpr(catchCtx.catch_expression);
for (JsoniqParser.EqNameContext eqNameCtx : catchCtx.errors) {
CatchPattern pattern = CatchPattern.exact(parseEqName(eqNameCtx, false, false, false, false));
if (!catchExpressions.containsKey(pattern)) {
catchExpressions.put(pattern, catchExpression);
}
}
for (JsoniqParser.WildcardContext wildcardCtx : catchCtx.jokers) {
CatchPattern pattern = this.parseWildcardPattern(wildcardCtx);

for (var catchTarget : catchCtx.nameTest()) {
var wildcard = catchTarget.wildcard();
var errorcode = catchTarget.eqName();

CatchPattern pattern = wildcard != null
? this.parseWildcardPattern(wildcard)
: CatchPattern.exact(parseEqName(errorcode, false, false, false, false));
if (!catchExpressions.containsKey(pattern)) {
catchExpressions.put(pattern, catchExpression);
}
Expand Down Expand Up @@ -3061,14 +3061,13 @@ public Node visitTryCatchStatement(JsoniqParser.TryCatchStatementContext ctx) {
Map<CatchPattern, BlockStatement> catchBlockStatements = new LinkedHashMap<>();
for (JsoniqParser.CatchCaseStatementContext catchCtx : ctx.catches) {
BlockStatement catchBlockStatement = (BlockStatement) this.visitBlockStatement(catchCtx.catch_block);
for (JsoniqParser.EqNameContext eqNameCtx : catchCtx.errors) {
CatchPattern pattern = CatchPattern.exact(parseEqName(eqNameCtx, false, false, false, false));
if (!catchBlockStatements.containsKey(pattern)) {
catchBlockStatements.put(pattern, catchBlockStatement);
}
}
for (JsoniqParser.WildcardContext wildcardCtx : catchCtx.jokers) {
CatchPattern pattern = this.parseWildcardPattern(wildcardCtx);
for (var catchTarget : catchCtx.nameTest()) {
var wildcard = catchTarget.wildcard();
var errorcode = catchTarget.eqName();

CatchPattern pattern = wildcard != null
? this.parseWildcardPattern(wildcard)
: CatchPattern.exact(parseEqName(errorcode, false, false, false, false));
if (!catchBlockStatements.containsKey(pattern)) {
catchBlockStatements.put(pattern, catchBlockStatement);
}
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/org/rumbledb/compiler/XQueryTranslationVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2510,14 +2510,13 @@ public Node visitTryCatchExpr(XQueryParser.TryCatchExprContext ctx) {
Expression catchExpression = catchCtx.catch_expression == null
? new CommaExpression(createMetadataFromContext(catchCtx))
: (Expression) this.visitExpr(catchCtx.catch_expression);
for (XQueryParser.EqNameContext eqNameCtx : catchCtx.errors) {
CatchPattern pattern = CatchPattern.exact(parseEqName(eqNameCtx, false, false, false, false));
if (!catchExpressions.containsKey(pattern)) {
catchExpressions.put(pattern, catchExpression);
}
}
for (XQueryParser.WildcardContext wildcardCtx : catchCtx.jokers) {
CatchPattern pattern = this.parseWildcardPattern(wildcardCtx);
for (var catchTarget : catchCtx.nameTest()) {
var wildcard = catchTarget.wildcard();
var errorcode = catchTarget.eqName();

CatchPattern pattern = wildcard != null
? this.parseWildcardPattern(wildcard)
: CatchPattern.exact(parseEqName(errorcode, false, false, false, false));
if (!catchExpressions.containsKey(pattern)) {
catchExpressions.put(pattern, catchExpression);
}
Expand Down Expand Up @@ -2837,14 +2836,13 @@ public Node visitTryCatchStatement(XQueryParser.TryCatchStatementContext ctx) {
Map<CatchPattern, BlockStatement> catchBlockStatements = new LinkedHashMap<>();
for (XQueryParser.CatchCaseStatementContext catchCtx : ctx.catches) {
BlockStatement catchBlockStatement = (BlockStatement) this.visitBlockStatement(catchCtx.catch_block);
for (XQueryParser.EqNameContext eqNameCtx : catchCtx.errors) {
CatchPattern pattern = CatchPattern.exact(parseEqName(eqNameCtx, false, false, false, false));
if (!catchBlockStatements.containsKey(pattern)) {
catchBlockStatements.put(pattern, catchBlockStatement);
}
}
for (XQueryParser.WildcardContext wildcardCtx : catchCtx.jokers) {
CatchPattern pattern = this.parseWildcardPattern(wildcardCtx);
for (var catchTarget : catchCtx.nameTest()) {
var wildcard = catchTarget.wildcard();
var errorcode = catchTarget.eqName();

CatchPattern pattern = wildcard != null
? this.parseWildcardPattern(wildcard)
: CatchPattern.exact(parseEqName(errorcode, false, false, false, false));
if (!catchBlockStatements.containsKey(pattern)) {
catchBlockStatements.put(pattern, catchBlockStatement);
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/rumbledb/parser/jsoniq/JsoniqParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,7 @@ tryCatchExpr
;

catchClause
: KW_CATCH
// replaced with the catchErrorList production to match the JSONiq grammar
((jokers += wildcard | errors += eqName) (VBAR (jokers += wildcard | errors += eqName))* | (LPAREN catch_var = varBinding RPAREN))
: KW_CATCH nameTest (VBAR nameTest)*
// replaced with the enclosedExpression production to match the JSONiq grammar
LBRACE catch_expression = expr? RBRACE
;
Expand Down Expand Up @@ -1413,7 +1411,7 @@ tryCatchStatement


catchCaseStatement
: KW_CATCH (jokers += wildcard | errors += eqName) (VBAR (jokers += wildcard | errors += eqName))* catch_block = blockStatement
: KW_CATCH nameTest (VBAR nameTest)* catch_block = blockStatement
;
// The optional variable is local to the default branch.

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/rumbledb/parser/xquery/XQueryParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,7 @@ tryCatchExpr
;

catchClause
: KW_CATCH
// replaced with the catchErrorList production to match the JSONiq grammar
((jokers += wildcard | errors += eqName) (VBAR (jokers += wildcard | errors += eqName))* | (LPAREN catch_var = varBinding RPAREN))
: KW_CATCH nameTest (VBAR nameTest)*
// replaced with the enclosedExpression production to match the JSONiq grammar
LBRACE catch_expression = expr? RBRACE
;
Expand Down Expand Up @@ -1383,7 +1381,7 @@ tryCatchStatement


catchCaseStatement
: KW_CATCH (jokers += wildcard | errors += eqName) (VBAR (jokers += wildcard | errors += eqName))* catch_block = blockStatement
: KW_CATCH nameTest (VBAR nameTest)* catch_block = blockStatement
;
// The optional variable is local to the default branch.

Expand Down
Loading