contentHandler.startElement(NS_OUTPUT, OUTPUT, OUTPUT, new AttributesImpl());
String symbol = grammar.getStartSymbol();
contentHandler.startElement(NS_OUTPUT, symbol, symbol, new AttributesImpl());
Stack stack = new Stack();
StackNodeList next = root;
char[] text = null;
int position = 0;
int lastposition = 0;
line = 1;
column = 1;
if (locatorImpl!=null)
{
locatorImpl.setLineNumber(line);
locatorImpl.setColumnNumber(column);
}
while (next!=null)
{
if (next.node instanceof NonterminalStackNode)
{
if (text!=null)
{
contentHandler.characters(text, position, (lastposition+1)-position);
increasePosition(text, position, (lastposition+1)-position);
if (locatorImpl!=null)
{
locatorImpl.setLineNumber(line);
locatorImpl.setColumnNumber(column);
}
text = null;
}
NonterminalStackNode nonterminal = (NonterminalStackNode)next.node;
AttributesImpl atts = new AttributesImpl();
/*if (localizable)
{
atts.addAttribute("", "line", "line", "CDATA", String.valueOf(next.linenumber));
atts.addAttribute("", "column", "column", "CDATA", String.valueOf(next.columnnumber));
}*/
contentHandler.startElement(NS_OUTPUT, next.node.pattern.getSymbol(),
next.node.pattern.getSymbol(), atts);
stack.push(next);
next = nonterminal.definition;
}
else
{
TerminalStackNode terminal = (TerminalStackNode)next.node;
if (text==null)
{
text = terminal.text;
position = terminal.position;
}
else if (text!=terminal.text)
{
contentHandler.characters(text, position, (lastposition+1)-position);
increasePosition(text, position, (lastposition+1)-position);
if (locatorImpl!=null)
{
locatorImpl.setLineNumber(line);
locatorImpl.setColumnNumber(column);
}
text = terminal.text;
position = terminal.position;
}
lastposition = terminal.position;
next = next.next;
}
while ((next==null) && (!stack.isEmpty()))
{
next = (StackNodeList)stack.pop();
if (text!=null)
{
contentHandler.characters(text, position, (lastposition+1)-position);
increasePosition(text, position, (lastposition+1)-position);