X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FParsedSource.h;h=c843de1889add9c37d22247ced22477533c37af1;hb=a67f7e662c85b2b8d46f26a3c6e018b2df6eb318;hp=8401777f54e0f43ebac98a6ed2e3286a268ec87f;hpb=09e8cfd4d7b2d187fed0870ebdb2e9e3f77fe4b9;p=l2e.git diff --git a/src/loader/ParsedSource.h b/src/loader/ParsedSource.h index 8401777..c843de1 100644 --- a/src/loader/ParsedSource.h +++ b/src/loader/ParsedSource.h @@ -1,13 +1,8 @@ -/* - * ParsedSource.h - * - * Created on: Aug 26, 2012 - * Author: holy - */ - #ifndef LOADER_PARSEDSOURCE_H_ #define LOADER_PARSEDSOURCE_H_ +#include "fwd.h" + #include #include #include @@ -16,8 +11,39 @@ namespace loader { -class PropertyList; -class Value; +class ScriptToken { + +public: + enum Type { + COMMAND, + REGISTER, + IDENTIFIER, + LITERAL, + LABEL, + }; + + ScriptToken(const std::string &, Type); + explicit ScriptToken(Literal *); + ~ScriptToken(); +private: + ScriptToken(const ScriptToken &); + ScriptToken &operator =(const ScriptToken &); + +public: + Type GetType() const { return type; } + const std::string &RegisterName() const; + const std::string &CommandName() const; + const std::string &Identifier() const; + const std::string &Label() const; + const Literal *GetLiteral() const; + +private: + Literal *literal; + std::string str; + Type type; + +}; + class Literal { @@ -25,25 +51,40 @@ public: enum Type { ARRAY_VALUES, ARRAY_PROPS, + ARRAY_IDENTS, BOOLEAN, COLOR, NUMBER, PATH, STRING, VECTOR, - OBJECT + OBJECT, + SCRIPT, }; public: + /// array of values explicit Literal(const std::vector &); - explicit Literal(const std::vector &); + /// array of objects + Literal(const std::string &, const std::vector &); + /// array of identifiers + Literal(const std::string &, const std::vector &); + /// boolean explicit Literal(bool); + /// color Literal(int r, int g, int b, int a = 255); + /// number explicit Literal(int number); + /// path string Literal(const std::string &dir, const std::string &path); + /// string Literal(const std::string &); + /// vector Literal(int x, int y); + /// object Literal(const std::string &typeName, PropertyList *properties); + /// script + explicit Literal(const std::vector &); ~Literal(); private: Literal(const Literal &); @@ -51,9 +92,14 @@ private: public: Type GetType() const { return type; } + bool IsArray() const { return GetType() == ARRAY_VALUES || GetType() == ARRAY_PROPS || GetType() == ARRAY_IDENTS; } + bool IsObject() const { return GetType() == OBJECT; } + int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size() + : (GetType() == ARRAY_PROPS ? GetPropertyLists().size() : GetIdentifiers().size()); } const std::vector &GetValues() const; const std::vector &GetPropertyLists() const; + const std::vector &GetIdentifiers() const; bool GetBoolean() const; int GetRed() const; int GetGreen() const; @@ -65,12 +111,15 @@ public: int GetY() const; const std::string &GetTypeName() const; const PropertyList *GetProperties() const; + const std::vector &GetScript() const; private: PropertyList *props; - std::string str; + std::string typeName, str; std::vector values; std::vector propertyLists; + std::vector identifiers; + std::vector script; int i1, i2, i3, i4; bool b; Type type; @@ -206,6 +255,9 @@ public: const std::map &Definitions() const { return definitions; } const std::set &Exports() const { return exports; } +public: + void WriteHeader(std::ostream &) const; + private: std::map declarations; std::map definitions;