Parsing

Boost Spirit (2.5.2) was selected for parsing which is based on template meta-programming.

Spirit mini-parsers are chained together using sequencing operator ‘>>’ and also greater operator ‘>’. The difference between the two is that the first is optional and the second does not allow backtracking, that is if no match occurs parsing fails, no matter if another parser can parse that.

Rules may be stored into individual objects of type (boost::spirit::)qi::rule<…>. A number of rules can be in encapsulated into a instanced qi::grammar<> class. A grid rule parser looks like this:

RuleType<PeelRule> peel_rule =
'('
>> range_param
>> ','
>> size1d
>> ')'
>> qi::lit('{') >> label >> '|' >> label >> '}'
;

Where range_param, size1d, and label are individual parsers each of which produce a synthesised attribute or simply speaking they return a value when applied to an input.

For instance size1d can parse an real value or a percent value – in the latter case during the rule application the real value is obtained by evaluating percent function on the input shape. Currently percent is evaluated from the average size of the input polygon’s side.

All parsed rule statements are stored into a dictionary as objects indexed with strings as labels.