--- /dev/null
+/*
+ * ParsedSource.h
+ *
+ * Created on: Aug 26, 2012
+ * Author: holy
+ */
+
+#ifndef LOADER_PARSEDSOURCE_H_
+#define LOADER_PARSEDSOURCE_H_
+
+#include <iosfwd>
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+
+namespace loader {
+
+class PropertyList;
+class Value;
+
+class Literal {
+
+ enum Type {
+ ARRAY,
+ BOOLEAN,
+ COLOR,
+ NUMBER,
+ STRING,
+ VECTOR,
+ OBJECT
+ };
+
+public:
+ explicit Literal(const std::vector<Value *> &);
+ explicit Literal(bool);
+ Literal(int r, int g, int b, int a = 255);
+ Literal(const std::string &);
+ Literal(int x, int y);
+ Literal(const std::string &typeName, PropertyList *properties);
+
+private:
+ PropertyList *props;
+ std::string str;
+ std::vector<Value *> values;
+ int i1, i2, i3, i4;
+ bool b;
+ Type type;
+
+};
+
+
+class Value {
+
+public:
+ explicit Value(const std::string &identifier)
+ : literal(0), identifier(identifier), isLiteral(false) { }
+ explicit Value(Literal *literal)
+ : literal(literal), isLiteral(false) { }
+
+private:
+ Literal *literal;
+ std::string identifier;
+ bool isLiteral;
+
+};
+
+
+class PropertyList {
+
+public:
+ ~PropertyList();
+
+public:
+ void SetProperty(const std::string &name, Value *value) {
+ props[name] = value;
+ }
+
+private:
+ std::map<std::string, Value *> props;
+
+};
+
+
+class Declaration {
+
+public:
+ Declaration(const std::string &typeName, const std::string &identifier)
+ : typeName(typeName), identifier(identifier) { }
+ virtual ~Declaration() { }
+
+public:
+ const std::string &TypeName() const { return typeName; }
+ const std::string &Identifier() const { return identifier; }
+
+private:
+ std::string typeName;
+ std::string identifier;
+
+};
+
+
+class Definition
+: public Declaration {
+
+public:
+ Definition(const std::string &typeName, const std::string &identifier)
+ : Declaration(typeName, identifier), value(0), isLiteral(false) { }
+
+public:
+ void SetValue(Literal *);
+ void SetValue(PropertyList *);
+
+ bool HasLiteralValue() const { return isLiteral && value; }
+ bool HasProperties() const { return !isLiteral && value; }
+ Literal *GetLiteral();
+ const Literal *GetLiteral() const;
+ PropertyList *GetProperties();
+ const PropertyList *GetProperties() const;
+
+private:
+ void *value;
+ bool isLiteral;
+
+};
+
+
+class ParsedSource {
+
+public:
+ ParsedSource() { }
+ ~ParsedSource() { }
+
+public:
+ void AddDeclaration(Declaration *);
+ void ExportDeclaration(Declaration *);
+ void ExportIdentifier(const std::string &);
+
+ const std::map<std::string, Declaration *> Declarations() const { return declarations; }
+ const std::set<std::string> Exports() const { return exports; }
+
+private:
+ std::map<std::string, Declaration *> declarations;
+ std::set<std::string> exports;
+
+};
+
+}
+
+
+namespace std {
+
+ostream &operator <<(ostream &, const loader::ParsedSource &);
+
+}
+
+#endif /* LOADER_PARSEDSOURCE_H_ */