OSDN Git Service

wikifunction returns lisp object.
authorvisor <visor@users.sourceforge.jp>
Mon, 12 Nov 2012 14:47:10 +0000 (23:47 +0900)
committervisor <visor@users.sourceforge.jp>
Mon, 12 Nov 2012 14:47:10 +0000 (23:47 +0900)
wiki/wikiformat.cc
wiki/wikiformat.h
wiki/wikimotor.cc
wiki/wikimotor.h

index e85e756..8c73e2d 100644 (file)
@@ -1916,18 +1916,20 @@ void  WikiFormat::wikiMotorInline (uiterator b, uiterator e, WikiMotorObjVec& an
     objv.eval (ans, this);
 }
 
-MNode*  WikiFormat::buildArgs (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e, bool dumpmode) {
+//MNode*  WikiFormat::buildArgs (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e, bool dumpmode) {
+MNode*  WikiFormat::buildArgs (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e) {
     MNodeList  ans;
 
-    if (dumpmode) {
+//    if (dumpmode) {
+//     for (; b < e; b ++) {
+//         ans.append (newMNode_str (new ustring ((*b)->dump ())));
+//     }
+//    } else {
        for (; b < e; b ++) {
-           ans.append (newMNode_str (new ustring ((*b)->dump ())));
+//         ans.append (newMNode_str (new ustring ((*b)->textOut (this))));
+           ans.append ((*b)->toMNode (this));
        }
-    } else {
-       for (; b < e; b ++) {
-           ans.append (newMNode_str (new ustring ((*b)->textOut (this))));
-       }
-    }
+//    }
     
     return ans.release ();
 }
index f1803d7..4501e8f 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef WIKIFORMAT_H
 #define WIKIFORMAT_H
 
-//#include "wikienv.h"
 #include "wikimotor.h"
 #include "wikiattrib.h"
 #include "wikitable.h"
@@ -592,7 +591,8 @@ class  WikiFormat {
     };
     virtual MNode*  arrayToSexp (const ustring& name);
     virtual MNode*  evalVar (const ustring& name);
-    virtual MNode*  buildArgs (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e, bool dumpmode = false);
+//    virtual MNode*  buildArgs (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e, bool dumpmode = false);
+    virtual MNode*  buildArgs (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e);
     virtual void  logLispFunctionError (const ustring& msg, const ustring& cmd);
 };
 
index c0986e6..192236f 100644 (file)
@@ -71,13 +71,7 @@ static const int  re_wiki1_quote = 17;
 void  WikiMotorObjVec::eval (WikiMotorObjVec& ans, WikiFormat* wiki) {
     const_iterator  b = begin ();
     const_iterator  e = end ();
-#ifdef DEBUG
-//    std::cerr << "(WikiMotorObjVec::eval)\n";
-#endif /* DEBUG */
     for (; b < e; b ++) {
-#ifdef DEBUG
-//     std::cerr << "(WikiMotorObjVec::eval:" << (*b)->typeName () << ")\n";
-#endif /* DEBUG */
        (*b)->eval (ans, &*b, wiki);
     }
 }
@@ -97,13 +91,41 @@ ustring  WikiMotorObjVec::textOut (WikiFormat* wiki) {
     return o.ans;
 }
 
+MNode*  WikiMotorObjVec::toMNode (WikiFormat* wiki) {
+    MNodePtr  e;
+    MNodePtr  t;
+    int  i = 0;
+    
+    while (1) {
+       if (i >= size ())
+           return NULL;
+       e = operator [] (i)->toMNode (wiki);
+       i ++;
+       if (! isNil (e ()))
+           break;
+    }
+    while (1) {
+       if (i >= size ())
+           return e.release ();
+       t = operator [] (i)->toMNode (wiki);
+       if (! isNil (t ())) {
+           e = newMNode_str (new ustring (to_string (e ())));
+           e ()->str->append (to_string (t ()));
+           break;
+       }
+       i ++;
+    }
+    for (; i < size (); i ++) {
+       t = operator [] (i)->toMNode (wiki);
+       e ()->str->append (to_string (t ()));
+    }
+    return e.release ();
+}
+
 void  WikiMotorObjVec::out_HTML (MotorOutputString& o, WikiFormat* wiki) {
     const_iterator  b = begin ();
     const_iterator  e = end ();
     for (; b < e; b ++) {
-#ifdef DEBUG
-//     std::cerr << "(WikiMotorObjVec::out_HTML:" << (*b)->typeName () << ")\n";
-#endif /* DEBUG */
        o.out_raw ((*b)->htmlOut (wiki));
     }
 }
@@ -581,6 +603,11 @@ ustring  WikiMotorObjVecVec::textOut (WikiFormat* wiki) {
     return o.ans;
 }
 
+#if 0
+MNode*  WikiMotorObjVecVec::toMNode (WikiFormat* wiki) {
+}
+#endif
+
 void  WikiMotorObjVecVec::out_HTML (MotorOutputString& o, WikiFormat* wiki) {
     for (int i = 0; i < size (); i ++) {
        operator [] (i)->out_HTML (o, wiki);
@@ -771,9 +798,11 @@ void  WikiMotorObjVar::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self,
     case opt_c3:
        o.outamp_c3 (val);
        break;
-//    case opt_wbr:
-//     o.outamp_wbr (val);
-//     break;
+#if 0
+    case opt_wbr:
+       o.outamp_wbr (val);
+       break;
+#endif
     default:
        assert (0);
     }
@@ -802,14 +831,20 @@ ustring  WikiMotorObjVar::htmlOut (WikiFormat* wiki) {
     case opt_c3:
        o.outamp_c3 (val);
        return o.ans;
-//    case opt_wbr:
-//     o.outamp_wbr (val);
-//     return o.ans;
+#if 0
+    case opt_wbr:
+       o.outamp_wbr (val);
+       return o.ans;
+#endif
     default:
        assert (0);
     }
 }
 
+MNode*  WikiMotorObjVar::toMNode (WikiFormat* wiki) {
+    return wiki->mlenv->getVar (name);
+}
+
 ustring  WikiMotorObjVar::dump () {
     ustring  ans;
 
@@ -827,9 +862,11 @@ ustring  WikiMotorObjVar::dump () {
     case opt_c3:
        ans.append (CharConst (",]]"));
        break;
-//    case opt_wbr:
-//     ans.append (CharConst ("^]]"));
-//     break;
+#if 0
+    case opt_wbr:
+       ans.append (CharConst ("^]]"));
+       break;
+#endif
     default:
        assert (0);
     }
@@ -890,6 +927,18 @@ ustring  WikiMotorObjFunc::htmlOut (WikiFormat* wiki) {
     return o.htmlOut (wiki);
 }
 
+MNode*  WikiMotorObjFunc::toMNode (WikiFormat* wiki) {
+    WikiFormat::DepthCount  dc (wiki);
+    WikiMotorObjVec  o;
+
+    if (dc.test ()) {
+       wiki->errorMsg.append (uErrorInclNest);
+       return NULL;
+    }
+    eval (o, NULL, wiki);
+    return o.toMNode (wiki);
+}
+
 /* ============================================================ */
 ustring  WikiMotorObjFunc1::execDefunArgs (WikiFormat* wiki) {
     MNodePtr  vargs;
@@ -905,7 +954,6 @@ void  WikiMotorObjFunc1::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self
        if (func->fn1 (&arg, ans, wiki)) {
        } else {
            // *** error
-//         return dump ();
            ans.push_back (WikiMotorObjPtr (new WikiMotorObjText (dump ())));
        }
     } else {
@@ -914,38 +962,6 @@ void  WikiMotorObjFunc1::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self
     }
 }
 
-#if 0
-ustring  WikiMotorObjFunc1::textOut (WikiFormat* wiki) {
-    if (func) {
-       MotorOutputString  o;
-       if (func->fn1 (&arg, &o, wiki)) {
-           return o.ans;
-       } else {
-           // *** error
-           return dump ();
-       }
-    } else {
-       return execDefunArgs (wiki);
-    }
-}
-#endif
-#if 0
-ustring  WikiMotorObjFunc1::htmlOut (WikiFormat* wiki) {
-    if (func) {
-       MotorOutputString  o;
-       if (func->fn1 (&arg, &o, wiki)) {
-           return o.ans;
-       } else {
-           // *** error
-           return dump ();
-       }
-    } else {
-       ustring  text = execDefunArgs (wiki);
-       return wiki->wikiMotor (text.begin (), text.end ());
-    }
-}
-#endif
-
 ustring  WikiMotorObjFunc1::dump () {
     ustring  ans;
     ans.append (CharConst ("[[")).append (name).append (uColon).append (arg.dump ()).append (CharConst ("]]"));
@@ -959,7 +975,6 @@ ustring  WikiMotorObjFuncM::execDefunArgs (WikiFormat* wiki) {
 
     autoIncl.inc ();
     vargs = wiki->buildArgs (arg.begin (), arg.end ());
-//    vargs = wiki->buildArgs (arg.begin (), arg.end (), true);
     return execDefun (vargs (), wiki);
 }
 
@@ -968,7 +983,6 @@ void  WikiMotorObjFuncM::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self
        if (func->fnM (&arg, ans, wiki)) {
        } else {
            // error
-//         return dump ();
            ans.push_back (WikiMotorObjPtr (new WikiMotorObjText (dump ())));
        }
     } else {
@@ -977,39 +991,6 @@ void  WikiMotorObjFuncM::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self
     }
 }
 
-#if 0
-ustring  WikiMotorObjFuncM::textOut (WikiFormat* wiki) {
-    if (func) {
-       MotorOutputString  o;
-       if (func->fnM (&arg, &o, wiki)) {
-           return o.ans;
-       } else {
-           // *** error
-           return dump ();
-       }
-    } else {
-       return execDefunArgs (wiki);
-    }
-}
-#endif
-
-#if 0
-ustring  WikiMotorObjFuncM::htmlOut (WikiFormat* wiki) {
-    if (func) {
-       MotorOutputString  o;
-       if (func->fnM (&arg, &o, wiki)) {
-           return o.ans;
-       } else {
-           // *** error
-           return dump ();
-       }
-    } else {
-       ustring  text = execDefunArgs (wiki);
-       return wiki->wikiMotor (text.begin (), text.end ());
-    }
-}
-#endif
-
 ustring  WikiMotorObjFuncM::dump () {
     ustring  ans;
     ans.append (CharConst ("[[")).append (name);
@@ -1027,10 +1008,8 @@ ustring  WikiMotorObjFuncM2::execDefunArgs (WikiFormat* wiki) {
 
     autoIncl.inc ();
     vargs = new MNode;
-//    vargs ()->set_car (newMNode_str (new ustring (arg2.textOut (wiki))));
     vargs ()->set_car (newMNode_str (new ustring (arg2.dump ())));
     vargs ()->set_cdr (wiki->buildArgs (arg.begin (), arg.end ()));
-//    vargs ()->set_cdr (wiki->buildArgs (arg.begin (), arg.end (), true));
     return execDefun (vargs (), wiki);
 }
 
@@ -1039,7 +1018,6 @@ void  WikiMotorObjFuncM2::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* sel
        if (func->fnM2 (&arg, &arg2, ans, wiki)) {
        } else {
            // error
-//         return dump ();
            ans.push_back (WikiMotorObjPtr (new WikiMotorObjText (dump ())));
        }
     } else {
@@ -1048,38 +1026,6 @@ void  WikiMotorObjFuncM2::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* sel
     }
 }
 
-#if 0
-ustring  WikiMotorObjFuncM2::textOut (WikiFormat* wiki) {
-    if (func) {
-       MotorOutputString  o;
-       if (func->fnM2 (&arg, &arg2, &o, wiki)) {
-           return o.ans;
-       } else {
-           // *** error
-           return dump ();
-       }
-    } else {
-       return execDefunArgs (wiki);
-    }
-}
-#endif
-#if 0
-ustring  WikiMotorObjFuncM2::htmlOut (WikiFormat* wiki) {
-    if (func) {
-       MotorOutputString  o;
-       if (func->fnM2 (&arg, &arg2, &o, wiki)) {
-           return o.ans;
-       } else {
-           // *** error
-           return dump ();
-       }
-    } else {
-       ustring  text = execDefunArgs (wiki);
-       return wiki->wikiMotor (text.begin (), text.end ());
-    }
-}
-#endif
-
 ustring  WikiMotorObjFuncM2::dump () {
     ustring  ans;
     ans.append (CharConst ("[[")).append (name);
@@ -1107,18 +1053,6 @@ void  WikiMotorObjFuncLink::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* s
     ans.push_back (WikiMotorObjPtr (new WikiMotorObjText (dump ())));
 }
 
-#if 0
-ustring  WikiMotorObjFuncLink::textOut (WikiFormat* wiki) {
-    ustring  ans;
-    ans.append (CharConst ("[[")).append (name);
-    for (int i = 0; i < arg.size (); i ++) {
-       ans.append (uColon).append (arg[i]->dump ());
-    }
-    ans.append (CharConst ("]]"));
-    return ans;
-}
-#endif
-
 ustring  WikiMotorObjFuncLink::dump () {
     ustring  ans;
     ans.append (CharConst ("[[")).append (name);
@@ -1137,10 +1071,8 @@ void  WikiMotorObjCond::eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self,
     WikiMotorObjVec*  o;
 
     if (c ^ fneg) {
-//     return trueobjs.textOut (wiki);
        o = &trueobjs;
     } else {
-//     return falseobjs.textOut (wiki);
        o = &falseobjs;
     }
     WikiMotorObjVec::iterator  b = o->begin ();
@@ -1291,9 +1223,11 @@ void  WikiMotor::compile_2 (WikiMotorObjVec& out) { // [[
        case ',':
            out.push_back (WikiMotorObjPtr (new WikiMotorObjVar (sp.matchBegin (re_wiki1_wikivar), sp.matchEnd (re_wiki1_wikivar), WikiMotorObjVar::opt_c3)));
            break;
-//     case '^':
-//         out.push_back (WikiMotorObjPtr (new WikiMotorObjVar (sp.matchBegin (re_wiki1_wikivar), sp.matchEnd (re_wiki1_wikivar), WikiMotorObjVar::opt_wbr)));
-//         break;
+#if 0
+       case '^':
+           out.push_back (WikiMotorObjPtr (new WikiMotorObjVar (sp.matchBegin (re_wiki1_wikivar), sp.matchEnd (re_wiki1_wikivar), WikiMotorObjVar::opt_wbr)));
+           break;
+#endif
        default:
            assert (0);
        }
index 1703d09..72dc14d 100644 (file)
@@ -25,6 +25,7 @@ class  WikiMotorObjVec: public std::vector<WikiMotorObjPtr> {
     virtual void  eval (WikiMotorObjVec& ans, WikiFormat* wiki);
     virtual void  out (MotorOutputString& o, WikiFormat* wiki);
     virtual ustring  textOut (WikiFormat* wiki);
+    virtual MNode*  toMNode (WikiFormat* wiki);
     virtual void  out_HTML (MotorOutputString& o, WikiFormat* wiki);
     virtual ustring  htmlOut (WikiFormat* wiki);
     virtual ustring  dump ();
@@ -111,6 +112,9 @@ class  WikiMotorObj {
     };
     virtual ustring  textOut (WikiFormat* wiki) = 0;
     virtual ustring  htmlOut (WikiFormat* wiki);
+    virtual MNode*  toMNode (WikiFormat* wiki) {
+       return newMNode_str (new ustring (textOut (wiki)));
+    };
     virtual ustring  dump () = 0;
     virtual bool  operator == (const ustring& b) {
        return false;
@@ -235,10 +239,10 @@ class  WikiMotorObjVar: public WikiMotorObj {
        vopt = op;
     };
     virtual  ~WikiMotorObjVar () {};
-//    virtual void  eval (WikiMotorObjVec& ans, WikiFormat* wiki);
     virtual void  eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self, WikiFormat* wiki);
     virtual ustring  textOut (WikiFormat* wiki);
     virtual ustring  htmlOut (WikiFormat* wiki);
+    virtual MNode*  toMNode (WikiFormat* wiki);
     virtual ustring  dump ();
     virtual ustring  typeName () {
        return ustring (CharConst ("var"));
@@ -262,10 +266,10 @@ class  WikiMotorObjFunc: public WikiMotorObj {
     };
     virtual  ~WikiMotorObjFunc () {};
     virtual ustring  execDefun (MNode* vargs, WikiFormat* wiki);
-//    virtual void  eval (WikiMotorObjVec& ans, WikiFormat* wiki) = 0;
     virtual void  eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self, WikiFormat* wiki) = 0;
     virtual ustring  textOut (WikiFormat* wiki);
     virtual ustring  htmlOut (WikiFormat* wiki);
+    virtual MNode*  toMNode (WikiFormat* wiki);
 };
 
 class  WikiMotorObjFunc1: public WikiMotorObjFunc {
@@ -276,10 +280,7 @@ class  WikiMotorObjFunc1: public WikiMotorObjFunc {
     WikiMotorObjFunc1 (const ustring& fn, MNode* fp): WikiMotorObjFunc (wiki_func1, fn, fp) {};
     virtual  ~WikiMotorObjFunc1 () {};
     virtual ustring  execDefunArgs (WikiFormat* wiki);
-//    virtual void  eval (WikiMotorObjVec& ans, WikiFormat* wiki);
     virtual void  eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self, WikiFormat* wiki);
-//    virtual ustring  textOut (WikiFormat* wiki);
-//    virtual ustring  htmlOut (WikiFormat* wiki);
     virtual ustring  dump ();
     virtual ustring  typeName () {
        return ustring (CharConst ("func1"));
@@ -294,10 +295,7 @@ class  WikiMotorObjFuncM: public WikiMotorObjFunc {
     WikiMotorObjFuncM (const ustring& fn, MNode* fp): WikiMotorObjFunc (wiki_funcM, fn, fp) {};
     virtual  ~WikiMotorObjFuncM () {};
     virtual ustring  execDefunArgs (WikiFormat* wiki);
-//    virtual void  eval (WikiMotorObjVec& ans, WikiFormat* wiki);
     virtual void  eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self, WikiFormat* wiki);
-//    virtual ustring  textOut (WikiFormat* wiki);
-//    virtual ustring  htmlOut (WikiFormat* wiki);
     virtual ustring  dump ();
     virtual ustring  typeName () {
        return ustring (CharConst ("funcM"));
@@ -313,10 +311,7 @@ class  WikiMotorObjFuncM2: public WikiMotorObjFunc {
     WikiMotorObjFuncM2 (const ustring& fn, MNode* fp): WikiMotorObjFunc (wiki_funcM2, fn, fp) {};
     virtual  ~WikiMotorObjFuncM2 () {};
     virtual ustring  execDefunArgs (WikiFormat* wiki);
-//    virtual void  eval (WikiMotorObjVec& ans, WikiFormat* wiki);
     virtual void  eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self, WikiFormat* wiki);
-//    virtual ustring  textOut (WikiFormat* wiki);
-//    virtual ustring  htmlOut (WikiFormat* wiki);
     virtual ustring  dump ();
     virtual ustring  typeName () {
        return ustring (CharConst ("funcM2"));
@@ -331,9 +326,7 @@ class  WikiMotorObjFuncLink: public WikiMotorObjFunc {
     WikiMotorObjFuncLink (const ustring& fn, MNode* fp): WikiMotorObjFunc (wiki_funcLink, fn, fp) {};
     virtual  ~WikiMotorObjFuncLink () {};
     virtual ustring  execDefunArgs (WikiFormat* wiki);
-//    virtual void  eval (WikiMotorObjVec& ans, WikiFormat* wiki);
     virtual void  eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self, WikiFormat* wiki);
-//    virtual ustring  textOut (WikiFormat* wiki);
     virtual ustring  dump ();
     virtual ustring  typeName () {
        return ustring (CharConst ("funcLink"));
@@ -357,7 +350,6 @@ class  WikiMotorObjCond: public WikiMotorObj {
        fneg = _neg;
     };
     virtual  ~WikiMotorObjCond () {};
-//    virtual void  eval (WikiMotorObjVec& ans, WikiFormat* wiki);
     virtual void  eval (WikiMotorObjVec& ans, const WikiMotorObjPtr* self, WikiFormat* wiki);
     virtual ustring  textOut (WikiFormat* wiki);
     virtual ustring  htmlOut (WikiFormat* wiki);