1/* 2 * The MIT License (MIT) 3 * 4 * Copyright (c) 2014 by Bart Kiers 5 * 6 * Permission is hereby granted, free of charge, to any person 7 * obtaining a copy of this software and associated documentation 8 * files (the "Software"), to deal in the Software without 9 * restriction, including without limitation the rights to use, 10 * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following 13 * conditions: 14 * 15 * The above copyright notice and this permission notice shall be 16 * included in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * OTHER DEALINGS IN THE SOFTWARE. 26 * 27 * Project : sqlite-parser; an ANTLR4 grammar for SQLite 28 * https://github.com/bkiers/sqlite-parser 29 * Developed by : Bart Kiers, bart@big-o.nl 30 */ 31grammar SQLite; 32 33parse 34 : ( sql_stmt_list | error )* EOF 35 ; 36 37error 38 : UNEXPECTED_CHAR 39 { 40 throw new RuntimeException("UNEXPECTED_CHAR=" + $UNEXPECTED_CHAR.text); 41 } 42 ; 43 44sql_stmt_list 45 : ';'* sql_stmt ( ';'+ sql_stmt )* ';'* 46 ; 47 48sql_stmt 49 : ( K_EXPLAIN ( K_QUERY K_PLAN )? )? ( alter_table_stmt 50 | analyze_stmt 51 | attach_stmt 52 | begin_stmt 53 | commit_stmt 54 | compound_select_stmt 55 | create_index_stmt 56 | create_table_stmt 57 | create_trigger_stmt 58 | create_view_stmt 59 | create_virtual_table_stmt 60 | delete_stmt 61 | delete_stmt_limited 62 | detach_stmt 63 | drop_index_stmt 64 | drop_table_stmt 65 | drop_trigger_stmt 66 | drop_view_stmt 67 | factored_select_stmt 68 | insert_stmt 69 | pragma_stmt 70 | reindex_stmt 71 | release_stmt 72 | rollback_stmt 73 | savepoint_stmt 74 | simple_select_stmt 75 | select_stmt 76 | update_stmt 77 | update_stmt_limited 78 | vacuum_stmt ) 79 ; 80 81alter_table_stmt 82 : K_ALTER K_TABLE ( database_name '.' )? table_name 83 ( K_RENAME K_TO new_table_name 84 | K_ADD K_COLUMN? column_def 85 ) 86 ; 87 88analyze_stmt 89 : K_ANALYZE ( database_name | table_or_index_name | database_name '.' table_or_index_name )? 90 ; 91 92attach_stmt 93 : K_ATTACH K_DATABASE? expr K_AS database_name 94 ; 95 96begin_stmt 97 : K_BEGIN ( K_DEFERRED | K_IMMEDIATE | K_EXCLUSIVE )? ( K_TRANSACTION transaction_name? )? 98 ; 99 100commit_stmt 101 : ( K_COMMIT | K_END ) ( K_TRANSACTION transaction_name? )? 102 ; 103 104compound_select_stmt 105 : with_clause? 106 select_core ( ( K_UNION K_ALL? | K_INTERSECT | K_EXCEPT ) select_core )+ 107 ( K_ORDER K_BY ordering_term ( ',' ordering_term )* )? 108 ( K_LIMIT expr ( ( K_OFFSET | ',' ) expr )? )? 109 ; 110 111create_index_stmt 112 : K_CREATE K_UNIQUE? K_INDEX ( K_IF K_NOT K_EXISTS )? 113 ( database_name '.' )? index_name K_ON table_name '(' indexed_column ( ',' indexed_column )* ')' 114 ( K_WHERE expr )? 115 ; 116 117create_table_stmt 118 : K_CREATE ( K_TEMP | K_TEMPORARY )? K_TABLE ( K_IF K_NOT K_EXISTS )? 119 ( database_name '.' )? table_name 120 ( '(' column_def ( ',' column_def )*? ( ',' table_constraint )* ')' ( K_WITHOUT IDENTIFIER )? 121 | K_AS select_stmt 122 ) 123 ; 124 125create_trigger_stmt 126 : K_CREATE ( K_TEMP | K_TEMPORARY )? K_TRIGGER ( K_IF K_NOT K_EXISTS )? 127 ( database_name '.' )? trigger_name ( K_BEFORE | K_AFTER | K_INSTEAD K_OF )? 128 ( K_DELETE | K_INSERT | K_UPDATE ( K_OF column_name ( ',' column_name )* )? ) K_ON ( database_name '.' )? table_name 129 ( K_FOR K_EACH K_ROW )? ( K_WHEN expr )? 130 K_BEGIN ( ( update_stmt | insert_stmt | delete_stmt | select_stmt ) ';' )+ K_END 131 ; 132 133create_view_stmt 134 : K_CREATE ( K_TEMP | K_TEMPORARY )? K_VIEW ( K_IF K_NOT K_EXISTS )? 135 ( database_name '.' )? view_name K_AS select_stmt 136 ; 137 138create_virtual_table_stmt 139 : K_CREATE K_VIRTUAL K_TABLE ( K_IF K_NOT K_EXISTS )? 140 ( database_name '.' )? table_name 141 K_USING module_name ( '(' module_argument ( ',' module_argument )* ')' )? 142 ; 143 144delete_stmt 145 : with_clause? K_DELETE K_FROM qualified_table_name 146 ( K_WHERE expr )? 147 ; 148 149delete_stmt_limited 150 : with_clause? K_DELETE K_FROM qualified_table_name 151 ( K_WHERE expr )? 152 ( ( K_ORDER K_BY ordering_term ( ',' ordering_term )* )? 153 K_LIMIT expr ( ( K_OFFSET | ',' ) expr )? 154 )? 155 ; 156 157detach_stmt 158 : K_DETACH K_DATABASE? database_name 159 ; 160 161drop_index_stmt 162 : K_DROP K_INDEX ( K_IF K_EXISTS )? ( database_name '.' )? index_name 163 ; 164 165drop_table_stmt 166 : K_DROP K_TABLE ( K_IF K_EXISTS )? ( database_name '.' )? table_name 167 ; 168 169drop_trigger_stmt 170 : K_DROP K_TRIGGER ( K_IF K_EXISTS )? ( database_name '.' )? trigger_name 171 ; 172 173drop_view_stmt 174 : K_DROP K_VIEW ( K_IF K_EXISTS )? ( database_name '.' )? view_name 175 ; 176 177factored_select_stmt 178 : with_clause? 179 select_core ( compound_operator select_core )* 180 ( K_ORDER K_BY ordering_term ( ',' ordering_term )* )? 181 ( K_LIMIT expr ( ( K_OFFSET | ',' ) expr )? )? 182 ; 183 184insert_stmt 185 : with_clause? ( K_INSERT 186 | K_REPLACE 187 | K_INSERT K_OR K_REPLACE 188 | K_INSERT K_OR K_ROLLBACK 189 | K_INSERT K_OR K_ABORT 190 | K_INSERT K_OR K_FAIL 191 | K_INSERT K_OR K_IGNORE ) K_INTO 192 ( database_name '.' )? table_name ( '(' column_name ( ',' column_name )* ')' )? 193 ( K_VALUES '(' expr ( ',' expr )* ')' ( ',' '(' expr ( ',' expr )* ')' )* 194 | select_stmt 195 | K_DEFAULT K_VALUES 196 ) 197 ; 198 199pragma_stmt 200 : K_PRAGMA ( database_name '.' )? pragma_name ( '=' pragma_value 201 | '(' pragma_value ')' )? 202 ; 203 204reindex_stmt 205 : K_REINDEX ( collation_name 206 | ( database_name '.' )? ( table_name | index_name ) 207 )? 208 ; 209 210release_stmt 211 : K_RELEASE K_SAVEPOINT? savepoint_name 212 ; 213 214rollback_stmt 215 : K_ROLLBACK ( K_TRANSACTION transaction_name? )? ( K_TO K_SAVEPOINT? savepoint_name )? 216 ; 217 218savepoint_stmt 219 : K_SAVEPOINT savepoint_name 220 ; 221 222simple_select_stmt 223 : with_clause? 224 select_core ( K_ORDER K_BY ordering_term ( ',' ordering_term )* )? 225 ( K_LIMIT expr ( ( K_OFFSET | ',' ) expr )? )? 226 ; 227 228select_stmt 229 : with_clause? 230 select_or_values ( compound_operator select_or_values )* 231 ( K_ORDER K_BY ordering_term ( ',' ordering_term )* )? 232 ( K_LIMIT expr ( ( K_OFFSET | ',' ) expr )? )? 233 ; 234 235select_or_values 236 : K_SELECT ( K_DISTINCT | K_ALL )? result_column ( ',' result_column )* 237 ( K_FROM ( table_or_subquery ( ',' table_or_subquery )* | join_clause ) )? 238 ( K_WHERE expr )? 239 ( K_GROUP K_BY expr ( ',' expr )* ( K_HAVING expr )? )? 240 | K_VALUES '(' expr ( ',' expr )* ')' ( ',' '(' expr ( ',' expr )* ')' )* 241 ; 242 243update_stmt 244 : with_clause? K_UPDATE ( K_OR K_ROLLBACK 245 | K_OR K_ABORT 246 | K_OR K_REPLACE 247 | K_OR K_FAIL 248 | K_OR K_IGNORE )? qualified_table_name 249 K_SET column_name '=' expr ( ',' column_name '=' expr )* ( K_WHERE expr )? 250 ; 251 252update_stmt_limited 253 : with_clause? K_UPDATE ( K_OR K_ROLLBACK 254 | K_OR K_ABORT 255 | K_OR K_REPLACE 256 | K_OR K_FAIL 257 | K_OR K_IGNORE )? qualified_table_name 258 K_SET column_name '=' expr ( ',' column_name '=' expr )* ( K_WHERE expr )? 259 ( ( K_ORDER K_BY ordering_term ( ',' ordering_term )* )? 260 K_LIMIT expr ( ( K_OFFSET | ',' ) expr )? 261 )? 262 ; 263 264vacuum_stmt 265 : K_VACUUM 266 ; 267 268column_def 269 : column_name type_name? column_constraint* 270 ; 271 272type_name 273 : name+? ( '(' signed_number ')' 274 | '(' signed_number ',' signed_number ')' )? 275 ; 276 277column_constraint 278 : ( K_CONSTRAINT name )? 279 ( K_PRIMARY K_KEY ( K_ASC | K_DESC )? conflict_clause K_AUTOINCREMENT? 280 | K_NOT? K_NULL conflict_clause 281 | K_UNIQUE conflict_clause 282 | K_CHECK '(' expr ')' 283 | K_DEFAULT (signed_number | literal_value | '(' expr ')') 284 | K_COLLATE collation_name 285 | foreign_key_clause 286 ) 287 ; 288 289conflict_clause 290 : ( K_ON K_CONFLICT ( K_ROLLBACK 291 | K_ABORT 292 | K_FAIL 293 | K_IGNORE 294 | K_REPLACE 295 ) 296 )? 297 ; 298 299/* 300 SQLite understands the following binary operators, in order from highest to 301 lowest precedence: 302 303 || 304 * / % 305 + - 306 << >> & | 307 < <= > >= 308 = == != <> IS IS NOT IN LIKE GLOB MATCH REGEXP 309 AND 310 OR 311*/ 312expr 313 : literal_value 314 | BIND_PARAMETER 315 | ( ( database_name '.' )? table_name '.' )? column_name 316 | unary_operator expr 317 | expr '||' expr 318 | expr ( '*' | '/' | '%' ) expr 319 | expr ( '+' | '-' ) expr 320 | expr ( '<<' | '>>' | '&' | '|' ) expr 321 | expr ( '<' | '<=' | '>' | '>=' ) expr 322 | expr ( '=' | '==' | '!=' | '<>' ) expr 323 | expr K_AND expr 324 | expr K_OR expr 325 | function_name '(' ( K_DISTINCT? expr ( ',' expr )* | '*' )? ')' 326 | '(' expr ')' 327 | K_CAST '(' expr K_AS type_name ')' 328 | expr K_COLLATE collation_name 329 | expr K_NOT? ( K_LIKE | K_GLOB | K_REGEXP | K_MATCH ) expr ( K_ESCAPE expr )? 330 | expr ( K_ISNULL | K_NOTNULL | K_NOT K_NULL ) 331 | expr K_IS K_NOT? expr 332 | expr K_NOT? K_BETWEEN expr K_AND expr 333 | expr K_NOT? K_IN ( '(' ( select_stmt 334 | expr ( ',' expr )* 335 )? 336 ')' 337 | ( database_name '.' )? table_name ) 338 | ( ( K_NOT )? K_EXISTS )? '(' select_stmt ')' 339 | K_CASE expr? ( K_WHEN expr K_THEN expr )+ ( K_ELSE expr )? K_END 340 | raise_function 341 ; 342 343foreign_key_clause 344 : K_REFERENCES foreign_table ( '(' column_name ( ',' column_name )* ')' )? 345 ( ( K_ON ( K_DELETE | K_UPDATE ) ( K_SET K_NULL 346 | K_SET K_DEFAULT 347 | K_CASCADE 348 | K_RESTRICT 349 | K_NO K_ACTION ) 350 | K_MATCH name 351 ) 352 )* 353 ( K_NOT? K_DEFERRABLE ( K_INITIALLY K_DEFERRED | K_INITIALLY K_IMMEDIATE )? )? 354 ; 355 356raise_function 357 : K_RAISE '(' ( K_IGNORE 358 | ( K_ROLLBACK | K_ABORT | K_FAIL ) ',' error_message ) 359 ')' 360 ; 361 362indexed_column 363 : column_name ( K_COLLATE collation_name )? ( K_ASC | K_DESC )? 364 ; 365 366table_constraint 367 : ( K_CONSTRAINT name )? 368 ( ( K_PRIMARY K_KEY | K_UNIQUE ) '(' indexed_column ( ',' indexed_column )* ')' conflict_clause 369 | K_CHECK '(' expr ')' 370 | K_FOREIGN K_KEY '(' column_name ( ',' column_name )* ')' foreign_key_clause 371 ) 372 ; 373 374with_clause 375 : K_WITH K_RECURSIVE? common_table_expression ( ',' common_table_expression )* 376 ; 377 378qualified_table_name 379 : ( database_name '.' )? table_name ( K_INDEXED K_BY index_name 380 | K_NOT K_INDEXED )? 381 ; 382 383ordering_term 384 : expr ( K_COLLATE collation_name )? ( K_ASC | K_DESC )? 385 ; 386 387pragma_value 388 : signed_number 389 | name 390 | STRING_LITERAL 391 ; 392 393common_table_expression 394 : table_name ( '(' column_name ( ',' column_name )* ')' )? K_AS '(' select_stmt ')' 395 ; 396 397result_column 398 : '*' 399 | table_name '.' '*' 400 | expr ( K_AS? column_alias )? 401 ; 402 403table_or_subquery 404 : ( schema_name '.' )? table_name ( K_AS? table_alias )? 405 ( K_INDEXED K_BY index_name 406 | K_NOT K_INDEXED )? 407 | ( schema_name '.' )? table_function_name '(' ( expr ( ',' expr )* )? ')' ( K_AS? table_alias )? 408 | '(' ( table_or_subquery ( ',' table_or_subquery )* 409 | join_clause ) 410 ')' 411 | '(' select_stmt ')' ( K_AS? table_alias )? 412 ; 413 414join_clause 415 : table_or_subquery ( join_operator table_or_subquery join_constraint )* 416 ; 417 418join_operator 419 : ',' 420 | K_NATURAL? ( K_LEFT K_OUTER? | K_INNER | K_CROSS )? K_JOIN 421 ; 422 423join_constraint 424 : ( K_ON expr 425 | K_USING '(' column_name ( ',' column_name )* ')' )? 426 ; 427 428select_core 429 : K_SELECT ( K_DISTINCT | K_ALL )? result_column ( ',' result_column )* 430 ( K_FROM ( table_or_subquery ( ',' table_or_subquery )* | join_clause ) )? 431 ( K_WHERE expr )? 432 ( K_GROUP K_BY expr ( ',' expr )* ( K_HAVING expr )? )? 433 | K_VALUES '(' expr ( ',' expr )* ')' ( ',' '(' expr ( ',' expr )* ')' )* 434 ; 435 436compound_operator 437 : K_UNION 438 | K_UNION K_ALL 439 | K_INTERSECT 440 | K_EXCEPT 441 ; 442 443signed_number 444 : ( '+' | '-' )? NUMERIC_LITERAL 445 ; 446 447literal_value 448 : NUMERIC_LITERAL 449 | STRING_LITERAL 450 | BLOB_LITERAL 451 | K_NULL 452 | K_CURRENT_TIME 453 | K_CURRENT_DATE 454 | K_CURRENT_TIMESTAMP 455 ; 456 457unary_operator 458 : '-' 459 | '+' 460 | '~' 461 | K_NOT 462 ; 463 464error_message 465 : STRING_LITERAL 466 ; 467 468module_argument // TODO check what exactly is permitted here 469 : expr 470 | column_def 471 ; 472 473column_alias 474 : IDENTIFIER 475 | STRING_LITERAL 476 ; 477 478keyword 479 : K_ABORT 480 | K_ACTION 481 | K_ADD 482 | K_AFTER 483 | K_ALL 484 | K_ALTER 485 | K_ANALYZE 486 | K_AND 487 | K_AS 488 | K_ASC 489 | K_ATTACH 490 | K_AUTOINCREMENT 491 | K_BEFORE 492 | K_BEGIN 493 | K_BETWEEN 494 | K_BY 495 | K_CASCADE 496 | K_CASE 497 | K_CAST 498 | K_CHECK 499 | K_COLLATE 500 | K_COLUMN 501 | K_COMMIT 502 | K_CONFLICT 503 | K_CONSTRAINT 504 | K_CREATE 505 | K_CROSS 506 | K_CURRENT_DATE 507 | K_CURRENT_TIME 508 | K_CURRENT_TIMESTAMP 509 | K_DATABASE 510 | K_DEFAULT 511 | K_DEFERRABLE 512 | K_DEFERRED 513 | K_DELETE 514 | K_DESC 515 | K_DETACH 516 | K_DISTINCT 517 | K_DROP 518 | K_EACH 519 | K_ELSE 520 | K_END 521 | K_ESCAPE 522 | K_EXCEPT 523 | K_EXCLUSIVE 524 | K_EXISTS 525 | K_EXPLAIN 526 | K_FAIL 527 | K_FOR 528 | K_FOREIGN 529 | K_FROM 530 | K_FULL 531 | K_GLOB 532 | K_GROUP 533 | K_HAVING 534 | K_IF 535 | K_IGNORE 536 | K_IMMEDIATE 537 | K_IN 538 | K_INDEX 539 | K_INDEXED 540 | K_INITIALLY 541 | K_INNER 542 | K_INSERT 543 | K_INSTEAD 544 | K_INTERSECT 545 | K_INTO 546 | K_IS 547 | K_ISNULL 548 | K_JOIN 549 | K_KEY 550 | K_LEFT 551 | K_LIKE 552 | K_LIMIT 553 | K_MATCH 554 | K_NATURAL 555 | K_NO 556 | K_NOT 557 | K_NOTNULL 558 | K_NULL 559 | K_OF 560 | K_OFFSET 561 | K_ON 562 | K_OR 563 | K_ORDER 564 | K_OUTER 565 | K_PLAN 566 | K_PRAGMA 567 | K_PRIMARY 568 | K_QUERY 569 | K_RAISE 570 | K_RECURSIVE 571 | K_REFERENCES 572 | K_REGEXP 573 | K_REINDEX 574 | K_RELEASE 575 | K_RENAME 576 | K_REPLACE 577 | K_RESTRICT 578 | K_RIGHT 579 | K_ROLLBACK 580 | K_ROW 581 | K_SAVEPOINT 582 | K_SELECT 583 | K_SET 584 | K_TABLE 585 | K_TEMP 586 | K_TEMPORARY 587 | K_THEN 588 | K_TO 589 | K_TRANSACTION 590 | K_TRIGGER 591 | K_UNION 592 | K_UNIQUE 593 | K_UPDATE 594 | K_USING 595 | K_VACUUM 596 | K_VALUES 597 | K_VIEW 598 | K_VIRTUAL 599 | K_WHEN 600 | K_WHERE 601 | K_WITH 602 | K_WITHOUT 603 ; 604 605// TODO check all names below 606 607name 608 : any_name 609 ; 610 611function_name 612 : any_name 613 ; 614 615database_name 616 : any_name 617 ; 618 619schema_name 620 : any_name 621 ; 622 623table_function_name 624 : any_name 625 ; 626 627table_name 628 : any_name 629 ; 630 631table_or_index_name 632 : any_name 633 ; 634 635new_table_name 636 : any_name 637 ; 638 639column_name 640 : any_name 641 ; 642 643collation_name 644 : any_name 645 ; 646 647foreign_table 648 : any_name 649 ; 650 651index_name 652 : any_name 653 ; 654 655trigger_name 656 : any_name 657 ; 658 659view_name 660 : any_name 661 ; 662 663module_name 664 : any_name 665 ; 666 667pragma_name 668 : any_name 669 ; 670 671savepoint_name 672 : any_name 673 ; 674 675table_alias 676 : IDENTIFIER 677 | STRING_LITERAL 678 | '(' table_alias ')' 679 ; 680 681transaction_name 682 : any_name 683 ; 684 685any_name 686 : IDENTIFIER 687 | keyword 688 | STRING_LITERAL 689 | '(' any_name ')' 690 ; 691 692SCOL : ';'; 693DOT : '.'; 694OPEN_PAR : '('; 695CLOSE_PAR : ')'; 696COMMA : ','; 697ASSIGN : '='; 698STAR : '*'; 699PLUS : '+'; 700MINUS : '-'; 701TILDE : '~'; 702PIPE2 : '||'; 703DIV : '/'; 704MOD : '%'; 705LT2 : '<<'; 706GT2 : '>>'; 707AMP : '&'; 708PIPE : '|'; 709LT : '<'; 710LT_EQ : '<='; 711GT : '>'; 712GT_EQ : '>='; 713EQ : '=='; 714NOT_EQ1 : '!='; 715NOT_EQ2 : '<>'; 716 717// http://www.sqlite.org/lang_keywords.html 718K_ABORT : A B O R T; 719K_ACTION : A C T I O N; 720K_ADD : A D D; 721K_AFTER : A F T E R; 722K_ALL : A L L; 723K_ALTER : A L T E R; 724K_ANALYZE : A N A L Y Z E; 725K_AND : A N D; 726K_AS : A S; 727K_ASC : A S C; 728K_ATTACH : A T T A C H; 729K_AUTOINCREMENT : A U T O I N C R E M E N T; 730K_BEFORE : B E F O R E; 731K_BEGIN : B E G I N; 732K_BETWEEN : B E T W E E N; 733K_BY : B Y; 734K_CASCADE : C A S C A D E; 735K_CASE : C A S E; 736K_CAST : C A S T; 737K_CHECK : C H E C K; 738K_COLLATE : C O L L A T E; 739K_COLUMN : C O L U M N; 740K_COMMIT : C O M M I T; 741K_CONFLICT : C O N F L I C T; 742K_CONSTRAINT : C O N S T R A I N T; 743K_CREATE : C R E A T E; 744K_CROSS : C R O S S; 745K_CURRENT_DATE : C U R R E N T '_' D A T E; 746K_CURRENT_TIME : C U R R E N T '_' T I M E; 747K_CURRENT_TIMESTAMP : C U R R E N T '_' T I M E S T A M P; 748K_DATABASE : D A T A B A S E; 749K_DEFAULT : D E F A U L T; 750K_DEFERRABLE : D E F E R R A B L E; 751K_DEFERRED : D E F E R R E D; 752K_DELETE : D E L E T E; 753K_DESC : D E S C; 754K_DETACH : D E T A C H; 755K_DISTINCT : D I S T I N C T; 756K_DROP : D R O P; 757K_EACH : E A C H; 758K_ELSE : E L S E; 759K_END : E N D; 760K_ESCAPE : E S C A P E; 761K_EXCEPT : E X C E P T; 762K_EXCLUSIVE : E X C L U S I V E; 763K_EXISTS : E X I S T S; 764K_EXPLAIN : E X P L A I N; 765K_FAIL : F A I L; 766K_FOR : F O R; 767K_FOREIGN : F O R E I G N; 768K_FROM : F R O M; 769K_FULL : F U L L; 770K_GLOB : G L O B; 771K_GROUP : G R O U P; 772K_HAVING : H A V I N G; 773K_IF : I F; 774K_IGNORE : I G N O R E; 775K_IMMEDIATE : I M M E D I A T E; 776K_IN : I N; 777K_INDEX : I N D E X; 778K_INDEXED : I N D E X E D; 779K_INITIALLY : I N I T I A L L Y; 780K_INNER : I N N E R; 781K_INSERT : I N S E R T; 782K_INSTEAD : I N S T E A D; 783K_INTERSECT : I N T E R S E C T; 784K_INTO : I N T O; 785K_IS : I S; 786K_ISNULL : I S N U L L; 787K_JOIN : J O I N; 788K_KEY : K E Y; 789K_LEFT : L E F T; 790K_LIKE : L I K E; 791K_LIMIT : L I M I T; 792K_MATCH : M A T C H; 793K_NATURAL : N A T U R A L; 794K_NO : N O; 795K_NOT : N O T; 796K_NOTNULL : N O T N U L L; 797K_NULL : N U L L; 798K_OF : O F; 799K_OFFSET : O F F S E T; 800K_ON : O N; 801K_OR : O R; 802K_ORDER : O R D E R; 803K_OUTER : O U T E R; 804K_PLAN : P L A N; 805K_PRAGMA : P R A G M A; 806K_PRIMARY : P R I M A R Y; 807K_QUERY : Q U E R Y; 808K_RAISE : R A I S E; 809K_RECURSIVE : R E C U R S I V E; 810K_REFERENCES : R E F E R E N C E S; 811K_REGEXP : R E G E X P; 812K_REINDEX : R E I N D E X; 813K_RELEASE : R E L E A S E; 814K_RENAME : R E N A M E; 815K_REPLACE : R E P L A C E; 816K_RESTRICT : R E S T R I C T; 817K_RIGHT : R I G H T; 818K_ROLLBACK : R O L L B A C K; 819K_ROW : R O W; 820K_SAVEPOINT : S A V E P O I N T; 821K_SELECT : S E L E C T; 822K_SET : S E T; 823K_TABLE : T A B L E; 824K_TEMP : T E M P; 825K_TEMPORARY : T E M P O R A R Y; 826K_THEN : T H E N; 827K_TO : T O; 828K_TRANSACTION : T R A N S A C T I O N; 829K_TRIGGER : T R I G G E R; 830K_UNION : U N I O N; 831K_UNIQUE : U N I Q U E; 832K_UPDATE : U P D A T E; 833K_USING : U S I N G; 834K_VACUUM : V A C U U M; 835K_VALUES : V A L U E S; 836K_VIEW : V I E W; 837K_VIRTUAL : V I R T U A L; 838K_WHEN : W H E N; 839K_WHERE : W H E R E; 840K_WITH : W I T H; 841K_WITHOUT : W I T H O U T; 842 843IDENTIFIER 844 : '"' (~'"' | '""')* '"' 845 | '`' (~'`' | '``')* '`' 846 | '[' ~']'* ']' 847 | [a-zA-Z_] [a-zA-Z_0-9]* // TODO check: needs more chars in set 848 ; 849 850NUMERIC_LITERAL 851 : DIGIT+ ( '.' DIGIT* )? ( E [-+]? DIGIT+ )? 852 | '.' DIGIT+ ( E [-+]? DIGIT+ )? 853 ; 854 855BIND_PARAMETER 856 : '?' DIGIT* 857 | [:@$] IDENTIFIER 858 ; 859 860STRING_LITERAL 861 : '\'' ( ~'\'' | '\'\'' )* '\'' 862 ; 863 864BLOB_LITERAL 865 : X STRING_LITERAL 866 ; 867 868SINGLE_LINE_COMMENT 869 : '--' ~[\r\n]* -> channel(HIDDEN) 870 ; 871 872MULTILINE_COMMENT 873 : '/*' .*? ( '*/' | EOF ) -> channel(HIDDEN) 874 ; 875 876SPACES 877 : [ \u000B\t\r\n] -> channel(HIDDEN) 878 ; 879 880UNEXPECTED_CHAR 881 : . 882 ; 883 884fragment DIGIT : [0-9]; 885 886fragment A : [aA]; 887fragment B : [bB]; 888fragment C : [cC]; 889fragment D : [dD]; 890fragment E : [eE]; 891fragment F : [fF]; 892fragment G : [gG]; 893fragment H : [hH]; 894fragment I : [iI]; 895fragment J : [jJ]; 896fragment K : [kK]; 897fragment L : [lL]; 898fragment M : [mM]; 899fragment N : [nN]; 900fragment O : [oO]; 901fragment P : [pP]; 902fragment Q : [qQ]; 903fragment R : [rR]; 904fragment S : [sS]; 905fragment T : [tT]; 906fragment U : [uU]; 907fragment V : [vV]; 908fragment W : [wW]; 909fragment X : [xX]; 910fragment Y : [yY]; 911fragment Z : [zZ];