[ragel-users] Acting when EOF
Adrian Thurston
thurston at complang.org
Mon Feb 2 02:48:38 UTC 2009
Hi Inaki,
You can either add another character or set eof = pe to induce the final action. Leaving actions require one char of lookahead.
Adrian
------Original Message------
From: Iñaki Baz Castillo
To: ragel-users at complang.org
ReplyTo: ragel-users at complang.org
Sent: Jan 30, 2009 7:08 AM
Subject: Re: [ragel-users] Acting when EOF
2009/1/27 Iñaki Baz Castillo <ibc at aliax.net>:
> Hi, I've done a simple parser for a SIP URI ("sip:user at domain.org")
> but I can't get the last field ("host"):
>
> --------------------------------------------------------
> %%{
> machine sip_uri;
>
> action _tag { mark_tag = p }
> action protocol { @uri.user = data[mark_tag..p-1].pack('c*') }
> action user { @uri.protocol = data[mark_tag..p-1].pack('c*') }
> action host { @uri.host = data[mark_tag..p-1].pack('c*') }
>
> protocol = ('sip'i|'sips'i) >_tag %protocol ;
> user = [a-zA-Z0-9]+ >_tag %user ;
> host = [.a-zA-Z0-9]+ >_tag %host ;
>
> main := protocol ':' user '@' host ;
> }%%
>
> run_machine "sip:user at domain.org"
> -------------------------------------------------------
>
> The actions "protocol" and "user" are executed, storing the parsed
> data into a Ruby attribute, but the action "host" is not executed. I
> assume this occurs because leaving action (%) doesn't take place but
> EOF action. So I try to use a EOF action:
>
> host = [.a-zA-Z0-9]+ >_tag %/host ;
>
> But it doesn't work. I can't imagine how to get this "host" field, any
> help please?
I can solve it by adding '\0' and the end of the Ruby String acting as
"run_machine" argument, and also adding the following to the machine
"main":
main := protocol ':' user '@' host '\0' ;
Not sure, however, if this is the cleaner solution.
--
Iñaki Baz Castillo
<ibc at aliax.net>
_______________________________________________
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