struct NestedStr;
typedef boost::variant<std::string, boost::recursive_wrapper< NestedStr>> expression;
struct NestedStr
{
vector<expression> children; // variant instantiated here...
NestedStr(const vector<expression> & child) : children(child)
{
}
NestedStr()
{
}
};
template <typename Iterator>
struct TimingGrammar : qi::grammar<Iterator, SDFDelayInfo(), ascii::space_type>
{
TimingGrammar() : TimingGrammar::base_type(start)
{
str_rule %= +(qi::char_ - (qi::lit('(') | qi::lit(')')));
brace_rule %= '(' >> str_rule >> brace_rule >> ')';
start %= '(' >> qi::lit("TIMING") >> brace_rule ')';
}
qi::rule<Iterator, string(), ascii::space_type> str_rule;
qi::rule<Iterator, NestedStr(), ascii::space_type> start;
};
I am parsing this nested expression and want to parse till the closing bracket.
(TIMING (RECOVERY (COND(COND(COND(COND))))) (WIDTH (COND AB == 1'b1 (pos CK)) (0.040::0.040)) )
But facing long compiler error.
And second question is there any way whenever "(TIMING" is encountered, omit everything in between the closing bracket of "(TIMING" and move the string iterator after the closing bracket.
Because your code couldn't work and wasn't self-contained, I took a stab at it: Live On Coliru
Now obviously, this may or may not be the same problem you ran into.
However, it does highlight a conceptual problem:
There is a problem propagating synthesized attributes into the actual attribute type.
Most interestingly, your production for subnode is
"(" >> key >> subnode >> ")". That doesn't match any of the AST nodes. Also, since nothing in that rule is optional AND it recurses, it will by definition never parse because unless the input is infinite, at some point it will fail to match.Going from the example I'd guess that you actually need something more like:
Changing the grammar to match makes things work:
Live On Coliru
Printing:
Debugging Parse Fail
You will note that I prepared BOOST_SPIRIT_DEBUG_NODES, enable it with
Subtler Notes
Things easily missed in the above:
value_doesn't have a skipper anymore - otherwise it lose the spaces inside longer keys; see also Boost spirit skipper issues*node_is a Kleene-star repeat, which means it is optional"TIMING"into aqi::stringparser, notqi::litbecause you need the attribute corresponding toNode::valueFull Listing For Reference
As on https://coliru.stacked-crooked.com/a/3e7acf29455d9477: