Skip to content

Commit 7f17e44

Browse files
committed
[fix] EnclosedExpression in element constructor with location
- In XQuery.g: copy lexer info (location) of enclosed expression to compElementConstructorContent, if present. Add virtual parenthesized expression otherwise, evaluating to `element test { () }` - Set AST node of enclosed expression in computed element constructor in XQueryTree.g - Adapt jUnit-tests to: 1. Ensure enclosed expression location is reported. 2. Ensure arrays are allowed as computed element constructor content.
1 parent 5d7e0cb commit 7f17e44

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

exist-core/src/main/antlr/org/exist/xquery/parser/XQuery.g

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,9 @@ compElemConstructor throws XPathException
16731673
compElemConstructorContent throws XPathException
16741674
:
16751675
( LCURLY RCURLY ) => LCURLY! RCURLY!
1676-
| LCURLY^ (expr)? RCURLY!
1676+
{ #compElemConstructorContent= #(#[PARENTHESIZED, "Parenthesized"], null); }
1677+
| LCURLY! e:expr RCURLY!
1678+
{ #compElemConstructorContent.copyLexInfo(#e); }
16771679
;
16781680
16791681

exist-core/src/main/antlr/org/exist/xquery/parser/XQueryTree.g

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,8 +3157,11 @@ throws PermissionDeniedException, EXistException, XPathException
31573157
qnameExpr=expr [qnamePathExpr]
31583158
(
31593159
{ elementContent = new PathExpr(context); }
3160-
contentExpr=expr[elementContent]
3161-
{ construct.addPathIfNotFunction(elementContent); }
3160+
contentExpr=ec:expr[elementContent]
3161+
{
3162+
elementContent.setASTNode(ec);
3163+
construct.addPathIfNotFunction(elementContent);
3164+
}
31623165
)*
31633166
)
31643167
|

exist-core/src/test/java/org/exist/xquery/FunctionTypeInElementContent.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,35 @@ public class FunctionTypeInElementContent {
4242
@Test
4343
public void arrayLiteral() throws XMLDBException {
4444
final String query = "element test { [] }";
45-
final String error = "err:XQTY0105 Function types are not allowed in element content. Got array(*) [at line 1, column 14, source: element test { [] }]";
46-
assertCompilationError(query, error);
45+
assertCompilationSuccess(query);
46+
}
47+
48+
@Test
49+
public void arrayConstructor() throws XMLDBException {
50+
final String query = "element test { array { () } }";
51+
assertCompilationSuccess(query);
4752
}
4853

54+
4955
@Test
5056
public void partialBuiltIn() throws XMLDBException {
5157
final String query = "element test { sum(?) }";
52-
final String error = "err:XQTY0105 Function types are not allowed in element content. Got function(*) [at line 1, column 14, source: element test { sum(?) }]";
58+
final String error = "err:XQTY0105 Function types are not allowed in element content. Got function(*) [at line 1, column 16, source: element test { sum(?) }]";
5359
assertCompilationError(query, error);
5460
}
5561

5662
@Test
5763
public void userDefinedFunction() throws XMLDBException {
5864
final String query = "element test { function () { () } }";
59-
final String error = "err:XQTY0105 Function types are not allowed in element content. Got function(*) [at line 1, column 14, source: element test { function () { () } }]";
60-
assertCompilationError(query, error);
61-
}
62-
63-
@Test
64-
public void arrayConstructor() throws XMLDBException {
65-
final String query = "element test { array { () } }";
66-
final String error = "err:XQTY0105 Function types are not allowed in element content. Got array(*) [at line 1, column 14, source: element test { array { () } }]";
65+
// TODO: user defined function has its location offset to a weird location
66+
final String error = "err:XQTY0105 Function types are not allowed in element content. Got function(*) [at line 1, column 25, source: element test { function () { () } }]";
6767
assertCompilationError(query, error);
6868
}
6969

7070
@Test
7171
public void mapConstructor() throws XMLDBException {
7272
final String query = "element test { map {} }";
73-
final String error = "err:XQTY0105 Function types are not allowed in element content. Got map(*) [at line 1, column 14, source: element test { map {} }]";
73+
final String error = "err:XQTY0105 Function types are not allowed in element content. Got map(*) [at line 1, column 16, source: element test { map {} }]";
7474
assertCompilationError(query, error);
7575
}
7676

@@ -107,4 +107,10 @@ private void assertCompilationError(final String query, final String error) thro
107107
assertEquals( error, ex.getMessage() );
108108
}
109109
}
110+
private void assertCompilationSuccess(final String query) throws XMLDBException {
111+
final XQueryService service = (XQueryService)existEmbeddedServer.getRoot().getService("XQueryService", "1.0");
112+
113+
service.compile(query);
114+
assertTrue( true );
115+
}
110116
}

0 commit comments

Comments
 (0)