james.jones@firstinvestors.com wrote:
From: moosefly
For example, I want to parse the following text: <input type=hidden value=1>
I have defined 2 rules match the "type" field and the "value" field, but the sequence of 2 rules is uncertain, that means "<input value=1 type=hidden>" is also legal,so I can't define the rules just like:
rule_type >> !space_p >> rule_value
The following works at this simple condition:
rule_type ) ) But if there are many out-of-order fields need to parser, how can I ignore
( (rule_type >> !space_p >> rule_value) | (rule_value >> !space_p the sequence of the rules?
What you seem to want to do (correct me if I'm wrong) is to have some set of N attributes, each of which may or may not be present, but can appear only once, in arbitrary order, and you want to check this in the parser. This is not a great idea, because it leads to a combinatorial explosion of states. There's really no way out of this (strictly within the parser).
FWIW, Spirit-2 now has this kind of parser, called the permutation parser. Yes, it is tricky to do in Spirit-1, but not impossible. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net