For the mysql-proxy I'm exploring several ways to write a small
SQL parser for the internal commands. As I want to use basic SQL
to modify the config and the internal operations I need a parser.
Some time ago I used lemon which is used in sqlite3, which is
easier to use than yacc, but you still have to write the
lexer/tokenizer.
This time I looked into ragel which is a state-machine compiler.
Time get rid of code like this:
....
} else if (0 == g_ascii_strncasecmp(s->str + NET_HEADER_SIZE + 1,
C("update proxy_config set value=0 where option=\"proxy.profiling\""))) {
....
Ragel is a bit different than lex/yacc. Ragel combines the two
into one and builds a full state-machine for the input stream.
Just one file, one state-machine for the parser and lexer.
%%{
machine sql;
SELECT = /SELECT/i;
FROM = /FROM/i;
WHERE = …[Read more]