void writeSiblingsXML(const tree<AstNode>& t, const tree<AstNode>::iterator iRoot, ostream& stream) { if(t.empty()) return; if (iRoot->getType() == "root") { tree<AstNode>::sibling_iterator iChildren = t.begin(iRoot); stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl; writeSiblingsXML(t,iChildren,stream); } else if (t.number_of_children(iRoot) == 0) { string type = iRoot->getType(); stream << "<php:" << type << '>'; if (iRoot->getValue().length() > 0) stream << htmlentities(iRoot->getValue()); stream << "</php:" << type << '>' << endl; } else { string type = iRoot->getType(); string xmlns=""; if (type == "start") xmlns = " xmlns:php=\"http://php.net/csl\""; stream << "<php:" << type << xmlns << '>' << endl; int siblingNum; tree<AstNode>::sibling_iterator iChildren; for (iChildren = t.begin(iRoot), siblingNum = 0; iChildren != t.end(iRoot); ++iChildren) { writeSiblingsXML(t,iChildren,stream); } stream << "</php:" << type << '>' << endl; } }
/** Insert a new statement. - Create a new inner_statement_list - Add the statement under it */ bool insert_statement(const tree<AstNode>::iterator& where, const tree<AstNode>::iterator& what, tree<AstNode>& tr) { if (where->getType() == "text" && where->getValue() == "$enter_the_new_statement") { // rewind to the inner_statement_list tree<AstNode>::iterator top = where; do { top = tr.parent(top); } while (top->getType() != "inner_statement" && tr.child(top,0)->getType() != "statement"); top = tr.parent(top); if (top->getType() != "inner_statement_list") return false; else { top = tr.append_child(top, AstNode("inner_statement_list")); top = tr.append_child(top, AstNode("inner_statement")); if (what->getType() == "statement") { top = tr.append_child(top, AstNode("statement")); //cout << "Seems to be okay..." << endl; move_branch(top, what, tr); } } return true; } return false; }
bool Ast::is_skeleton_node(const tree<AstNode>::iterator& it) const { string t = it->getType(); if (t == "T_INLINE_HTML") return false; else if (t == "text") { // look at the parent, if it's T_VARIABLE or T_STRING, keep it tree<AstNode>::iterator parent = tr.parent(it); string pt = parent->getType(); if (pt == "T_VARIABLE" || pt == "T_STRING" || pt == "T_CONSTANT_ENCAPSED_STRING") return true; return false; } else if ((t == "root" || t == "start" || t == "CHAR61" || t == "expr" || t == "top_statement_list" || t == "internal_functions_in_yacc" || t == "function_call" || t == "statement" || t == "unticked_statement" || utils::start_with(t, "T_"))) return true; return false; }
bool Ast::detectFunction(const tree<AstNode>::iterator& i) const { if (i->getType() == "function_call") return true; return false; }