File indexing completed on 2022-12-06 13:08:26

0001 /*
0002     SPDX-FileCopyrightText: 2003-2006 Cies Breijs <cies AT kde DOT nl>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 
0008 #ifndef _INTERPRETER_H_
0009 #define _INTERPRETER_H_
0010 
0011 #include <QStringList>
0012 
0013 #include "errormsg.h"
0014 #include "executer.h"
0015 #include "parser.h"
0016 #include "tokenizer.h"
0017 #include "translator.h"
0018 #include "treenode.h"
0019 
0020 
0021 /**
0022  * @short Step-wise interpreter for KTurtle code.
0023  *
0024  * This class handles the interpreting of KTurtle code.
0025  * It does so in a few steps:
0026  * 1. @TODO 
0027  *
0028  * @author Cies Breijs
0029  */
0030 class Interpreter : public QObject
0031 {
0032     Q_OBJECT
0033     Q_CLASSINFO("D-Bus Interface", "org.kde.kturtle.Interpreter")
0034 
0035     public:
0036         /**
0037          * Default Constructor
0038          */
0039         Interpreter(QObject* parent, bool testing);
0040 
0041         /**
0042          * Default Destructor
0043          */
0044         ~Interpreter() override;
0045 
0046         enum State {
0047             Uninitialized, // unusable
0048             Initialized,   // ready to interpret something
0049             Parsing,       // parsing the code string to a tree
0050             Executing,     // executing the tree
0051             Finished,      // successfully finished executing
0052             Aborted        // unsuccessfully finished
0053         };
0054 
0055         void        abort() { m_state = Aborted; }
0056 
0057         Executer*   getExecuter() { return executer; }
0058         ErrorList*  getErrorList() { return errorList; }
0059 
0060     public Q_SLOTS:
0061         void        interpret();
0062         int         state() { return m_state; }
0063         void        initialize(const QString& inputString);  // resets
0064         bool        encounteredErrors() { return errorList->count() > 0; }
0065         QStringList getErrorStrings() { return errorList->asStringList(); }
0066 
0067     Q_SIGNALS:
0068         void parsing();
0069         void executing();
0070         void finished();
0071         
0072         void treeUpdated(TreeNode* rootNode);
0073 
0074     private:
0075         int            m_state;
0076 
0077         Translator    *translator;
0078         Tokenizer     *tokenizer;
0079         Parser        *parser;
0080         Executer      *executer;
0081 
0082         ErrorList     *errorList;
0083 
0084         bool           m_testing;
0085 };
0086 
0087 #endif  // _INTERPRETER_H_