[ragel-users] How to call an 'action' from other 'action' ?

Iñaki Baz Castillo ibc at aliax.net
Wed Feb 18 19:59:02 UTC 2009


El Miércoles, 18 de Febrero de 2009, Iñaki Baz Castillo escribió:
> Hi, I'm trying the following (using Ruby host language):
>
>
> 	action _start { start = p }
> 	action _stop { stop = p-1 ; value = data[start..stop].pack('c*') ; }
> 	action set_user { _stop ; user = value ; puts "---user=#{user}---" }
>
> 	user = ( unreserved | escaped | user_unreserved )+ >_start %set_user  ;
>
>
> What I want to do is avoid writting the stuff in '_stop' action in every
> leaving action (%). But it seems to fail since '_stop' is executed as Ruby
> language:
>   ERROR: undefined local variable or method `_stop'
>
>
> How could I invoke '_stop' action from 'set_user' action?
>
> Thanks.

Ops, I've found a workaround:

 action _start { start = p }
 action _stop { stop = p-1 ; value = data[start..stop].pack('c*') ; }
 action set_user { user = value ; puts "---user=#{user}---" }

 user = ( unreserved | escaped | user_unreserved )+ >_start %stop %set_user  ;

As you see I use two leaving actions (%) in "user". It works but I've no idea 
about if it *should* really work. Any problem with it?

Thanks a lot.

-- 
Iñaki Baz Castillo




More information about the ragel-users mailing list