[ragel-users] Problem with an indetermination
Adrian Thurston
thurston at complang.org
Wed Feb 11 23:46:32 UTC 2009
The problem here is an ambiguity. When a space is seen it is unknown
whether or not the space extends the name or is the beginning of the end
("<"). You can change it to this:
name = ( token ( SP token )* ) > { _tag = p }
%{ @value = data[_tag..p-1].pack("c*") };
full = name SP* %{ puts "--name=#{@value}--" } "<" [a-z]+ ">";
main := full;
Now on each space the value is only stored. Basically you need to mark
the end separately from doing something about it because ever time you
think you see the end, it may not be the end.
An alternative would be to include the SP* in name and strip trailing
whitespace after.
-Adrian
IƱaki Baz Castillo wrote:
> Hi, I'm finishing a complete SIP protocol parser with Ragel, but I have an
> issue I can't solve. The problem is basically the following (I use Ruby):
>
> --------------
> name = ( token ( SP token )* ) > { _tag = p }
> %{ @value = data[_tag..p-1].pack("c*"); puts "--name=#{@value}--"} ;
>
> full = name SP* "<" [a-z]+ ">" ;
>
> main := full
> --------------
>
> I parse the following valid string:
> 'Alice Kiske <alice>'
> and I get two results for "name" node:
>
> --name=Alice--
> --name=Alice Kiske--
>
> Obviously I just want the second result, the first one shouldn't occur.
>
> I've solved similar problems using priorities but they don't help me in this
> issue. Any help please?
>
> Thanks a lot.
>
>
More information about the ragel-users
mailing list