Open adrian-thurston opened 4 years ago
Cannot see how you could handle ragel machines that have c-comments in their dispatch actions. Or do you introduce a comment() builtin to emit comments for the target code?
That's a good point, you can't use them. Would be a limitation of the feature. Probably I would just point out the limitation in the docs, rather than add something to ragel to accommodate them.
Cannot see how you could handle ragel machines that have c-comments in their dispatch actions.
/*
and */
could be escaped with a noop token → /\%*
and *\%/
instead of comments, im currently using pseudo macro functions
#include <stdio.h>
RAGEL({
// ragel block
// set machine name
machine some_machine;
/*
comment block
*/
})
// "write error;" evaluates to "some_machine_error"
if (state->rc == RAGEL(write error;)) {
printf("error\n");
}
... but thats not valid C code. slightly more valid:
#include <stdio.h>
#ifdef RAGEL
// ragel block
// set machine name
machine some_machine;
/*
comment block
*/
#endif
// "write error;" evaluates to "some_machine_error"
if (state->rc == /* %ragel write error; */) {
printf("error\n");
}
prototype solution: add one more preprocessor https://github.com/milahu/ragel-from-comments
i've used the approach to embed build instructions in comments once but wasn't really satisfied with the solution, as i had to parse the code before the C preprocessor and so didn't get the opportunity to leverage preprocessor conditions. at one point i then realized i could use #pragma
instead because the preprocessor leaves those lines in the context where they appeared, and the compiler ignores them (the project using this approach is https://github.com/rofl0r/rcb2 ). maybe this could be leveraged in some form for use in ragel, too.
This way we can add a ragel state machine to a C file without disrupting the C syntax. The resulting file can still be handled as a C (or whichever) language by the IDE.
http://www.colm.net/pipermail/ragel-users/2019-April/003622.html