adrian-thurston / ragel

Ragel State Machine Compiler
MIT License
532 stars 46 forks source link

multiple machine write statements in one file #54

Closed rofl0r closed 4 years ago

rofl0r commented 4 years ago

this is basically what's been asked here: https://stackoverflow.com/questions/32265063/is-it-possible-to-invocate-multiple-machines-in-one-ragel-file

since ragel's write statement doesn't allow to specify the machine name, the offered solution seems hackish.

would it make sense to introduce another statement e.g. write-machine that acts just like write but takes a machine name as first parameter ?

adrian-thurston commented 4 years ago

The %% write .. statements are just single line forms of arbitrary ragel statements. If a machine block (single or multiline) doesn't have a name then it just uses the name of the previous block. You could write:

%% machine test; 
%% main := ( "" >{puts("x");} ( [0-9]+ ) "foo" );
%% write data;
%% write exec;

If you wanted to. So to put a write in with a name just use:

%%{
    machine foo;
    write data;
}%%