basix_doc 0.1
/Users/mourrain/Devel/mmx/basix/src/lisp_parser.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : lisp_parser.cpp
00004 * DESCRIPTION: Parsing 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/string.hpp>
00014 #include <basix/vector.hpp>
00015 #include <basix/compound.hpp>
00016 namespace mmx {
00017 
00018 static generic
00019 parse_lisp (const string& s, nat& pos, bool unquote_flag, bool fun_flag) {
00020   while (pos < N(s) && s[pos] == ' ') pos++;
00021   if (s[pos] == '(') {
00022     vector<generic> v;
00023     pos++;
00024     while (pos < N(s) && s[pos] != ')') {
00025       bool fun= (N(v) == 0);
00026       v << parse_lisp (s, pos, unquote_flag, fun);
00027       while (pos < N(s) && s[pos] == ' ') pos++;
00028     }
00029     if (pos < N(s)) pos++;
00030     return vector_to_compound (v);
00031   }
00032   else if (unquote_flag && !fun_flag && pos < N(s) && s[pos] == '\"') {
00033     nat start= pos;
00034     pos++;
00035     while (pos < N(s) && s[pos] != '\"')
00036       if (s[pos] == '\\') pos += 2;
00037       else pos++;
00038     if (pos < N(s)) pos++;
00039     return generic (unquote (s (start, pos)));
00040   }
00041   else {
00042     nat start= pos;
00043     while (pos < N(s) && s[pos] != ' ' && s[pos] != '(' && s[pos] != ')')
00044       pos++;
00045     return generic (s (start, pos));
00046   }
00047 }
00048 
00049 generic
00050 parse_lisp (const string& s, bool unquote_flag) {
00051   nat pos= 0;
00052   return parse_lisp (s, pos, unquote_flag, false);
00053 }
00054 
00055 } // namespace mmx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines