/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifndef MSP_PARSER_CONSTANT_H_
/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#include "input.h"
/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifndef MSP_PARSER_INPUT_H_
/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifndef MSP_PARSER_LOADER_H_
/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#include <cctype>
result.args.push_back(Value(Value::STRING, token.str));
else if(token.type==Token::IDENTIFIER)
{
+ if(token.str=="true")
+ result.args.push_back(Value(Value::BOOLEAN, "1"));
+ else if(token.str=="false")
+ result.args.push_back(Value(Value::BOOLEAN, "0"));
+ else
+ result.args.push_back(Value(Value::ENUM, token.str));
//result.args.push_back(resolve_identifiertoken.str);
}
else if(token.str=="")
/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifndef MSP_PARSER_PARSER_H_
/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifndef MSP_PARSER_STATEMENT_H_
/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifndef MSP_PARSER_TOKEN_H_
+++ /dev/null
-/*
-This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-#include <msp/error.h>
-#include "value.h"
-
-namespace Msp {
-namespace Parser {
-
-template<>
-std::string Value::get<std::string>() const
-{
- if(type!=STRING)
- throw TypeError("Value is not a string");
- return data;
-}
-
-template<>
-const std::string &Value::get<const std::string&>() const
-{
- if(type!=STRING)
- throw TypeError("Value is not a string");
- return data;
-}
-
-} // namespace Msp
-} // namespace Parser
/*
This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifndef MSP_PARSER_VALUE_H_
INTEGER,
FLOAT,
STRING,
- BOOLEAN
+ BOOLEAN,
+ ENUM
};
Value(Type t, const std::string &d): type(t), data(d) { }
template<typename T>
- T get() const
- {
- std::istringstream ss(data);
- T result;
- ss>>result;
- if(ss.fail())
- throw TypeError("Type mismatch");
- return result;
- }
+ T get() const;
private:
Type type;
std::string data;
};
typedef std::vector<Value> ValueArray;
+template<typename T> struct TypeResolver { };
+
+template<> struct TypeResolver<short> { static const Value::Type type=Value::INTEGER; };
+template<> struct TypeResolver<unsigned short> { static const Value::Type type=Value::INTEGER; };
+template<> struct TypeResolver<int> { static const Value::Type type=Value::INTEGER; };
+template<> struct TypeResolver<unsigned> { static const Value::Type type=Value::INTEGER; };
+template<> struct TypeResolver<long> { static const Value::Type type=Value::INTEGER; };
+template<> struct TypeResolver<unsigned long> { static const Value::Type type=Value::INTEGER; };
+template<> struct TypeResolver<float> { static const Value::Type type=Value::FLOAT; };
+template<> struct TypeResolver<double> { static const Value::Type type=Value::FLOAT; };
+template<> struct TypeResolver<bool> { static const Value::Type type=Value::BOOLEAN; };
+
+template<Value::Type T> inline bool check_type(Value::Type) { return false; }
+
+template<> inline bool check_type<Value::INTEGER>(Value::Type t) { return t==Value::INTEGER; }
+template<> inline bool check_type<Value::FLOAT>(Value::Type t) { return t==Value::INTEGER || t==Value::FLOAT; }
+template<> inline bool check_type<Value::BOOLEAN>(Value::Type t) { return t==Value::BOOLEAN; }
+template<> inline bool check_type<Value::STRING>(Value::Type t) { return t==Value::STRING; }
+template<> inline bool check_type<Value::ENUM>(Value::Type t) { return t==Value::ENUM; }
+
+template<typename T>
+inline T Value::get() const
+{
+ if(!check_type<TypeResolver<T>::type>(type))
+ throw TypeError("Type mismatch");
+
+ std::istringstream ss(data);
+ T result;
+ ss>>result;
+ if(ss.fail())
+ throw ValueError("Invalid value");
+
+ return result;
+}
+
+template<>
+inline std::string Value::get<std::string>() const
+{
+ if(type!=STRING)
+ throw TypeError("Value is not a string");
+ return data;
+}
+
+template<>
+inline const std::string &Value::get<const std::string&>() const
+{
+ if(type!=STRING)
+ throw TypeError("Value is not a string");
+ return data;
+}
+
} // namespace Parser
} // namespace Msp