Mon, 26 Jan 2015 01:16:56 +0200
- commit work done on scripting
src/script/ast.cpp | file | annotate | diff | comparison | revisions | |
src/script/ast.h | file | annotate | diff | comparison | revisions | |
src/script/parser.cpp | file | annotate | diff | comparison | revisions | |
src/script/parser.h | file | annotate | diff | comparison | revisions |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/ast.cpp Mon Jan 26 01:16:56 2015 +0200 @@ -0,0 +1,7 @@ +#include "ast.h" + +Script::AstNode::AstNode (QSharedPointer<AstNode> parent) : + m_parent (parent) +{ + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/ast.h Mon Jan 26 01:16:56 2015 +0200 @@ -0,0 +1,21 @@ +#pragma once +#include <QVector> +#include <QSharedPointer> + +namespace Script +{ + enum AstNodeType + { + + }; + + class AstNode + { + public: + AstNode (QSharedPointer<AstNode> parent); + + private: + QVector<QSharedPointer<AstNode>> m_children; + QSharedPointer<AstNode> m_parent; + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/parser.cpp Mon Jan 26 01:16:56 2015 +0200 @@ -0,0 +1,35 @@ +#include "parser.h" + +Script::Parser::Parser(QString text) : + m_data (text) {} + +void Script::Parser::parse() +{ + m_position.reset(); +} + +bool Script::Parser::next(TokenType desiredType) +{ + SavedPosition oldpos = position(); +} + +void Script::Parser::mustGetNext(TokenType desiredType) +{ + +} + +bool Script::Parser::peekNext(Token& tok) +{ + +} + + +const Script::SavedPosition& Script::Parser::position() const +{ + return m_position; +} + +void Script::Parser::setPosition(const SavedPosition& pos) +{ + m_position = pos; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/parser.h Mon Jan 26 01:16:56 2015 +0200 @@ -0,0 +1,94 @@ +#pragma once +#include <QString> +#include "ast.h" + +namespace Script +{ + enum TokenType + { + TOK_Dollar, + TOK_Semicolon, + TOK_BraceLeft, + TOK_BraceRight, + TOK_BracketLeft, + TOK_BracketRight, + TOK_ParenLeft, + TOK_ParenRight, + TOK_String, + TOK_Symbol, + TOK_Number, + TOK_Any + }; + + enum Type + { + TYPE_Var, // mixed + TYPE_Int, + TYPE_Real, + TYPE_String, + TYPE_Type, // heh + TYPE_Vertex, + TYPE_Object, + TYPE_Line, + TYPE_OptLine, + TYPE_Triangle, + TYPE_Quad, + TYPE_Reference, + }; + + enum Function + { + FUNC_Abs, + FUNC_Print, + FUNC_Typeof, + }; + + struct Token + { + TokenType type; + QString text; + }; + + struct SavedPosition + { + int position; + int lineNumber; + + void reset() + { + position = 0; + lineNumber = 1; + } + }; + + class ParseError : public std::exception + { + public: + ParseError(QString text) : m_text (text) {} + const char* what() const { return m_text; } + + private: + QString m_text; + }; + + class Parser + { + public: + Parser(QString text); + ~Parser(); + + void parse(); + void scriptError(QString text) { throw ParseError(text); } + bool next(TokenType desiredType = TOK_Any); + void mustGetNext(TokenType desiredType = TOK_Any); + bool peekNext(Token& tok); + const SavedPosition& position() const; + void setPosition(const SavedPosition& pos); + + private: + QString m_data; + SavedPosition m_position; + Token m_token; + AstNode* m_astRoot; + }; +}