[ragel-users] Alternative syntax for Ragel spec blocks
Denis Naumov
deniska.nm at gmail.com
Sat Apr 13 13:09:25 UTC 2019
Alternative syntax for Ragel spec blocks.
Ragel uses code block syntax typical for other lexical generators (
%%{...}%% ).
But as a rule, we edit *.rl the file in some IDE and type of editor for
*.rl file and for main code file is the same.
I.e. if we use C++, then *.rl is often also edited as C++ the file.
Using %%{...}%% blocks break IDE code analisis as C++(or other) code.
It would be good if Ragel could maintain "comment syntax" of code blocks in
style like Re2C:
/*!ragel
<multi-line FSM spec>
*/
//!ragel <single-line FSM spec>
"comment syntax" can be implement all languages with C-style comments.
With "comment syntax" *.rl file would IDE frendly:
- *.rl the file is 100% correct c/c++/java file.
- syntax highlighting of the source code - works correctly.
- IntelliSence, auto-formatting and so on - works correctly.
Ragel can process %%{...}%% and /*! ragel... */ syntax at the same time or
to use a special option (for example, --syntax=general/comment)
Example:
--- general ragel ragel file ------------------
#include <string.h>
#include <stdio.h>
%%{
machine foo;
main := ( 'foo' | 'bar' ) 0 @{ res = 1; };
}%%
%% write data;
int main( int argc, char **argv )
{
int cs, res = 0;
if ( argc > 1 ) {
char *p = argv[1];
char *pe = p + strlen(p) + 1;
%% write init;
%% write exec;
}
printf("result = %i\n", res );
return 0;
}
-----------------------------------------------
--- IDE frendly ragel file --------------------
#include <string.h>
#include <stdio.h>
/*!ragel
machine foo;
main := ( 'foo' | 'bar' ) 0 @{ res = 1; };
*/
//!ragel write data;
int main( int argc, char **argv )
{
int cs, res = 0;
if ( argc > 1 ) {
char *p = argv[1];
char *pe = p + strlen(p) + 1;
//!ragel write init;
//!ragel write exec;
}
printf("result = %i\n", res );
return 0;
}
-----------------------------------------------
What do you think?
Thanks for good tool.
Best regards,
Denis.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20190413/61484a48/attachment.html>
More information about the ragel-users
mailing list