1// 2// Copyright (C) 2004 Stefan Seefeld 3// All rights reserved. 4// Licensed to the public under the terms of the GNU LGPL (>= 2), 5// see the file COPYING for details. 6// 7#ifndef Synopsis_PTree_Writer_hh_ 8#define Synopsis_PTree_Writer_hh_ 9 10#include <Synopsis/PTree.hh> 11#include <sstream> 12 13namespace Synopsis 14{ 15namespace PTree 16{ 17 18class Writer : private Visitor 19{ 20public: 21 Writer(std::ostream &os); 22 23 unsigned long write(Node const *); 24 25private: 26 27 virtual void visit(Atom *); 28 virtual void visit(List *); 29 virtual void visit(Brace *); 30 31 void newline(); 32 33 std::ostream &my_os; 34 size_t my_indent; 35 unsigned long my_lines; 36}; 37 38inline std::string reify(Node const *p) 39{ 40 if (!p) return ""; 41 else if (p->is_atom()) return std::string(p->position(), p->length()); 42 43 std::ostringstream oss; 44 Writer writer(oss); 45 writer.write(p); 46 return oss.str(); 47} 48 49} 50} 51 52#endif