Hi Iñaki,

Using conditionals is one way. I'm not sure I fully understand your use case, but I think you can also make use of the ability to enter into any named instantiation. All machine instances are defined in the data section as constant values. It's just a matter of setting the current state to the appropriate value.

-Adrian

On 14-04-10 04:52 PM, Iñaki Baz Castillo wrote:
2014-04-10 22:08 GMT+02:00 Iñaki Baz Castillo <i...@aliax.net>:
Hi,

I'm building a parser for a protocol message similar to HTTP (let's
say: a main header and N key: value separated by CRLF until a final
double CRLF). My concern is:

- I parse the messages in a "Dispatcher" module that just needs to
parse a few fields in each message.
- Then the Dispatcher passes the message to a Worker thread via UNIX Socket.
- And the Worker must parse it again, but in this case I need all the
fields parsed.

Note that during the Worker's parsing, a C++ complex object is build
with all the parsed fields mapped into member variables, so I don't
want to play with those complex objects in the Dispatcher module.

How could I reuse the same Ragel machine for both cases? Of course I
would like something like:



%%{
   machine Parser;

   [...]

   if (dispatcher) {
     main :=  xxxxxxx
   }
   else {
     main := yyyyyyy
   }

}%%



Mmm, I think using the "when" statement is the way to go :)




_______________________________________________
ragel-users mailing list
ragel-users@complang.org
http://www.complang.org/mailman/listinfo/ragel-users

Reply via email to