if(excludedChildren.contains(child)) {
continue;
}
Pattern pat = child.getPattern();
Matcher m = pat.matcher(txt);
if(m.find()) {
String tokText;
int pg = child.getParseGroup();
try {
tokText = m.group(pg);
} catch(ArrayIndexOutOfBoundsException e) {
pg = 0;
tokText = m.group(0);
}
textNode.setValue(txt.substring(0, m.start()));
Node currentNode = textNode;
if(m.start(pg) > m.start()) {
Text invincibleText =
new Text(txt.substring(m.start(), m.start(pg)));
XOMTools.insertAfter(currentNode, invincibleText);
currentNode = invincibleText;
}
Element elem = new Element(child.getType());
XOMTools.insertAfter(currentNode, elem);
currentNode = elem;
if(child.getValue() != null && child.getValue().length() > 0) {
elem.addAttribute(new Attribute("type", child.getValue()));
}
if(child.saf) elem.addAttribute(new Attribute("saf", "yes"));
Text childText = new Text(tokText);
elem.appendChild(childText);
child.parseXOMText(childText);
if(m.end() > m.end(pg)) {
Text invincibleText =
new Text(txt.substring(m.end(pg), m.end()));
XOMTools.insertAfter(currentNode, invincibleText);
currentNode = invincibleText;
}
if(child.isUnique()) {
excludedChildren.add(child);
}
if(m.end() < txt.length()) {
Text endText = new Text(txt.substring(m.end()));
XOMTools.insertAfter(currentNode, endText);
parseXOMText(endText, excludedChildren);
// Do something about uniqueness here...
}
foundSomethingFlag = true;