I'm trying to use spirit to parse a simple logical expression. eg: variable_name == value_name && ...
After reading the docs (spirit, qi), it's still defeating me to parse a simple variable-like tokens that may include '_'.
I get ASAN violations in my build, or segfaults on coliru.
The problem is the line:
auto term_eq_ = +(qi::alpha|qi::char_('_'))
What's wrong with this?
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
std::string SpiritAsan(std::string expr_string)
{
auto f = expr_string.begin();
auto l = expr_string.end();
// Seg fault or ASAN violaton:
auto term_eq_ = +(qi::alpha|qi::char_('_')); // close to what i want, variable-like "read a token"
//auto term_eq_ = +qi::char_("A-Z"); //another try, seg fault
// Works fine:
//auto term_eq_ = +(qi::alpha|qi::int_); // dumb, but has a alternate '|'
try
{
bool ok = qi::parse(f,l,term_eq_ );
if (!ok)
return "invalid input";
else
return "result: Parsed! (some at least), remaining:" + std::string(f,l);
}
catch (const qi::expectation_failure<decltype(f)>& e)
{
return "expectation_failure";
}
}
int main()
{
std::cout << SpiritAsan("Some_Attrib == SomeVal");
return 0;
}
Live here: http://coliru.stacked-crooked.com/a/14a193daebdc9ed1
Thanks for your help.