summaryrefslogtreecommitdiffstats
path: root/kommander/widget/parserdata.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite9ae80694875f869892f13f4fcaf1170a00dea41 (patch)
treeaa2f8d8a217e2d376224c8d46b7397b68d35de2d /kommander/widget/parserdata.cpp
downloadtdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.tar.gz
tdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kommander/widget/parserdata.cpp')
-rw-r--r--kommander/widget/parserdata.cpp134
1 files changed, 134 insertions, 0 deletions
diff --git a/kommander/widget/parserdata.cpp b/kommander/widget/parserdata.cpp
new file mode 100644
index 00000000..778be3d6
--- /dev/null
+++ b/kommander/widget/parserdata.cpp
@@ -0,0 +1,134 @@
+/***************************************************************************
+ parserdata.cpp - Parser data: keywords, functions etc.
+ -------------------
+ copyright : (C) 2004 Michal Rudolf <[email protected]>
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "parserdata.h"
+using namespace Parse;
+
+KeywordGroup ParserData::keywordGroup(Keyword k) const
+{
+ if (m_groups.contains(k))
+ return m_groups[k];
+ else
+ return GroupMisc;
+}
+
+Keyword ParserData::stringToKeyword(const QString& s) const
+{
+ QString k = s.lower();
+ if (m_keywords.contains(k))
+ return m_keywords[k];
+ else
+ return Variable;
+}
+
+QString ParserData::keywordToString(Parse::Keyword k) const
+{
+ for (QMapConstIterator<QString, Keyword> it = m_keywords.begin(); it != m_keywords.end(); ++it)
+ if (it.data() == k)
+ return it.key();
+ return QString();
+}
+
+bool ParserData::registerFunction(const QString& name, Function f)
+{
+ m_functions[name.lower()] = f;
+ return true;
+}
+
+ParserData::ParserData()
+{
+ m_keywords["for"] = For;
+ m_keywords["foreach"] = Foreach;
+ m_keywords["in"] = In;
+ m_keywords["end"] = End;
+ m_keywords["if"] = If;
+ m_keywords["then"] = Then;
+ 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;
+ m_keywords["to"] = To;
+ m_keywords["step"] = Step;
+ m_keywords["do"] = Do;
+ m_keywords["break"] = Break;
+ m_keywords["continue"] = Continue;
+ m_keywords["exit"] = Exit;
+ m_keywords["."] = Dot;
+ m_keywords[";"] = Semicolon;
+ m_keywords[","] = Comma;
+ m_keywords["="] = Assign;
+ m_keywords["<"] = Less;
+ m_keywords["<="] = LessEqual;
+ m_keywords[">"] = Greater;
+ m_keywords[">="] = GreaterEqual;
+ m_keywords["=="] = Equal;
+ m_keywords["!="] = NotEqual;
+ m_keywords["<>"] = NotEqual;
+ m_keywords["not"] = Not;
+ m_keywords["!"] = Not;
+ m_keywords["and"] = And;
+ m_keywords["&&"] = And;
+ m_keywords["or"] = Or;
+ m_keywords["||"] = Or;
+ m_keywords["false"] = False;
+ m_keywords["true"] = True;
+ m_keywords["("] = LeftParenthesis;
+ m_keywords[")"] = RightParenthesis;
+ m_keywords["["] = LeftBracket;
+ m_keywords["]["] = DoubleBracket;
+ m_keywords["]"] = RightBracket;
+ m_keywords["+"] = Plus;
+ m_keywords["-"] = Minus;
+ m_keywords["*"] = Multiply;
+ m_keywords["/"] = Divide;
+ m_keywords["%"] = Mod;
+ m_keywords["+="] = PlusEqual;
+ m_keywords["-="] = MinusEqual;
+ m_keywords["++"] = Increment;
+ m_keywords["--"] = Decrement;
+ m_keywords["mod"] = Mod;
+ m_keywords["with"] = ArrKeyVal;
+
+ m_groups[Less] = GroupComparison;
+ m_groups[LessEqual] = GroupComparison;
+ m_groups[Equal] = GroupComparison;
+ m_groups[NotEqual] = GroupComparison;
+ m_groups[Greater] = GroupComparison;
+ m_groups[GreaterEqual] = GroupComparison;
+
+ m_groups[Plus] = GroupAdd;
+ m_groups[Minus] = GroupAdd;
+ m_groups[Multiply] = GroupMultiply;
+ m_groups[Divide] = GroupMultiply;
+ m_groups[Mod] = GroupMultiply;
+
+ registerStandardFunctions();
+}
+
+bool ParserData::isFunction(const QString& name) const
+{
+ return m_functions.contains(name.lower());
+}
+
+const Function& ParserData::function(const QString& name) const
+{
+ return m_functions[name.lower()];
+}
+