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: [email protected] ReplyTo: [email protected] Sent: Jan 30, 2009 7:08 AM Subject: Re: [ragel-users] Acting when EOF 2009/1/27 Iñaki Baz Castillo <[email protected]>: > Hi, I've done a simple parser for a SIP URI ("sip:[email protected]") > 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:[email protected]" > ------------------------------------------------------- > > 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 <[email protected]> _______________________________________________ ragel-users mailing list [email protected] http://www.complang.org/mailman/listinfo/ragel-users _______________________________________________ ragel-users mailing list [email protected] http://www.complang.org/mailman/listinfo/ragel-users
