Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ScriptEngine.h
Go to the documentation of this file.
1#pragma once
2
3#include "../global.h"
4#include "ScriptObject.h"
5#include "TStrings.h"
6
7namespace sf
8{
9
14{
15 public:
20
98
102 bool calculate(const std::string& script, Value& result);
103
107 [[nodiscard]] EArithError getError() const
108 {
109 return _errorValue;
110 }
111
115 [[nodiscard]] std::string getErrorReason() const;
116
120 bool setError(EArithError error_value, const std::string& reason = std::string());
121
127 [[nodiscard]] const char* getErrorText(EArithError error_value = EArithError::aeCurrent) const;
128
132 [[nodiscard]] pos_type getPos() const
133 {
134 return _pos;
135 }
136
140 [[nodiscard]] virtual strings getInfoNames() const;
141
148 [[nodiscard]] const IdInfo* getInfo(const std::string& name) const override;
149
155 [[nodiscard]] virtual strings getIdentifiers(EIdentifier id) const;
156
157 protected:
163 bool getSetValue(const IdInfo* info, Value* value, Value::vector_type* params, bool flag_set) override;
164
168 bool isAlpha(char ch);
169
170 private:
174 void destroyObject(bool& should_delete) override
175 {
176 should_delete = false;
177 }
178
182 struct DataCode
183 {
184 explicit DataCode(ScriptObject* object)
185 {
186 Clear(object);
187 }
188
189 void Clear(ScriptObject* object)
190 {
191 _info = nullptr;
192 _object = object;
193 }
194
195 explicit operator bool() const
196 {
197 return _info && _object;
198 }
199
200 const IdInfo* _info{nullptr};
201
202 ScriptObject* _object{nullptr};
203 };
204
208 void eatWhite();
209
213 void getNumber(Value& d);
214
218 bool getName(std::string& name);
219
223 bool getParameter(Value& result);
224
228 bool arith(Value& result, DataCode& left);
229
233 bool partial(Value& result);
234
239 bool operator_(Value& result, DataCode& left);
240
244 pos_type _pos{0};
248 const char* _cmd{};
252 EArithError _errorValue{aeSuccess};
256 std::string _errorReason;
260 static IdInfo _idInfo[];
261};
262
269_MISC_FUNC Value calculator(const std::string& script, const Value& def);
270
277_MISC_FUNC Value::flt_type calculator(const std::string& script, Value::flt_type def);
278
290
291}// namespace sf
Simple script engine able.
Definition ScriptEngine.h:14
virtual strings getInfoNames() const
Gets names of info structures in lines.
bool setError(EArithError error_value, const std::string &reason=std::string())
Sets the error value for this instance.
const char * getErrorText(EArithError error_value=EArithError::aeCurrent) const
bool getSetValue(const IdInfo *info, Value *value, Value::vector_type *params, bool flag_set) override
Gets and sets a value using a returned Info structure.
bool isAlpha(char ch)
Determines if the passed character is an alpha one.
virtual strings getIdentifiers(EIdentifier id) const
Gets a list of available identifiers.
EArithError getError() const
Gets the error value of this instance.
Definition ScriptEngine.h:107
EArithError
Errors when compiling a script.
Definition ScriptEngine.h:25
@ aeNotObject
Definition ScriptEngine.h:93
@ aeUnexpectedEnd
Definition ScriptEngine.h:34
@ aeExpectedRightParenthesis
Definition ScriptEngine.h:41
@ aeScriptTimeout
Definition ScriptEngine.h:87
@ aeExpectedIdentifier
Definition ScriptEngine.h:49
@ aeExpectedDelimiter
Definition ScriptEngine.h:45
@ aeMaxIdentifierLength
Definition ScriptEngine.h:67
@ aeNotLValue
Definition ScriptEngine.h:91
@ aeUnknownObjectMember
Definition ScriptEngine.h:62
@ aeLabelNotFound
Definition ScriptEngine.h:81
@ aeExpectedLeftParenthesis
Definition ScriptEngine.h:43
@ aeExpectedFunction
Definition ScriptEngine.h:47
@ aeIpStack
Definition ScriptEngine.h:83
@ aeTooManyParameters
Definition ScriptEngine.h:70
@ aeUnknownConstant
Definition ScriptEngine.h:54
@ aeUnknownSymbol
Definition ScriptEngine.h:58
@ aeTooFewParameters
Definition ScriptEngine.h:72
@ aeAssignConstant
Definition ScriptEngine.h:65
@ aeUnknownVariable
Definition ScriptEngine.h:56
@ aeDivisionByZero
Definition ScriptEngine.h:79
@ aeFunctionError
Definition ScriptEngine.h:89
@ aeStringTooLong
Definition ScriptEngine.h:31
@ aeUnknownFunction
Definition ScriptEngine.h:52
@ aeMultipleDeclaration
Definition ScriptEngine.h:75
@ aeUnexpectedIdentifier
Definition ScriptEngine.h:38
@ aeUnknownIdentifier
Definition ScriptEngine.h:60
@ aeUnexpectedKeyword
Definition ScriptEngine.h:77
@ aeExternalKeyword
Definition ScriptEngine.h:85
@ aeUnexpectedCharacter
Definition ScriptEngine.h:36
std::string getErrorReason() const
Gets the associated error reason string.
const IdInfo * getInfo(const std::string &name) const override
Functions to be overloaded in derived classes to add functions, parameters, constants and keywords.
pos_type getPos() const
Gets the current position.
Definition ScriptEngine.h:132
ScriptEngine()
Default constructor.
bool calculate(const std::string &script, Value &result)
Calculates the passed script.
Info structure for objects used in scripts.
Definition ScriptObject.h:15
EIdentifier
Keyword identifiers.
Definition ScriptObject.h:42
std::string::size_type pos_type
Source position type.
Definition ScriptObject.h:33
Counted vector of strings.
Definition TStrings.h:13
Counted vector having additional methods and operators for ease of usage.
Definition TVector.h:28
Value container class able to performing arithmetic functions.
Definition Value.h:19
double flt_type
Type used internally for storing floating point value.
Definition Value.h:28
#define _MISC_FUNC
Definition misc/global.h:34
#define _MISC_CLASS
Definition misc/global.h:35
Definition CodeEditor.h:8
Value calculator(const std::string &script, const Value &def)
Calculator function that converts a formula of the passed string to a #sf::Value.
Used to create static lookup lists.
Definition ScriptObject.h:61