[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/3.5/kdewebdev
From:       Eric Laffoon <sequitur () kde ! org>
Date:       2009-02-20 0:06:01
Message-ID: 1235088361.338800.21504.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 928742 by sequitur:

back ported the new parser features from HEAD
new += for text and numbers
new { } for loops and if statements

 M  +1 -2      AUTHORS  
 M  +1 -1      kommander/widget/parsenode.h  
 M  +49 -8     kommander/widget/parser.cpp  
 M  +3 -0      kommander/widget/parserdata.cpp  


--- branches/KDE/3.5/kdewebdev/AUTHORS #928741:928742
@@ -12,8 +12,7 @@
       Nicolas Deschildre <ndeschildre@kdewebdev.org>
       Paulo Moura Guedes <moura@kdewebdev.org>
 
-    Home page:  http://quanta.sourceforge.net/
-    Download:   http://sourceforge.net/projects/quanta
+    Home page:  http://kdewebdev.org
     Bug form:   http://bugs.kde.org
 
 Kommander (kommander):
--- branches/KDE/3.5/kdewebdev/kommander/widget/parsenode.h #928741:928742
@@ -23,7 +23,7 @@
 {
   enum Keyword {For, To, Step, End, While, Do, Foreach, In, If, Then, Else, Elseif, \
                Endif, Switch, Case, 
     Break, Continue, Exit, Dot, Semicolon, Comma, Assign, Less, LessEqual, Greater, \
                GreaterEqual, Equal, NotEqual, 
-    Not, And, Or, False, True, LeftParenthesis, RightParenthesis, LeftBracket, \
RightBracket, +    Not, And, Or, False, True, LeftParenthesis, RightParenthesis, \
                LeftBracket, RightBracket, LeftCurlyBrace, RightCurlyBrace, \
                PlusEqual,
     Plus, Minus, Multiply, Divide, Mod, LastRealKeyword = Mod, Variable, Invalid};
 
   enum KeywordGroup {GroupComparison, GroupAdd, GroupMultiply, GroupMisc};
--- branches/KDE/3.5/kdewebdev/kommander/widget/parser.cpp #928741:928742
@@ -499,6 +499,21 @@
     if (mode == Execute)
       setVariable(var, p);
   }
+  else if (tryKeyword(PlusEqual, CheckOnly))
+  {
+    ParseNode p = parseExpression(mode);
+    if (mode == Execute)
+    {
+      ParseNode p2 = variable(var);
+      if (p2.type() == ValueString)
+        p = QString(p2.toString() + p.toString());
+      else if (p2.type() == ValueDouble)
+        p = p2.toDouble() + p.toDouble();
+      else
+        p = p2.toInt() + p.toInt();
+      setVariable(var, p);
+    }
+  }
   else if (tryKeyword(Dot, CheckOnly))
   {
     QString value = variable(var).toString();
@@ -529,11 +544,14 @@
   ParseNode p = next();
   Flow flow = FlowStandard;
   bool matched = false;
+  bool thenFound = false;
   do {
     m_start++;
     Mode m = matched ? CheckOnly : mode;
     p = parseCondition(m);
-    tryKeyword(Then);
+    thenFound = tryKeyword(Then, CheckOnly);
+    if (!thenFound)
+      tryKeyword(LeftCurlyBrace);
     bool condition = !matched && p.toBool();
     if (condition)
     {
@@ -544,14 +562,21 @@
     else 
       parseBlock(CheckOnly);
     matched = matched || p.toBool();
+    if (!thenFound)
+      tryKeyword(RightCurlyBrace);
   } while (next().isKeyword(Elseif));
+  bool braceFound = false;
   if (tryKeyword(Else, CheckOnly))
   {
+    braceFound = tryKeyword(LeftCurlyBrace, CheckOnly);
     if (!matched)
       flow = parseBlock(mode);
     else
       parseBlock(CheckOnly);
   }
+  if (braceFound)
+    tryKeyword(RightCurlyBrace);
+  if (thenFound)
   tryKeyword(Endif);
   return flow;
 }
@@ -562,11 +587,13 @@
   int start = m_start;
   bool running = true;
   Parse::Flow flow = FlowStandard;
+  bool doFound = false;
   while (running)
   {
     m_start = start;
     ParseNode p = parseCondition(mode);
-    if (!tryKeyword(Do))
+    doFound = tryKeyword(Do, CheckOnly);
+    if (!doFound && !tryKeyword(LeftCurlyBrace))
       break;
     running = p.toBool();
     flow = parseBlock(running ? mode : CheckOnly);
@@ -575,7 +602,10 @@
   }
   if (flow != FlowExit)
   {
-    tryKeyword(End);
+    if (doFound)
+      tryKeyword(End);
+    else
+      tryKeyword(RightCurlyBrace);
     return FlowStandard;
   }
   else 
@@ -593,7 +623,10 @@
   int step = 1;
   if (tryKeyword(Step, CheckOnly))
     step = parseExpression(mode).toInt();
-  tryKeyword(Do);
+
+  bool doFound = tryKeyword(Do, CheckOnly);
+  if (!doFound)
+    tryKeyword(LeftCurlyBrace);
   int block = m_start;
   Parse::Flow flow = FlowStandard;
   if (end >= start)
@@ -610,7 +643,10 @@
     parseBlock(Parse::CheckOnly);
   if (flow != FlowExit)
   {
-    tryKeyword(End);
+    if (doFound)
+      tryKeyword(End);
+    else
+      tryKeyword(RightCurlyBrace);
     return FlowStandard;
   }
   else 
@@ -623,7 +659,9 @@
   QString var = nextVariable();
   tryKeyword(In);
   QString arr = nextVariable();
-  tryKeyword(Do);
+  bool doFound = tryKeyword(Do, CheckOnly);
+  if (!doFound)
+    tryKeyword(LeftCurlyBrace);
   int start = m_start;
   Parse::Flow flow = FlowStandard;
   if (isArray(arr) && array(arr).count())
@@ -642,7 +680,10 @@
     parseBlock(CheckOnly);
   if (flow != FlowExit)
   {
-    tryKeyword(End);
+    if (doFound)
+      tryKeyword(End);
+    else
+      tryKeyword(RightCurlyBrace);
     return FlowStandard;
   }
   else 
@@ -740,7 +781,7 @@
     if (k == Dot)
       setError(i18n("Expected '%1'<br><br>Possible cause of the error is having a \
variable with the same name as a widget").arg(m_data->keywordToString(k)));  else
-     setError(i18n("Expected '%1'").arg(m_data->keywordToString(k)));
+     setError(i18n("Expected '%1' got \
'%2'.").arg(m_data->keywordToString(k)).arg(next().toString()));  }
   return false;
 }
--- branches/KDE/3.5/kdewebdev/kommander/widget/parserdata.cpp #928741:928742
@@ -59,6 +59,8 @@
   m_keywords["else"] =  Else;
   m_keywords["elseif"] =  Elseif;
   m_keywords["endif"] =  Endif;
+  m_keywords["{"] = LeftCurlyBrace;
+  m_keywords["}"] = RightCurlyBrace;
   m_keywords["switch"] =  Switch;
   m_keywords["case"] =  Case;
   m_keywords["while"] =  While;
@@ -96,6 +98,7 @@
   m_keywords["*"] = Multiply;
   m_keywords["/"] = Divide;
   m_keywords["%"] = Mod;
+  m_keywords["+="] = PlusEqual;
   m_keywords["mod"] = Mod;
   
   m_groups[Less] = GroupComparison;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic