[英]antlr4 lexer rule to not match a string
How to write an antlr4 grammar lexer rule to not match a string. 如何编写不匹配字符串的antlr4语法词法分析器规则。 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. 在这里,我需要跳过包含“ PRIMARY KEY”约束的上述创建表查询。
Can we use regular expressions directly in lexer rules ? 我们可以在词法分析器规则中直接使用正则表达式吗?
Write a couple of rules for SQLs which are required and not required. 为SQL编写一些必需和不需要的规则。
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. 您必须在此之后定义
Id
, typeDef
和keyDef
。 Adding ->skip
will not parse SQL statements that match the rule. 添加
->skip
将不会解析与规则匹配的SQL语句。
Good Luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.