OSDN Git Service

fix symbol bug.
authorvisor <visor@users.sourceforge.jp>
Fri, 6 Mar 2015 15:31:10 +0000 (00:31 +0900)
committervisor <visor@users.sourceforge.jp>
Fri, 6 Mar 2015 15:31:10 +0000 (00:31 +0900)
18 files changed:
lib/expr.cc
lib/expr.h
lib/ml.cc
lib/ml.h
lib/mlenv.cc
lib/motor.cc
lib/util_check.cc
lib/util_check.h
lib/util_const.cc
lib/util_const.h
lib/util_string.cc
lib/util_string.h
modules/ml-string.cc
modules/ml-struct.cc
modules/ml-texp.cc
modules/ml-variable.cc
modules/ml-wiki.cc
modules/ml-xml.cc

index fd44a54..fef2ed8 100644 (file)
@@ -16,7 +16,7 @@ static MNode*  callFunc (MNode* cell, MlEnv* mlenv) {
     MNodePtr  ans;
     FTableVal*  t;
     MLFunc*  u;
-    ustring*  name = cell->car ()->sym;
+    const ustring*  name = ptr_symbol (cell->car ());
     MNodePtr  bcell;
     MNode*  sexp;
 
@@ -82,24 +82,22 @@ MNode*  eval (MNode* cell, MlEnv* mlenv) {
        break;
     case MNode::MC_STR:
        return cell;
-    case MNode::MC_SYM:
-       if (cell->sym->length () > 0) {
-           switch ((*cell->sym)[0]) {
+    case MNode::MC_SYM: {
+       const ustring*  u = ptr_symbol (cell);
+       if (u->length () > 0) {
+           switch ((*u)[0]) {
            case '#':
            case ':':
                return cell;
            }
        }
-       return mlenv->getVar (*cell->sym);
+       return mlenv->getVar (*u);
+    }
     case MNode::MC_DOUBLE:
        return cell;
     case MNode::MC_VECTOR:
-//     return vectorEval (cell, mlenv);
-//     return cell;
        return vectorDup (cell);
     case MNode::MC_TABLE:
-//     return tableEval (cell, mlenv);
-//     return cell;
        return tableDup (cell);
     default:
        assert (0);
@@ -173,7 +171,7 @@ MNode*  tableEval (MNode* c, MlEnv* mlenv) {
 #ifdef DEBUG2
 //     std::cerr << "eval:" << to_string ((*b) ()) << "\n";
 #endif /* DEBUG */
-       x->tablePut ((*b).first, eval ((*b).second (), mlenv));
+       x->tablePut ((*b).first, eval ((*b).second (), mlenv)); // テーブルのキーは、文字列。
     }
 
     return ans.release ();
@@ -308,10 +306,6 @@ MNode*  newLambda (MNode* cell) {
     return ans;
 }
 
-bool  isLambda (MNode* sexp) {
-    return (sexp && sexp->isCons () && sexp->car () && sexp->car ()->isSym () && (*sexp->car ()->sym) == uLambda);
-}
-
 MNode*  buildArgs (int start, const std::vector<ustring>& args) {
     MNodeList  ans;
 
@@ -375,12 +369,12 @@ bool  checkDefunArgs (MNode* lambda, MNode* values) {
     MNode*  sexp = lambda->cdr ();
     MNode*  param;
     AutoDelete<KwList>  kwlist;
-    ustring*  u;
+    const ustring*  u;
     ustring  k;
     bool  skip;
 
     for (param = sexp->car (); param; nextNode (param)) {
-       u = param->car ()->sym;
+       u = ptr_symbol (param->car ());
        if (match (*u, CharConst ("&rest"))) {
            break;
        } else if (match (*u, CharConst ("&key"))) {
@@ -400,7 +394,7 @@ bool  checkDefunArgs (MNode* lambda, MNode* values) {
     for (param = sexp->car (); param;) {
        u = NULL;
        if (kwlist () && values && values->car ()->isSym ()
-           && (u = values->car ()->sym)->length () > 0
+           && (u = ptr_symbol (values->car ()))->length () > 0
            && (*u)[0] == '#'
            && kwlist ()->defined (k = ustring (u->begin () + 1, u->end ()))) {
            nextNode (values);
@@ -409,7 +403,7 @@ bool  checkDefunArgs (MNode* lambda, MNode* values) {
                   && kwlist ()->defined (k = ustring (u->begin () + 1, u->end ()))) {
            nextNode (values);
            nextNode (values);
-       } else if (match (*(u = param->car ()->sym), CharConst ("&rest"))) {
+       } else if (match (*(u = ptr_symbol (param->car ())), CharConst ("&rest"))) {
            nextNode (param);
            if (param) {
                values = NULL;
@@ -433,7 +427,7 @@ bool  checkDefunArgs (MNode* lambda, MNode* values) {
     for (; values;) {
        u = NULL;
        if (kwlist () && values && values->car ()->isSym ()
-           && (u = values->car ()->sym)->length () > 0
+           && (u = ptr_symbol (values->car ()))->length () > 0
            && (*u)[0] == '#'
            && kwlist ()->defined (k = ustring (u->begin () + 1, u->end ()))) {
            nextNode (values);
@@ -464,7 +458,7 @@ MNode*  execDefun (MlEnv* mlenv, MNode* lambda, MNode* values, const ustring& na
     MNode*  body = sexp->cdr ();
     MNodePtr  ans;
     AutoDelete<KwList>  kwlist;
-    ustring*  u;
+    const ustring*  u;
     ustring  k;
     bool  skip;
     MNode*  values0 = values;
@@ -472,7 +466,7 @@ MNode*  execDefun (MlEnv* mlenv, MNode* lambda, MNode* values, const ustring& na
     mlenv->beginLocal ();
 // it is assumed that param is a list of symbols.
     for (param = sexp->car (); param; nextNode (param)) {
-       u = param->car ()->sym;
+       u = ptr_symbol (param->car ());
        if (match (*u, CharConst ("&rest"))) {
            break;
        } else if (match (*u, CharConst ("&key"))) {
@@ -494,7 +488,7 @@ MNode*  execDefun (MlEnv* mlenv, MNode* lambda, MNode* values, const ustring& na
     for (param = sexp->car (); param;) {
        u = NULL;
        if (kwlist () && values && values->car () && values->car ()->isSym ()
-           && (u = values->car ()->sym)->length () > 0
+           && (u = ptr_symbol (values->car ()))->length () > 0
            && (*u)[0] == '#'
            && kwlist ()->defined (k = ustring (u->begin () + 1, u->end ()))) {
            mlenv->setLocalVar (k, mlTrue);
@@ -508,10 +502,10 @@ MNode*  execDefun (MlEnv* mlenv, MNode* lambda, MNode* values, const ustring& na
            else
                mlenv->setLocalVar (k, NULL);
            nextNode (values);
-       } else if (match (*(u = param->car ()->sym), CharConst ("&rest"))) {
+       } else if (match (*(u = ptr_symbol (param->car ())), CharConst ("&rest"))) {
            nextNode (param);
            if (param) {
-               mlenv->setLocalVar (*param->car ()->sym, values);
+               mlenv->setLocalVar (*ptr_symbol (param->car ()), values);
                values = NULL;
            } else {
                throw (sexp->car ()->dump_string_short () + uErrorBadParamDef);
@@ -536,7 +530,7 @@ MNode*  execDefun (MlEnv* mlenv, MNode* lambda, MNode* values, const ustring& na
     for (; values;) {
        u = NULL;
        if (kwlist () && values && values->car ()->isSym ()
-           && (u = values->car ()->sym)->length () > 0
+           && (u = ptr_symbol (values->car ()))->length () > 0
            && (*u)[0] == '#'
            && kwlist ()->defined (k = ustring (u->begin () + 1, u->end ()))) {
            mlenv->setLocalVar (k, mlTrue);
@@ -579,7 +573,7 @@ void  onErrorFn (MNode* fn, MlEnv* mlenv) {
 
 void  setParams (MNode* list, int nparam, std::vector<MNode*>* params, paramList *kwlist, std::vector<MNode*>* keywords, MNode** rest, bool padding) {
     KwList*  kw = NULL;
-    ustring*  u;
+    const ustring*  u;
     MNode*  a;
     int  i;
     ustring  name;
@@ -593,7 +587,7 @@ void  setParams (MNode* list, int nparam, std::vector<MNode*>* params, paramList
 
     while (list) {
        a = list->car ();
-       if (a && kw && a->isSym () && (u = a->sym) && u->size () > 0) {
+       if (a && kw && a->isSym () && (u = ptr_symbol (a)) && u->size () > 0) {
            switch ((*u)[0]) {
            case ':':
                name = ustring (u->begin () + 1, u->end ());
index a0aa81c..7603740 100644 (file)
@@ -31,7 +31,6 @@ MNode*  progn (MNode* arg, MlEnv* mlenv);
 void  progn_ex (MNode* arg, MlEnv* mlenv);
 void  checkDefun (MNode* cell, ustring& rname, MNode*& sexp);
 MNode*  newLambda (MNode* cell);
-bool  isLambda (MNode* sexp);
 MNode*  buildArgs (int start, const std::vector<ustring>& args);
 MNode*  buildArgs (int start, const std::vector<ustring>& args, const ustring& arg2);
 MNode*  buildArgs (const ustring& arg1);
index f94035f..69741a2 100644 (file)
--- a/lib/ml.cc
+++ b/lib/ml.cc
@@ -181,13 +181,31 @@ bool  MNode::to_bool () {
     }
 }
 
+ustring  MNode::sym_to_string () {
+    assert (type == MC_SYM);
+    uiterator  b = sym->begin ();
+    uiterator  e = sym->end ();
+    umatch  m;
+    if (b < e && usearch (b, e, m, re_nonsymbolchar)) {
+       ustring  ans;
+       do {
+           ans.append (b, m[0].first).append (1, '\\').append (octchar (*m[0].first));
+           b = m[0].second;
+       } while (b < e && usearch (b, e, m, re_nonsymbolchar));
+       if (b < e)
+           ans.append (b, e);
+       return ans;
+    } else {
+       return *sym;
+    }
+}
+
 ustring  MNode::cons_to_texp (bool fcdr) {
     // fcdr: cdr部の出力
     ustring  ans;
 
     assert (type == MC_CONS);
     if (! fcdr
-//     && cons.car && cons.car->type == MC_SYM && cons.car->str->compare ("quote") == 0
        && cons.car && cons.car->type == MC_SYM && *cons.car->str == uQuote
        && cons.cdr && cons.cdr->type == MC_CONS
        && ::isNil (cons.cdr->cons.cdr)) {
@@ -230,7 +248,7 @@ ustring  MNode::to_texp () {
     case MNode::MC_STR:
        return uQ2 + slashEncode (*str) + uQ2;
     case MNode::MC_SYM:
-       return *sym;
+       return sym_to_string ();
     case MNode::MC_DOUBLE:
        return to_ustring (real);
     case MNode::MC_VECTOR:
@@ -251,7 +269,7 @@ ustring  MNode::to_string () {
     case MNode::MC_STR:
        return *str;
     case MNode::MC_SYM:
-       return *sym;
+       return *sym;            // to-stringでは、エンコードしない
     case MNode::MC_DOUBLE:
        return to_ustring (real);
     case MNode::MC_VECTOR:
@@ -301,6 +319,62 @@ ustring  MNode::table_to_string () {
     return ans;
 }
 
+MNode*  quoted (MNode* v) {
+    if (v) {
+       switch (v->type) {
+       case MNode::MC_SYM:
+           if (v->sym
+               && v->sym->length () > 0
+               && ((*v->sym)[0] == '#' || (*v->sym)[0] == ':')) {
+           } else {
+               v = newMNode_quote (v);
+           }
+           break;
+       case MNode::MC_CONS:
+           v = newMNode_quote (v);
+           break;
+       default:;
+       }
+    }
+    return v;
+}
+
+MNode*  newMNode_sym (ustring* v) {
+    static uregex  re_special ("[\\x00-\x1f\\\\]");
+    static uregex  re_oct ("^[0-7][0-7][0-7]");
+    MNode*  ans = new MNode;
+    uiterator  b = v->begin ();
+    uiterator  e = v->end ();
+    umatch  m;
+
+    if (b < e && usearch (b, e, m, re_special)) {
+       ustring*  w = new ustring;
+       do {
+           w->append (b, m[0].first);
+           b = m[0].second;
+           if (*(m[0].first) == '\\') {
+               if (b < e && usearch (b, e, m, re_oct)) {
+                   int  c = octchar (b);
+                   if (32 <= c && c < 127)
+                       w->append (1, c);
+                   b = m[0].second;
+               } else {
+                   w->append (1, '\\');
+               }
+           } else {
+               // skip;
+           }
+       } while (b < e && usearch (b, e, m, re_special));
+       if (b < e)
+           w->append (b, e);
+       ans->set_sym (w);
+       delete v;
+    } else {
+       ans->set_sym (v);
+    }
+    return ans;
+}
+
 void  MNode::dump (std::ostream& o, bool c) {
     o << logText (to_texp ());
 }
@@ -759,13 +833,21 @@ void  MotorTexp::skipHead (uiterator& b, uiterator& e, int& linenum) {
 void  MotorTexp::scanWord (int& linenum, uiterator& b, uiterator& e, word_type& type, ustring*& ans) {
     ustring::value_type  c;
     umatch  m;
-    static uregex  re ("^[^\\x00- ()\\[\\]\\{\\}\";]+");
-    static uregex  re_num ("[\\-+]?[0-9]+(\\.[0-9]*)?");
  Ep1:;
     skipWhite (linenum, b, e);
     if (b != e) {
        c = *b;
        switch (c) {
+       case '\"':
+           b ++;
+           type = YYTEXT;
+           ans = scanText (linenum, b, e);
+           break;
+       case '\'':
+           b ++;
+           type = YYQUOTE;
+           ans = NULL;
+           break;
        case '(':
            b ++;
            type = YYPAR;
@@ -774,6 +856,18 @@ void  MotorTexp::scanWord (int& linenum, uiterator& b, uiterator& e, word_type&
            b ++;
            type = YYREN;
            break;
+       case ';':
+           b ++;
+           if (usearch (b, e, m, re_nl)) {
+               b = m[0].second;
+               linenum ++;
+               goto Ep1;
+           } else {
+               // end of comment but without nl.
+               b = e;
+               type = YYNONE;
+           }
+           break;
        case '[':
            b ++;
            type = YYPAR2;
@@ -790,44 +884,20 @@ void  MotorTexp::scanWord (int& linenum, uiterator& b, uiterator& e, word_type&
            b ++;
            type = YYREN3;
            break;
-       case '\"':
-           b ++;
-           type = YYTEXT;
-           ans = scanText (linenum, b, e);
-           break;
-       case ';':
-           b ++;
-           if (usearch (b, e, m, re_nl)) {
-               b = m[0].second;
-               linenum ++;
-               goto Ep1;
-           } else {
-               // end of comment but without nl.
-               b = e;
-               type = YYNONE;
-           }
-           break;
        default:
-           if (usearch (b, e, m, re)) {
+           if (usearch (b, e, m, re_realnumber)) {
+               type = YYNUM;
+               ans = new ustring (m[0]);
+               b = m[0].second;
+           } else if (usearch (b, e, m, re_symbol)) {
                assert (b == m[0].first);
-               if (*b == '\'') {
-                   b ++;
-                   type = YYQUOTE;
-                   ans = NULL;
-               } else if (*b == '.' && m[0].second - m[0].first == 1) {
+               if (*b == '.' && m[0].second - m[0].first == 1) {
                    type = YYPERIOD;
                    b = m[0].second;
                } else {
-                   umatch  m2;
-                   if (regex_match (m[0].first, m[0].second, m2, re_num)) {
-                       type = YYNUM;
-                       ans = new ustring (m[0]);
-                       b = m[0].second;
-                   } else {
-                       type = YYSIM;
-                       ans = new ustring (m[0]);
-                       b = m[0].second;
-                   }
+                   type = YYSIM;
+                   ans = new ustring (m[0]);
+                   b = m[0].second;
                }
                skipWhite (linenum, b, e);
            } else {
index eee2c1d..86ed5a4 100644 (file)
--- a/lib/ml.h
+++ b/lib/ml.h
@@ -171,6 +171,7 @@ class  MNode {
        return (int64_t)to_double ();
     };
     bool  to_bool ();
+    ustring  sym_to_string ();
     ustring  cons_to_texp (bool fcdr = false);
     ustring  to_texp ();
     ustring  to_string ();
@@ -209,6 +210,15 @@ inline bool  isTable (MNode* a) {
     return (a != NULL && a->isTable ());
 }
 
+inline bool  isLambda (MNode* sexp) {
+    return (sexp && sexp->isCons () && sexp->car () && sexp->car ()->isSym () && (*sexp->car ()->sym) == uLambda);
+}
+
+inline const ustring*  ptr_symbol (MNode* e) {
+    assert (isSym (e));
+    return e->sym;
+}
+
 class  MNodePtr;
 ustring  formatString (const ustring& format, boost::ptr_vector<MNodePtr>& par);
 bool  eq (MNode* a, MNode* b);
@@ -274,11 +284,8 @@ inline ustring  dump_to_texp (MNode* c) {
 }
 #define dump_to_sexp(x)                dump_to_texp(x)
 
-inline MNode*  newMNode_sym (ustring* v) {
-    MNode*  ans = new MNode;
-    ans->set_sym (v);
-    return ans;
-}
+MNode*  quoted (MNode* v);
+MNode*  newMNode_sym (ustring* v);
 
 inline MNode*  newMNode_str (ustring* v) {
     MNode*  ans = new MNode;
@@ -316,7 +323,6 @@ inline MNode*  newMNode_cons (MNode* a, MNode* d) {
 }
 
 inline MNode*  newMNode_symQuote () {
-//    return newMNode_sym (new ustring (CharConst ("quote")));
     return newMNode_sym (new ustring (uQuote));
 }
 
index 383f53c..d3889ee 100644 (file)
@@ -491,9 +491,8 @@ void  MlEnv::logSexp (MNode* c) {
        for (i = 0; i < mlPool->includeCount; i ++)
            *log << ":";
        logLinenum (c);
-//     *log << c->dump_string_short () << "\n";
        if (c->car () && c->car ()->isSym ()
-           && (match (*c->car ()->sym, CharConst ("defun")) || matchHead (*c->car ()->sym, CharConst ("defun-")))
+           && (match (*ptr_symbol (c->car ()), CharConst ("defun")) || matchHead (*ptr_symbol (c->car ()), CharConst ("defun-")))
            && c->cdr () && c->cdr ()->isCons ()
            && c->cdr ()->cdr () && c->cdr ()->cdr ()->isCons ()) {
            *log << "(" << c->car ()->dump_string ();
index f78333f..69ee2d4 100644 (file)
@@ -563,7 +563,7 @@ int  HTMLMotor::s4 (MotorObj::MotorObjVec* sobjs, uiterator start, upair name) {
        if (! s5 (sobjs, start)) {
            return 0;                   // NG
        }
-    } else if (usearch (name.first, name.second, m, re_num)) {// [[NUM:
+    } else if (usearch (name.first, name.second, m, re_digits)) {// [[NUM:
        AutoDelete<MotorObjTempl>  o;
        uiterator  b = begin;
 
index 8c28968..a8b8b89 100644 (file)
@@ -97,7 +97,7 @@ bool  checkNum (const ustring& text) {
 }
 
 bool  checkNum (const uiterator& b, const uiterator& e) {
-    return (checkRe (b, e, re_num));
+    return (checkRe (b, e, re_digits));
 }
 
 bool  checkWidth (const uiterator& b, const uiterator& e) {
index 748ef69..ece9385 100644 (file)
@@ -25,7 +25,7 @@ bool  checkHostname (const ustring& name);
 bool  checkMimeType (const ustring& name);
 bool  checkMailAddr (const ustring& name);
 bool  checkAlNum (const uiterator& b, const uiterator& e);
-bool  checkNum (const ustring& text);
+bool  checkNum (const ustring& text);                  // [0-9]+
 bool  checkNum (const uiterator& b, const uiterator& e);
 bool  checkWidth (const uiterator& b, const uiterator& e);
 bool  checkWidth (const ustring& text);
index 3bb0ea0..c116663 100644 (file)
@@ -91,7 +91,10 @@ uregex  re_colon (":");
 uregex  re_comma (",");
 //uregex  re_amp ("&");
 //uregex  re_eq ("=");
-uregex  re_num ("^[0-9]+$");
+uregex  re_digits ("^[0-9]+$");
+uregex  re_realnumber ("^[+-]?[0-9]+(\\.[0-9]*)?([eE][+-]?[0-9]+)?");
+uregex  re_symbol ("^[^\\x00- \"'();\\[\\]\\{\\}]+");
+uregex  re_nonsymbolchar ("[\\x00- \"'();\\[\\]\\{\\}\\\\]");  // \を含める
 uregex  re_q ("\"");
 
 MNode*  mlTrue = NULL;
index 725fd28..2ad1762 100644 (file)
@@ -80,7 +80,10 @@ extern uregex  re_colon;
 extern uregex  re_comma;
 //extern uregex  re_amp;
 //extern uregex  re_eq;
-extern uregex  re_num;
+extern uregex  re_digits;
+extern uregex  re_realnumber;
+extern uregex  re_symbol;
+extern uregex  re_nonsymbolchar;
 extern uregex  re_q;
 extern MNode*  mlTrue;
 
index efec261..948bd2c 100644 (file)
@@ -986,3 +986,23 @@ ustring  hexEncode (const ustring& data) {
     }
     return ans;
 }
+
+int  octchar (uiterator b) {   // 3bytes
+    int  ans = 0;
+    ans = *b - '0';
+    ++ b;
+    ans = ans * 8 + *b - '0';
+    ++ b;
+    ans = ans * 8 + *b - '0';
+    return ans;
+}
+
+ustring  octchar (int c) {
+    ustring  ans (3, 0);
+    ans[2] = (c & 0x7) + '0';
+    c >>= 3;
+    ans[1] = (c & 0x7) + '0';
+    c >>= 3;
+    ans[0] = (c & 0x3) + '0';
+    return ans;
+}
index e685fa2..9f7f8e9 100644 (file)
@@ -109,5 +109,7 @@ ustring  formatDateString (const ustring& format, struct tm& v);
 ustring  toLower (const ustring& str);
 ustring  toUpper (const ustring& str);
 ustring  hexEncode (const ustring& data);
+int  octchar (uiterator b);
+ustring  octchar (int c);
 
 #endif /* UTIL_STRING_H */
index 41a317b..1361906 100644 (file)
@@ -1046,7 +1046,6 @@ MNode*  ml_to_symbol (MNode* cell, MlEnv* mlenv) {
     } else {
        return NULL;
     }
-//    return newMNode_str (new ustring (text));
 }
 
 /*DOC:
index 39f8c7c..90fdfc9 100644 (file)
@@ -8,26 +8,6 @@
 #include "ustring.h"
 #include <exception>
 
-static MNode*  symquote (MNode* v) {
-    if (v) {
-       switch (v->type) {
-       case MNode::MC_SYM:
-           if (v->sym
-               && v->sym->length () > 0
-               && ((*v->sym)[0] == '#' || (*v->sym)[0] == ':')) {
-           } else {
-               v = newMNode_quote (v);
-           }
-           break;
-       case MNode::MC_CONS:
-           v = newMNode_quote (v);
-           break;
-       default:;
-       }
-    }
-    return v;
-}
-
 /*DOC:
 ==lisp structure==
 
@@ -663,13 +643,13 @@ MNode*  ml_apply (MNode* cell, MlEnv* mlenv) {
     } else if (fn ()->isSym ()) {
        while (arg) {
            if (! isNil (arg->cdr ())) {
-               list.append (symquote (eval (arg->car (), mlenv)));
+               list.append (quoted (eval (arg->car (), mlenv)));
            } else {
                MNode*  a;
                h = eval (arg->car (), mlenv);
                a = h ();
                while (a && a->isCons ()) {
-                   list.append (symquote (a->car ()));
+                   list.append (quoted (a->car ()));
                    nextNode (a);
                }
            }
index 9dae6cc..639615a 100644 (file)
@@ -602,7 +602,7 @@ MNode*  ml_table_to_list (MNode* cell, MlEnv* mlenv) {
     MotorVar::iterator  b = e ()->table->begin ();
     MotorVar::iterator  t = e ()->table->end ();
     for (; b != t; ++ b) {
-       ans.append (newMNode_cons (newMNode_sym (new ustring ((*b).first)), (*b).second ()));
+       ans.append (newMNode_cons (newMNode_str (new ustring ((*b).first)), (*b).second ())); // テーブルのキーは、シンボルではなく文字列
     }
 
     return ans.release ();
@@ -670,7 +670,7 @@ MNode*  ml_table_each (MNode* cell, MlEnv* mlenv) {
        MotorVar::iterator  b = tbl ()->table->begin ();
        MotorVar::iterator  t = tbl ()->table->end ();
        for (; b != t; ++ b) {
-           mlenv->setVar (vkey, newMNode_sym (new ustring ((*b).first)));
+           mlenv->setVar (vkey, newMNode_str (new ustring ((*b).first))); // テーブルのキーは、文字列
            mlenv->setVar (vval, (*b).second ());
            ans = progn (rest, mlenv);
            if (mlenv->breaksym ()) {
index 7076303..54dfe2c 100644 (file)
@@ -21,10 +21,11 @@ static void  setvar (MNode* name, MNode* val, MlEnv* mlenv) {
     }
 }
 
-static void  setLocalVar (ustring& name, MNode* val, MlEnv* mlenv) {
-    if (checkAry (name, name)) {
-       mlenv->defineLocalVar (name);
-       mlenv->setAry (name, val);
+static void  setLocalVar (const ustring& name, MNode* val, MlEnv* mlenv) {
+    ustring  aname;
+    if (checkAry (name, aname)) {
+       mlenv->defineLocalVar (aname);
+       mlenv->setAry (aname, val);
     } else {
        mlenv->setLocalVar (name, val);
     }
@@ -210,7 +211,7 @@ MNode*  ml_let (MNode* cell, MlEnv* mlenv) {
        if (varlist && varlist->isCons ()) {
            MNode*  v;
            MNodePtr  p;
-           ustring*  name;
+           const ustring*  name;
 
            while (varlist) {
                v = varlist->car ();
@@ -218,14 +219,14 @@ MNode*  ml_let (MNode* cell, MlEnv* mlenv) {
                    switch (v->type) {
                    case MNode::MC_CONS:
                        if (v->car ()->isSym ()) {
-                           name = v->car ()->sym;
+                           name = ptr_symbol (v->car ());
                            nextNode (v);
                            p = eval (v->car (), mlenv);
                            setLocalVar (*name, p (), mlenv);
                        }
                        break;
                    case MNode::MC_SYM:
-                       name = v->sym;
+                       name = ptr_symbol (v);
                        mlenv->setLocalVar (*name, NULL);
                        break;
                    default:
index f749c0d..ecd566f 100644 (file)
@@ -347,7 +347,7 @@ MNode*  ml_guestuser_function (MNode* cell, MlEnv* mlenv) {
 
 /*DOC:
 ===wiki-output===
- (wiki-output TEXT... [#flush | :flush BOOL]) -> NIL
+ (wiki-output [#flush | :flush BOOL] TEXT...) -> NIL
 
 */
 //#AFUNC       wiki-output     ml_wiki_output
@@ -356,32 +356,23 @@ MNode*  ml_wiki_output (MNode* cell, MlEnv* mlenv) {
     ustring  text;
     MNode*  a;
     ustring*  u;
+    bool  b;
+    std::vector<MNode*>  keywords;
+    MNode*  rest;
+    static paramList  kwlist[] = {
+       {CharConst ("flush"), true},
+       {NULL, 0, 0}
+    };
 
-    while (arg) {
-       a = arg->car ();
-       if (a && a->isSym ()) {
-           u = a->sym;
-           if (match ((*u), CharConst (":flush"))) {
-               nextNodeNonNil (arg);
-               if (eval_bool (arg->car (), mlenv)) {
-                   if (mlenv->env->wikioutput)
-                       mlenv->env->wikioutput->flush (true);
-               }
-               nextNode (arg);
-           } else if (match ((*u), CharConst ("#flush"))) {
-               nextNode (arg);
-               if (mlenv->env->wikioutput)
-                   mlenv->env->wikioutput->flush (true);
-           } else {
-               if (mlenv->env->wikioutput)
-                   mlenv->env->wikioutput->out_toText (eval_str (arg->car (), mlenv));
-               nextNode (arg);
-           }
-       } else {
-           if (mlenv->env->wikioutput)
-               mlenv->env->wikioutput->out_toText (eval_str (arg->car (), mlenv));
-           nextNode (arg);
-       }
+    setParams (arg, 0, NULL, kwlist, &keywords, &rest);
+    if (evkw_bool (0, b))
+       if (mlenv->env->wikioutput)
+           mlenv->env->wikioutput->flush (true);
+
+    while (rest) {
+       if (mlenv->env->wikioutput)
+           mlenv->env->wikioutput->out_toText (eval_str (rest->car (), mlenv));
+       nextNode (rest);
     }
 
     return NULL;
index 0df8232..d051dd9 100644 (file)
@@ -213,20 +213,16 @@ public:
     virtual  ~XmlReaderData_txml () {};
 
     virtual void  newNode (const XML_Char* name, const XML_Char** atts) {
-//     MNode*  a = newMNode_vector ();
        MNodeList  a;
-//     a->vectorPush (newMNode_sym (new ustring (fixUTF8 (ustring (name)))));
        a.append (newMNode_sym (new ustring (fixUTF8 (ustring (name)))));
        a.append (NULL);
        if (atts && *atts) {
            MNode*  c = newMNode_table ();
-//         a->vectorPush (c);
            a.append (c);
            for (; *atts; ) {
                c->tablePut (fixUTF8 (ustring (*atts ++)), newMNode_str (new ustring (fixUTF8 (ustring (*atts ++)))));
            }
        }
-//     ptr.push_back (a);
        ptr.push_back (a.release ());
        mode.push_back (M_START);
        text.resize (0);
@@ -250,7 +246,6 @@ public:
        case M_START:
            break;
        case M_TEXT:
-//         a->vectorPush (newMNode_str (new ustring (text)));
            a->cdr ()->set_car (newMNode_str (new ustring (text)));
            break;
        case M_CHILD:
@@ -260,7 +255,6 @@ public:
        if (ptr.size () == 0) {
            ans = a;
        } else {
-//         ptr.back ()->vectorPush (a);
            MNode*  b = ptr.back ()->cdr ();
            MNode*  c = b->car ();
            if (! c) {
@@ -336,7 +330,7 @@ public:
        if (isCons (list) && isSym (list->car ())) {
            MNode*  c;
            MNode*  d;
-           ustring*  name = list->car ()->sym;
+           const ustring*  name = ptr_symbol (list->car ());
            list = list->cdr ();
            if (isCons (list)) {
                out->out_raw (CharConst ("<"))->out_toHTML_noCtrl (*name);
@@ -387,11 +381,11 @@ public:
            MNode*  c;
            MNode*  d;
            MNode*  e;
-           ustring*  name = list->car ()->sym;
+           const ustring*  name = ptr_symbol (list->car ());
            list = list->cdr ();
            out->out_raw (CharConst ("<"))->out_toHTML_noCtrl (*name);
            if (isCons (list) && isCons (c = list->car ())
-               && isSym (d = c->car ()) && *d->sym == uAt) { // attribute
+               && isSym (d = c->car ()) && *ptr_symbol (d) == uAt) { // attribute
                c = c->cdr ();
                list = list->cdr ();
                while (isCons (c)) {
@@ -441,7 +435,7 @@ public:
        MNode*  c;
        MNode*  d;
        if (isCons (list) && isSym (c = list->car ())) {
-           ustring*  name = c->sym;
+           const ustring*  name = ptr_symbol (c);
            list = list->cdr ();
            out->out_raw (CharConst ("<"))->out_toHTML_noCtrl (*name);
            if (isCons (list)) {