Sat, 22 Aug 2015 13:04:58 +0300
Commit work on scripting
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/functions.cpp Sat Aug 22 13:04:58 2015 +0300 @@ -0,0 +1,1 @@ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/functions.h Sat Aug 22 13:04:58 2015 +0300 @@ -0,0 +1,24 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +namespace Script +{ + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/object.cpp Sat Aug 22 13:04:58 2015 +0300 @@ -0,0 +1,6 @@ +#include "object.h" + +Script::Object::Object() +{ + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/object.h Sat Aug 22 13:04:58 2015 +0300 @@ -0,0 +1,41 @@ +#pragma once +#include "../main.h" +#include "objtype.h" + +namespace Script +{ + using ObjectPointer = QSharedPointer<class Object>; + + class Object + { + public: + Object(); + + private: + ObjectType m_type; + }; + + class IntObject : public Object + { + private: + qint32 m_value; + }; + + class RealObject : public Object + { + private: + qreal m_value; + }; + + class StringObject : public Object + { + private: + QString m_value; + }; + + class ContainerObject : public Object + { + private: + QList<ObjectPointer> m_elements; + } +}
--- a/src/script/objtype.cpp Tue Feb 03 15:30:30 2015 +0200 +++ b/src/script/objtype.cpp Sat Aug 22 13:04:58 2015 +0300 @@ -19,7 +19,7 @@ #include "objtype.h" -Script::Type::Type() {} +Script::ObjectType::ObjectType() {} QString Script::ContainerType::asString() const {
--- a/src/script/objtype.h Tue Feb 03 15:30:30 2015 +0200 +++ b/src/script/objtype.h Sat Aug 22 13:04:58 2015 +0300 @@ -21,14 +21,14 @@ namespace Script { - class Type + class ObjectType { public: - Type(); + ObjectType(); virtual QString asString() const = 0; }; - class BasicType : public Type + class BasicType : public ObjectType { public: enum Kind @@ -48,7 +48,7 @@ Kind m_kind; }; - class ContainerType : public Type + class ContainerType : public ObjectType { public: enum Kind @@ -65,11 +65,11 @@ Kind kind() const { return m_kind; } int n1() const { return m_n1; } int n2() const { return m_n1; } - QSharedPointer<Type> elementType() const { return m_elementType; } + QSharedPointer<ObjectType> elementType() const { return m_elementType; } private: Kind m_kind; - QSharedPointer<Type> m_elementType; + QSharedPointer<ObjectType> m_elementType; int m_n1; int m_n2; };
--- a/src/script/parser.cpp Tue Feb 03 15:30:30 2015 +0200 +++ b/src/script/parser.cpp Sat Aug 22 13:04:58 2015 +0300 @@ -248,7 +248,7 @@ // bool Script::Parser::next (TokenType desiredType) { - SavedState oldpos = state(); + State oldpos = state(); Token oldtoken = m_state.token; if (not getNextToken()) @@ -330,7 +330,7 @@ // bool Script::Parser::parseNumber() { - SavedState pos = state(); + State pos = state(); char ch = read(); unread(); QString numberString; @@ -539,7 +539,7 @@ // bool Script::Parser::peekNext (Token& tok) { - SavedState pos = state(); + State pos = state(); if (next (TOK_Any)) { @@ -554,15 +554,7 @@ // // ------------------------------------------------------------------------------------------------- // -const Script::SavedState& Script::Parser::state() const -{ - return m_state; -} - -// -// ------------------------------------------------------------------------------------------------- -// -void Script::Parser::setState (const SavedState& pos) +void Script::Parser::setState (const State& pos) { m_state = pos; }
--- a/src/script/parser.h Tue Feb 03 15:30:30 2015 +0200 +++ b/src/script/parser.h Sat Aug 22 13:04:58 2015 +0300 @@ -95,7 +95,7 @@ qreal real; }; - struct SavedState + struct State { int position; int lineNumber; @@ -127,21 +127,21 @@ Parser(QString text); ~Parser(); - void parse(); - void scriptError (QString text); - bool next (TokenType desiredType = TOK_Any); + bool isAtEnd() const { return m_state.position >= m_data.length(); } void mustGetNext (TokenType desiredType = TOK_Any); + bool next (TokenType desiredType = TOK_Any); + void parse(); bool peekNext (Token& tok); - const SavedState& state() const; - void setState(const SavedState& pos); void preprocess(); QString preprocessedScript() const { return QString::fromAscii (m_data); } char read(); - void unread(); + void scriptError (QString text); + void setState (const State& pos); void skipSpace(); - bool isAtEnd() const { return m_state.position >= m_data.length(); } + State state() const { return m_state; } + void tokenMustBe (TokenType desiredType); bool tryMatch (const char* text, bool caseSensitive); - void tokenMustBe (TokenType desiredType); + void unread(); template<typename... Args> void scriptError (QString text, Args... args) @@ -153,7 +153,7 @@ QString m_script; QByteArray m_data; QVector<int> m_lineEndings; - SavedState m_state; + State m_state; Ast::RootPointer m_astRoot; Token m_rejectedToken;