[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeedu/kalgebra
From: Aleix Pol Gonzalez <aleixpol () gmail ! com>
Date: 2011-03-10 21:23:39
Message-ID: 20110310212340.0014CAC8C5 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1224430 by apol:
Add API to import module files from the Analyzer class.
M +21 -0 analitza/analyzer.cpp
M +5 -0 analitza/analyzer.h
M +8 -0 analitza/expression.cpp
M +3 -0 analitza/expression.h
M +2 -7 calgebra/main.cpp
M +2 -16 src/consolehtml.cpp
--- trunk/KDE/kdeedu/kalgebra/analitza/analyzer.cpp #1224429:1224430
@@ -101,6 +101,27 @@
}
}
+void Analyzer::importScript(QTextStream* stream)
+{
+ QString line;
+ while (isCorrect() && !stream->atEnd()) {
+ line += stream->readLine(); // line of text excluding '\n'
+
+ if(!line.isEmpty() && Expression::isCompleteExpression(line)) {
+ setExpression(Expression(line, Expression::isMathML(line)));
+
+ calculate();
+ line.clear();
+ }
+ }
+
+ if(!line.isEmpty()) {
+ setExpression(Expression(line, Expression::isMathML(line)));
+
+ calculate();
+ }
+}
+
Expression Analyzer::evaluate()
{
m_err.clear();
--- trunk/KDE/kdeedu/kalgebra/analitza/analyzer.h #1224429:1224430
@@ -26,6 +26,8 @@
#include "analitzaexport.h"
#include "expressiontype.h"
#include "builtinmethods.h"
+#include <analitza/explexer.h>
+#include <analitza/expressionparser.h>
#include <QStack>
namespace Analitza
@@ -140,6 +142,9 @@
void setStack(const QVector<Object*>& stack) { m_runStack = stack; }
BuiltinMethods* builtinMethods();
+
+ /** Makes it possible to easily enter a bunch of data to execute it */
+ void importScript(QTextStream* stream);
private:
Expression m_exp;
Variables *m_vars;
--- trunk/KDE/kdeedu/kalgebra/analitza/expression.cpp #1224429:1224430
@@ -775,3 +775,11 @@
print_dom(in.childNodes().item(i), ind+1);
}
}
+
+bool Expression::isCompleteExpression(const QString& exp)
+{
+ ExpLexer lex(exp);
+ while(lex.lex()!=0) {}
+
+ return lex.isCompletelyRead();
+}
--- trunk/KDE/kdeedu/kalgebra/analitza/expression.h #1224429:1224430
@@ -210,6 +210,9 @@
/** creates an expression filled with just a custom object */
static Expression constructCustomObject(const QVariant& custom);
+
+ /** @returns if a non-mathml expression is fully introduced (e.g. has closed all parentheses) */
+ static bool isCompleteExpression(const QString& exp);
private:
class ExpressionPrivate;
QSharedDataPointer<ExpressionPrivate> d;
--- trunk/KDE/kdeedu/kalgebra/calgebra/main.cpp #1224429:1224430
@@ -18,8 +18,6 @@
#include <analitza/expression.h>
#include <analitza/analyzer.h>
-#include <analitza/explexer.h>
-#include <analitza/expressionparser.h>
#include <readline/readline.h>
#include <readline/history.h>
@@ -117,11 +115,8 @@
add_history(expr);
entry+=QString(expr);
- ExpLexer lex(entry);
- ExpressionParser ex;
- ex.parse(&lex);
- if(lex.isCompletelyRead()) {
- Expression e(ex.mathML(), true);
+ if(Expression::isCompleteExpression(entry)) {
+ Expression e(entry, Expression::isMathML(entry));
// qDebug() << entry << e.toString();
calculate(e, configuration.calcType);
inside =false;
--- trunk/KDE/kdeedu/kalgebra/src/consolehtml.cpp #1224429:1224430
@@ -36,8 +36,6 @@
#include <kio/netaccess.h>
#include <kio/job.h>
-#include <analitza/explexer.h>
-#include <analitza/expressionparser.h>
#include <analitza/variables.h>
#include <analitza/expression.h>
@@ -190,22 +188,10 @@
if(file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream stream(&file);
- correct=true;
- QString line;
- while (correct && !stream.atEnd()) {
- line += stream.readLine(); // line of text excluding '\n'
-
- ExpLexer lex(line);
- ExpressionParser parser;
- parser.parse(&lex);
-
- if(!line.isEmpty() && lex.isCompletelyRead()) {
- correct &= addOperation(Analitza::Expression(line, Analitza::Expression::isMathML(line)), line);
- line.clear();
+ a.importScript(&stream);
+ correct=a.isCorrect();
}
- }
- }
if(!correct) {
m_htmlLog += i18n("<ul class='error'>Error: Could not load %1</ul>", path.prettyUrl());
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic