[antlr-interest] Generating XML from the parse tree in C++
Kurt at AlphaSoftware.com
Fri Apr 21 13:07:36 PDT 2006
In generating and reconstructing XML from the parse tree using the C++
runtime, I ran into problems and made the following changes to my local copy
(see bolded source below).
Seems like this could be simplified, but it works. Very handy feature!
The following is the section of BaseAST.cpp that I changed. Specific
changes are in bold.
/* This whole XML output stuff needs a little bit more thought
* I'd like to store extra XML data in the node. e.g. for custom ast's
* with for instance symboltable references. This
* should be more pluggable..
* @returns boolean value indicating wether a closetag should be produced.
bool BaseAST::attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out )
out << "text=\"" << this->getText()
<< "\" type=\"" << this->getType() << "\"";
void BaseAST::toStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const
for( RefAST node = this; node != 0; node = node->getNextSibling() )
out << "<" << this->typeName() << " ";
// Write out attributes and if there is extra data...
bool need_close_tag = node->attributesToStream( out );
out << ">" << endl;
// got children so write them...
if( node->getFirstChild() != 0 )
node->getFirstChild()->toStream( out );
if( need_close_tag ) // This condition seems like it should
always be true
// and a closing tag..
out << "</" << node->typeName() << ">" << endl;
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the antlr-interest