@@ -1083,17 +1083,42 @@ std::string Token::expressionString() const
10831083
10841084}
10851085
1086- void Token::printAst (bool verbose) const
1086+ static std::string astStringXml (const Token *tok, std::size_t indent)
1087+ {
1088+ const std::string strindent (indent, ' ' );
1089+
1090+ if (!tok->astOperand1 () && !tok->astOperand2 ()) {
1091+ std::ostringstream ret;
1092+ ret << strindent << " <token text=\" " << tok->str () << " \" " ;
1093+ if (tok->varId () > 0U )
1094+ ret << " varId=\" " << MathLib::toString (tok->varId ()) << " \" " ;
1095+ ret << " />" ;
1096+ return ret.str ();
1097+ }
1098+
1099+ std::string ret = strindent + " <token text=\" " + tok->str () + " \" >\n " ;
1100+ if (tok->astOperand1 ())
1101+ ret += astStringXml (tok->astOperand1 (),indent+2U ) + ' \n ' ;
1102+ if (tok->astOperand2 ())
1103+ ret += astStringXml (tok->astOperand2 (),indent+2U ) + ' \n ' ;
1104+ return ret + strindent + " </token>" ;
1105+ }
1106+
1107+ void Token::printAst (bool verbose, bool xml) const
10871108{
10881109 bool title = false ;
10891110
10901111 bool print = true ;
10911112 for (const Token *tok = this ; tok; tok = tok->next ()) {
10921113 if (print && tok->_astOperand1 ) {
1093- if (!title)
1114+ if (!title && !xml )
10941115 std::cout << " \n\n ##AST" << std::endl;
10951116 title = true ;
1096- if (verbose)
1117+ if (xml) {
1118+ std::cout << " <ast scope=\" " << tok->scope () << " \" >" << std::endl;
1119+ std::cout << astStringXml (tok->astTop (), 2U ) << std::endl;
1120+ std::cout << " </ast>" << std::endl;
1121+ } else if (verbose)
10971122 std::cout << tok->astTop ()->astStringVerbose (0 ,0 ) << std::endl;
10981123 else
10991124 std::cout << tok->astTop ()->astString (" " ) << std::endl;
0 commit comments