[ragel-users] Conditional parsing, is it possible?

Adrian Thurston adrian.thurston at esentire.com
Thu Dec 30 01:26:23 UTC 2010


Hi Iñaki,

There are a few approaches. You can do it using fgoto/fcall/fret, but 
then you lose the single-regex property. You can also do it using 
conditions, which are a more recent feature. The drawback there is that 
you run into trouble if using int and unsigned int alphabet types (as 
opposed to char). That won't affect you though. See the manual and the 
mailing list for more info about conditions.

-Adrian

On 10-12-29 05:26 PM, Iñaki Baz Castillo wrote:
> 2010/12/30 Iñaki Baz Castillo<ibc at aliax.net>:
>> Hi, I wonder if there is a way to parse (or not) some fragments of the
>> stream depending on previous parsed elements.
>>
>> For example, in HTTP, imagine I just want to parse a custom header
>> "X-MyHeader" (which has a specific value format)  in case the request
>> method is POST. But in case it's a GET then I just want to store the
>> header raw value.
>
> This is, there would be two valid syntax for "X-MyHeader":
>
>
>    generic_value = any* -CRLF;
>    x_value = [0-9] ":" [a-z]+;
>    x_myheader_value = generic_value | x_value;
>
> If a previous field of the stream (the request method) is POST (an
> action could set a variable) I want 'x_myheader_value' just to be
> checked with 'x_value', and if the method is other, then
> 'x_myheader_value' should be just checked with 'generic_value'.
>
> Thanks for any suggestion or clarification.
>
>

_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users


More information about the ragel-users mailing list