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.
>
>
_______________________________________________
ragel-users mailing list
[email protected]
http://www.complang.org/mailman/listinfo/ragel-users