[ragel-users] Passing data to actions

Ico ragel at zevv.nl
Wed Apr 18 22:12:51 UTC 2018


Hello,

First let me thank you for writing Ragel - my #1 tool for implementing
protocol parsers.

When writing machines I often find myself repeating a lot of similar
code, for example like this when parsing the RTSP protocol:

  action method_describe { rtsp.method = RTSP_DESCRIBE; }
  action method_options  { rtsp.method = RTSP_OPTIONS; }
  action method_play     { rtsp.method = RTSP_PLAY; }
  action method_setup    { rtsp.method = RTSP_SETUP; }

  method = ('DESCRIBE' %method_describe) |
           ('OPTIONS' %method_options) |
           ('PLAY' %method_play) |
           ('SETUP' %method_setup);

Would it be possible to pass information from the machine definition
expressions into a action blocks do get a cpp/macro-like behaviour:
  
  action method(x) { rtsp.method = x; }

  method = ('DESCRIBE' %method(RTSP_DESCRIBE)) |
           ('OPTIONS' %method(RTSP_OPTIONS)) |
           ('PLAY' %method(RTSP_PLAY)) |
           ('SETUP' %method(RTSP_SETUP))

Would something like this be feasible?

Thanks,

Ico

--
:wq
^X^Cy^K^X^C^C^C^C



More information about the ragel-users mailing list