parsing SQL CREATE statement using ANTLR4: no viable alternative at input 'conflict' -


i'm newbie antlr user , trying parse following sql create statement. (i dropped unimportant part of both sql , grammar)

create table account (_id integer primary key, conflict integer default 1); 

and grammar this: (you can compile grammar copy&paste)

grammar createtable;  tablelist : (createtablestmt)* ;  createtablestmt : create table tablename lp columndefs (comma tableconstraints)? rp semicolon ;  columndefs      : columndef (comma columndef)* ; columndef       : columnname typename? columnconstraint* ; typename        : sqlitetype (lp signed_number (comma signed_number)? rp)?  ; sqlitetype      : inttype | texttype | id ; inttype         : 'integer'|'long'; texttype        : text ;   columnconstraint     : (constraint name)? primary key conflictclause?     | (constraint name)? unique conflictclause?     | (constraint name)? default signed_number     ;  tableconstraints     : tableconstraint (comma tableconstraint)* ;  tableconstraint     : (constraint name)? (primary key|unique) lp indexedcolumns rp conflictclause? ;  conflictclause  : on conflict replace ; indexedcolumns  : indexedcolumn (comma indexedcolumn)* ; indexedcolumn   : columnname; columnname      : name ; tablename       : name ; name            : id | '\"' id '\"' | string_literal ;  signed_number   : (plus|minus)? numeric_literal ; numeric_literal : digit+ ; string_literal  : '\'' (~'\'')* '\'' ;  lp              : '(' ; rp              : ')' ; comma           : ',' ; semicolon       : ';' ; plus            : '+' ; minus           : '-' ;  conflict        : c o n f l c t ;  constraint      : c o n s t r n t ;  create          : c r e t e ;  default         : d e f u l t; key             : k e y ;  on              : o n; primary         : p r m r y ;  replace         : r e p l c e; table           : t b l e ;  text            : t e x t; unique          : u n q u e ;   ws              : [ \t\r\n\f]+ -> channel(hidden); id              : letter (letter|digit)*; fragment letter : [a-za-z_]; fragment digit  : [0-9] ; nl              : '\r'? '\n' ;  fragment a:('a'|'a'); fragment b:('b'|'b'); fragment c:('c'|'c');  fragment d:('d'|'d'); fragment e:('e'|'e'); fragment f:('f'|'f');  fragment g:('g'|'g'); fragment i:('i'|'i'); fragment k:('k'|'k');  fragment l:('l'|'l'); fragment m:('m'|'m'); fragment n:('n'|'n');  fragment o:('o'|'o'); fragment p:('p'|'p'); fragment q:('q'|'q');  fragment r:('r'|'r'); fragment s:('s'|'s'); fragment t:('t'|'t');  fragment u:('u'|'u'); fragment x:('x'|'x'); 

by way, above sql statement should parse uses reserved word 'conflict' column name. if change column name 'conflict' other name 'conflict1' okay.

where should change parse above sql statement?

the parse trees this.

wrong case correct case

thanks

you defining input "conflict" separate token conflict. if valid table name , column name, should work:

name            : id | '\"' id '\"' | string_literal | conflict 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -