-/*
- * ParsedSource.h
- *
- * Created on: Aug 26, 2012
- * Author: holy
- */
-
#ifndef LOADER_PARSEDSOURCE_H_
#define LOADER_PARSEDSOURCE_H_
+namespace loader {
+ class Literal;
+ class PropertyList;
+ class Value;
+}
+
#include <iosfwd>
#include <map>
#include <set>
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 {
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<Value *> &);
- explicit Literal(const std::vector<PropertyList *> &);
+ /// array of objects
+ Literal(const std::string &, const std::vector<PropertyList *> &);
+ /// array of identifiers
+ Literal(const std::string &, const std::vector<std::string> &);
+ /// 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<ScriptToken *> &);
~Literal();
private:
Literal(const Literal &);
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<Value *> &GetValues() const;
const std::vector<PropertyList *> &GetPropertyLists() const;
+ const std::vector<std::string> &GetIdentifiers() const;
bool GetBoolean() const;
int GetRed() const;
int GetGreen() const;
int GetY() const;
const std::string &GetTypeName() const;
const PropertyList *GetProperties() const;
+ const std::vector<ScriptToken *> &GetScript() const;
private:
PropertyList *props;
- std::string str;
+ std::string typeName, str;
std::vector<Value *> values;
std::vector<PropertyList *> propertyLists;
+ std::vector<std::string> identifiers;
+ std::vector<ScriptToken *> script;
int i1, i2, i3, i4;
bool b;
Type type;
const std::map<std::string, Definition *> &Definitions() const { return definitions; }
const std::set<std::string> &Exports() const { return exports; }
+public:
+ void WriteHeader(std::ostream &) const;
+
private:
std::map<std::string, Declaration *> declarations;
std::map<std::string, Definition *> definitions;
}
-#endif /* LOADER_PARSEDSOURCE_H_ */
+#endif