summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kommander/widget/functionlib.cpp506
-rw-r--r--kommander/widget/parsenode.cpp17
-rw-r--r--kommander/widget/parsenode.h10
-rw-r--r--kommander/widget/parser.cpp380
-rw-r--r--kommander/widget/parser.h16
-rw-r--r--kommander/widget/parserdata.cpp8
6 files changed, 27 insertions, 910 deletions
diff --git a/kommander/widget/functionlib.cpp b/kommander/widget/functionlib.cpp
index 3389d523..d763ff96 100644
--- a/kommander/widget/functionlib.cpp
+++ b/kommander/widget/functionlib.cpp
@@ -80,18 +80,6 @@ static ParseNode f_stringFindRev(Parser*, const ParameterList& params)
params.count() == 3 ? params[2].toInt() : params[0].toString().length());
}
-static ParseNode f_stringCount(Parser*, const ParameterList& params)
-{
- int c = 0;
- int s = 0;
- while (params[0].toString().find(params[1].toString(), s) > -1)
- {
- s = params[0].toString().find(params[1].toString(), s) + 1;
- c++;
- }
- return c;
-}
-
static ParseNode f_stringLeft(Parser*, const ParameterList& params)
{
return params[0].toString().left(params[1].toInt());
@@ -132,44 +120,6 @@ static ParseNode f_stringIsEmpty(Parser*, const ParameterList& params)
return params[0].toString().isEmpty();
}
-static ParseNode f_stringSort(Parser*, const ParameterList& params)
-{
- if (params.count() == 2 )
- {
- QStringList tmplst = QStringList::split(params[1].toString(), params[0].toString());
- tmplst.sort();
- return tmplst.join(params[1].toString());
- }
- else
- {
- QStringList tmplst = QStringList::split("\n", params[0].toString());
- tmplst.sort();
- return tmplst.join("\n");
- }
-}
-static ParseNode f_stringTrim(Parser*, const ParameterList& params)
-{
- return params[0].toString().stripWhiteSpace();
-}
-
-static ParseNode f_stringPadLeft(Parser*, const ParameterList& params)
-{
- if (params.count() == 2 )
- return params[0].toString().rightJustify(params[1].toInt(), ' ', false);
- QString s = params[2].toString();
- QChar ch = s.at(0);
- return params[0].toString().rightJustify(params[1].toInt(), ch, false);
-}
-
-static ParseNode f_stringPadRight(Parser*, const ParameterList& params)
-{
- if (params.count() == 2 )
- return params[0].toString().leftJustify(params[1].toInt(), ' ', false);
- QString s = params[2].toString();
- QChar ch = s.at(0);
- return params[0].toString().leftJustify(params[1].toInt(), ch, false);
-}
-
static ParseNode f_stringSection(Parser*, const ParameterList& params)
{
return params[0].toString().section(params[1].toString(), params[2].toInt(),
@@ -603,7 +553,7 @@ static ParseNode f_arrayValues(Parser* P, const ParameterList& params)
static ParseNode f_arrayRemove(Parser* P, const ParameterList& params)
{
- if (P->isArray(params[0].toString()))
+ if (!P->isArray(params[0].toString()))
P->unsetArray(params[0].toString(), params[1].toString());
return ParseNode();
}
@@ -747,427 +697,6 @@ static ParseNode f_arrayIndexedInsertElements(Parser* P, const ParameterList& pa
return ParseNode();
}
-static ParseNode f_arrayFlipCopy(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (!P->isArray(name))
- return ParseNode();
- QString arr = params[1].toString();
- const QMap<QString, ParseNode> A = P->array(name);
- for (QMapConstIterator<QString, ParseNode> It = A.begin(); It != A.end(); ++It )
- {
- P->setArray(arr, (*It).toString(), It.key() );
- }
- return ParseNode();
-}
-
-/*********** matrix (2D array) functions ********/
-static ParseNode f_matrixClear(Parser* P, const ParameterList& params)
-{
- P->unsetMatrix(params[0].toString());
- return ParseNode();
-}
-
-static ParseNode f_matrixToString(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (!P->isMatrix(name))
- return ParseNode();
- QString matrix;
- QString colhead;
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- int r = 0;
- int c = 0;
- int frow = 0;
- int fcol = 0;
- if (params.count() >= 1)
- frow = params[1].toInt(); //row headings
- if (params.count() >= 2)
- fcol = params[2].toInt(); //col headings
- QString tmp;
- typedef QMap<int, QString> col_map;
- col_map col_head;
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It1 = A.begin(); It1 != A.end(); ++It1 )
- {
- const QMap<QString, ParseNode> B = It1.data();
- for (QMapConstIterator<QString, ParseNode> It2 = B.begin(); It2 != B.end(); ++It2 )
- {
- bool colfound = false;
- for (QMapConstIterator<int, QString> It3 = col_head.begin(); It3 != col_head.end(); ++It3 )
- {
- if (It2.key() == (*It3))
- {
- colfound = true;
- break;
- }
- }
- if (!colfound)
- {
- col_head[c] = It2.key();
- if (c > 0)
- colhead.append("\t");
- colhead.append(It2.key());
- c++;
- }
- }
- }
- if (fcol && frow)
- colhead.prepend("\t");
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It1 = A.begin(); It1 != A.end(); ++It1)
- {
- if (r > 0 )
- matrix.append("\n");
- if (frow) //add row keys
- {
- tmp = It1.key();
- matrix.append(tmp+"\t");
- }
- c = 0;
- const QMap<int, QString> B = col_head;
- for (QMapConstIterator<int, QString> It2 = B.begin(); It2 != B.end(); ++It2 )
- {
- if (c > 0)
- matrix.append("\t");
- matrix.append(P->matrixValue(name, It1.key(), (*It2) ).toString());
- c++;
- }
- r++;
- }
- if (fcol)
- matrix.prepend(colhead+"\n");
- return matrix;
-}
-
-static ParseNode f_matrixFromString(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- QStringList rows = QStringList::split("\n", params[1].toString());
- int r = 0;
- int frow = 0;
- int fcol = 0;
- QString rkey;
- QMap<int, QString> colhead;
- if (params.count() > 1)
- frow = params[2].toInt(); //row headings
- if (params.count() > 2)
- fcol = params[3].toInt(); //col headings
- for (QStringList::Iterator itr = rows.begin(); itr != rows.end(); ++itr )
- {
- int c = 0;
- QString ckey;
- QStringList cols = QStringList::split("\t", (*itr), true);
- for (QStringList::Iterator itc = cols.begin(); itc != cols.end(); ++itc )
- {
- QString val = (*itc).stripWhiteSpace();
- if (frow)
- {
- if (c == 0 && !val.isEmpty())
- {
- rkey = val;
- }
- }
- else
- rkey = QString::number(r);
- if (fcol && r == 0 && c >= 0)
- {
- if (!val.isEmpty())
- colhead[c] = val;
- else
- colhead[c] = QString::number(c);
- }
- if (!val.isEmpty() && !(c == 0 && frow) && !(r == 0 && fcol))
- {
- if (fcol)
- ckey = colhead[c];
- else
- ckey = QString::number(c);
- P->setMatrix(name, rkey, ckey, val);
- }
- c++;
- }
- r++;
- }
- return ParseNode();
-}
-
-static ParseNode f_matrixRows(Parser* P, const ParameterList& params)
-{
- if (P->isMatrix(params[0].toString()))
- return (uint)(P->matrix(params[0].toString()).count());
- else
- return (uint)0;
-
-}
-
-static ParseNode f_matrixRowKeys(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (!P->isMatrix(name))
- return ParseNode();
- QString matrix;
- QString tmp;
- QString separator = "\t";
- if (params.count() == 2)
- separator = params[1].toString();
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- int r = 0;
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It1 = A.begin(); It1 != A.end(); ++It1)
- {
- if (r > 0 )
- matrix.append(separator);
- tmp = It1.key();
- matrix.append(tmp);
- r++;
- }
- return matrix;
-}
-
-static ParseNode f_matrixFindRow(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (!P->isMatrix(name))
- return ParseNode();
- QString col = params[1].toString();
- QString val = params[2].toString();
- QString tmp;
- int i = 0;
- int find;
- if (params.count() == 4)
- find = params[3].toInt();
- else
- find = 0;
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It = A.begin(); It != A.end(); ++It)
- {
- if (val == P->matrixValue(name, It.key(), col).toString())
- {
- if (find == i)
- return It.key();
- i++;
- }
- }
- return ParseNode();
-}
-
-static ParseNode f_matrixCols(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (P->isMatrix(name))
- {
- typedef QMap<int, QString> col_map;
- col_map col_head;
- uint cols = 0;
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It = A.begin(); It != A.end(); ++It)
- {
- const QMap<QString, ParseNode> B = It.data();
- for (QMapConstIterator<QString, ParseNode> It2 = B.begin(); It2 != B.end(); ++It2 )
- {
- bool colfound = false;
- for (QMapConstIterator<int, QString> It3 = col_head.begin(); It3 != col_head.end(); ++It3 )
- {
- if (It2.key() == (*It3))
- {
- colfound = true;
- break;
- }
- }
- if (!colfound)
- {
- col_head[cols] = It2.key();
- cols++;
- }
- }
- }
- return (uint)cols;
- }
- else
- return (uint)0;
-}
-
-static ParseNode f_matrixColumnKeys(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (!P->isMatrix(name))
- return ParseNode();
- QString matrix;
- QString tmp;
- QString separator = "\t";
- if (params.count() == 2)
- separator = params[1].toString();
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- QStringList colnames;
- int c =0;
-
- typedef QMap<int, QString> col_map;
- col_map col_head;
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It1 = A.begin(); It1 != A.end(); ++It1 )
- {
- const QMap<QString, ParseNode> B = It1.data();
- for (QMapConstIterator<QString, ParseNode> It2 = B.begin(); It2 != B.end(); ++It2 )
- {
- bool colfound = false;
- for (QMapConstIterator<int, QString> It3 = col_head.begin(); It3 != col_head.end(); ++It3 )
- {
- if (It2.key() == (*It3))
- {
- colfound = true;
- break;
- }
- }
- if (!colfound)
- {
- col_head[c] = It2.key();
- if (c > 0)
- matrix.append(separator);
- matrix.append(It2.key());
- c++;
- }
- }
- }
- return matrix;
-}
-
-static ParseNode f_matrixRowToArray(Parser* P, const ParameterList& params)
-{
- QString mtr = params[0].toString();
- if (P->isMatrix(mtr))
- {
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(mtr);
- int i = 0;
- int rclear = 1;
- int ridx = 1;
- if (params.count() > 2)
- rclear = params[3].toInt();
- if (params.count() > 3)
- ridx = params[4].toInt();
- QString arr = params[2].toString();
- if (rclear)
- P->unsetArray(arr);
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It1 = A.begin(); It1 != A.end(); ++It1)
- {
- if (It1.key() == params[1].toString() )
- {
- const QMap<QString, ParseNode> B = It1.data();
- for (QMapConstIterator<QString, ParseNode> It2 = B.begin(); It2 != B.end(); ++It2 )
- {
- if (ridx)
- P->setArray(arr, QString::number(i), (*It2));
- else
- P->setArray(arr, It2.key(), (*It2));
- i++;
- }
- }
- }
- }
- return ParseNode();
-}
-
-static ParseNode f_matrixColumnToArray(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (P->isMatrix(name))
- {
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It1 = A.begin(); It1 != A.end(); ++It1)
- {
- const QMap<QString, ParseNode> B = It1.data();
- for (QMapConstIterator<QString, ParseNode> It2 = B.begin(); It2 != B.end(); ++It2 )
- {
- if (It2.key() == params[1].toString() )
- {
- P->setArray(params[2].toString(), It1.key(), (*It2));
- }
- }
- }
- }
- return ParseNode();
-}
-
-static ParseNode f_matrixColumnToIndexedArray(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (P->isMatrix(name))
- {
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- int i = 0;
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It1 = A.begin(); It1 != A.end(); ++It1)
- {
- const QMap<QString, ParseNode> B = It1.data();
- for (QMapConstIterator<QString, ParseNode> It2 = B.begin(); It2 != B.end(); ++It2 )
- {
- if (It2.key() == params[1].toString() )
- {
- P->setArray(params[2].toString(), QString::number(i), (*It2));
- i++;
- }
- }
- }
- }
- return ParseNode();
-}
-
-static ParseNode f_matrixAddRow(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- QString rowkey = params[1].toString();
- QStringList rows = QStringList::split("\n", params[2].toString());
- for (QStringList::Iterator itr = rows.begin(); itr != rows.end(); ++itr )
- {
- QStringList cols = QStringList::split("\t", (*itr));
- if (cols.count() != 2 )
- continue;
- QStringList::Iterator itc = cols.begin();
- QString rkey = (*itc).stripWhiteSpace();
- ++itc;
- QString rval = (*itc).stripWhiteSpace();
- if (!rkey.isEmpty() && !rval.isEmpty())
- P->setMatrix(name, rowkey, rkey, rval);
- }
- return ParseNode();
-}
-
-static ParseNode f_matrixRemoveRow(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- if (!P->isMatrix(name))
- return ParseNode();
- QString rowkey = params[1].toString();
- int found = 0;
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- if (A.contains(rowkey))
- {
- P->unsetMatrix(name, rowkey);
- found = 1;
- }
- return QString::number(found);
-}
-/*
-static ParseNode f_matrixAddColumn(Parser* P, const ParameterList& params)
-{
-}
-*/
-static ParseNode f_matrixRemoveColumn(Parser* P, const ParameterList& params)
-{
- QString name = params[0].toString();
- QString colkey = params[1].toString();
- if (!P->isMatrix(name))
- return ParseNode();
- int found = 0;
- const QMap<QString, QMap<QString, ParseNode> > A = P->matrix(name);
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It = A.begin(); It != A.end(); ++It)
- {
- if (A[It.key()].contains(colkey))
- found = 1;
- P->unsetMatrix(name, It.key(), colkey);
- }
- return QString::number(found);
-}
-/*
-static ParseNode f_matrixIndexedCopy(Parser* P, const ParameterList& params)
-{
-}
-*/
/********** input functions *********************/
static ParseNode f_inputColor(Parser*, const ParameterList& params)
{
@@ -1264,7 +793,7 @@ static ParseNode f_message_info(Parser*, const ParameterList& params)
if (params.count() > 1)
caption = params[1].toString();
KMessageBox::information(0, text, caption);
- return 1;
+ return ParseNode();
}
static ParseNode f_message_error(Parser*, const ParameterList& params)
@@ -1275,7 +804,7 @@ static ParseNode f_message_error(Parser*, const ParameterList& params)
if (params.count() > 1)
caption = params[1].toString();
KMessageBox::error(0, text, caption);
- return 1;
+ return ParseNode();
}
static ParseNode f_message_warning(Parser*, const ParameterList& params)
@@ -1386,7 +915,6 @@ void ParserData::registerStandardFunctions()
registerFunction("str_find", Function(&f_stringFind, ValueInt, ValueString, ValueString, ValueInt, 2));
registerFunction("str_findrev", Function(&f_stringFindRev, ValueInt, ValueString, ValueString, ValueInt, 2));
registerFunction("str_left", Function(&f_stringLeft, ValueString, ValueString, ValueInt));
- registerFunction("str_count", Function(&f_stringCount, ValueInt, ValueString, ValueString));
registerFunction("str_right", Function(&f_stringRight, ValueString, ValueString, ValueInt));
registerFunction("str_mid", Function(&f_stringMid, ValueString, ValueString, ValueInt, ValueInt, 2));
registerFunction("str_remove", Function(&f_stringRemove, ValueString, ValueString, ValueString));
@@ -1400,10 +928,6 @@ void ParserData::registerStandardFunctions()
registerFunction("str_toint", Function(&f_stringToInt, ValueString, ValueInt, 1));
registerFunction("str_todouble", Function(&f_stringToDouble, ValueString, ValueDouble, 1));
registerFunction("str_round", Function(&f_stringRound, ValueInt, ValueDouble, ValueInt, 2));
- registerFunction("str_sort", Function(&f_stringSort, ValueString, ValueString, ValueString, 1, 2));
- registerFunction("str_trim", Function(&f_stringTrim, ValueString, ValueString, 1));
- registerFunction("str_padLeft", Function(&f_stringPadLeft, ValueString, ValueInt, ValueString, ValueString, 1, 2));
- registerFunction("str_padRight", Function(&f_stringPadRight, ValueString, ValueInt, ValueString, ValueString, 1, 2));
registerFunction("return", Function(&f_return, ValueNone, ValueString, 1, 1));
registerFunction("debug", Function(&f_debug, ValueNone, ValueString, 1, 100));
registerFunction("echo", Function(&f_echo, ValueNone, ValueString, 1, 100));
@@ -1439,35 +963,19 @@ void ParserData::registerStandardFunctions()
registerFunction("array_indexedRemoveElements", Function(&f_arrayIndexedRemoveElements, ValueNone, ValueString, ValueInt, ValueInt, 2 , 3));
registerFunction("array_indexedInsertElements", Function(&f_arrayIndexedInsertElements, ValueNone, ValueString, ValueInt, ValueString, ValueString, 3, 4));
registerFunction("array_remove", Function(&f_arrayRemove, ValueNone, ValueString, ValueString));
- registerFunction("matrix_fromString", Function(&f_matrixFromString, ValueNone, ValueString, ValueString, ValueInt, ValueInt, 2, 4));
- registerFunction("matrix_toString", Function(&f_matrixToString, ValueNone, ValueString, ValueInt, ValueInt, 1, 3));
- registerFunction("matrix_clear", Function(&f_matrixClear, ValueNone, ValueString));
- registerFunction("matrix_rows", Function(&f_matrixRows, ValueInt, ValueString));
- registerFunction("matrix_columns", Function(&f_matrixCols, ValueInt, ValueString));
- registerFunction("matrix_rowToArray", Function(&f_matrixRowToArray, ValueNone, ValueString, ValueInt, ValueString, ValueInt, ValueInt, 3, 5));
- registerFunction("matrix_columnToArray", Function(&f_matrixColumnToArray, ValueNone, ValueString, ValueString, ValueString, 3, 3));
- registerFunction("matrix_columnToIndexedArray", Function(&f_matrixColumnToIndexedArray, ValueNone, ValueString, ValueString, ValueString, 3, 3));
- registerFunction("array_flipCopy", Function(&f_arrayFlipCopy, ValueNone, ValueString, ValueString, 2, 2));
- registerFunction("matrix_rowKeys", Function(&f_matrixRowKeys, ValueString, ValueString, ValueString, 1, 2));
- registerFunction("matrix_columnKeys", Function(&f_matrixColumnKeys, ValueString, ValueString, ValueString, 1, 2));
- registerFunction("matrix_addRow", Function(&f_matrixAddRow, ValueNone, ValueString, ValueString, ValueString, 3, 3));
- registerFunction("matrix_removeRow", Function(&f_matrixRemoveRow, ValueInt, ValueString, ValueString, 2, 2));
- registerFunction("matrix_removeColumn", Function(&f_matrixRemoveColumn, ValueInt, ValueString, ValueString, 2, 2));
- registerFunction("matrix_findRow", Function(&f_matrixFindRow, ValueString, ValueString, ValueString, ValueString, 3, 4));
-
registerFunction("input_color", Function(&f_inputColor, ValueString, ValueString, 0));
registerFunction("input_text", Function(&f_inputText, ValueString, ValueString, ValueString, ValueString, 2));
registerFunction("input_password", Function(&f_inputPassword, ValueString, ValueString, ValueString, 1));
registerFunction("input_value", Function(&f_inputValue, ValueInt, ValueString, ValueString, ValueInt, ValueInt,
- ValueInt, ValueInt, 6));
+ ValueInt, ValueInt, 5));
registerFunction("input_double", Function(&f_inputValueDouble, ValueDouble, ValueString, ValueString, ValueDouble, ValueDouble,
- ValueDouble, ValueDouble, 6));
+ ValueDouble, ValueDouble, 5));
registerFunction("input_openfile", Function(&f_inputOpenFile, ValueString, ValueString, ValueString, ValueString, 0));
registerFunction("input_openfiles", Function(&f_inputOpenFiles, ValueString, ValueString, ValueString, ValueString, 0));
registerFunction("input_savefile", Function(&f_inputSaveFile, ValueString, ValueString, ValueString, ValueString, 0));
registerFunction("input_directory", Function(&f_inputDirectory, ValueString, ValueString, ValueString, 0));
- registerFunction("message_info", Function(&f_message_info, ValueInt, ValueString, ValueString, 1));
- registerFunction("message_error", Function(&f_message_error, ValueInt, ValueString, ValueString, 1));
+ registerFunction("message_info", Function(&f_message_info, ValueNone, ValueString, ValueString, 1));
+ registerFunction("message_error", Function(&f_message_error, ValueNone, ValueString, ValueString, 1));
registerFunction("message_warning", Function(&f_message_warning, ValueInt, ValueString, ValueString,
ValueString, ValueString, ValueString, 1));
registerFunction("message_question", Function(&f_message_question, ValueInt, ValueString, ValueString,
diff --git a/kommander/widget/parsenode.cpp b/kommander/widget/parsenode.cpp
index 09ad66a7..d080e114 100644
--- a/kommander/widget/parsenode.cpp
+++ b/kommander/widget/parsenode.cpp
@@ -120,21 +120,11 @@ bool ParseNode::isVariable() const
return type() == ValueKeyword && keyword() == Variable;
}
-bool ParseNode::isArray() const
-{
- return type() == ValueKeyword && keyword() == Array;
-}
-
QString ParseNode::variableName() const
{
return isVariable() ? m_string : QString();
}
-QString ParseNode::arrayName() const
-{
- return isArray() ? m_string : QString();
-}
-
QString ParseNode::errorMessage() const
{
return isValid() ? QString() : m_string;
@@ -238,13 +228,6 @@ void ParseNode::setVariable(const QString& name)
m_string = name;
}
-void ParseNode::setArray(const QString& name)
-{
- m_type = ValueKeyword;
- m_keyword = Array;
- m_string = name;
-}
-
bool ParseNode::isValue() const
{
return m_type <= ValueValue;
diff --git a/kommander/widget/parsenode.h b/kommander/widget/parsenode.h
index 305b0998..aa657d35 100644
--- a/kommander/widget/parsenode.h
+++ b/kommander/widget/parsenode.h
@@ -23,8 +23,8 @@ namespace Parse
{
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, DoubleBracket, RightBracket, LeftCurlyBrace, RightCurlyBrace, PlusEqual, MinusEqual, Increment, Decrement,
- Plus, Minus, Multiply, Divide, Mod, LastRealKeyword = Mod, Variable, Invalid, Array, Matrix, ArrKeyVal};
+ Not, And, Or, False, True, LeftParenthesis, RightParenthesis, LeftBracket, RightBracket,
+ Plus, Minus, Multiply, Divide, Mod, LastRealKeyword = Mod, Variable, Invalid};
enum KeywordGroup {GroupComparison, GroupAdd, GroupMultiply, GroupMisc};
enum ValueType {ValueString, ValueInt, ValueDouble, ValueValue = ValueDouble, ValueKeyword,
@@ -74,12 +74,8 @@ public:
bool isKeyword(Parse::Keyword k) const;
/* Check if current value is a variable */
bool isVariable() const;
- /* Check if current value is an Array */
- bool isArray() const;
/* Return the name of variable */
QString variableName() const;
- /* Return the name of array */
- QString arrayName() const;
/* Return error message if applicable */
QString errorMessage() const;
/* Calculate common type for two nodes */
@@ -104,8 +100,6 @@ public:
void setValue(const QString& s);
/* set value as variable */
void setVariable(const QString& name);
- /* set value as array */
- void setArray(const QString& name);
/* check if it is correct value */
bool isValue() const;
/* for setting some context information, f. e. for bug reporting */
diff --git a/kommander/widget/parser.cpp b/kommander/widget/parser.cpp
index 9bc9637b..1424d6c7 100644
--- a/kommander/widget/parser.cpp
+++ b/kommander/widget/parser.cpp
@@ -99,15 +99,6 @@ bool Parser::setString(const QString& s)
{
while (start < s.length() && s[start] != '\n')
start++;
- } // enable /* */ block comments
- else if (s[start] == '/' && start < s.length() +1 && s[start+1] == '*')
- {
- start += 2;
- while (start < s.length() +1 && !(s[start] == '*' && s[start+1] == '/'))
- {
- start++;
- }
- start += 2;
} // special keyword: <>
else if (m_data->stringToKeyword(s.mid(start, 2)) <= LastRealKeyword)
{
@@ -203,12 +194,10 @@ ParseNode Parser::parseConstant(Parse::Mode)
}
return p;
}
-//attempting to allow assign or copy of array, so far with no joy
+
ParseNode Parser::parseValue(Mode mode)
{
ParseNode p = next();
- //QString p2 = QString(p.toString());
- //qDebug("parseValue p2 = "+p2);
if (isFunction())
return parseFunction(mode);
else if (isWidget())
@@ -218,13 +207,6 @@ ParseNode Parser::parseValue(Mode mode)
if (tryKeyword(LeftBracket, CheckOnly))
{
QString index = parseValue(mode).toString();
- if (tryKeyword(DoubleBracket, CheckOnly))
- {//2D array "matrix"
- QString index2 = parseValue(mode).toString();
- tryKeyword(RightBracket);
- QString arr = p.variableName();
- return matrixValue(arr, index, index2);
- }
tryKeyword(RightBracket);
QString arr = p.variableName();
return arrayValue(arr, index);
@@ -260,11 +242,6 @@ ParseNode Parser::parseValue(Mode mode)
return ParseNode(0);
else if (tryKeyword(True, CheckOnly))
return ParseNode(1);
-/* else if (isArray(p2))
- {
- qDebug("returning array fpr p2");
- return p2;
- }*/
else if (p.isKeyword())
setError(i18n("Expected value"));
else // single value
@@ -434,7 +411,6 @@ ParseNode Parser::parseFunction(Mode mode)
{
int pos = m_start;
QString name = next().variableName();
- //qDebug("Parsing function: "+name);
Function f = m_data->function(name);
m_start++;
ParameterList params;
@@ -508,188 +484,20 @@ ParseNode Parser::parseWidget(Mode mode, const QString &widgetName)
ParseNode Parser::parseAssignment(Mode mode)
{
QString var = nextVariable();
- //qDebug("var = "+var+" Pos:"+QString::number(m_start));
if (tryKeyword(LeftBracket, CheckOnly))
{
QString index = parseValue(mode).toString();
- if (tryKeyword(DoubleBracket, CheckOnly))
- {//2D array "matrix"
- ParseNode p1 = next(); //move along...
- QString index2 = parseValue(mode).toString();
- tryKeyword(RightBracket);
- p1 = next();
- ParseNode p2 = matrixValue(var, index, index2);
- if (p1.isKeyword(PlusEqual))
- {
- tryKeyword(PlusEqual);
- ParseNode p = parseExpression(mode);
- if (mode == Execute)
- {
- 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();
- setMatrix(var, index, index2, p);
- }
- }
- else if (p1.isKeyword(MinusEqual))
- {
- tryKeyword(MinusEqual);
- ParseNode p = parseExpression(mode);
- if (mode == Execute)
- {
- if (p2.type() == ValueDouble)
- p = p2.toDouble() - p.toDouble();
- else
- p = p2.toInt() - p.toInt();
- setMatrix(var, index, index2, p);
- }
- }
- else if (p1.isKeyword(Increment))
- {
- tryKeyword(Increment);
- if (mode == Execute)
- {
- p2 = p2.toInt() + 1;
- setMatrix(var, index, index2, p2);
- }
- }
- else if (p1.isKeyword(Decrement))
- {
- tryKeyword(Decrement);
- if (mode == Execute)
- {
- p2 = p2.toInt() - 1;
- setMatrix(var, index, index2, p2);
- }
- }
- else
- {
- tryKeyword(Assign);
- ParseNode p = parseExpression(mode);
- if (mode == Execute)
- setMatrix(var, index, index2, p);
- }
- }
- else
- {
- tryKeyword(RightBracket);
- ParseNode p1 = next();
- // seems awkward and pedantic but array values are now handled like variables
- // for special assign with oparator
- ParseNode p2 = arrayValue(var, index);
- if (p1.isKeyword(PlusEqual))
- {
- tryKeyword(PlusEqual);
- ParseNode p = parseExpression(mode);
- if (mode == Execute)
- {
- 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();
- setArray(var, index, p);
- }
- }
- else if (p1.isKeyword(MinusEqual))
- {
- tryKeyword(MinusEqual);
- ParseNode p = parseExpression(mode);
- if (mode == Execute)
- {
- if (p2.type() == ValueDouble)
- p = p2.toDouble() - p.toDouble();
- else
- p = p2.toInt() - p.toInt();
- setArray(var, index, p);
- }
- }
- else if (p1.isKeyword(Increment))
- {
- tryKeyword(Increment);
- if (mode == Execute)
- {
- p2 = p2.toInt() + 1;
- setArray(var, index, p2);
- }
- }
- else if (p1.isKeyword(Decrement))
- {
- tryKeyword(Decrement);
- if (mode == Execute)
- {
- p2 = p2.toInt() - 1;
- setArray(var, index, p2);
- }
- }
- else
- {
- tryKeyword(Assign);
- ParseNode p = parseExpression(mode);
- if (mode == Execute)
- setArray(var, index, p);
- }
- }
- }
- else if (tryKeyword(Assign, CheckOnly))
- {
+ tryKeyword(RightBracket);
+ tryKeyword(Assign);
ParseNode p = parseExpression(mode);
if (mode == Execute)
- {
- setVariable(var, p);
- }
+ setArray(var, index, p);
}
- else if (tryKeyword(PlusEqual, CheckOnly))
+ else if (tryKeyword(Assign, 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(MinusEqual, CheckOnly))
- {
- ParseNode p = parseExpression(mode);
- if (mode == Execute)
- {
- ParseNode p2 = variable(var);
- if (p2.type() == ValueDouble)
- p = p2.toDouble() - p.toDouble();
- else
- p = p2.toInt() - p.toInt();
- setVariable(var, p);
- }
- }
- else if (tryKeyword(Increment, CheckOnly))
- {
- //ParseNode p = parseExpression(mode);
- if (mode == Execute)
- {
- ParseNode p = variable(var);
- p = p.toInt() + 1;
- setVariable(var, p);
- }
- }
- else if (tryKeyword(Decrement, CheckOnly))
- {
- //ParseNode p = parseExpression(mode);
- if (mode == Execute)
- {
- ParseNode p = variable(var);
- p = p.toInt() - 1;
- setVariable(var, p);
- }
}
else if (tryKeyword(Dot, CheckOnly))
{
@@ -721,14 +529,11 @@ Flow Parser::parseIf(Mode mode)
ParseNode p = next();
Flow flow = FlowStandard;
bool matched = false;
- bool thenFound = false;
do {
m_start++;
Mode m = matched ? CheckOnly : mode;
p = parseCondition(m);
- thenFound = tryKeyword(Then, CheckOnly);
- if (!thenFound)
- tryKeyword(LeftCurlyBrace);
+ tryKeyword(Then);
bool condition = !matched && p.toBool();
if (condition)
{
@@ -739,52 +544,29 @@ Flow Parser::parseIf(Mode mode)
else
parseBlock(CheckOnly);
matched = matched || p.toBool();
- if (!thenFound)
- tryKeyword(RightCurlyBrace);
- } while (nextElseIf() == true);
- bool braceFound = false;
+ } while (next().isKeyword(Elseif));
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;
}
-bool Parser::nextElseIf()
-{
- ParseNode p1 = next();
- if (p1.isKeyword(Elseif))
- return true;
- else
- {
- ParseNode p2 = next();
- if (p1.isKeyword(Else) && p2.isKeyword(If) )
- return true;
- }
- return false;
-}
-
Parse::Flow Parser::parseWhile(Mode mode)
{
m_start++;
int start = m_start;
bool running = true;
Parse::Flow flow = FlowStandard;
- bool doFound = false;
while (running)
{
m_start = start;
ParseNode p = parseCondition(mode);
- doFound = tryKeyword(Do, CheckOnly);
- if (!doFound && !tryKeyword(LeftCurlyBrace))
+ if (!tryKeyword(Do))
break;
running = p.toBool();
flow = parseBlock(running ? mode : CheckOnly);
@@ -793,10 +575,7 @@ Parse::Flow Parser::parseWhile(Mode mode)
}
if (flow != FlowExit)
{
- if (doFound)
- tryKeyword(End);
- else
- tryKeyword(RightCurlyBrace);
+ tryKeyword(End);
return FlowStandard;
}
else
@@ -814,13 +593,10 @@ Parse::Flow Parser::parseFor(Mode mode)
int step = 1;
if (tryKeyword(Step, CheckOnly))
step = parseExpression(mode).toInt();
-
- bool doFound = tryKeyword(Do, CheckOnly);
- if (!doFound)
- tryKeyword(LeftCurlyBrace);
+ tryKeyword(Do);
int block = m_start;
Parse::Flow flow = FlowStandard;
- if (end >= start && step > 0)
+ if (end >= start)
{
for (int i = start; i <= end; i+=step)
{
@@ -830,24 +606,11 @@ Parse::Flow Parser::parseFor(Mode mode)
if (flow == FlowBreak || flow == FlowExit)
break;
}
- } else if (end <= start && step < 0)
- {
- for (int i = start; i >= end; i+=step)
- {
- m_start = block;
- setVariable(var, ParseNode(i));
- flow = parseBlock(mode);
- if (flow == FlowBreak || flow == FlowExit)
- break;
- }
} else
parseBlock(Parse::CheckOnly);
if (flow != FlowExit)
{
- if (doFound)
- tryKeyword(End);
- else
- tryKeyword(RightCurlyBrace);
+ tryKeyword(End);
return FlowStandard;
}
else
@@ -858,22 +621,12 @@ Parse::Flow Parser::parseForeach(Mode mode)
{
m_start++;
QString var = nextVariable();
- QString var2 = "";
- bool matrixfound = tryKeyword(ArrKeyVal, CheckOnly);
- if (matrixfound == true)
- {
- m_start--;
- tryKeyword(ArrKeyVal);
- var2 = nextVariable();
- }
tryKeyword(In);
QString arr = nextVariable();
- bool doFound = tryKeyword(Do, CheckOnly);
- if (!doFound)
- tryKeyword(LeftCurlyBrace);
+ tryKeyword(Do);
int start = m_start;
Parse::Flow flow = FlowStandard;
- if (isArray(arr) && array(arr).count() && !matrixfound)
+ if (isArray(arr) && array(arr).count())
{
const QMap<QString, ParseNode> A = array(arr);
for (QMapConstIterator<QString, ParseNode> It = A.begin(); It != A.end(); ++It)
@@ -885,41 +638,11 @@ Parse::Flow Parser::parseForeach(Mode mode)
break;
}
}
- else if (isMatrix(arr) && matrix(arr).count() )
- {
- const QMap<QString, QMap<QString, ParseNode> > A = matrix(arr);
- for (QMapConstIterator<QString, QMap<QString, ParseNode> > It = A.begin(); It != A.end(); ++It)
- {
- m_start = start;
- setVariable(var, It.key());
- if (matrixfound == true)
- {
- const QMap<QString, ParseNode> B = It.data();
- for (QMapConstIterator<QString, ParseNode> It2 = B.begin(); It2 != B.end(); ++It2 )
- {
- m_start = start;
- setVariable(var2, It2.key());
- flow = parseBlock(mode);
- if (flow == FlowBreak || flow == FlowExit)
- break;
- }
- }
- else
- {
- flow = parseBlock(mode);
- if (flow == FlowBreak || flow == FlowExit)
- break;
- }
- }
- }
else
parseBlock(CheckOnly);
if (flow != FlowExit)
{
- if (doFound)
- tryKeyword(End);
- else
- tryKeyword(RightCurlyBrace);
+ tryKeyword(End);
return FlowStandard;
}
else
@@ -932,8 +655,6 @@ void Parser::parseSwitch(Mode mode)
QString var = nextVariable();
ParseNode caseValue = variable(var);
bool executed = false;
- bool braceFound = false;
- braceFound = tryKeyword(LeftCurlyBrace, CheckOnly);
tryKeyword(Semicolon, CheckOnly);
while (tryKeyword(Case, CheckOnly))
{
@@ -945,17 +666,12 @@ void Parser::parseSwitch(Mode mode)
}
if (tryKeyword(Else, CheckOnly))
parseBlock(executed ? CheckOnly : mode);
- if (!braceFound)
- tryKeyword(End);
- else
- tryKeyword(RightCurlyBrace);
+ tryKeyword(End);
}
Flow Parser::parseCommand(Mode mode)
{
ParseNode p = next();
- QString p2 = p.toString();
- //qDebug("Parsing command: "+p2);
if (next().isKeyword(If))
return parseIf(mode);
else if (next().isKeyword(While))
@@ -1024,7 +740,7 @@ bool Parser::tryKeyword(Keyword k, Mode mode)
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' got '%2'.").arg(m_data->keywordToString(k)).arg(next().toString()));
+ setError(i18n("Expected '%1'").arg(m_data->keywordToString(k)));
}
return false;
}
@@ -1170,66 +886,6 @@ ParseNode Parser::arrayValue(const QString& name, const QString& key) const
return m_arrays[name].contains(key) ? m_arrays[name][key] : ParseNode();
}
-// 2D arrays "Matrix"
-const QMap<QString, QMap<QString, ParseNode> >& Parser::matrix(const QString& name) const
-{
- if (isGlobal(name))
- return m_globalMatrices[name];
- else
- return m_matrices[name];
-}
-
-bool Parser::isMatrix(const QString& name) const
-{
- return m_matrices.contains(name) || m_globalMatrices.contains(name);
-}
-
-void Parser::setMatrix(const QString& name, const QString& keyr, const QString& keyc, ParseNode value)
-{
- if (isGlobal(name))
- m_globalMatrices[name][keyr][keyc] = value;
- else
- m_matrices[name][keyr][keyc] = value;
-}
-
-void Parser::unsetMatrix(const QString& name, const QString& keyr, const QString& keyc)
-{
- if (isGlobal(name))
- {
- if (keyr.isNull())
- m_globalMatrices.remove(name);
- else if (isMatrix(name))
- {
- if (keyc.isNull())
- m_globalMatrices[name].remove(keyr);
- else
- m_globalMatrices[name][keyr].remove(keyc);
- }
- }
- else
- {
- if (keyr.isNull())
- m_matrices.remove(name);
- else if (isMatrix(name))
- {
- if (keyc.isNull())
- m_matrices[name].remove(keyr);
- else
- m_matrices[name][keyr].remove(keyc);
- }
- }
-}
-
-ParseNode Parser::matrixValue(const QString& name, const QString& keyr, const QString& keyc) const
-{
- if (!isMatrix(name))
- return ParseNode();
- if (isGlobal(name))
- return m_globalMatrices[name].contains(keyr) && m_globalMatrices[name][keyr].contains(keyc) ? m_globalMatrices[name][keyr][keyc] : ParseNode();
- else
- return m_matrices[name].contains(keyr) && m_matrices[name][keyr].contains(keyc) ? m_matrices[name][keyr][keyc] : ParseNode();
-}
-
KommanderWidget* Parser::currentWidget() const
@@ -1239,5 +895,5 @@ KommanderWidget* Parser::currentWidget() const
QMap<QString, ParseNode> Parser::m_globalVariables;
QMap<QString, QMap<QString, ParseNode> > Parser::m_globalArrays;
-QMap<QString, QMap<QString, QMap<QString, ParseNode> > > Parser::m_globalMatrices;
+
diff --git a/kommander/widget/parser.h b/kommander/widget/parser.h
index cc7c6010..6dc66258 100644
--- a/kommander/widget/parser.h
+++ b/kommander/widget/parser.h
@@ -68,16 +68,6 @@ public:
void unsetArray(const QString& name, const QString& key = QString::null);
// array value
ParseNode arrayValue(const QString& name, const QString& key) const;
- // access 2D array
- const QMap<QString, QMap<QString, ParseNode> >& matrix(const QString& name) const;
- // check if this is name of a 2D array
- bool isMatrix(const QString& name) const;
- // set array key
- void setMatrix(const QString& name, const QString& keyr, const QString& keyc, ParseNode value);
- // unset array key or whole array
- void unsetMatrix(const QString& name, const QString& keyr = QString::null, const QString& keyc = QString::null);
- // array value
- ParseNode matrixValue(const QString& name, const QString& keyr, const QString& keyc) const;
// get associated widget
KommanderWidget* currentWidget() const;
@@ -143,8 +133,6 @@ private:
void insertNode(ParseNode p, int line);
// next item to be parsed
ParseNode next() const;
- // next is Else or Else && If?
- bool nextElseIf();
// check if next item is keyword k, if so - go further, if no, set error
bool tryKeyword(Parse::Keyword k, Parse::Mode mode = Parse::Execute);
// check if next item is a variable, if so, return its name
@@ -181,16 +169,12 @@ private:
QMap<QString, ParseNode> m_variables;
// arrays
QMap<QString, QMap<QString, ParseNode> > m_arrays;
- // 2D arrays
- QMap<QString, QMap<QString, QMap<QString, ParseNode> > > m_matrices;
// Kommander
KommanderWidget* m_widget;
// global variables
static QMap<QString, ParseNode> m_globalVariables;
// global arrays
static QMap<QString, QMap<QString, ParseNode> > m_globalArrays;
- // global 2D arrays
- static QMap<QString, QMap<QString, QMap<QString, ParseNode> > > m_globalMatrices;
};
#endif
diff --git a/kommander/widget/parserdata.cpp b/kommander/widget/parserdata.cpp
index 778be3d6..f803283e 100644
--- a/kommander/widget/parserdata.cpp
+++ b/kommander/widget/parserdata.cpp
@@ -59,8 +59,6 @@ ParserData::ParserData()
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;
@@ -92,19 +90,13 @@ ParserData::ParserData()
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;