File indexing completed on 2024-04-28 11:20:33

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2009-2012 Alexander Rieder <alexanderrieder@gmail.com>
0004 */
0005 
0006 #ifndef _MAXIMASESSION_H
0007 #define _MAXIMASESSION_H
0008 
0009 #include "session.h"
0010 #include "expression.h"
0011 #include <QProcess>
0012 #include <QRegularExpression>
0013 
0014 class MaximaExpression;
0015 class MaximaVariableModel;
0016 
0017 class MaximaSession : public Cantor::Session
0018 {
0019   Q_OBJECT
0020   public:
0021     static const QRegularExpression MaximaOutputPrompt;
0022     static const QRegularExpression MaximaInputPrompt;
0023 
0024     enum Mode {Maxima, Lisp};
0025 
0026     explicit MaximaSession(Cantor::Backend*);
0027 
0028     void login() override;
0029     void logout() override;
0030 
0031     Cantor::Expression* evaluateExpression(const QString& command, Cantor::Expression::FinishingBehavior behave = Cantor::Expression::FinishingBehavior::DoNotDelete, bool internal = false) override;
0032 
0033     void interrupt() override;
0034     void sendInputToProcess(const QString&);
0035 
0036     void setTypesettingEnabled(bool) override;
0037 
0038     Cantor::CompletionObject* completionFor(const QString& command, int index=-1) override;
0039     Cantor::SyntaxHelpObject* syntaxHelpFor(const QString& command) override;
0040     QSyntaxHighlighter* syntaxHighlighter(QObject*) override;
0041     void runFirstExpression() override;
0042 
0043     Mode mode() const;
0044     void setMode(Mode);
0045 
0046   public Q_SLOTS:
0047     void readStdOut();
0048     void readStdErr();
0049 
0050   private Q_SLOTS:
0051     void restartMaxima();
0052     void restartsCooledDown();
0053     void reportProcessError(QProcess::ProcessError);
0054 
0055   private:
0056     void write(const QString&);
0057 
0058     QProcess* m_process{nullptr};
0059     QString m_cache;
0060     bool m_justRestarted{false};
0061     Mode m_mode{Maxima};
0062 };
0063 
0064 #endif /* _MAXIMASESSION_H */