[ragel-users] Conditional parsing

Tim Goddard tim at goddard.net.nz
Mon Jun 30 02:19:31 UTC 2014


Sounds like you have a common language, but want two separate sets of actions.

You can include a file within a ragel machine - I'd write the grammar in one 
file, then declare the "main" object and actions within two separate parsers.

Cheers,

Tim

On Thu, 10 Apr 2014 22:52:41 Iñaki Baz Castillo wrote:
> 2014-04-10 22:08 GMT+02:00 Iñaki Baz Castillo <ibc at 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 at complang.org
http://www.complang.org/mailman/listinfo/ragel-users



More information about the ragel-users mailing list