[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/3.5/kdewebdev/kommander/widget
From: Eric Laffoon <sequitur () kde ! org>
Date: 2009-06-26 8:46:00
Message-ID: 1246005960.166010.16842.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 987510 by sequitur:
rudimentary 2D array support
M +8 -2 parsenode.h
M +176 -48 parser.cpp
M +14 -0 parser.h
M +1 -0 parserdata.cpp
--- branches/KDE/3.5/kdewebdev/kommander/widget/parsenode.h #987509:987510
@@ -23,8 +23,8 @@
{
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, LeftCurlyBrace, RightCurlyBrace, PlusEqual, MinusEqual, Increment, \
Decrement,
- Plus, Minus, Multiply, Divide, Mod, LastRealKeyword = Mod, Variable, Invalid};
+ 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};
enum KeywordGroup {GroupComparison, GroupAdd, GroupMultiply, GroupMisc};
enum ValueType {ValueString, ValueInt, ValueDouble, ValueValue = ValueDouble, \
ValueKeyword, @@ -74,8 +74,12 @@
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 */
@@ -100,6 +104,8 @@
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 */
--- branches/KDE/3.5/kdewebdev/kommander/widget/parser.cpp #987509:987510
@@ -218,6 +218,14 @@
if (tryKeyword(LeftBracket, CheckOnly))
{
QString index = parseValue(mode).toString();
+ if (tryKeyword(DoubleBracket, CheckOnly))
+ {//2D array "matrix"
+ //qDebug("Found double bracket: parseValue");
+ 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);
@@ -500,67 +508,131 @@
ParseNode Parser::parseAssignment(Mode mode)
{
QString var = nextVariable();
- //qDebug("var = "+var);
+ //qDebug("var = "+var+" Pos:"+QString::number(m_start));
if (tryKeyword(LeftBracket, CheckOnly))
{
QString index = parseValue(mode).toString();
- 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 (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))
{
- 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);
+ 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)
+ else if (p1.isKeyword(MinusEqual))
{
- if (p2.type() == ValueDouble)
- p = p2.toDouble() - p.toDouble();
- else
- p = p2.toInt() - p.toInt();
- setArray(var, index, p);
+ 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)
+ else if (p1.isKeyword(Increment))
{
- p2 = p2.toInt() + 1;
- setArray(var, index, p2);
+ tryKeyword(Increment);
+ if (mode == Execute)
+ {
+ p2 = p2.toInt() + 1;
+ setMatrix(var, index, index2, p2);
+ }
}
- }
- else if (p1.isKeyword(Decrement))
- {
- tryKeyword(Decrement);
- if (mode == Execute)
+ else if (p1.isKeyword(Decrement))
{
- p2 = p2.toInt() - 1;
- setArray(var, index, p2);
+ 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(Assign);
- ParseNode p = parseExpression(mode);
- if (mode == Execute)
- setArray(var, index, p);
+ 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))
@@ -1066,8 +1138,64 @@
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() && keyc.isNull())
+ m_globalMatrices.remove(name);
+ else if (isMatrix(name))
+ {
+ m_globalMatrices[name][keyr].remove(keyc);
+ m_globalMatrices[name].remove(keyr);
+ }
+ }
+ else
+ {
+ if (keyr.isNull() && keyc.isNull())
+ m_matrices.remove(name);
+ else if (isMatrix(name))
+ {
+ m_matrices[name][keyr].remove(keyc);
+ m_matrices[name].remove(keyr);
+ }
+ }
+}
+
+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
{
return m_widget;
@@ -1075,5 +1203,5 @@
QMap<QString, ParseNode> Parser::m_globalVariables;
QMap<QString, QMap<QString, ParseNode> > Parser::m_globalArrays;
+QMap<QString, QMap<QString, QMap<QString, ParseNode> > > Parser::m_globalMatrices;
-
--- branches/KDE/3.5/kdewebdev/kommander/widget/parser.h #987509:987510
@@ -68,6 +68,16 @@
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;
@@ -171,12 +181,16 @@
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
--- branches/KDE/3.5/kdewebdev/kommander/widget/parserdata.cpp #987509:987510
@@ -92,6 +92,7 @@
m_keywords["("] = LeftParenthesis;
m_keywords[")"] = RightParenthesis;
m_keywords["["] = LeftBracket;
+ m_keywords["]["] = DoubleBracket;
m_keywords["]"] = RightBracket;
m_keywords["+"] = Plus;
m_keywords["-"] = Minus;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic