[antlr-interest] Help on parsing SQL statements
Andi Clemens
Andi.Clemens at gmx.net
Tue Apr 6 04:23:30 PDT 2010
Hi,
I'm implementing a parser that returns the table_spec that is used in an (Oracle)SQL-Statement. The parser decides whether the statement should be executed or not.
I don't need all SQL statements that can occur, only the ones with table_specs in it, like SELECT, INSERT, DELETE, CREATE TABLE etc.
In most cases I don't even need to know the whole SQL statement, only parts of it. So I have rules that look something like this:
alter_materialized_view_statement
: 'ALTER' 'MATERIALIZED' 'VIEW'
('LOG' 'FORCE'? 'ON')? table_spec .*
;
alter_view_statement
: 'ALTER' 'VIEW' table_spec
('ADD' | 'MODIFY' | 'DROP' | 'COMPILE') .*
;
But when I type in the following statement, the parser is not able to parse it:
ALTER VIEW schema.table [...];
Also the next statement is not working:
ALTER MATERIALIZED VIEW LOG ON schema.test [...];
Is it because I use ".*" in the rules? Why isn't ANTLR able to decide which rule to use here? They clearly start differently.
I always get the following error:
statementString(1) : error 3 : , at offset -1
near [Index: 0 (Start: 4058184-Stop: 4058188) ='alter', type<118> Line: 1 LinePos:-1]
: cannot match to any predicted input...
Any idea how to fix that?
In the end, I only want to have some statements checked (the one with table_specs), other statements should be ignored (on parse error).
Andi
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
More information about the antlr-interest
mailing list