[ragel-users] Acting when EOF
Iñaki Baz Castillo
ibc at aliax.net
Fri Jan 30 12:08:20 UTC 2009
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>
More information about the ragel-users
mailing list