This commit is contained in:
Terence Parr 2013-09-10 19:51:11 -07:00
parent 913cda0721
commit 20d8545e3d
2 changed files with 8 additions and 19 deletions

View File

@ -16,16 +16,10 @@ public class XPathRootRuleElement extends XPathElement {
@Override
public Collection<? extends ParseTree> evaluate(final ParseTree t) {
// /* means whatever the root is
if ( isWildcard() ) {
ParserRuleContext ctx = (ParserRuleContext)t.getPayload();
if ( ctx.getRuleIndex() == ruleIndex ) {
return new ArrayList<ParseTree>() {{add(t);}};
}
else { // /x means x must be root
ParserRuleContext ctx = (ParserRuleContext)t.getPayload();
if ( ctx.getRuleIndex() == ruleIndex ) {
return new ArrayList<ParseTree>() {{add(t);}};
}
}
return new ArrayList<ParseTree>();
}
}

View File

@ -13,18 +13,13 @@ public class XPathTokenElement extends XPathElement {
@Override
public Collection<? extends ParseTree> evaluate(ParseTree t) {
if ( isWildcard() ) {
return t.getChildren();
}
else {
// return all children of t that match nodeName
List<ParseTree> nodes = new ArrayList<ParseTree>();
for (ParseTree c : t.getChildren()) {
if ( c.getText().equals(nodeName) ) {
nodes.add(c);
}
// return all children of t that match nodeName
List<ParseTree> nodes = new ArrayList<ParseTree>();
for (ParseTree c : t.getChildren()) {
if ( c.getText().equals(nodeName) ) {
nodes.add(c);
}
return nodes;
}
return nodes;
}
}