@Override
public void visitConcatStm(ConcatStm s) {
ChoiceNode cn = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
SequenceNode sn = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
OneOrMoreNode on = new OneOrMoreNode(cn.getIndex(), s.getOrigin());
TextNode tn = new TextNode(Automaton.makeEmpty(), s.getOrigin());
global_xg.addNode(cn);
global_xg.addNode(sn);
global_xg.addNode(on);
global_xg.addNode(tn);
on.setContent(cn.getIndex());
stm_nodes.setConcatOneOrMoreNode(s, on);
stm_nodes.setConcatTextNode(s, tn);
stm_nodes.setConcatChoiceNode(s, cn);
stm_nodes.setConcatSequenceNode(s, sn);
}
@Override
public void visitConstStm(ConstStm s) {
TemplateConstant t = s.getConst();
try {
stm_nodes.setTemplateConstantXMLFragment(t, t.getFragment());
} catch (XMLTemplateException e) {
Throwable tr = e;
if (tr.getCause() != null)
tr = tr.getCause();
String msg = tr.getMessage();
if (msg.endsWith("."))
msg = msg.substring(0, msg.length() - 1);
if (System.getProperty("dk.brics.xact.analysis.tolerate-errors") != null) {
// error recovery if enabled
System.err.println("Error: " + msg + " at " + s.getOrigin());
Node empty = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
global_xg.addNode(empty);
stm_nodes.setTemplateConstantXMLFragment(t, new XMLGraphFragment(empty, new HashSet<String>(), new HashSet<String>(), new HashMap<String,String>()));
} else {
throw new XMLAnalysisException(msg, s.getOrigin());
}
}
}
@Override
public void visitGetStm(GetStm s) {
ChoiceNode cn = new ChoiceNode(new HashSet<Integer>(), s.getOrigin());
global_xg.addNode(cn);
stm_nodes.setGetChoiceNode(s, cn);
switch (s.getKind()) {
case GETNEXTATTR:
case GETNEXTATTRIBUTE:
case GETNEXTSIBLING:
case GETFIRSTELEMENT:
SequenceNode sq = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
global_xg.addNode(sq);
stm_nodes.setGetEmptySequence(s, sq);
// OneOrMoreNode on = new OneOrMoreNode(cn.getIndex(), s.getOrigin());
// global_xg.addNode(on);
// stm_nodes.setGetOneOrMoreNode(s, on);
break;
}
}
@Override
public void visitGapifyStm(GapifyStm s) {
ChoiceNode cn = new ChoiceNode(s.getGapName(), false, false, new HashSet<Integer>(), s.getOrigin());
global_xg.addNode(cn);
stm_nodes.setGapifyChoiceNode(s, cn);
}
@Override
public void visitPlugStm(PlugStm s) {
switch (s.getKind()) {
case CLOSE:
SequenceNode sn = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
global_xg.addNode(sn);
stm_nodes.setPlugSequenceNode(s, sn);
break;
case PLUGMULTI:
case PLUG: {
TextNode tn = new TextNode(Automaton.makeEmpty(), s.getOrigin());
global_xg.addNode(tn);
stm_nodes.setPlugTextNode(s, tn);
break;
}
case PLUGWRAP: {
ChoiceNode top = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
SequenceNode empty = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
OneOrMoreNode on = new OneOrMoreNode(-1, s.getOrigin());
ChoiceNode content = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
TextNode tn = new TextNode(Automaton.makeEmpty(), s.getOrigin());
global_xg.addNode(top);
global_xg.addNode(empty);
global_xg.addNode(on);
global_xg.addNode(content);
global_xg.addNode(tn);
top.getContents().add(empty.getIndex());
top.getContents().add(on.getIndex());
on.setContent(content.getIndex());
content.getContents().add(tn.getIndex());
stm_nodes.setPlugWrapTopNode(s, top);
stm_nodes.setPlugWrapContentNode(s, content);
stm_nodes.setPlugTextNode(s, tn);