commit
511c60fe7b
|
@ -12,6 +12,8 @@ import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Represent a subset of XPath XML path syntax for use in identifying nodes in
|
/** Represent a subset of XPath XML path syntax for use in identifying nodes in
|
||||||
|
@ -176,14 +178,14 @@ loop:
|
||||||
*/
|
*/
|
||||||
public Collection<ParseTree> evaluate(final ParseTree t) {
|
public Collection<ParseTree> evaluate(final ParseTree t) {
|
||||||
ParserRuleContext dummyRoot = new ParserRuleContext();
|
ParserRuleContext dummyRoot = new ParserRuleContext();
|
||||||
dummyRoot.children = new ArrayList<ParseTree>() {{add(t);}}; // don't set t's parent.
|
dummyRoot.children = Collections.singletonList(t); // don't set t's parent.
|
||||||
|
|
||||||
Collection<ParseTree> work = new ArrayList<ParseTree>();
|
Collection<ParseTree> work = Collections.<ParseTree>singleton(dummyRoot);
|
||||||
work.add(dummyRoot);
|
work.add(dummyRoot);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while ( i < elements.length ) {
|
while ( i < elements.length ) {
|
||||||
Collection<ParseTree> next = new ArrayList<ParseTree>();
|
Collection<ParseTree> next = new LinkedHashSet<ParseTree>();
|
||||||
for (ParseTree node : work) {
|
for (ParseTree node : work) {
|
||||||
if ( node.getChildCount()>0 ) {
|
if ( node.getChildCount()>0 ) {
|
||||||
// only try to match next element if it has children
|
// only try to match next element if it has children
|
||||||
|
|
|
@ -76,6 +76,7 @@ public class TestXPath extends BaseTest {
|
||||||
"//expr/!primary", // anything but primary under any expr node
|
"//expr/!primary", // anything but primary under any expr node
|
||||||
"//!*", // nothing anywhere
|
"//!*", // nothing anywhere
|
||||||
"/!*", // nothing at root
|
"/!*", // nothing at root
|
||||||
|
"//expr//ID", // any ID under any expression (tests antlr/antlr4#370)
|
||||||
};
|
};
|
||||||
String expected[] = {
|
String expected[] = {
|
||||||
"[func, func]",
|
"[func, func]",
|
||||||
|
@ -97,6 +98,7 @@ public class TestXPath extends BaseTest {
|
||||||
"[expr, expr, expr, expr, expr, expr]",
|
"[expr, expr, expr, expr, expr, expr]",
|
||||||
"[]",
|
"[]",
|
||||||
"[]",
|
"[]",
|
||||||
|
"[y, x]",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i=0; i<xpath.length; i++) {
|
for (int i=0; i<xpath.length; i++) {
|
||||||
|
|
Loading…
Reference in New Issue