While testing some XQuery lookup expressions on BaseX 8.6.7, I got a wrong result for this one:
(map{'a':(1,3)},map{'a':(2,4)})!?a[2]
It should have returned the second item of the 'a' entry for each of the maps, i.e.
3 4
but it returns just
3
Apparently the predicate is applied as if everything before it was in parentheses, i.e. as if it were
((map{'a':(1,3)},map{'a':(2,4)})!?a)[2]
The (simplified) parse tree for the original expression and the XQuery 3.1 grammar however indicates that the predicate is part of the mapping target expression:
<SimpleMapExpr> <ParenthesizedExpr> ... </ParenthesizedExpr> <TOKEN>!</TOKEN> <PostfixExpr> <UnaryLookup> <TOKEN>?</TOKEN> <NCName>a</NCName> </UnaryLookup> <Predicate> <TOKEN>[</TOKEN> <IntegerLiteral>2</IntegerLiteral> <TOKEN>]</TOKEN> </Predicate> </PostfixExpr> </SimpleMapExpr>
Best regards Gunther