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 @Override
public Collection<? extends ParseTree> evaluate(final ParseTree t) { public Collection<? extends ParseTree> evaluate(final ParseTree t) {
// /* means whatever the root is ParserRuleContext ctx = (ParserRuleContext)t.getPayload();
if ( isWildcard() ) { if ( ctx.getRuleIndex() == ruleIndex ) {
return new ArrayList<ParseTree>() {{add(t);}}; 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>(); return new ArrayList<ParseTree>();
} }
} }

View File

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