Alexandru Tică
2013-01-19 21:29:06 UTC
Hi,
I've written a simple scanner to match the "FROM t1, t2, .. , tn"
clause within an SQL statement.
The target language is ruby.
Please see below:
%%{
machine from_detector;
# define intereseting keywords
K_FROM = /from/i;
# strings
squoted_string = "'" ( (any - "''")** ) "'";
dquoted_string = '"' ( any )* :>> '"';
# comments
ml_comment = '/*' ( any )* :>> '*/';
sl_comment = '--' ( any )* :>> '\n';
comment = ml_comment | sl_comment;
# define whitespace
ws = space | comment;
simple_identifier = [0-9A-Za-z$#]+;
identifier = simple_identifier | dquoted_string;
# interesting spots
table_reference = (identifier '.')? identifier ('@' identifier)?;
from_spot = ws+ K_FROM ws+ table_reference (ws? ',' ws? table_reference)*;
main := |*
squoted_string;
dquoted_string;
comment;
from_spot => { puts "found FROM at #{ts}-#{te}" };
any;
*|;
}%%
data = 'select * from/*comment*/dual, sys.dba_tables;'
eof = data.length
%% write data;
%% write init;
%% write exec;
The problem is that the generated ruby code is invalid and I end up
with the following errors:
from_detector.rb:403: syntax error, unexpected keyword_else, expecting
keyword_when
from_detector.rb:453: syntax error, unexpected keyword_end, expecting $end
Apparently something is wrong with the "any" pattern. If I replace it with:
any => {}
everything's fine and the scanner is working without any problems. Is
this a bug?
I'm using ragel 6.7 with ruby 1.9.3.
Thanks!
I've written a simple scanner to match the "FROM t1, t2, .. , tn"
clause within an SQL statement.
The target language is ruby.
Please see below:
%%{
machine from_detector;
# define intereseting keywords
K_FROM = /from/i;
# strings
squoted_string = "'" ( (any - "''")** ) "'";
dquoted_string = '"' ( any )* :>> '"';
# comments
ml_comment = '/*' ( any )* :>> '*/';
sl_comment = '--' ( any )* :>> '\n';
comment = ml_comment | sl_comment;
# define whitespace
ws = space | comment;
simple_identifier = [0-9A-Za-z$#]+;
identifier = simple_identifier | dquoted_string;
# interesting spots
table_reference = (identifier '.')? identifier ('@' identifier)?;
from_spot = ws+ K_FROM ws+ table_reference (ws? ',' ws? table_reference)*;
main := |*
squoted_string;
dquoted_string;
comment;
from_spot => { puts "found FROM at #{ts}-#{te}" };
any;
*|;
}%%
data = 'select * from/*comment*/dual, sys.dba_tables;'
eof = data.length
%% write data;
%% write init;
%% write exec;
The problem is that the generated ruby code is invalid and I end up
with the following errors:
from_detector.rb:403: syntax error, unexpected keyword_else, expecting
keyword_when
from_detector.rb:453: syntax error, unexpected keyword_end, expecting $end
Apparently something is wrong with the "any" pattern. If I replace it with:
any => {}
everything's fine and the scanner is working without any problems. Is
this a bug?
I'm using ragel 6.7 with ruby 1.9.3.
Thanks!
--
talek
talek