#ifndef DOMAIN_LIBRARY_VALUE_H #define DOMAIN_LIBRARY_VALUE_H #include #include #include class Value: AstNode { public: enum ValueType { INT, STRING, BOOL, IDENTIFIER }; private: ValueType type; std::optional intValue; std::optional stringValue; std::optional boolValue; std::optional identifierValue; public: Value(); ValueType getType() { return type; } long long asInt() { if(is(INT)) { return intValue.value(); } throw "cannot convert type to int"; } std::string asString() { if(is(STRING)) { return stringValue.value(); } throw "cannot convert type to string"; } std::string asIdentifier() { if(is(IDENTIFIER)) { return identifierValue.value(); } throw "cannot convert type to identifier"; } bool asBool() { if(is(BOOL)) { return boolValue.value(); } throw "cannot convert type to bool"; } bool is(ValueType type) { return this->type == type; } static Value ofBool(bool _value) { Value value; value.type = BOOL; value.boolValue = std::optional(_value); return value; } static Value ofInt(long long _value) { Value value; value.type = INT; value.intValue = std::optional(_value); return value; } static Value ofString(std::string _value) { Value value; value.type = STRING; value.stringValue = std::optional(_value); return value; } static Value ofIdentifier(std::string _value) { Value value; value.type = IDENTIFIER; value.identifierValue = std::optional(_value); return value; } }; class PropertyNode: public AstNode { public: IdentifierNode key; Value value; PropertyNode() {} }; #endif // DOMAIN_LIBRARY_VALUE_H