27 #include <boost/variant/apply_visitor.hpp> 28 #include <boost/variant/variant.hpp> 29 #include <boost/variant/get.hpp> 36 #include "../parser/parser_logger.hpp" 37 #include "../parser/parse_info.hpp" 44 shared_ptr<STNode>
parseEval(string::const_iterator begin, string::const_iterator end,
const shared_ptr<ParserLogger>& logger);
52 template<
typename TargetType>
91 shared_ptr<STNode> result =
parseEval(expr.cbegin(), expr.cend(),
logger);
100 if(!
Conv(expr, &boost::get<TargetType>(
value),
true))
105 <<
excp::InfoWhat(
"Failed to parse the expression into an eval or a '" +
string(
typeid(TargetType).name()) +
"'"));
107 if(expr.find(
"eval") == 0)
109 logger->warnStream() <<
"In line " << info.
getLine() <<
" could be an eval but failed to parse so.";
110 logger->warnStream() <<
"Expression is used as " <<
string(
typeid(TargetType).name()) <<
"!";
129 *v = boost::get<TargetType>(
value);
131 assert(
value.which() == 1);
133 string result = boost::get<node_ptr>(
value)->
eval(obj);
137 logger->warnStream() <<
"Evaluation evaluated into \"" << result <<
"\", then failed to convert into " <<
typeid(TargetType).name() <<
".";
147 return value.which() == 1;
170 template<
typename TargetType>
171 class Eval< std::vector<TargetType> >
177 Eval(
const std::vector<TargetType>& values)
195 string::const_iterator begin = expr.cbegin();
196 string::const_iterator end = begin;
198 while(end != expr.end())
204 if(parentheses == 0 && !dquote && !quote)
206 addValue(
string(begin, end));
215 if(!dquote && !quote)
221 else if(*end ==
')' && parentheses > 0)
251 addValue(
string(begin, end));
259 for(
auto& e : valuelist)
265 v->push_back(boost::get<TargetType>(e));
267 string result = boost::get<node_ptr>(e)->
eval(obj);
272 logger->warnStream() <<
"Evaluation evaluated into \"" << result <<
"\", then failed to convert into " <<
typeid(TargetType).name() <<
".";
275 v->push_back(target);
283 return valuelist.size();
290 return valuelist[i].which() == 1;
295 valuelist.push_back(TargetType());
296 if(!
Conv(part, &boost::get<TargetType>(valuelist.back()),
true))
298 shared_ptr<STNode> result =
parseEval(part.cbegin(), part.cend(),
logger);
304 <<
excp::InfoWhat(
"Failed to parse the expression into an list of eval's or a " +
string(
typeid(TargetType).name()) +
"'s"));
306 valuelist.back() = result;
shared_ptr< STNode > parseEval(string::const_iterator begin, string::const_iterator end, const shared_ptr< ParserLogger > &logger)
Creates a new eval.
Eval(const string &expr, const shared_ptr< ParserLogger > &logger, const ParseInfo &info)
Creates an eval from a string.
Thrown if the parsing fails.
Eval(const string &expr, const shared_ptr< ParserLogger > &logger, const ParseInfo &info)
bool Conv(const string &str, bool *out, bool tryToCache)
Use some extra function for bool conversion.
boost::variant< TargetType, node_ptr > value_type
shared_ptr< STNode > node_ptr
shared_ptr< ParserLogger > logger
void addValue(const string &part)
boost::error_info< struct TagWhatInfo, string > InfoWhat
Use this info to give an what msg to the exception.
const unsigned int & getLine() const
std::vector< value_type > valuelist
boost::error_info< struct TagFailureLine, int > InfoFailureLine
Specifies the Line in the file where the failure appeared.
This file is part of alaCarte.
boost::error_info< struct TagFailureLineContent, string > InfoFailureLineContent
Contains the content of the line where a failure appeared.
Eval(const TargetType &value)
Creates an Eval from the value type, the eval should evaluated to.
Represents a value in a style template.
void overwrite(GeoObject *obj, std::vector< TargetType > *v) const
shared_ptr< STNode > node_ptr
string ToString(const bool &v)
Eval(const std::vector< TargetType > &values)
shared_ptr< ParserLogger > logger
void overwrite(GeoObject *obj, TargetType *v) const
Will overwrite the second parameter with an evaluated value.
const string & getLineContent() const
boost::variant< TargetType, node_ptr > value_type