OSDN Git Service

dotable wiki command, eval wiki inline function.
authorvisor <visor@users.sourceforge.jp>
Sat, 11 Apr 2015 07:37:50 +0000 (16:37 +0900)
committervisor <visor@users.sourceforge.jp>
Sat, 11 Apr 2015 07:37:50 +0000 (16:37 +0900)
wiki/wikicmd.cc
wiki/wikicmd.h
wiki/wikiline.cc
wiki/wikiline.h

index 6849164..fee9331 100644 (file)
@@ -243,7 +243,7 @@ void  wc_dovector (WikiLine* wl, WikiFormat* wiki) {
            }
            do_linevec (wl->block, wiki);
        }
-       for (it = 0; it < iu; ++ it) {
+       for (it = 0; it < iu; ++ it) {                  // 書き戻す
            wiki->mlenv->setVar (lv[it], lvv[it] ());
        }
     }
@@ -251,6 +251,65 @@ void  wc_dovector (WikiLine* wl, WikiFormat* wiki) {
 
 /* ============================================================ */
 /*DOC:
+===$dotable===
+ $dotable:''VARKEY'',''VARVAL'':''TABLEVAR''
+ ...
+ $enddotable
+
+テーブル''TABLEVAR''の各要素のキーと値ををそれぞれ変数''VAR1'', ''VAR2''に代入しながら,$enddotableまでのブロックを繰り返し実行する。
+
+*/
+//#WIKICMD     $dotable        $enddotable     wc_dotable
+void  wc_dotable (WikiLine* wl, WikiFormat* wiki) {
+    WikiMotor  motor (wl->begin, wl->end, wiki);
+    WikiMotorObjVec  objv;
+    WikiMotorObjVecVec  args;
+    ustring  vkey, vval;
+    MNodePtr  tbl;
+    ustring  s;
+
+#ifdef WIKIREPEATPROTECT
+    if (wiki->protectMode && ! wl->fsuper) {
+#ifdef DEBUG
+       std::cerr << "(wiki):(protected)\n";
+#endif /* DEBUG */
+       return;
+    }
+#endif
+
+#ifdef DEBUG
+    std::cerr << "(wiki):" << ustring (wl->begin0, wl->end) << "\n";
+#endif /* DEBUG */
+    motor.compile (objv);
+    objv.splitCharA (':', args);
+    if (args.size () != 2) {
+       wiki->errorMsg.append (CharConst ("$dovector: wrong number of parameters.\n"));
+       return;
+    }
+    WikiMotorObjVecVec  v;
+    args[0]->splitCharA (',', v);
+    if (0 < v.size ())
+       vkey = clipWhite (v[0]->textOut (wiki));
+    if (1 < v.size ())
+       vval = clipWhite (v[1]->textOut (wiki));
+    s = clipWhite (args[1]->textOut (wiki));
+    tbl = wiki->getVar (s);
+    if (! isTable (tbl ())) {
+       wiki->errorMsg.append (CharConst ("$dovector: bad value type.\n"));
+       return;
+    }
+
+    MotorVar::iterator  b = tbl ()->table->begin ();
+    MotorVar::iterator  t = tbl ()->table->end ();
+    for (; b != t; ++ b) {
+       wiki->mlenv->setVar (vkey, newMNode_str (new ustring ((*b).first))); // テーブルのキーは、文字列
+       wiki->mlenv->setVar (vval, (*b).second ());
+       do_linevec (wl->block, wiki);
+    }
+}
+
+/* ============================================================ */
+/*DOC:
 ===$block===
  $block:''EXPR''
  ...
index e02fd69..d6e3012 100644 (file)
@@ -10,6 +10,7 @@ class  WikiFormat;
 void  wc_repeat (WikiLine* wl, WikiFormat* wiki);
 void  wc_doarray (WikiLine* wl, WikiFormat* wiki);
 void  wc_dovector (WikiLine* wl, WikiFormat* wiki);
+void  wc_dotable (WikiLine* wl, WikiFormat* wiki);
 void  wc_block (WikiLine* wl, WikiFormat* wiki);
 void  wc_setvar (WikiLine* wl, WikiFormat* wiki);
 void  wc_eval (WikiLine* wl, WikiFormat* wiki);
index 788acb6..a6ff1aa 100644 (file)
@@ -281,6 +281,44 @@ bool  wl_table (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki
     return true;
 }
 
+/*DOC:
+===Lispファンクション実行===
+ [[eval:FUNC]]
+
+*/
+//#WIKILINE    eval    wl_eval
+bool  wl_eval (WikiMotorObjVec* arg2, WikiMotorObjVec& out, WikiFormat* wiki) {
+#ifdef WIKIEVALPROTECT
+    if (wiki->protectMode && ! wl->fsuper) {
+       return false;
+    }
+#endif
+
+    MotorTexp  ml (wiki->mlenv);
+    ustring  sexp = arg2->textOut (wiki);
+    MNodePtr  v;
+
+    if (! sexp.empty ()) {
+       ml.scan (sexp);
+       if (ml.top.isCons ()) {
+           MNode*  arg = ml.top.cdr ();
+           if (arg && arg->isCons ()) {
+               try {
+                   v = eval (arg->car (), wiki->mlenv);
+                   MotorOutputWiki  o (out);
+                   o.outamp (to_string (v ()));
+               } catch (ustring& msg) {
+                   if (wiki->mlenv->currentCell ()) {
+                       wiki->errorMsg.append (wiki->mlenv->currentCell ()->dump_string_short ()).append (CharConst (": "));
+                   }
+                   wiki->errorMsg.append (msg).append (uLF);
+               }
+           }
+       }
+    }
+    return true;
+}
+
 /* ============================================================ */
 /*DOC:
 ===強調===
index 327056a..3ea4af7 100644 (file)
@@ -13,6 +13,7 @@ bool  wl_car (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki);
 bool  wl_cdr (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki);
 bool  wl_join (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki);
 bool  wl_table (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki);
+bool  wl_eval (WikiMotorObjVec* arg2, WikiMotorObjVec& out, WikiFormat* wiki);
 bool  wl_italic (WikiMotorObjVec* arg2, WikiMotorObjVec& out, WikiFormat* wiki);
 bool  wl_bold (WikiMotorObjVec* arg2, WikiMotorObjVec& out, WikiFormat* wiki);
 bool  wl_bolditalic (WikiMotorObjVec* arg2, WikiMotorObjVec& out, WikiFormat* wiki);