Skip to content

Commit

Permalink
Merge pull request #1636 from adamretter/hotfix/abbrevForwardStep
Browse files Browse the repository at this point in the history
Fixes Node kind tests for "@"
  • Loading branch information
wolfgangmm authored Nov 27, 2017
2 parents 5f269d3 + 6033b14 commit 603ce3c
Show file tree
Hide file tree
Showing 5 changed files with 4,120 additions and 3,300 deletions.
83 changes: 83 additions & 0 deletions src/org/exist/xquery/FailTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* eXist Open Source Native XML Database
* Copyright (C) 2001-2017 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

package org.exist.xquery;

import org.exist.dom.QName;
import org.exist.dom.persistent.NodeProxy;
import org.w3c.dom.Node;

import javax.xml.stream.XMLStreamReader;

/**
* A NodeTest which never matches.
*
* Used for the AbbrevForwardStep '@' when
* attempting to match not attribute node kinds.
*
* @author Adam Retter <[email protected]>
*/
public class FailTest implements NodeTest {
private static final int NO_TYPE = Integer.MIN_VALUE;

public static final FailTest INSTANCE = new FailTest();

private FailTest() {
}

@Override
public void setType(final int nodeType) {
}

@Override
public int getType() {
return NO_TYPE;
}

@Override
public boolean matches(final NodeProxy proxy) {
return false;
}

@Override
public boolean matches(final Node node) {
return false;
}

@Override
public boolean matches(final XMLStreamReader reader) {
return false;
}

@Override
public boolean matches(final QName name) {
return false;
}

@Override
public boolean isWildcardTest() {
return false;
}

@Override
public QName getName() {
return null;
}
}
121 changes: 113 additions & 8 deletions src/org/exist/xquery/parser/XQueryTree.g
Original file line number Diff line number Diff line change
Expand Up @@ -2363,36 +2363,141 @@ throws PermissionDeniedException, EXistException, XPathException
( predicate [(LocationStep) step] )*
|
at:AT
{ QName qname= null; }
{ NodeTest test = null; }
(
attr:EQNAME
{
try {
qname = QName.parse(staticContext, attr.getText(), "");
QName qname = QName.parse(staticContext, attr.getText(), "");
qname = new QName(qname, ElementValue.ATTRIBUTE);
test = new NameTest(Type.ATTRIBUTE, qname);
} catch (final IllegalQNameException iqe) {
throw new XPathException(attr.getLine(), attr.getColumn(), ErrorCodes.XPST0081, "No namespace defined for prefix " + attr.getText());
}
}
|
#( PREFIX_WILDCARD nc2:NCNAME )
{
qname = new QName.WildcardNamespaceURIQName(nc2.getText(), ElementValue.ATTRIBUTE);
final QName qname = new QName.WildcardNamespaceURIQName(nc2.getText(), ElementValue.ATTRIBUTE);
test = new NameTest(Type.ATTRIBUTE, qname);
}
|
#( nc3:NCNAME WILDCARD )
{
String namespaceURI= staticContext.getURIForPrefix(nc3.getText());
if (namespaceURI == null)
final String namespaceURI = staticContext.getURIForPrefix(nc3.getText());
if (namespaceURI == null) {
throw new EXistException("No namespace defined for prefix " + nc3.getText());
qname= new QName.WildcardLocalPartQName(namespaceURI, ElementValue.ATTRIBUTE);
}
final QName qname = new QName.WildcardLocalPartQName(namespaceURI, ElementValue.ATTRIBUTE);
test = new NameTest(Type.ATTRIBUTE, qname);
}
|
WILDCARD
{
test = new TypeTest(Type.ATTRIBUTE);
}
|
adn:"document-node"
{
test = FailTest.INSTANCE;
// ast = adn;
}
(
#( "element"
(
adneq:EQNAME
|
WILDCARD
( adneq1:EQNAME)?
)?
)
|
#( "schema-element" EQNAME )
)?
|
#( ae:"element"
{
test = FailTest.INSTANCE;
// ast = ae;
}
(
aeq2:EQNAME
|
WILDCARD
( aeq21:EQNAME )?
)?
)
|
#( aatt:ATTRIBUTE_TEST
{
test = new TypeTest(Type.ATTRIBUTE);
// ast = aatt;
}
(
aeq3:EQNAME
{
try {
QName qname = QName.parse(staticContext, eq3.getText());
qname = new QName(qname, ElementValue.ATTRIBUTE);
test = new NameTest(Type.ATTRIBUTE, qname);
} catch (final IllegalQNameException iqe) {
throw new XPathException(eq3.getLine(), eq3.getColumn(), ErrorCodes.XPST0081, "No namespace defined for prefix " + eq3.getText());
}
}
|
WILDCARD
( aeq31:EQNAME
{
try {
QName qname = QName.parse(staticContext, eq31.getText());
qname = new QName(qname, ElementValue.ATTRIBUTE);
test = new TypeTest(Type.getType(qname));
} catch (final IllegalQNameException iqe) {
throw new XPathException(eq31.getLine(), eq31.getColumn(), ErrorCodes.XPST0081, "No namespace defined for prefix " + eq31.getText());
}
}
)?
)?
)
|
#( aapi:"processing-instruction"
{
test = FailTest.INSTANCE;
// ast = aapi;
}
(
ancpi:NCNAME
|
aslpi:STRING_LITERAL
)?
)
|
acom:"comment"
{
test = FailTest.INSTANCE;
// ast = acom;
}
|
aat:"text"
{
test = FailTest.INSTANCE;
// ast = aat;
}
|
ant:"namespace-node"
{
test = FailTest.INSTANCE;
// ast = ant;
}
|
an:"node"
{
test = new TypeTest(Type.ATTRIBUTE);
// ast = an;
}
)
{
NodeTest test= qname == null ? new TypeTest(Type.ATTRIBUTE) : new NameTest(Type.ATTRIBUTE, qname);
step= new LocationStep(context, Constants.ATTRIBUTE_AXIS, test);
step = new LocationStep(context, Constants.ATTRIBUTE_AXIS, test);
step.setASTNode(at);
path.add(step);
}
Expand Down
Loading

0 comments on commit 603ce3c

Please sign in to comment.