basix_doc 0.1
/Users/mourrain/Devel/mmx/basix/src/lisp_printer.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : lisp_printer.cpp
00004 * DESCRIPTION: Printing lisp expressions
00005 * COPYRIGHT  : (C) 2005  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00011 ******************************************************************************/
00012 
00013 #include <basix/lisp_syntax.hpp>
00014 #include <basix/literal.hpp>
00015 #include <basix/compound.hpp>
00016 namespace mmx {
00017 
00018 static void
00019 as_lisp (string& out, const generic& g, bool quote_flag, bool fun_flag) {
00020   if (is<literal> (g)) {
00021     if (quote_flag && !fun_flag) out << quote (literal_to_string (g));
00022     else out << literal_to_string (g);
00023   }
00024   else if (is<compound> (g)) {
00025     nat i, n= N (g);
00026     out << "(";
00027     if (n>0) as_lisp (out, g[0], quote_flag, true);
00028     for (i=1; i<n; i++) {
00029       out << " ";
00030       as_lisp (out, g[i], quote_flag, false);
00031     }
00032     out << ")";
00033   }
00034   else {
00035     generic f= as_generic (flatten (g));
00036     as_lisp (out, f, quote_flag, fun_flag);
00037   }
00038 }
00039 
00040 string
00041 as_lisp (const generic& g, bool quote_flag) {
00042   string out;
00043   as_lisp (out, g, quote_flag, false);
00044   return out;
00045 }
00046 
00047 string
00048 flatten_as_lisp (const generic& g) {
00049   generic f= as_generic (flatten (g));
00050   return as_lisp (f);
00051 }
00052 
00053 } // namespace mmx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines