00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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 }