Commit 81f8a780 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

[Maxima backend] Port QRegExp to QRegularExpression

testmaxima unit test still passes, and a quick test by starting a maxima
session shows that syntax highlighting still works.
parent 12abee6a
......@@ -36,7 +36,7 @@
#include <KLocalizedString>
#include <QDebug>
#include <QTimer>
#include <QRegExp>
#include <QRegularExpression>
#include <QChar>
#include <QUrl>
......@@ -78,7 +78,9 @@ void MaximaExpression::evaluate()
|| command().startsWith(QLatin1String(":lisp(cl-info::info-exact")))
m_isHelpRequest=true;
if(command().contains(QRegExp(QLatin1String("(?:plot2d|plot3d|contour_plot)\\s*\\([^\\)]"))) && MaximaSettings::self()->integratePlots() && !command().contains(QLatin1String("ps_file")))
if (MaximaSettings::self()->integratePlots()
&& !command().contains(QLatin1String("ps_file"))
&& command().contains(QRegularExpression(QStringLiteral("(?:plot2d|plot3d|contour_plot)\\s*\\([^\\)]"))))
{
m_isPlot=true;
#ifdef WITH_EPS
......@@ -171,7 +173,8 @@ QString MaximaExpression::internalCommand()
const QString plotParameters = QLatin1String("[gnuplot_term, \"png size 500,340\"], [gnuplot_out_file, \"")+fileName+QLatin1String("\"]");
#endif
cmd.replace(QRegExp(QLatin1String("((plot2d|plot3d|contour_plot)\\s*\\(.*)\\)([;\n$]|$)")), QLatin1String("\\1, ")+plotParameters+QLatin1String(");"));
cmd.replace(QRegularExpression(QStringLiteral("((plot2d|plot3d|contour_plot)\\s*\\(.*)\\)([;\n$]|$)")),
QLatin1String("\\1, ") + plotParameters + QLatin1String(");"));
}
......@@ -190,7 +193,7 @@ QString MaximaExpression::internalCommand()
//lisp-quiet doesn't print a prompt after the command
//is completed, which causes the parsing to hang.
//replace the command with the non-quiet version
cmd.replace(QRegExp(QLatin1String("^:lisp-quiet")), QLatin1String(":lisp"));
cmd.replace(QRegularExpression(QStringLiteral("^:lisp-quiet")), QStringLiteral(":lisp"));
return cmd;
}
......@@ -273,7 +276,7 @@ bool MaximaExpression::parseOutput(QString& out)
else if(m_isHelpRequest || m_isHelpRequestAdditional) //help messages are also part of the error output
{
//we've got help result, but maybe additional input is required -> check this
const int index = MaximaSession::MaximaInputPrompt.indexIn(prompt.trimmed());
const int index = prompt.trimmed().indexOf(MaximaSession::MaximaInputPrompt);
if (index == -1) {
// No input label found in the prompt -> additional info is required
qDebug()<<"asking for additional input for the help request" << prompt;
......@@ -319,11 +322,11 @@ void MaximaExpression::parseResult(const QString& resultContent)
qDebug()<<"text content: " << textContent;
//output label can be a part of the text content -> determine it
const QRegExp regex = QRegExp(MaximaSession::MaximaOutputPrompt.pattern());
const int index = regex.indexIn(textContent);
const QRegularExpression regex = QRegularExpression(MaximaSession::MaximaOutputPrompt.pattern());
QRegularExpressionMatch match = regex.match(textContent);
QString outputLabel;
if (index != -1) // No match, so output don't contain output label
outputLabel = textContent.mid(index, regex.matchedLength()).trimmed();
if (match.hasMatch()) // a match is found, so the output contains output label
outputLabel = textContent.mid(match.capturedStart(0), match.capturedLength(0)).trimmed();
qDebug()<<"output label: " << outputLabel;
//extract the expression id
......
......@@ -40,8 +40,8 @@ MaximaHighlighter::MaximaHighlighter(QObject* parent, MaximaSession* session)
//addRule(QRegExp("\".*\""), stringFormat());
//addRule(QRegExp("'.*'"), stringFormat());
commentStartExpression = QRegExp(QLatin1String("/\\*"));
commentEndExpression = QRegExp(QLatin1String("\\*/"));
commentStartExpression = QRegularExpression(QStringLiteral("/\\*"));
commentEndExpression = QRegularExpression(QStringLiteral("\\*/"));
}
void MaximaHighlighter::highlightBlock(const QString& text)
......
......@@ -21,6 +21,8 @@
#ifndef _MAXIMAHIGHLIGHTER_H
#define _MAXIMAHIGHLIGHTER_H
#include <QRegularExpression>
#include "defaulthighlighter.h"
class MaximaSession;
......@@ -37,8 +39,8 @@ class MaximaHighlighter : public Cantor::DefaultHighlighter
QString nonSeparatingCharacters() const override;
private:
QRegExp commentStartExpression;
QRegExp commentEndExpression;
QRegularExpression commentStartExpression;
QRegularExpression commentEndExpression;
};
#endif /* _MAXIMAHIGHLIGHTER_H */
......@@ -44,8 +44,10 @@
//NOTE: the \\s in the expressions is needed, because Maxima seems to sometimes insert newlines/spaces between the letters
//maybe this is caused by some behaviour if the Prompt is split into multiple "readStdout" calls
//the Expressions are encapsulated in () to allow capturing for the text
const QRegExp MaximaSession::MaximaOutputPrompt=QRegExp(QLatin1String("(\\(\\s*%\\s*o\\s*[0-9\\s]*\\))")); //Text, maxima outputs, before any output
const QRegExp MaximaSession::MaximaInputPrompt = QRegExp(QLatin1String("(\\(\\s*%\\s*i\\s*[0-9\\s]*\\))"));
const QRegularExpression MaximaSession::MaximaOutputPrompt =
QRegularExpression(QStringLiteral("(\\(\\s*%\\s*o\\s*[0-9\\s]*\\))")); //Text, maxima outputs, before any output
const QRegularExpression MaximaSession::MaximaInputPrompt =
QRegularExpression(QStringLiteral("(\\(\\s*%\\s*i\\s*[0-9\\s]*\\))"));
MaximaSession::MaximaSession( Cantor::Backend* backend ) : Session(backend),
......
......@@ -24,6 +24,7 @@
#include "session.h"
#include "expression.h"
#include <QProcess>
#include <QRegularExpression>
class MaximaExpression;
class MaximaVariableModel;
......@@ -32,8 +33,8 @@ class MaximaSession : public Cantor::Session
{
Q_OBJECT
public:
static const QRegExp MaximaOutputPrompt;
static const QRegExp MaximaInputPrompt;
static const QRegularExpression MaximaOutputPrompt;
static const QRegularExpression MaximaInputPrompt;
explicit MaximaSession( Cantor::Backend* backend);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment