Reputation: 312
How to write an antlr4 grammar lexer rule to not match a string. For example, I have the following input string :
CREATE TABLE person ( age integer, id integer, name character varying(30)), PRIMARY KEY ( id ) );
Here, I need to skip those create table queries like above which contains "PRIMARY KEY" constraint.
Can we use regular expressions directly in lexer rules ?
Upvotes: 0
Views: 706
Reputation: 231
Write a couple of rules for SQLs which are required and not required.
goodSQL:
'CREATE' 'TABLE' Id '('
Id typeDef (',' Id typeDef)? ','
')'
;
badSQL:
'CREATE' 'TABLE' Id '('
Id typeDef (',' Id typeDef)? ','
'PRIMARY' 'KEY' keyDef
')' ->skip
;
This is something to start with. You have to define Id
, typeDef
and keyDef
after this. Adding ->skip
will not parse SQL statements that match the rule.
Good Luck!
Upvotes: 0