OSDN Git Service

WikiMotorObjSelect feature.
authorvisor <visor@users.sourceforge.jp>
Sun, 24 Jan 2010 05:51:03 +0000 (14:51 +0900)
committervisor <visor@users.sourceforge.jp>
Sun, 24 Jan 2010 05:51:03 +0000 (14:51 +0900)
wiki/wikiformat.cc
wiki/wikiformat.h
wiki/wikiline.cc
wiki/wikimotor.cc
wiki/wikimotor.h

index b22cb94..e8db132 100644 (file)
@@ -99,6 +99,7 @@ size_t  WikiMlEnv::getArySize (const ustring& name) {
 }
 
 /* ============================================================ */
+#if 0
 bool  WikiTableSplitter::next () {
     int  nest = 0;
     uiterator  ab;
@@ -123,6 +124,7 @@ bool  WikiTableSplitter::next () {
     t = u = e;
     return true;
 }
+#endif
 
 /* ============================================================ */
 void  WikiBlockComplex::outputBlock (MotorOutput* out) {
index 34dda58..afedae7 100644 (file)
@@ -104,6 +104,7 @@ class  WikiLineScanner {
     };
 };
 
+#if 0
 class  WikiTableSplitter {
  public:
     uregex*  re;
@@ -137,6 +138,7 @@ class  WikiTableSplitter {
     };
     virtual bool  next ();
 };
+#endif
 
 class  WikiBlock {
  public:
index 8bb96ed..b129b78 100644 (file)
@@ -41,8 +41,10 @@ static void  errorBadParam (WikiMotorObjVec* param, WikiFormat* wiki) {
 */
 /*DOC:
 ===選択出力===
- [[variable?value:text1]]
- [[variable?value:text1||text2]]
+ [[variable?value:TRUE TEXT]]
+ [[variable!?value:FALSE TEXT]]
+ [[variable?value:TRUE TEXT||FALSE TEXT]]
+ [[variable!?value:FALSE TEXT||TRUE TEXT]]
 
 */
 /* ============================================================ */
index ef6601e..2a8e87a 100644 (file)
@@ -22,13 +22,13 @@ uregex  re_wiki1 (
                        "(/|~|,|\\^)?"          // 4
                        "\\]\\]"
                "|"
-                       "(:)"                   // 5
+                       "(:|!?\\?)"             // 5
                ")"
-       ")|("                                   // 6
-               "\\]\\]"
-       ")|("                                   // 7
-               "\\|"
        ")|"
+               "(\\]\\])"                      // 6
+       "|"
+               "(\\|\\|)"                      // 7
+       "|"
                "&"
                "("                             // 8
                        ";"
@@ -813,8 +813,27 @@ ustring  WikiMotorObjFuncM2::dump () {
 
 /* ============================================================ */
 ustring  WikiMotorObjSelect::textOut (WikiFormat* wiki) {
-    ustring  ans;
-    return ans;
+    ustring  v = wiki->getVar (name);
+    ustring  val = value.textOut (wiki);
+    bool  c = (v == val);
+
+    if (c ^ fneg) {
+       return trueobjs.textOut (wiki);
+    } else {
+       return falseobjs.textOut (wiki);
+    }
+}
+
+ustring  WikiMotorObjSelect::htmlOut (WikiFormat* wiki) {
+    ustring  v = wiki->getVar (name);
+    ustring  val = value.textOut (wiki);
+    bool  c = (v == val);
+
+    if (c ^ fneg) {
+       return trueobjs.htmlOut (wiki);
+    } else {
+       return falseobjs.htmlOut (wiki);
+    }
 }
 
 ustring  WikiMotorObjSelect::dump () {
@@ -842,8 +861,8 @@ void  WikiMotor::compile (WikiMotorObjVec& out, int tmatch) {
                compile_text (out);
                return;
            }
-       } else if (sp.match (7)) { // |
-           if (tmatch & TMATCH_BAR) {
+       } else if (sp.match (7)) { // ||
+           if (tmatch & TMATCH_BAR2) {
                compile_text (out);
                return;
            }
@@ -902,10 +921,23 @@ void  WikiMotor::compile_text (WikiMotorObjVec& out) {
 }
 
 void  WikiMotor::compile_2 (WikiMotorObjVec& out) { // [[
-    if (sp.match (5)) {                // NAME:
-       compile_3 (out, ustring (sp.matchBegin (2), sp.matchEnd (2)));
+    if (sp.match (5)) {                // : | !? | ?
+       uiterator  b = sp.matchBegin (5);
+       switch (*b) {
+       case ':':               // NAME:
+           compile_3 (out, ustring (sp.matchBegin (2), sp.matchEnd (2)));
+           break;
+       case '?':               // NAME?
+           compile_6 (out, sp.matchBegin (2), sp.matchEnd (2), false);
+           break;
+       case '!':               // NAME!?
+           compile_6 (out, sp.matchBegin (2), sp.matchEnd (2), true);
+           break;
+       default:
+           assert (0);
+       }
     } else {
-       if (sp.match (4)) {
+       if (sp.match (4)) {     // / | ~ | , | ^
            uiterator  b = sp.matchBegin (4);
            switch (*b) {
            case '/':
@@ -1079,6 +1111,21 @@ void  WikiMotor::compile_5 (WikiMotorObjVec& out, int nchar) { // ''
     }
 }
 
+void  WikiMotor::compile_6 (WikiMotorObjVec& out, const uiterator& b, const uiterator& e, bool fneg) {         // [[NAME?
+    WikiMotorObjSelect*  obj = new WikiMotorObjSelect (b, e, fneg);
+
+    out.push_back (WikiMotorObjPtr (obj));
+    compile (obj->value, TMATCH_COLN | TMATCH_CKET);
+    if (sp.match (13)) {       // :
+       compile (obj->trueobjs, TMATCH_BAR2 | TMATCH_CKET);
+       if (sp.match (7)) {     // ||
+           compile (obj->falseobjs, TMATCH_CKET);
+       }
+    } else {
+       // syntax error
+    }
+}
+
 /* ============================================================ */
 void  join (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e, const ustring& ch, WikiMotorObjVec& ans) {
     WikiMotorObjVec*  v;
index 185e8bd..bad0f2b 100644 (file)
@@ -233,18 +233,19 @@ class  WikiMotorObjFuncM2: public WikiMotorObjFunc {
 
 class  WikiMotorObjSelect: public WikiMotorObj {
  public:
-    ustring  variable;
+    ustring  name;
     WikiMotorObjVec  value;
-    bool  fbang;
+    bool  fneg;
     WikiMotorObjVec  trueobjs;
     WikiMotorObjVec  falseobjs;
 
-    WikiMotorObjSelect (uiterator b, uiterator e, bool neg): WikiMotorObj (wiki_select) {
-       variable.assign (b, e);
-       fbang = neg;
+    WikiMotorObjSelect (uiterator b, uiterator e, bool _neg): WikiMotorObj (wiki_select) {
+       name.assign (b, e);
+       fneg = _neg;
     };
     virtual  ~WikiMotorObjSelect () {};
     virtual ustring  textOut (WikiFormat* wiki);
+    virtual ustring  htmlOut (WikiFormat* wiki);
     virtual ustring  dump ();
 };
 
@@ -256,7 +257,7 @@ class  WikiMotor {
     static const int TMATCH_COLN = 0x02;
     static const int TMATCH_SPC = 0x04;
     static const int TMATCH_QUOT = 0x08;
-    static const int TMATCH_BAR = 0x10;
+    static const int TMATCH_BAR2 = 0x10;
 
     WikiFormat*  wiki;
     Splitter  sp;
@@ -273,6 +274,7 @@ class  WikiMotor {
     virtual void  compile_3 (WikiMotorObjVec& out, const ustring& name);
     virtual bool  compile_4 (WikiMotorObjVec& out, const ustring& name);
     virtual void  compile_5 (WikiMotorObjVec& out, int nchar);
+    virtual void  compile_6 (WikiMotorObjVec& out, const uiterator& b, const uiterator& e, bool fneg);
 };
 
 void  join (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e, const ustring& ch, WikiMotorObjVec& ans);