Boost logo

Boost Users :

From: james.jones_at_[hidden]
Date: 2007-09-11 17:48:31


> From: moosefly <moosefly_at_[hidden]>
> 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 >> !space_p >> rule_value) | (rule_value >> !space_p
> >>rule_type ) )
>
> But if there are many out-of-order fields need to parser, how can I
> ignore 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).

What you CAN do to avoid the explosion is to delegate the uniqueness checking to helper functions outside the parser. So instead of allowing only rule_type then rule_value or the reverse, allow this:

rule_any = rule_type | rule_value;
rule_input_attributes = *rule_any; // ignoring whitespace issues here

This will match:

<input type=hidden value=1> or
<input value=1 type=hidden>

as you want. But it'll also match:

<input value=1 type=hidden type=visible> and
<input>

which you might not want.

So you have to add an action to rule_any, which will pass the name-value pair data to a function which will check the uniqueness of the names in the NVP.

I'm not an expert on Spirit, so you might want to consult the Spirit mailing list if you get stuck creating actions.

HTH,
-
James Jones Administrative Data Mgmt.
Webmaster 375 Raritan Center Pkwy, Suite A
Data Architect Edison, NJ 08837


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net