├── .gitattributes ├── .prettierignore ├── .gitignore ├── README.md ├── test └── corpus │ ├── expr.parenthesis.txt │ ├── stmt.savepoint.txt │ ├── empty.txt │ ├── stmt.attach.txt │ ├── stmt.commit.txt │ ├── stmt.detach.txt │ ├── stmt.explain.txt │ ├── stmt.reindex.txt │ ├── stmt.release.txt │ ├── stmt.begin.txt │ ├── expr.is.txt │ ├── stmt.analyze.txt │ ├── expr.collate.txt │ ├── expr.table.txt │ ├── expr.null.txt │ ├── expr.unary.txt │ ├── expr.between.txt │ ├── stmt.drop_view.txt │ ├── stmt.drop_index.txt │ ├── stmt.drop_table.txt │ ├── stmt.rollback.txt │ ├── stmt.drop_trigger.txt │ ├── stmt.vacuum.txt │ ├── stmt.pragma.txt │ ├── expr.json-operator.txt │ ├── expr.cast.txt │ ├── expr.exists.txt │ ├── expr.parammeter.txt │ ├── expr.function.txt │ ├── expr.raise-function.txt │ ├── expr.literal-value.txt │ ├── stmt.alter_table.txt │ ├── expr.signed-number.txt │ ├── stmt.select.result-column.txt │ ├── stmt.select.ordering-term.txt │ ├── stmt.select.compound-operator.txt │ ├── stmt.select.join-constraint.txt │ ├── expr.in.txt │ ├── expr.case.txt │ ├── expr.like.txt │ ├── stmt.create_table.strict.txt │ ├── expr.binary.txt │ ├── stmt.create_table.table-constraint.txt │ ├── stmt.delete.txt │ ├── stmt.select.join-op.txt │ ├── stmt.create_table.txt │ ├── stmt.select.txt │ ├── stmt.create_table.column-constraint.txt │ ├── stmt.update.txt │ ├── stmt.create_table.reference.txt │ └── stmt.select.core.txt ├── binding.gyp ├── Makefile ├── bindings ├── node │ ├── index.js │ └── binding.cc └── rust │ ├── build.rs │ └── lib.rs ├── Cargo.toml ├── package.json ├── .github └── workflows │ └── ci.yaml ├── LICENSE ├── pnpm-lock.yaml ├── queries └── highlights.scm ├── src └── tree_sitter │ └── parser.h └── grammar.js /.gitattributes: -------------------------------------------------------------------------------- 1 | /src/** linguist-vendored 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | pnpm-lock.yaml 3 | bindings 4 | src 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /node_modules/ 3 | /package-lock.json 4 | /target/ 5 | /Cargo.lock 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tree-sitter-sqlite 2 | 3 | SQLite grammar for the [tree-sitter](https://github.com/tree-sitter/tree-sitter) parsing library. 4 | 5 | ## credit 6 | 7 | - https://github.com/bkiers/sqlite-parser 8 | - https://github.com/sqlite/sqlite/blob/version-3.35.5/src/parse.y 9 | -------------------------------------------------------------------------------- /test/corpus/expr.parenthesis.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.parenthesis 3 | ================================================================================ 4 | 5 | SELECT ( 1 ); 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (sql_stmt_list 10 | (sql_stmt 11 | (select_stmt 12 | (SELECT) 13 | (numeric_literal)))) 14 | -------------------------------------------------------------------------------- /test/corpus/stmt.savepoint.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.savepoint 3 | ================================================================================ 4 | 5 | SAVEPOINT point; 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (sql_stmt_list 10 | (sql_stmt 11 | (savepoint_stmt 12 | (SAVEPOINT) 13 | (identifier)))) 14 | -------------------------------------------------------------------------------- /test/corpus/empty.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | empty 3 | ================================================================================ 4 | 5 | ; 6 | -- comment 7 | ;; 8 | /* comment */ 9 | ;;; 10 | /* /* comment * / */ 11 | 12 | -------------------------------------------------------------------------------- 13 | 14 | (sql_stmt_list 15 | (comment) 16 | (comment) 17 | (comment)) 18 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "tree_sitter_sqlite_binding", 5 | "include_dirs": [ 6 | " '$.a'; 6 | SELECT '{"a":NULL}' ->> '$.a'; 7 | SELECT y -> '$'; 8 | SELECT x -> '$'; 9 | 10 | -------------------------------------------------------------------------------- 11 | 12 | (sql_stmt_list 13 | (sql_stmt 14 | (select_stmt 15 | (SELECT) 16 | (string_literal) 17 | (string_literal))) 18 | (sql_stmt 19 | (select_stmt 20 | (SELECT) 21 | (string_literal) 22 | (string_literal))) 23 | (sql_stmt 24 | (select_stmt 25 | (SELECT) 26 | (identifier) 27 | (string_literal))) 28 | (sql_stmt 29 | (select_stmt 30 | (SELECT) 31 | (identifier) 32 | (string_literal)))) 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tree-sitter-sqlite", 3 | "version": "0.0.2", 4 | "description": "SQLite grammar for the tree-sitter parsing library", 5 | "author": "H11", 6 | "license": "MIT", 7 | "dependencies": { 8 | "nan": "2.17.0" 9 | }, 10 | "devDependencies": { 11 | "prettier": "2.8.8", 12 | "tree-sitter-cli": "0.20.8" 13 | }, 14 | "tree-sitter": [ 15 | { 16 | "scope": "source.sql", 17 | "file-types": [ 18 | "sql" 19 | ], 20 | "highlights": "queries/highlights.scm", 21 | "injection-regex": "^(sql)$" 22 | } 23 | ], 24 | "main": "bindings/node", 25 | "prettier": { 26 | "printWidth": 80, 27 | "tabWidth": 4, 28 | "useTabs": true, 29 | "semi": false, 30 | "singleQuote": false, 31 | "quoteProps": "as-needed", 32 | "trailingComma": "all", 33 | "bracketSpacing": true, 34 | "bracketSameLine": false, 35 | "arrowParens": "always", 36 | "endOfLine": "lf" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/corpus/expr.cast.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.cast 3 | ================================================================================ 4 | 5 | SELECT CAST ( '123' AS integer ); 6 | SELECT CAST ( '123' AS 'abcd' ); 7 | SELECT CAST ( '123' AS 'ab$ $cd' ); 8 | 9 | -------------------------------------------------------------------------------- 10 | 11 | (sql_stmt_list 12 | (sql_stmt 13 | (select_stmt 14 | (SELECT) 15 | (CAST) 16 | (string_literal) 17 | (AS) 18 | (type_name 19 | (identifier)))) 20 | (sql_stmt 21 | (select_stmt 22 | (SELECT) 23 | (CAST) 24 | (string_literal) 25 | (AS) 26 | (type_name 27 | (string_literal)))) 28 | (sql_stmt 29 | (select_stmt 30 | (SELECT) 31 | (CAST) 32 | (string_literal) 33 | (AS) 34 | (type_name 35 | (string_literal))))) 36 | -------------------------------------------------------------------------------- /test/corpus/expr.exists.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.exists 3 | ================================================================================ 4 | 5 | SELECT EXISTS (SELECT cname FROM tblname); 6 | SELECT NOT EXISTS (SELECT cname FROM tblname); 7 | 8 | -------------------------------------------------------------------------------- 9 | 10 | (sql_stmt_list 11 | (sql_stmt 12 | (select_stmt 13 | (SELECT) 14 | (EXISTS) 15 | (select_stmt 16 | (SELECT) 17 | (identifier) 18 | (from_clause 19 | (FROM) 20 | (table_or_subquery 21 | (identifier)))))) 22 | (sql_stmt 23 | (select_stmt 24 | (SELECT) 25 | (NOT) 26 | (EXISTS) 27 | (select_stmt 28 | (SELECT) 29 | (identifier) 30 | (from_clause 31 | (FROM) 32 | (table_or_subquery 33 | (identifier))))))) 34 | -------------------------------------------------------------------------------- /bindings/node/binding.cc: -------------------------------------------------------------------------------- 1 | #include "tree_sitter/parser.h" 2 | #include 3 | #include "nan.h" 4 | 5 | using namespace v8; 6 | 7 | extern "C" TSLanguage * tree_sitter_sqlite(); 8 | 9 | namespace { 10 | 11 | NAN_METHOD(New) {} 12 | 13 | void Init(Local exports, Local module) { 14 | Local tpl = Nan::New(New); 15 | tpl->SetClassName(Nan::New("Language").ToLocalChecked()); 16 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 17 | 18 | Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); 19 | Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); 20 | Nan::SetInternalFieldPointer(instance, 0, tree_sitter_sqlite()); 21 | 22 | Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("sqlite").ToLocalChecked()); 23 | Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); 24 | } 25 | 26 | NODE_MODULE(tree_sitter_sqlite_binding, Init) 27 | 28 | } // namespace 29 | -------------------------------------------------------------------------------- /test/corpus/expr.parammeter.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.parameter 3 | ================================================================================ 4 | 5 | SELECT ?; 6 | SELECT ?123; 7 | SELECT @hello; 8 | SELECT :world; 9 | SELECT $tcl; 10 | -- SELECT $tcl(array); -- SQLITE_OMIT_TCL_VARIABLE https://github.com/sqlite/sqlite/blob/version-3.35.5/src/tokenize.c#L482-L495 11 | 12 | -------------------------------------------------------------------------------- 13 | 14 | (sql_stmt_list 15 | (sql_stmt 16 | (select_stmt 17 | (SELECT) 18 | (bind_parameter))) 19 | (sql_stmt 20 | (select_stmt 21 | (SELECT) 22 | (bind_parameter))) 23 | (sql_stmt 24 | (select_stmt 25 | (SELECT) 26 | (bind_parameter))) 27 | (sql_stmt 28 | (select_stmt 29 | (SELECT) 30 | (bind_parameter))) 31 | (sql_stmt 32 | (select_stmt 33 | (SELECT) 34 | (bind_parameter))) 35 | (comment)) 36 | -------------------------------------------------------------------------------- /test/corpus/expr.function.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.function 3 | ================================================================================ 4 | 5 | SELECT changes(); 6 | SELECT count(*); 7 | SELECT count(DISTINCT "a"); 8 | SELECT substr('abc', 10, 20); 9 | 10 | -------------------------------------------------------------------------------- 11 | 12 | (sql_stmt_list 13 | (sql_stmt 14 | (select_stmt 15 | (SELECT) 16 | (function_name 17 | (identifier)))) 18 | (sql_stmt 19 | (select_stmt 20 | (SELECT) 21 | (function_name 22 | (identifier)))) 23 | (sql_stmt 24 | (select_stmt 25 | (SELECT) 26 | (function_name 27 | (identifier)) 28 | (DISTINCT) 29 | (identifier))) 30 | (sql_stmt 31 | (select_stmt 32 | (SELECT) 33 | (function_name 34 | (identifier)) 35 | (string_literal) 36 | (numeric_literal) 37 | (numeric_literal)))) 38 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | pull_request: 4 | push: 5 | jobs: 6 | test: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | fail-fast: true 10 | matrix: 11 | os: 12 | - macos-latest 13 | - ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3.5.2 16 | - uses: actions/setup-node@v3.6.0 17 | with: 18 | node-version: "20.x" 19 | - uses: actions/cache@v3.3.1 20 | with: 21 | path: ~/.local/share/pnpm/store 22 | key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} 23 | restore-keys: ${{ runner.os }}-pnpm- 24 | - run: | 25 | corepack enable 26 | corepack prepare pnpm@8.6.3 --activate 27 | pnpm config set store-dir ~/.local/share/pnpm/store 28 | pnpm install 29 | env: 30 | PNPM_HOME: /home/runner/.local/bin 31 | - run: make test 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 h11 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/corpus/expr.raise-function.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.raise-function 3 | ================================================================================ 4 | 5 | SELECT RAISE(IGNORE); 6 | SELECT RAISE(ROLLBACK, 'error message'); 7 | SELECT RAISE(ABORT, 'error message'); 8 | SELECT RAISE(FAIL, 'error message'); 9 | 10 | -------------------------------------------------------------------------------- 11 | 12 | (sql_stmt_list 13 | (sql_stmt 14 | (select_stmt 15 | (SELECT) 16 | (raise_function 17 | (RAISE) 18 | (IGNORE)))) 19 | (sql_stmt 20 | (select_stmt 21 | (SELECT) 22 | (raise_function 23 | (RAISE) 24 | (ROLLBACK) 25 | (error_message 26 | (string_literal))))) 27 | (sql_stmt 28 | (select_stmt 29 | (SELECT) 30 | (raise_function 31 | (RAISE) 32 | (ABORT) 33 | (error_message 34 | (string_literal))))) 35 | (sql_stmt 36 | (select_stmt 37 | (SELECT) 38 | (raise_function 39 | (RAISE) 40 | (FAIL) 41 | (error_message 42 | (string_literal)))))) 43 | -------------------------------------------------------------------------------- /test/corpus/expr.literal-value.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.literal-value 3 | ================================================================================ 4 | 5 | SELECT 123; 6 | SELECT 123.4e05; 7 | SELECT 'abcde'; 8 | SELECT X'414243'; 9 | SELECT NULL; 10 | SELECT CURRENT_TIME; 11 | SELECT CURRENT_DATE; 12 | SELECT CURRENT_TIMESTAMP; 13 | 14 | -------------------------------------------------------------------------------- 15 | 16 | (sql_stmt_list 17 | (sql_stmt 18 | (select_stmt 19 | (SELECT) 20 | (numeric_literal))) 21 | (sql_stmt 22 | (select_stmt 23 | (SELECT) 24 | (numeric_literal))) 25 | (sql_stmt 26 | (select_stmt 27 | (SELECT) 28 | (string_literal))) 29 | (sql_stmt 30 | (select_stmt 31 | (SELECT) 32 | (blob_literal))) 33 | (sql_stmt 34 | (select_stmt 35 | (SELECT) 36 | (NULL))) 37 | (sql_stmt 38 | (select_stmt 39 | (SELECT) 40 | (CURRENT_TIME))) 41 | (sql_stmt 42 | (select_stmt 43 | (SELECT) 44 | (CURRENT_DATE))) 45 | (sql_stmt 46 | (select_stmt 47 | (SELECT) 48 | (CURRENT_TIMESTAMP)))) 49 | -------------------------------------------------------------------------------- /test/corpus/stmt.alter_table.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.alter_table 3 | ================================================================================ 4 | 5 | ALTER TABLE schema.tbl RENAME TO tbl2; 6 | ALTER TABLE tbl RENAME TO tbl2; 7 | ALTER TABLE tbl RENAME col1 TO col2; 8 | ALTER TABLE tbl RENAME COLUMN col1 TO col2; 9 | 10 | -------------------------------------------------------------------------------- 11 | 12 | (sql_stmt_list 13 | (sql_stmt 14 | (alter_table_stmt 15 | (ALTER) 16 | (TABLE) 17 | (identifier) 18 | (identifier) 19 | (RENAME) 20 | (TO) 21 | (identifier))) 22 | (sql_stmt 23 | (alter_table_stmt 24 | (ALTER) 25 | (TABLE) 26 | (identifier) 27 | (RENAME) 28 | (TO) 29 | (identifier))) 30 | (sql_stmt 31 | (alter_table_stmt 32 | (ALTER) 33 | (TABLE) 34 | (identifier) 35 | (RENAME) 36 | (identifier) 37 | (TO) 38 | (identifier))) 39 | (sql_stmt 40 | (alter_table_stmt 41 | (ALTER) 42 | (TABLE) 43 | (identifier) 44 | (RENAME) 45 | (COLUMN) 46 | (identifier) 47 | (TO) 48 | (identifier)))) 49 | -------------------------------------------------------------------------------- /pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: "6.0" 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | dependencies: 8 | nan: 9 | specifier: 2.17.0 10 | version: 2.17.0 11 | 12 | devDependencies: 13 | prettier: 14 | specifier: 2.8.8 15 | version: 2.8.8 16 | tree-sitter-cli: 17 | specifier: 0.20.8 18 | version: 0.20.8 19 | 20 | packages: 21 | /nan@2.17.0: 22 | resolution: 23 | { 24 | integrity: sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==, 25 | } 26 | dev: false 27 | 28 | /prettier@2.8.8: 29 | resolution: 30 | { 31 | integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==, 32 | } 33 | engines: { node: ">=10.13.0" } 34 | hasBin: true 35 | dev: true 36 | 37 | /tree-sitter-cli@0.20.8: 38 | resolution: 39 | { 40 | integrity: sha512-XjTcS3wdTy/2cc/ptMLc/WRyOLECRYcMTrSWyhZnj1oGSOWbHLTklgsgRICU3cPfb0vy+oZCC33M43u6R1HSCA==, 41 | } 42 | hasBin: true 43 | requiresBuild: true 44 | dev: true 45 | -------------------------------------------------------------------------------- /test/corpus/expr.signed-number.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.signed-number 3 | ================================================================================ 4 | 5 | SELECT 0, +0, -0; 6 | SELECT 1, +1, -1; 7 | SELECT 2, +2, -2; 8 | SELECT 1.4, +1.4, -1.4; 9 | SELECT 1.5e+5, +1.5e+5, -1.5e+5; 10 | SELECT 0.0001, +0.0001, -0.0001; 11 | 12 | -------------------------------------------------------------------------------- 13 | 14 | (sql_stmt_list 15 | (sql_stmt 16 | (select_stmt 17 | (SELECT) 18 | (numeric_literal) 19 | (numeric_literal) 20 | (numeric_literal))) 21 | (sql_stmt 22 | (select_stmt 23 | (SELECT) 24 | (numeric_literal) 25 | (numeric_literal) 26 | (numeric_literal))) 27 | (sql_stmt 28 | (select_stmt 29 | (SELECT) 30 | (numeric_literal) 31 | (numeric_literal) 32 | (numeric_literal))) 33 | (sql_stmt 34 | (select_stmt 35 | (SELECT) 36 | (numeric_literal) 37 | (numeric_literal) 38 | (numeric_literal))) 39 | (sql_stmt 40 | (select_stmt 41 | (SELECT) 42 | (numeric_literal) 43 | (numeric_literal) 44 | (numeric_literal))) 45 | (sql_stmt 46 | (select_stmt 47 | (SELECT) 48 | (numeric_literal) 49 | (numeric_literal) 50 | (numeric_literal)))) 51 | -------------------------------------------------------------------------------- /bindings/rust/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let src_dir = std::path::Path::new("src"); 3 | 4 | let mut c_config = cc::Build::new(); 5 | c_config.include(&src_dir); 6 | c_config 7 | .flag_if_supported("-Wno-unused-parameter") 8 | .flag_if_supported("-Wno-unused-but-set-variable") 9 | .flag_if_supported("-Wno-trigraphs"); 10 | let parser_path = src_dir.join("parser.c"); 11 | c_config.file(&parser_path); 12 | 13 | // If your language uses an external scanner written in C, 14 | // then include this block of code: 15 | 16 | /* 17 | let scanner_path = src_dir.join("scanner.c"); 18 | c_config.file(&scanner_path); 19 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 20 | */ 21 | 22 | c_config.compile("parser"); 23 | println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); 24 | 25 | // If your language uses an external scanner written in C++, 26 | // then include this block of code: 27 | 28 | /* 29 | let mut cpp_config = cc::Build::new(); 30 | cpp_config.cpp(true); 31 | cpp_config.include(&src_dir); 32 | cpp_config 33 | .flag_if_supported("-Wno-unused-parameter") 34 | .flag_if_supported("-Wno-unused-but-set-variable"); 35 | let scanner_path = src_dir.join("scanner.cc"); 36 | cpp_config.file(&scanner_path); 37 | cpp_config.compile("scanner"); 38 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 39 | */ 40 | } 41 | -------------------------------------------------------------------------------- /test/corpus/stmt.select.result-column.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.select.result-column 3 | ================================================================================ 4 | 5 | SELECT * FROM t1; 6 | SELECT t1.* FROM t1; 7 | SELECT 'x'||a||'x' FROM t1; 8 | SELECT 'x'||a||'x' alias FROM t1; 9 | SELECT 'x'||a||'x' AS alias FROM t1; 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | (sql_stmt_list 14 | (sql_stmt 15 | (select_stmt 16 | (SELECT) 17 | (from_clause 18 | (FROM) 19 | (table_or_subquery 20 | (identifier))))) 21 | (sql_stmt 22 | (select_stmt 23 | (SELECT) 24 | (identifier) 25 | (from_clause 26 | (FROM) 27 | (table_or_subquery 28 | (identifier))))) 29 | (sql_stmt 30 | (select_stmt 31 | (SELECT) 32 | (string_literal) 33 | (identifier) 34 | (string_literal) 35 | (from_clause 36 | (FROM) 37 | (table_or_subquery 38 | (identifier))))) 39 | (sql_stmt 40 | (select_stmt 41 | (SELECT) 42 | (string_literal) 43 | (identifier) 44 | (string_literal) 45 | (identifier) 46 | (from_clause 47 | (FROM) 48 | (table_or_subquery 49 | (identifier))))) 50 | (sql_stmt 51 | (select_stmt 52 | (SELECT) 53 | (string_literal) 54 | (identifier) 55 | (string_literal) 56 | (AS) 57 | (identifier) 58 | (from_clause 59 | (FROM) 60 | (table_or_subquery 61 | (identifier)))))) 62 | -------------------------------------------------------------------------------- /test/corpus/stmt.select.ordering-term.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.select.ordering-term 3 | ================================================================================ 4 | 5 | SELECT b||a FROM t1 ORDER BY b||a; 6 | SELECT b||a FROM t1 ORDER BY (b||a) COLLATE nocase; 7 | SELECT b||a FROM t1 ORDER BY (b||a) ASC; 8 | SELECT b||a FROM t1 ORDER BY (b||a) DESC; 9 | 10 | -------------------------------------------------------------------------------- 11 | 12 | (sql_stmt_list 13 | (sql_stmt 14 | (select_stmt 15 | (SELECT) 16 | (identifier) 17 | (identifier) 18 | (from_clause 19 | (FROM) 20 | (table_or_subquery 21 | (identifier))) 22 | (order_by_clause 23 | (ORDER) 24 | (BY) 25 | (ordering_term 26 | (identifier) 27 | (identifier))))) 28 | (sql_stmt 29 | (select_stmt 30 | (SELECT) 31 | (identifier) 32 | (identifier) 33 | (from_clause 34 | (FROM) 35 | (table_or_subquery 36 | (identifier))) 37 | (order_by_clause 38 | (ORDER) 39 | (BY) 40 | (ordering_term 41 | (identifier) 42 | (identifier) 43 | (COLLATE) 44 | (collation_name 45 | (identifier)))))) 46 | (sql_stmt 47 | (select_stmt 48 | (SELECT) 49 | (identifier) 50 | (identifier) 51 | (from_clause 52 | (FROM) 53 | (table_or_subquery 54 | (identifier))) 55 | (order_by_clause 56 | (ORDER) 57 | (BY) 58 | (ordering_term 59 | (identifier) 60 | (identifier) 61 | (ASC))))) 62 | (sql_stmt 63 | (select_stmt 64 | (SELECT) 65 | (identifier) 66 | (identifier) 67 | (from_clause 68 | (FROM) 69 | (table_or_subquery 70 | (identifier))) 71 | (order_by_clause 72 | (ORDER) 73 | (BY) 74 | (ordering_term 75 | (identifier) 76 | (identifier) 77 | (DESC)))))) 78 | -------------------------------------------------------------------------------- /test/corpus/stmt.select.compound-operator.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.select.compound-operator 3 | ================================================================================ 4 | 5 | SELECT rowid FROM t1 UNION ALL SELECT rowid+2 FROM t4; 6 | SELECT rowid FROM t1 UNION SELECT rowid+2 FROM t4; 7 | SELECT rowid FROM t1 INTERSECT SELECT rowid+2 FROM t4; 8 | SELECT rowid FROM t1 EXCEPT SELECT rowid+2 FROM t4; 9 | 10 | -------------------------------------------------------------------------------- 11 | 12 | (sql_stmt_list 13 | (sql_stmt 14 | (select_stmt 15 | (SELECT) 16 | (identifier) 17 | (from_clause 18 | (FROM) 19 | (table_or_subquery 20 | (identifier))) 21 | (UNION) 22 | (ALL) 23 | (SELECT) 24 | (identifier) 25 | (numeric_literal) 26 | (from_clause 27 | (FROM) 28 | (table_or_subquery 29 | (identifier))))) 30 | (sql_stmt 31 | (select_stmt 32 | (SELECT) 33 | (identifier) 34 | (from_clause 35 | (FROM) 36 | (table_or_subquery 37 | (identifier))) 38 | (UNION) 39 | (SELECT) 40 | (identifier) 41 | (numeric_literal) 42 | (from_clause 43 | (FROM) 44 | (table_or_subquery 45 | (identifier))))) 46 | (sql_stmt 47 | (select_stmt 48 | (SELECT) 49 | (identifier) 50 | (from_clause 51 | (FROM) 52 | (table_or_subquery 53 | (identifier))) 54 | (INTERSECT) 55 | (SELECT) 56 | (identifier) 57 | (numeric_literal) 58 | (from_clause 59 | (FROM) 60 | (table_or_subquery 61 | (identifier))))) 62 | (sql_stmt 63 | (select_stmt 64 | (SELECT) 65 | (identifier) 66 | (from_clause 67 | (FROM) 68 | (table_or_subquery 69 | (identifier))) 70 | (EXCEPT) 71 | (SELECT) 72 | (identifier) 73 | (numeric_literal) 74 | (from_clause 75 | (FROM) 76 | (table_or_subquery 77 | (identifier)))))) 78 | -------------------------------------------------------------------------------- /bindings/rust/lib.rs: -------------------------------------------------------------------------------- 1 | //! This crate provides sqlite language support for the [tree-sitter][] parsing library. 2 | //! 3 | //! Typically, you will use the [language][language func] function to add this language to a 4 | //! tree-sitter [Parser][], and then use the parser to parse some code: 5 | //! 6 | //! ``` 7 | //! let code = ""; 8 | //! let mut parser = tree_sitter::Parser::new(); 9 | //! parser.set_language(tree_sitter_sqlite::language()).expect("Error loading sqlite grammar"); 10 | //! let tree = parser.parse(code, None).unwrap(); 11 | //! ``` 12 | //! 13 | //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 14 | //! [language func]: fn.language.html 15 | //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html 16 | //! [tree-sitter]: https://tree-sitter.github.io/ 17 | 18 | use tree_sitter::Language; 19 | 20 | extern "C" { 21 | fn tree_sitter_sqlite() -> Language; 22 | } 23 | 24 | /// Get the tree-sitter [Language][] for this grammar. 25 | /// 26 | /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 27 | pub fn language() -> Language { 28 | unsafe { tree_sitter_sqlite() } 29 | } 30 | 31 | /// The content of the [`node-types.json`][] file for this grammar. 32 | /// 33 | /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types 34 | pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); 35 | 36 | // Uncomment these to include any queries that this grammar contains 37 | 38 | pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); 39 | // pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); 40 | // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); 41 | // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); 42 | 43 | #[cfg(test)] 44 | mod tests { 45 | #[test] 46 | fn test_can_load_grammar() { 47 | let mut parser = tree_sitter::Parser::new(); 48 | parser 49 | .set_language(super::language()) 50 | .expect("Error loading sqlite language"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/corpus/stmt.select.join-constraint.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.select.join-constraint 3 | ================================================================================ 4 | 5 | SELECT count(*) FROM t1, t2 ON (t1.a=t2.a); 6 | SELECT count(*) FROM t1 JOIN t2 ON (t1.a=t2.a); 7 | SELECT count(*) FROM t1 CROSS JOIN t2 USING (a); 8 | SELECT count(*) FROM t1 INNER JOIN t2; 9 | 10 | -------------------------------------------------------------------------------- 11 | 12 | (sql_stmt_list 13 | (sql_stmt 14 | (select_stmt 15 | (SELECT) 16 | (function_name 17 | (identifier)) 18 | (from_clause 19 | (FROM) 20 | (table_or_subquery 21 | (identifier)) 22 | (join_operator) 23 | (table_or_subquery 24 | (identifier)) 25 | (join_constraint 26 | (ON) 27 | (identifier) 28 | (identifier) 29 | (identifier) 30 | (identifier))))) 31 | (sql_stmt 32 | (select_stmt 33 | (SELECT) 34 | (function_name 35 | (identifier)) 36 | (from_clause 37 | (FROM) 38 | (table_or_subquery 39 | (identifier)) 40 | (join_operator 41 | (JOIN)) 42 | (table_or_subquery 43 | (identifier)) 44 | (join_constraint 45 | (ON) 46 | (identifier) 47 | (identifier) 48 | (identifier) 49 | (identifier))))) 50 | (sql_stmt 51 | (select_stmt 52 | (SELECT) 53 | (function_name 54 | (identifier)) 55 | (from_clause 56 | (FROM) 57 | (table_or_subquery 58 | (identifier)) 59 | (join_operator 60 | (CROSS) 61 | (JOIN)) 62 | (table_or_subquery 63 | (identifier)) 64 | (join_constraint 65 | (USING) 66 | (identifier))))) 67 | (sql_stmt 68 | (select_stmt 69 | (SELECT) 70 | (function_name 71 | (identifier)) 72 | (from_clause 73 | (FROM) 74 | (table_or_subquery 75 | (identifier)) 76 | (join_operator 77 | (INNER) 78 | (JOIN)) 79 | (table_or_subquery 80 | (identifier)))))) 81 | -------------------------------------------------------------------------------- /test/corpus/expr.in.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.in 3 | ================================================================================ 4 | 5 | SELECT 1 IN (SELECT cname FROM tblname); 6 | SELECT 1 IN (1); 7 | SELECT 1 IN (1, 2, 3); 8 | SELECT 1 IN tblname; 9 | SELECT 1 IN dbname.tblname; 10 | SELECT 1 NOT IN (SELECT cname FROM tblname); 11 | SELECT 1 NOT IN (1); 12 | SELECT 1 NOT IN (1, 2, 3); 13 | SELECT 1 NOT IN tblname; 14 | SELECT 1 NOT IN dbname.tblname; 15 | 16 | -------------------------------------------------------------------------------- 17 | 18 | (sql_stmt_list 19 | (sql_stmt 20 | (select_stmt 21 | (SELECT) 22 | (numeric_literal) 23 | (IN) 24 | (select_stmt 25 | (SELECT) 26 | (identifier) 27 | (from_clause 28 | (FROM) 29 | (table_or_subquery 30 | (identifier)))))) 31 | (sql_stmt 32 | (select_stmt 33 | (SELECT) 34 | (numeric_literal) 35 | (IN) 36 | (numeric_literal))) 37 | (sql_stmt 38 | (select_stmt 39 | (SELECT) 40 | (numeric_literal) 41 | (IN) 42 | (numeric_literal) 43 | (numeric_literal) 44 | (numeric_literal))) 45 | (sql_stmt 46 | (select_stmt 47 | (SELECT) 48 | (numeric_literal) 49 | (IN) 50 | (identifier))) 51 | (sql_stmt 52 | (select_stmt 53 | (SELECT) 54 | (numeric_literal) 55 | (IN) 56 | (identifier) 57 | (identifier))) 58 | (sql_stmt 59 | (select_stmt 60 | (SELECT) 61 | (numeric_literal) 62 | (NOT) 63 | (IN) 64 | (select_stmt 65 | (SELECT) 66 | (identifier) 67 | (from_clause 68 | (FROM) 69 | (table_or_subquery 70 | (identifier)))))) 71 | (sql_stmt 72 | (select_stmt 73 | (SELECT) 74 | (numeric_literal) 75 | (NOT) 76 | (IN) 77 | (numeric_literal))) 78 | (sql_stmt 79 | (select_stmt 80 | (SELECT) 81 | (numeric_literal) 82 | (NOT) 83 | (IN) 84 | (numeric_literal) 85 | (numeric_literal) 86 | (numeric_literal))) 87 | (sql_stmt 88 | (select_stmt 89 | (SELECT) 90 | (numeric_literal) 91 | (NOT) 92 | (IN) 93 | (identifier))) 94 | (sql_stmt 95 | (select_stmt 96 | (SELECT) 97 | (numeric_literal) 98 | (NOT) 99 | (IN) 100 | (identifier) 101 | (identifier)))) 102 | -------------------------------------------------------------------------------- /test/corpus/expr.case.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.case 3 | ================================================================================ 4 | 5 | SELECT CASE 'abc' WHEN 1 THEN 'true' ELSE 'false' END; 6 | SELECT CASE 'abc' WHEN 1 THEN 'true' END; 7 | SELECT CASE 'abc' WHEN 1 THEN 'true' WHEN 2 THEN 'false' ELSE 'fallback' END; 8 | SELECT CASE 'abc' WHEN 1 THEN 'true' WHEN 2 THEN 'false' END; 9 | SELECT CASE WHEN 0 THEN 'true' ELSE 'false' END; 10 | SELECT CASE WHEN 0 THEN 'true' END; 11 | SELECT CASE WHEN 0 THEN 'true' WHEN 1 THEN 'false' ELSE 'fallback' END; 12 | SELECT CASE WHEN 0 THEN 'true' WHEN 1 THEN 'false' END; 13 | 14 | -------------------------------------------------------------------------------- 15 | 16 | (sql_stmt_list 17 | (sql_stmt 18 | (select_stmt 19 | (SELECT) 20 | (CASE) 21 | (string_literal) 22 | (WHEN) 23 | (numeric_literal) 24 | (THEN) 25 | (string_literal) 26 | (ELSE) 27 | (string_literal) 28 | (END))) 29 | (sql_stmt 30 | (select_stmt 31 | (SELECT) 32 | (CASE) 33 | (string_literal) 34 | (WHEN) 35 | (numeric_literal) 36 | (THEN) 37 | (string_literal) 38 | (END))) 39 | (sql_stmt 40 | (select_stmt 41 | (SELECT) 42 | (CASE) 43 | (string_literal) 44 | (WHEN) 45 | (numeric_literal) 46 | (THEN) 47 | (string_literal) 48 | (WHEN) 49 | (numeric_literal) 50 | (THEN) 51 | (string_literal) 52 | (ELSE) 53 | (string_literal) 54 | (END))) 55 | (sql_stmt 56 | (select_stmt 57 | (SELECT) 58 | (CASE) 59 | (string_literal) 60 | (WHEN) 61 | (numeric_literal) 62 | (THEN) 63 | (string_literal) 64 | (WHEN) 65 | (numeric_literal) 66 | (THEN) 67 | (string_literal) 68 | (END))) 69 | (sql_stmt 70 | (select_stmt 71 | (SELECT) 72 | (CASE) 73 | (WHEN) 74 | (numeric_literal) 75 | (THEN) 76 | (string_literal) 77 | (ELSE) 78 | (string_literal) 79 | (END))) 80 | (sql_stmt 81 | (select_stmt 82 | (SELECT) 83 | (CASE) 84 | (WHEN) 85 | (numeric_literal) 86 | (THEN) 87 | (string_literal) 88 | (END))) 89 | (sql_stmt 90 | (select_stmt 91 | (SELECT) 92 | (CASE) 93 | (WHEN) 94 | (numeric_literal) 95 | (THEN) 96 | (string_literal) 97 | (WHEN) 98 | (numeric_literal) 99 | (THEN) 100 | (string_literal) 101 | (ELSE) 102 | (string_literal) 103 | (END))) 104 | (sql_stmt 105 | (select_stmt 106 | (SELECT) 107 | (CASE) 108 | (WHEN) 109 | (numeric_literal) 110 | (THEN) 111 | (string_literal) 112 | (WHEN) 113 | (numeric_literal) 114 | (THEN) 115 | (string_literal) 116 | (END)))) 117 | -------------------------------------------------------------------------------- /test/corpus/expr.like.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.like 3 | ================================================================================ 4 | 5 | SELECT 'abc' LIKE 'abcd'; 6 | SELECT 'abc' LIKE 'abcd' ESCAPE '%'; 7 | SELECT 'abc' GLOB 'abcd'; 8 | SELECT 'abc' GLOB 'abcd' ESCAPE '%'; 9 | SELECT 'abc' REGEXP 'abcd'; 10 | SELECT 'abc' REGEXP 'abcd' ESCAPE '%'; 11 | SELECT 'abc' MATCH 'abcd'; 12 | SELECT 'abc' MATCH 'abcd' ESCAPE '%'; 13 | SELECT 'abc' NOT LIKE 'abcd'; 14 | SELECT 'abc' NOT LIKE 'abcd' ESCAPE '%'; 15 | SELECT 'abc' NOT GLOB 'abcd'; 16 | SELECT 'abc' NOT GLOB 'abcd' ESCAPE '%'; 17 | SELECT 'abc' NOT REGEXP 'abcd'; 18 | SELECT 'abc' NOT REGEXP 'abcd' ESCAPE '%'; 19 | SELECT 'abc' NOT MATCH 'abcd'; 20 | SELECT 'abc' NOT MATCH 'abcd' ESCAPE '%'; 21 | 22 | -------------------------------------------------------------------------------- 23 | 24 | (sql_stmt_list 25 | (sql_stmt 26 | (select_stmt 27 | (SELECT) 28 | (string_literal) 29 | (LIKE) 30 | (string_literal))) 31 | (sql_stmt 32 | (select_stmt 33 | (SELECT) 34 | (string_literal) 35 | (LIKE) 36 | (string_literal) 37 | (ESCAPE) 38 | (string_literal))) 39 | (sql_stmt 40 | (select_stmt 41 | (SELECT) 42 | (string_literal) 43 | (GLOB) 44 | (string_literal))) 45 | (sql_stmt 46 | (select_stmt 47 | (SELECT) 48 | (string_literal) 49 | (GLOB) 50 | (string_literal) 51 | (ESCAPE) 52 | (string_literal))) 53 | (sql_stmt 54 | (select_stmt 55 | (SELECT) 56 | (string_literal) 57 | (REGEXP) 58 | (string_literal))) 59 | (sql_stmt 60 | (select_stmt 61 | (SELECT) 62 | (string_literal) 63 | (REGEXP) 64 | (string_literal) 65 | (ESCAPE) 66 | (string_literal))) 67 | (sql_stmt 68 | (select_stmt 69 | (SELECT) 70 | (string_literal) 71 | (MATCH) 72 | (string_literal))) 73 | (sql_stmt 74 | (select_stmt 75 | (SELECT) 76 | (string_literal) 77 | (MATCH) 78 | (string_literal) 79 | (ESCAPE) 80 | (string_literal))) 81 | (sql_stmt 82 | (select_stmt 83 | (SELECT) 84 | (string_literal) 85 | (NOT) 86 | (LIKE) 87 | (string_literal))) 88 | (sql_stmt 89 | (select_stmt 90 | (SELECT) 91 | (string_literal) 92 | (NOT) 93 | (LIKE) 94 | (string_literal) 95 | (ESCAPE) 96 | (string_literal))) 97 | (sql_stmt 98 | (select_stmt 99 | (SELECT) 100 | (string_literal) 101 | (NOT) 102 | (GLOB) 103 | (string_literal))) 104 | (sql_stmt 105 | (select_stmt 106 | (SELECT) 107 | (string_literal) 108 | (NOT) 109 | (GLOB) 110 | (string_literal) 111 | (ESCAPE) 112 | (string_literal))) 113 | (sql_stmt 114 | (select_stmt 115 | (SELECT) 116 | (string_literal) 117 | (NOT) 118 | (REGEXP) 119 | (string_literal))) 120 | (sql_stmt 121 | (select_stmt 122 | (SELECT) 123 | (string_literal) 124 | (NOT) 125 | (REGEXP) 126 | (string_literal) 127 | (ESCAPE) 128 | (string_literal))) 129 | (sql_stmt 130 | (select_stmt 131 | (SELECT) 132 | (string_literal) 133 | (NOT) 134 | (MATCH) 135 | (string_literal))) 136 | (sql_stmt 137 | (select_stmt 138 | (SELECT) 139 | (string_literal) 140 | (NOT) 141 | (MATCH) 142 | (string_literal) 143 | (ESCAPE) 144 | (string_literal)))) 145 | -------------------------------------------------------------------------------- /test/corpus/stmt.create_table.strict.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.create_table.strict 3 | ================================================================================ 4 | 5 | CREATE TABLE t1(a) STRICT; 6 | CREATE TABLE t1(a PRIMARY KEY) STRICT, WITHOUT ROWID; 7 | CREATE TABLE t1(a PRIMARY KEY) WITHOUT ROWID, STRICT; 8 | CREATE TABLE t1(a BANJO PRIMARY KEY) WITHOUT ROWID, STRICT; 9 | CREATE TABLE t1(a TEXT PRIMARY KEY, b INT, c INTEGER, d REAL, e BLOB, f DATE) strict; 10 | CREATE TABLE t1(a TEXT PRIMARY KEY, b INT, c INTEGER, d REAL, e BLOB, f TEXT(50)) WITHOUT ROWID, STRICT; 11 | 12 | -------------------------------------------------------------------------------- 13 | 14 | (sql_stmt_list 15 | (sql_stmt 16 | (create_table_stmt 17 | (CREATE) 18 | (TABLE) 19 | (identifier) 20 | (column_def 21 | (identifier)) 22 | (STRICT))) 23 | (sql_stmt 24 | (create_table_stmt 25 | (CREATE) 26 | (TABLE) 27 | (identifier) 28 | (column_def 29 | (identifier) 30 | (column_constraint 31 | (PRIMARY) 32 | (KEY))) 33 | (STRICT) 34 | (WITHOUT) 35 | (ROWID))) 36 | (sql_stmt 37 | (create_table_stmt 38 | (CREATE) 39 | (TABLE) 40 | (identifier) 41 | (column_def 42 | (identifier) 43 | (column_constraint 44 | (PRIMARY) 45 | (KEY))) 46 | (WITHOUT) 47 | (ROWID) 48 | (STRICT))) 49 | (sql_stmt 50 | (create_table_stmt 51 | (CREATE) 52 | (TABLE) 53 | (identifier) 54 | (column_def 55 | (identifier) 56 | (type_name 57 | (identifier)) 58 | (column_constraint 59 | (PRIMARY) 60 | (KEY))) 61 | (WITHOUT) 62 | (ROWID) 63 | (STRICT))) 64 | (sql_stmt 65 | (create_table_stmt 66 | (CREATE) 67 | (TABLE) 68 | (identifier) 69 | (column_def 70 | (identifier) 71 | (type_name 72 | (identifier)) 73 | (column_constraint 74 | (PRIMARY) 75 | (KEY))) 76 | (column_def 77 | (identifier) 78 | (type_name 79 | (identifier))) 80 | (column_def 81 | (identifier) 82 | (type_name 83 | (identifier))) 84 | (column_def 85 | (identifier) 86 | (type_name 87 | (identifier))) 88 | (column_def 89 | (identifier) 90 | (type_name 91 | (identifier))) 92 | (column_def 93 | (identifier) 94 | (type_name 95 | (identifier))) 96 | (STRICT))) 97 | (sql_stmt 98 | (create_table_stmt 99 | (CREATE) 100 | (TABLE) 101 | (identifier) 102 | (column_def 103 | (identifier) 104 | (type_name 105 | (identifier)) 106 | (column_constraint 107 | (PRIMARY) 108 | (KEY))) 109 | (column_def 110 | (identifier) 111 | (type_name 112 | (identifier))) 113 | (column_def 114 | (identifier) 115 | (type_name 116 | (identifier))) 117 | (column_def 118 | (identifier) 119 | (type_name 120 | (identifier))) 121 | (column_def 122 | (identifier) 123 | (type_name 124 | (identifier))) 125 | (column_def 126 | (identifier) 127 | (type_name 128 | (identifier) 129 | (signed_number 130 | (numeric_literal)))) 131 | (WITHOUT) 132 | (ROWID) 133 | (STRICT)))) 134 | -------------------------------------------------------------------------------- /test/corpus/expr.binary.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | expr.binary 3 | ================================================================================ 4 | 5 | SELECT 'hello' || 'world'; 6 | SELECT 1 * 2; 7 | SELECT 1 / 2; 8 | SELECT 1 % 2; 9 | SELECT 1 + 2; 10 | SELECT 1 - 2; 11 | SELECT 1 << 2; 12 | SELECT 1 >> 2; 13 | SELECT 1 & 2; 14 | SELECT 1 | 2; 15 | SELECT 1 < 2; 16 | SELECT 1 <= 2; 17 | SELECT 1 > 2; 18 | SELECT 1 >= 2; 19 | SELECT 1 = 2; 20 | SELECT 1 == 2; 21 | SELECT 1 != 2; 22 | SELECT 1 <> 2; 23 | SELECT 1 IS 2; 24 | SELECT 1 IS NOT 2; 25 | SELECT 1 IS DISTINCT FROM 2; 26 | SELECT 1 IS NOT DISTINCT FROM 2; 27 | SELECT 1 AND 2; 28 | SELECT 1 OR 2; 29 | 30 | -------------------------------------------------------------------------------- 31 | 32 | (sql_stmt_list 33 | (sql_stmt 34 | (select_stmt 35 | (SELECT) 36 | (string_literal) 37 | (string_literal))) 38 | (sql_stmt 39 | (select_stmt 40 | (SELECT) 41 | (numeric_literal) 42 | (numeric_literal))) 43 | (sql_stmt 44 | (select_stmt 45 | (SELECT) 46 | (numeric_literal) 47 | (numeric_literal))) 48 | (sql_stmt 49 | (select_stmt 50 | (SELECT) 51 | (numeric_literal) 52 | (numeric_literal))) 53 | (sql_stmt 54 | (select_stmt 55 | (SELECT) 56 | (numeric_literal) 57 | (numeric_literal))) 58 | (sql_stmt 59 | (select_stmt 60 | (SELECT) 61 | (numeric_literal) 62 | (numeric_literal))) 63 | (sql_stmt 64 | (select_stmt 65 | (SELECT) 66 | (numeric_literal) 67 | (numeric_literal))) 68 | (sql_stmt 69 | (select_stmt 70 | (SELECT) 71 | (numeric_literal) 72 | (numeric_literal))) 73 | (sql_stmt 74 | (select_stmt 75 | (SELECT) 76 | (numeric_literal) 77 | (numeric_literal))) 78 | (sql_stmt 79 | (select_stmt 80 | (SELECT) 81 | (numeric_literal) 82 | (numeric_literal))) 83 | (sql_stmt 84 | (select_stmt 85 | (SELECT) 86 | (numeric_literal) 87 | (numeric_literal))) 88 | (sql_stmt 89 | (select_stmt 90 | (SELECT) 91 | (numeric_literal) 92 | (numeric_literal))) 93 | (sql_stmt 94 | (select_stmt 95 | (SELECT) 96 | (numeric_literal) 97 | (numeric_literal))) 98 | (sql_stmt 99 | (select_stmt 100 | (SELECT) 101 | (numeric_literal) 102 | (numeric_literal))) 103 | (sql_stmt 104 | (select_stmt 105 | (SELECT) 106 | (numeric_literal) 107 | (numeric_literal))) 108 | (sql_stmt 109 | (select_stmt 110 | (SELECT) 111 | (numeric_literal) 112 | (numeric_literal))) 113 | (sql_stmt 114 | (select_stmt 115 | (SELECT) 116 | (numeric_literal) 117 | (numeric_literal))) 118 | (sql_stmt 119 | (select_stmt 120 | (SELECT) 121 | (numeric_literal) 122 | (numeric_literal))) 123 | (sql_stmt 124 | (select_stmt 125 | (SELECT) 126 | (numeric_literal) 127 | (IS) 128 | (numeric_literal))) 129 | (sql_stmt 130 | (select_stmt 131 | (SELECT) 132 | (numeric_literal) 133 | (IS) 134 | (NOT) 135 | (numeric_literal))) 136 | (sql_stmt 137 | (select_stmt 138 | (SELECT) 139 | (numeric_literal) 140 | (IS) 141 | (DISTINCT) 142 | (FROM) 143 | (numeric_literal))) 144 | (sql_stmt 145 | (select_stmt 146 | (SELECT) 147 | (numeric_literal) 148 | (IS) 149 | (NOT) 150 | (DISTINCT) 151 | (FROM) 152 | (numeric_literal))) 153 | (sql_stmt 154 | (select_stmt 155 | (SELECT) 156 | (numeric_literal) 157 | (AND) 158 | (numeric_literal))) 159 | (sql_stmt 160 | (select_stmt 161 | (SELECT) 162 | (numeric_literal) 163 | (OR) 164 | (numeric_literal)))) 165 | -------------------------------------------------------------------------------- /test/corpus/stmt.create_table.table-constraint.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.create_table.table-constraint 3 | ================================================================================ 4 | 5 | CREATE TABLE t1(c1, c2, PRIMARY KEY(c1)); 6 | CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2)); 7 | CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2) ON CONFLICT IGNORE); 8 | CREATE TABLE t1(c1, c2, UNIQUE(c1)); 9 | CREATE TABLE t1(c1, c2, UNIQUE(c1, c2)); 10 | CREATE TABLE t1(c1, c2, UNIQUE(c1, c2) ON CONFLICT IGNORE); 11 | CREATE TABLE t1(c1, c2, CHECK(c1 IS NOT c2)); 12 | CREATE TABLE t1(c1, c2, FOREIGN KEY(c1) REFERENCES t2); 13 | 14 | -------------------------------------------------------------------------------- 15 | 16 | (sql_stmt_list 17 | (sql_stmt 18 | (create_table_stmt 19 | (CREATE) 20 | (TABLE) 21 | (identifier) 22 | (column_def 23 | (identifier)) 24 | (column_def 25 | (identifier)) 26 | (table_constraint 27 | (PRIMARY) 28 | (KEY) 29 | (indexed_column 30 | (identifier))))) 31 | (sql_stmt 32 | (create_table_stmt 33 | (CREATE) 34 | (TABLE) 35 | (identifier) 36 | (column_def 37 | (identifier)) 38 | (column_def 39 | (identifier)) 40 | (table_constraint 41 | (PRIMARY) 42 | (KEY) 43 | (indexed_column 44 | (identifier)) 45 | (indexed_column 46 | (identifier))))) 47 | (sql_stmt 48 | (create_table_stmt 49 | (CREATE) 50 | (TABLE) 51 | (identifier) 52 | (column_def 53 | (identifier)) 54 | (column_def 55 | (identifier)) 56 | (table_constraint 57 | (PRIMARY) 58 | (KEY) 59 | (indexed_column 60 | (identifier)) 61 | (indexed_column 62 | (identifier)) 63 | (conflict_clause 64 | (ON) 65 | (CONFLICT) 66 | (IGNORE))))) 67 | (sql_stmt 68 | (create_table_stmt 69 | (CREATE) 70 | (TABLE) 71 | (identifier) 72 | (column_def 73 | (identifier)) 74 | (column_def 75 | (identifier)) 76 | (table_constraint 77 | (UNIQUE) 78 | (indexed_column 79 | (identifier))))) 80 | (sql_stmt 81 | (create_table_stmt 82 | (CREATE) 83 | (TABLE) 84 | (identifier) 85 | (column_def 86 | (identifier)) 87 | (column_def 88 | (identifier)) 89 | (table_constraint 90 | (UNIQUE) 91 | (indexed_column 92 | (identifier)) 93 | (indexed_column 94 | (identifier))))) 95 | (sql_stmt 96 | (create_table_stmt 97 | (CREATE) 98 | (TABLE) 99 | (identifier) 100 | (column_def 101 | (identifier)) 102 | (column_def 103 | (identifier)) 104 | (table_constraint 105 | (UNIQUE) 106 | (indexed_column 107 | (identifier)) 108 | (indexed_column 109 | (identifier)) 110 | (conflict_clause 111 | (ON) 112 | (CONFLICT) 113 | (IGNORE))))) 114 | (sql_stmt 115 | (create_table_stmt 116 | (CREATE) 117 | (TABLE) 118 | (identifier) 119 | (column_def 120 | (identifier)) 121 | (column_def 122 | (identifier)) 123 | (table_constraint 124 | (CHECK) 125 | (identifier) 126 | (IS) 127 | (NOT) 128 | (identifier)))) 129 | (sql_stmt 130 | (create_table_stmt 131 | (CREATE) 132 | (TABLE) 133 | (identifier) 134 | (column_def 135 | (identifier)) 136 | (column_def 137 | (identifier)) 138 | (table_constraint 139 | (FOREIGN) 140 | (KEY) 141 | (identifier) 142 | (foreign_key_clause 143 | (REFERENCES) 144 | (identifier)))))) 145 | -------------------------------------------------------------------------------- /queries/highlights.scm: -------------------------------------------------------------------------------- 1 | ;;; 2 | 3 | ";" @punctuation.delimiter 4 | "," @punctuation.delimiter 5 | "." @punctuation.delimiter 6 | 7 | "(" @punctuation.bracket 8 | ")" @punctuation.bracket 9 | 10 | [ 11 | "||" 12 | "~" "&" "|" "<<" ">>" 13 | "+" "-" "*" "/" "%" 14 | "=" "==" "!=" "<>" ">" ">=" "<" "<=" 15 | "->" "->>" 16 | ] @operator 17 | 18 | ;;; 19 | 20 | (signed_number) @number 21 | 22 | (numeric_literal) @number 23 | (string_literal) @string 24 | (blob_literal) @string.special 25 | (identifier) @constant 26 | (bind_parameter) @variable.parameter 27 | (comment) @comment 28 | 29 | ;;; 30 | 31 | (ABORT) @keyword 32 | (ACTION) @keyword 33 | (ADD) @keyword 34 | (AFTER) @keyword 35 | (ALL) @keyword 36 | (ALTER) @keyword 37 | (ALWAYS) @keyword 38 | (ANALYZE) @keyword 39 | (AND) @keyword 40 | (AS) @keyword 41 | (ASC) @keyword 42 | (ATTACH) @keyword 43 | (AUTOINCREMENT) @keyword 44 | (BEFORE) @keyword 45 | (BEGIN) @keyword 46 | (BETWEEN) @keyword 47 | (BY) @keyword 48 | (CASCADE) @keyword 49 | (CASE) @keyword 50 | (CAST) @keyword 51 | (CHECK) @keyword 52 | (COLLATE) @keyword 53 | (COLUMN) @keyword 54 | (COMMIT) @keyword 55 | (CONFLICT) @keyword 56 | (CONSTRAINT) @keyword 57 | (CREATE) @keyword 58 | (CROSS) @keyword 59 | (CURRENT) @keyword 60 | (CURRENT_DATE) @keyword 61 | (CURRENT_TIME) @keyword 62 | (CURRENT_TIMESTAMP) @keyword 63 | (DATABASE) @keyword 64 | (DEFAULT) @keyword 65 | (DEFERRABLE) @keyword 66 | (DEFERRED) @keyword 67 | (DELETE) @keyword 68 | (DESC) @keyword 69 | (DETACH) @keyword 70 | (DISTINCT) @keyword 71 | (DO) @keyword 72 | (DROP) @keyword 73 | (EACH) @keyword 74 | (ELSE) @keyword 75 | (END) @keyword 76 | (ESCAPE) @keyword 77 | (EXCEPT) @keyword 78 | (EXCLUDE) @keyword 79 | (EXCLUSIVE) @keyword 80 | (EXISTS) @keyword 81 | (EXPLAIN) @keyword 82 | (FAIL) @keyword 83 | (FALSE) @keyword 84 | (FILTER) @keyword 85 | (FIRST) @keyword 86 | (FOLLOWING) @keyword 87 | (FOR) @keyword 88 | (FOREIGN) @keyword 89 | (FROM) @keyword 90 | (GENERATED) @keyword 91 | (GLOB) @keyword 92 | (GROUP) @keyword 93 | (GROUPS) @keyword 94 | (HAVING) @keyword 95 | (IF) @keyword 96 | (IGNORE) @keyword 97 | (IMMEDIATE) @keyword 98 | (IN) @keyword 99 | (INDEX) @keyword 100 | (INDEXED) @keyword 101 | (INITIALLY) @keyword 102 | (INNER) @keyword 103 | (INSERT) @keyword 104 | (INSTEAD) @keyword 105 | (INTERSECT) @keyword 106 | (INTO) @keyword 107 | (IS) @keyword 108 | (ISNULL) @keyword 109 | (JOIN) @keyword 110 | (KEY) @keyword 111 | (LAST) @keyword 112 | (LEFT) @keyword 113 | (LIKE) @keyword 114 | (LIMIT) @keyword 115 | (MATCH) @keyword 116 | (MATERIALIZED) @keyword 117 | (NATURAL) @keyword 118 | (NO) @keyword 119 | (NOT) @keyword 120 | (NOTHING) @keyword 121 | (NOTNULL) @keyword 122 | (NULL) @keyword 123 | (NULLS) @keyword 124 | (OF) @keyword 125 | (OFFSET) @keyword 126 | (ON) @keyword 127 | (OR) @keyword 128 | (ORDER) @keyword 129 | (OTHERS) @keyword 130 | (OUTER) @keyword 131 | (OVER) @keyword 132 | (PARTITION) @keyword 133 | (PLAN) @keyword 134 | (PRAGMA) @keyword 135 | (PRECEDING) @keyword 136 | (PRIMARY) @keyword 137 | (QUERY) @keyword 138 | (RAISE) @keyword 139 | (RANGE) @keyword 140 | (RECURSIVE) @keyword 141 | (REFERENCES) @keyword 142 | (REGEXP) @keyword 143 | (REINDEX) @keyword 144 | (RELEASE) @keyword 145 | (RENAME) @keyword 146 | (REPLACE) @keyword 147 | (RESTRICT) @keyword 148 | (RETURNING) @keyword 149 | (ROLLBACK) @keyword 150 | (ROW) @keyword 151 | (ROWID) @keyword 152 | (ROWS) @keyword 153 | (SAVEPOINT) @keyword 154 | (SELECT) @keyword 155 | (SET) @keyword 156 | (STORED) @keyword 157 | (TABLE) @keyword 158 | (TEMP) @keyword 159 | (TEMPORARY) @keyword 160 | (THEN) @keyword 161 | (TIES) @keyword 162 | (TO) @keyword 163 | (TRANSACTION) @keyword 164 | (TRIGGER) @keyword 165 | (TRUE) @keyword 166 | (UNBOUNDED) @keyword 167 | (UNION) @keyword 168 | (UNIQUE) @keyword 169 | (UPDATE) @keyword 170 | (USING) @keyword 171 | (VACUUM) @keyword 172 | (VALUES) @keyword 173 | (VIEW) @keyword 174 | (VIRTUAL) @keyword 175 | (WHEN) @keyword 176 | (WHERE) @keyword 177 | (WINDOW) @keyword 178 | (WITH) @keyword 179 | (WITHOUT) @keyword 180 | -------------------------------------------------------------------------------- /test/corpus/stmt.delete.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.delete 3 | ================================================================================ 4 | 5 | DELETE FROM t1; 6 | DELETE FROM t1 INDEXED BY i1; 7 | DELETE FROM t1 NOT INDEXED; 8 | DELETE FROM main.t1; 9 | DELETE FROM main.t1 INDEXED BY i1; 10 | DELETE FROM main.t1 NOT INDEXED; 11 | DELETE FROM t1 WHERE a>2; 12 | DELETE FROM t1 INDEXED BY i1 WHERE a>2; 13 | DELETE FROM t1 NOT INDEXED WHERE a>2; 14 | DELETE FROM main.t1 WHERE a>2; 15 | DELETE FROM main.t1 INDEXED BY i1 WHERE a>2; 16 | DELETE FROM main.t1 NOT INDEXED WHERE a>2; 17 | DELETE FROM t1 ORDER BY a ASC LIMIT 4 OFFSET 2; 18 | DELETE FROM t1 LIMIT 1 OFFSET 0; 19 | DELETE FROM t1 ORDER BY a DESC LIMIT 2; 20 | 21 | -------------------------------------------------------------------------------- 22 | 23 | (sql_stmt_list 24 | (sql_stmt 25 | (delete_stmt 26 | (DELETE) 27 | (FROM) 28 | (qualified_table_name 29 | (identifier)))) 30 | (sql_stmt 31 | (delete_stmt 32 | (DELETE) 33 | (FROM) 34 | (qualified_table_name 35 | (identifier) 36 | (INDEXED) 37 | (BY) 38 | (identifier)))) 39 | (sql_stmt 40 | (delete_stmt 41 | (DELETE) 42 | (FROM) 43 | (qualified_table_name 44 | (identifier) 45 | (NOT) 46 | (INDEXED)))) 47 | (sql_stmt 48 | (delete_stmt 49 | (DELETE) 50 | (FROM) 51 | (qualified_table_name 52 | (identifier) 53 | (identifier)))) 54 | (sql_stmt 55 | (delete_stmt 56 | (DELETE) 57 | (FROM) 58 | (qualified_table_name 59 | (identifier) 60 | (identifier) 61 | (INDEXED) 62 | (BY) 63 | (identifier)))) 64 | (sql_stmt 65 | (delete_stmt 66 | (DELETE) 67 | (FROM) 68 | (qualified_table_name 69 | (identifier) 70 | (identifier) 71 | (NOT) 72 | (INDEXED)))) 73 | (sql_stmt 74 | (delete_stmt 75 | (DELETE) 76 | (FROM) 77 | (qualified_table_name 78 | (identifier)) 79 | (where_clause 80 | (WHERE) 81 | (identifier) 82 | (numeric_literal)))) 83 | (sql_stmt 84 | (delete_stmt 85 | (DELETE) 86 | (FROM) 87 | (qualified_table_name 88 | (identifier) 89 | (INDEXED) 90 | (BY) 91 | (identifier)) 92 | (where_clause 93 | (WHERE) 94 | (identifier) 95 | (numeric_literal)))) 96 | (sql_stmt 97 | (delete_stmt 98 | (DELETE) 99 | (FROM) 100 | (qualified_table_name 101 | (identifier) 102 | (NOT) 103 | (INDEXED)) 104 | (where_clause 105 | (WHERE) 106 | (identifier) 107 | (numeric_literal)))) 108 | (sql_stmt 109 | (delete_stmt 110 | (DELETE) 111 | (FROM) 112 | (qualified_table_name 113 | (identifier) 114 | (identifier)) 115 | (where_clause 116 | (WHERE) 117 | (identifier) 118 | (numeric_literal)))) 119 | (sql_stmt 120 | (delete_stmt 121 | (DELETE) 122 | (FROM) 123 | (qualified_table_name 124 | (identifier) 125 | (identifier) 126 | (INDEXED) 127 | (BY) 128 | (identifier)) 129 | (where_clause 130 | (WHERE) 131 | (identifier) 132 | (numeric_literal)))) 133 | (sql_stmt 134 | (delete_stmt 135 | (DELETE) 136 | (FROM) 137 | (qualified_table_name 138 | (identifier) 139 | (identifier) 140 | (NOT) 141 | (INDEXED)) 142 | (where_clause 143 | (WHERE) 144 | (identifier) 145 | (numeric_literal)))) 146 | (sql_stmt 147 | (delete_stmt 148 | (DELETE) 149 | (FROM) 150 | (qualified_table_name 151 | (identifier)) 152 | (order_by_clause 153 | (ORDER) 154 | (BY) 155 | (ordering_term 156 | (identifier) 157 | (ASC))) 158 | (limit_clause 159 | (LIMIT) 160 | (numeric_literal) 161 | (OFFSET) 162 | (numeric_literal)))) 163 | (sql_stmt 164 | (delete_stmt 165 | (DELETE) 166 | (FROM) 167 | (qualified_table_name 168 | (identifier)) 169 | (limit_clause 170 | (LIMIT) 171 | (numeric_literal) 172 | (OFFSET) 173 | (numeric_literal)))) 174 | (sql_stmt 175 | (delete_stmt 176 | (DELETE) 177 | (FROM) 178 | (qualified_table_name 179 | (identifier)) 180 | (order_by_clause 181 | (ORDER) 182 | (BY) 183 | (ordering_term 184 | (identifier) 185 | (DESC))) 186 | (limit_clause 187 | (LIMIT) 188 | (numeric_literal))))) 189 | -------------------------------------------------------------------------------- /src/tree_sitter/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef TREE_SITTER_PARSER_H_ 2 | #define TREE_SITTER_PARSER_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define ts_builtin_sym_error ((TSSymbol)-1) 13 | #define ts_builtin_sym_end 0 14 | #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 15 | 16 | typedef uint16_t TSStateId; 17 | 18 | #ifndef TREE_SITTER_API_H_ 19 | typedef uint16_t TSSymbol; 20 | typedef uint16_t TSFieldId; 21 | typedef struct TSLanguage TSLanguage; 22 | #endif 23 | 24 | typedef struct { 25 | TSFieldId field_id; 26 | uint8_t child_index; 27 | bool inherited; 28 | } TSFieldMapEntry; 29 | 30 | typedef struct { 31 | uint16_t index; 32 | uint16_t length; 33 | } TSFieldMapSlice; 34 | 35 | typedef struct { 36 | bool visible; 37 | bool named; 38 | bool supertype; 39 | } TSSymbolMetadata; 40 | 41 | typedef struct TSLexer TSLexer; 42 | 43 | struct TSLexer { 44 | int32_t lookahead; 45 | TSSymbol result_symbol; 46 | void (*advance)(TSLexer *, bool); 47 | void (*mark_end)(TSLexer *); 48 | uint32_t (*get_column)(TSLexer *); 49 | bool (*is_at_included_range_start)(const TSLexer *); 50 | bool (*eof)(const TSLexer *); 51 | }; 52 | 53 | typedef enum { 54 | TSParseActionTypeShift, 55 | TSParseActionTypeReduce, 56 | TSParseActionTypeAccept, 57 | TSParseActionTypeRecover, 58 | } TSParseActionType; 59 | 60 | typedef union { 61 | struct { 62 | uint8_t type; 63 | TSStateId state; 64 | bool extra; 65 | bool repetition; 66 | } shift; 67 | struct { 68 | uint8_t type; 69 | uint8_t child_count; 70 | TSSymbol symbol; 71 | int16_t dynamic_precedence; 72 | uint16_t production_id; 73 | } reduce; 74 | uint8_t type; 75 | } TSParseAction; 76 | 77 | typedef struct { 78 | uint16_t lex_state; 79 | uint16_t external_lex_state; 80 | } TSLexMode; 81 | 82 | typedef union { 83 | TSParseAction action; 84 | struct { 85 | uint8_t count; 86 | bool reusable; 87 | } entry; 88 | } TSParseActionEntry; 89 | 90 | struct TSLanguage { 91 | uint32_t version; 92 | uint32_t symbol_count; 93 | uint32_t alias_count; 94 | uint32_t token_count; 95 | uint32_t external_token_count; 96 | uint32_t state_count; 97 | uint32_t large_state_count; 98 | uint32_t production_id_count; 99 | uint32_t field_count; 100 | uint16_t max_alias_sequence_length; 101 | const uint16_t *parse_table; 102 | const uint16_t *small_parse_table; 103 | const uint32_t *small_parse_table_map; 104 | const TSParseActionEntry *parse_actions; 105 | const char * const *symbol_names; 106 | const char * const *field_names; 107 | const TSFieldMapSlice *field_map_slices; 108 | const TSFieldMapEntry *field_map_entries; 109 | const TSSymbolMetadata *symbol_metadata; 110 | const TSSymbol *public_symbol_map; 111 | const uint16_t *alias_map; 112 | const TSSymbol *alias_sequences; 113 | const TSLexMode *lex_modes; 114 | bool (*lex_fn)(TSLexer *, TSStateId); 115 | bool (*keyword_lex_fn)(TSLexer *, TSStateId); 116 | TSSymbol keyword_capture_token; 117 | struct { 118 | const bool *states; 119 | const TSSymbol *symbol_map; 120 | void *(*create)(void); 121 | void (*destroy)(void *); 122 | bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); 123 | unsigned (*serialize)(void *, char *); 124 | void (*deserialize)(void *, const char *, unsigned); 125 | } external_scanner; 126 | const TSStateId *primary_state_ids; 127 | }; 128 | 129 | /* 130 | * Lexer Macros 131 | */ 132 | 133 | #define START_LEXER() \ 134 | bool result = false; \ 135 | bool skip = false; \ 136 | bool eof = false; \ 137 | int32_t lookahead; \ 138 | goto start; \ 139 | next_state: \ 140 | lexer->advance(lexer, skip); \ 141 | start: \ 142 | skip = false; \ 143 | lookahead = lexer->lookahead; 144 | 145 | #define ADVANCE(state_value) \ 146 | { \ 147 | state = state_value; \ 148 | goto next_state; \ 149 | } 150 | 151 | #define SKIP(state_value) \ 152 | { \ 153 | skip = true; \ 154 | state = state_value; \ 155 | goto next_state; \ 156 | } 157 | 158 | #define ACCEPT_TOKEN(symbol_value) \ 159 | result = true; \ 160 | lexer->result_symbol = symbol_value; \ 161 | lexer->mark_end(lexer); 162 | 163 | #define END_STATE() return result; 164 | 165 | /* 166 | * Parse Table Macros 167 | */ 168 | 169 | #define SMALL_STATE(id) id - LARGE_STATE_COUNT 170 | 171 | #define STATE(id) id 172 | 173 | #define ACTIONS(id) id 174 | 175 | #define SHIFT(state_value) \ 176 | {{ \ 177 | .shift = { \ 178 | .type = TSParseActionTypeShift, \ 179 | .state = state_value \ 180 | } \ 181 | }} 182 | 183 | #define SHIFT_REPEAT(state_value) \ 184 | {{ \ 185 | .shift = { \ 186 | .type = TSParseActionTypeShift, \ 187 | .state = state_value, \ 188 | .repetition = true \ 189 | } \ 190 | }} 191 | 192 | #define SHIFT_EXTRA() \ 193 | {{ \ 194 | .shift = { \ 195 | .type = TSParseActionTypeShift, \ 196 | .extra = true \ 197 | } \ 198 | }} 199 | 200 | #define REDUCE(symbol_val, child_count_val, ...) \ 201 | {{ \ 202 | .reduce = { \ 203 | .type = TSParseActionTypeReduce, \ 204 | .symbol = symbol_val, \ 205 | .child_count = child_count_val, \ 206 | __VA_ARGS__ \ 207 | }, \ 208 | }} 209 | 210 | #define RECOVER() \ 211 | {{ \ 212 | .type = TSParseActionTypeRecover \ 213 | }} 214 | 215 | #define ACCEPT_INPUT() \ 216 | {{ \ 217 | .type = TSParseActionTypeAccept \ 218 | }} 219 | 220 | #ifdef __cplusplus 221 | } 222 | #endif 223 | 224 | #endif // TREE_SITTER_PARSER_H_ 225 | -------------------------------------------------------------------------------- /test/corpus/stmt.select.join-op.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.select.join-op 3 | ================================================================================ 4 | 5 | SELECT t1.rowid FROM t1; 6 | SELECT t1.rowid FROM t1,t2; 7 | SELECT t1.rowid FROM t1,t2,t3; 8 | SELECT t1.rowid FROM t1; 9 | SELECT t1.rowid FROM t1 JOIN t2; 10 | SELECT t1.rowid FROM t1 JOIN t2 JOIN t3; 11 | SELECT t1.rowid FROM t1 NATURAL JOIN t3; 12 | SELECT t1.rowid FROM t1 NATURAL LEFT OUTER JOIN t3; 13 | SELECT t1.rowid FROM t1 NATURAL LEFT JOIN t3; 14 | SELECT t1.rowid FROM t1 NATURAL INNER JOIN t3; 15 | SELECT t1.rowid FROM t1 NATURAL CROSS JOIN t3; 16 | SELECT t1.rowid FROM t1 JOIN t3; 17 | SELECT t1.rowid FROM t1 LEFT OUTER JOIN t3; 18 | SELECT t1.rowid FROM t1 LEFT JOIN t3; 19 | SELECT t1.rowid FROM t1 INNER JOIN t3; 20 | SELECT t1.rowid FROM t1 CROSS JOIN t3; 21 | 22 | -------------------------------------------------------------------------------- 23 | 24 | (sql_stmt_list 25 | (sql_stmt 26 | (select_stmt 27 | (SELECT) 28 | (identifier) 29 | (identifier) 30 | (from_clause 31 | (FROM) 32 | (table_or_subquery 33 | (identifier))))) 34 | (sql_stmt 35 | (select_stmt 36 | (SELECT) 37 | (identifier) 38 | (identifier) 39 | (from_clause 40 | (FROM) 41 | (table_or_subquery 42 | (identifier)) 43 | (join_operator) 44 | (table_or_subquery 45 | (identifier))))) 46 | (sql_stmt 47 | (select_stmt 48 | (SELECT) 49 | (identifier) 50 | (identifier) 51 | (from_clause 52 | (FROM) 53 | (table_or_subquery 54 | (identifier)) 55 | (join_operator) 56 | (table_or_subquery 57 | (identifier)) 58 | (join_operator) 59 | (table_or_subquery 60 | (identifier))))) 61 | (sql_stmt 62 | (select_stmt 63 | (SELECT) 64 | (identifier) 65 | (identifier) 66 | (from_clause 67 | (FROM) 68 | (table_or_subquery 69 | (identifier))))) 70 | (sql_stmt 71 | (select_stmt 72 | (SELECT) 73 | (identifier) 74 | (identifier) 75 | (from_clause 76 | (FROM) 77 | (table_or_subquery 78 | (identifier)) 79 | (join_operator 80 | (JOIN)) 81 | (table_or_subquery 82 | (identifier))))) 83 | (sql_stmt 84 | (select_stmt 85 | (SELECT) 86 | (identifier) 87 | (identifier) 88 | (from_clause 89 | (FROM) 90 | (table_or_subquery 91 | (identifier)) 92 | (join_operator 93 | (JOIN)) 94 | (table_or_subquery 95 | (identifier)) 96 | (join_operator 97 | (JOIN)) 98 | (table_or_subquery 99 | (identifier))))) 100 | (sql_stmt 101 | (select_stmt 102 | (SELECT) 103 | (identifier) 104 | (identifier) 105 | (from_clause 106 | (FROM) 107 | (table_or_subquery 108 | (identifier)) 109 | (join_operator 110 | (NATURAL) 111 | (JOIN)) 112 | (table_or_subquery 113 | (identifier))))) 114 | (sql_stmt 115 | (select_stmt 116 | (SELECT) 117 | (identifier) 118 | (identifier) 119 | (from_clause 120 | (FROM) 121 | (table_or_subquery 122 | (identifier)) 123 | (join_operator 124 | (NATURAL) 125 | (LEFT) 126 | (OUTER) 127 | (JOIN)) 128 | (table_or_subquery 129 | (identifier))))) 130 | (sql_stmt 131 | (select_stmt 132 | (SELECT) 133 | (identifier) 134 | (identifier) 135 | (from_clause 136 | (FROM) 137 | (table_or_subquery 138 | (identifier)) 139 | (join_operator 140 | (NATURAL) 141 | (LEFT) 142 | (JOIN)) 143 | (table_or_subquery 144 | (identifier))))) 145 | (sql_stmt 146 | (select_stmt 147 | (SELECT) 148 | (identifier) 149 | (identifier) 150 | (from_clause 151 | (FROM) 152 | (table_or_subquery 153 | (identifier)) 154 | (join_operator 155 | (NATURAL) 156 | (INNER) 157 | (JOIN)) 158 | (table_or_subquery 159 | (identifier))))) 160 | (sql_stmt 161 | (select_stmt 162 | (SELECT) 163 | (identifier) 164 | (identifier) 165 | (from_clause 166 | (FROM) 167 | (table_or_subquery 168 | (identifier)) 169 | (join_operator 170 | (NATURAL) 171 | (CROSS) 172 | (JOIN)) 173 | (table_or_subquery 174 | (identifier))))) 175 | (sql_stmt 176 | (select_stmt 177 | (SELECT) 178 | (identifier) 179 | (identifier) 180 | (from_clause 181 | (FROM) 182 | (table_or_subquery 183 | (identifier)) 184 | (join_operator 185 | (JOIN)) 186 | (table_or_subquery 187 | (identifier))))) 188 | (sql_stmt 189 | (select_stmt 190 | (SELECT) 191 | (identifier) 192 | (identifier) 193 | (from_clause 194 | (FROM) 195 | (table_or_subquery 196 | (identifier)) 197 | (join_operator 198 | (LEFT) 199 | (OUTER) 200 | (JOIN)) 201 | (table_or_subquery 202 | (identifier))))) 203 | (sql_stmt 204 | (select_stmt 205 | (SELECT) 206 | (identifier) 207 | (identifier) 208 | (from_clause 209 | (FROM) 210 | (table_or_subquery 211 | (identifier)) 212 | (join_operator 213 | (LEFT) 214 | (JOIN)) 215 | (table_or_subquery 216 | (identifier))))) 217 | (sql_stmt 218 | (select_stmt 219 | (SELECT) 220 | (identifier) 221 | (identifier) 222 | (from_clause 223 | (FROM) 224 | (table_or_subquery 225 | (identifier)) 226 | (join_operator 227 | (INNER) 228 | (JOIN)) 229 | (table_or_subquery 230 | (identifier))))) 231 | (sql_stmt 232 | (select_stmt 233 | (SELECT) 234 | (identifier) 235 | (identifier) 236 | (from_clause 237 | (FROM) 238 | (table_or_subquery 239 | (identifier)) 240 | (join_operator 241 | (CROSS) 242 | (JOIN)) 243 | (table_or_subquery 244 | (identifier)))))) 245 | -------------------------------------------------------------------------------- /test/corpus/stmt.create_table.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.create_table 3 | ================================================================================ 4 | 5 | CREATE TABLE t1(a, b, c); 6 | CREATE TEMP TABLE t1(a, b, c); 7 | CREATE TEMPORARY TABLE t1(a, b, c); 8 | CREATE TABLE IF NOT EXISTS t1(a, b, c); 9 | CREATE TEMP TABLE IF NOT EXISTS t1(a, b, c); 10 | CREATE TEMPORARY TABLE IF NOT EXISTS t1(a, b, c); 11 | CREATE TABLE main.t1(a, b, c); 12 | CREATE TEMP TABLE temp.t1(a, b, c); 13 | CREATE TEMPORARY TABLE temp.t1(a, b, c); 14 | CREATE TABLE IF NOT EXISTS main.t1(a, b, c); 15 | CREATE TEMP TABLE IF NOT EXISTS temp.t1(a, b, c); 16 | CREATE TEMPORARY TABLE IF NOT EXISTS temp.t1(a, b, c); 17 | CREATE TABLE t1 AS SELECT * FROM t2; 18 | CREATE TEMP TABLE t1 AS SELECT c, b, a FROM t2; 19 | CREATE TABLE t1 AS SELECT count(*), max(b), min(a) FROM t2; 20 | CREATE TABLE t1(col1, col2 TEXT, col3 INTEGER UNIQUE, col4 VARCHAR(10, 10) PRIMARY KEY, "name with spaces" REFERENCES t1); 21 | 22 | -------------------------------------------------------------------------------- 23 | 24 | (sql_stmt_list 25 | (sql_stmt 26 | (create_table_stmt 27 | (CREATE) 28 | (TABLE) 29 | (identifier) 30 | (column_def 31 | (identifier)) 32 | (column_def 33 | (identifier)) 34 | (column_def 35 | (identifier)))) 36 | (sql_stmt 37 | (create_table_stmt 38 | (CREATE) 39 | (TEMP) 40 | (TABLE) 41 | (identifier) 42 | (column_def 43 | (identifier)) 44 | (column_def 45 | (identifier)) 46 | (column_def 47 | (identifier)))) 48 | (sql_stmt 49 | (create_table_stmt 50 | (CREATE) 51 | (TEMPORARY) 52 | (TABLE) 53 | (identifier) 54 | (column_def 55 | (identifier)) 56 | (column_def 57 | (identifier)) 58 | (column_def 59 | (identifier)))) 60 | (sql_stmt 61 | (create_table_stmt 62 | (CREATE) 63 | (TABLE) 64 | (IF) 65 | (NOT) 66 | (EXISTS) 67 | (identifier) 68 | (column_def 69 | (identifier)) 70 | (column_def 71 | (identifier)) 72 | (column_def 73 | (identifier)))) 74 | (sql_stmt 75 | (create_table_stmt 76 | (CREATE) 77 | (TEMP) 78 | (TABLE) 79 | (IF) 80 | (NOT) 81 | (EXISTS) 82 | (identifier) 83 | (column_def 84 | (identifier)) 85 | (column_def 86 | (identifier)) 87 | (column_def 88 | (identifier)))) 89 | (sql_stmt 90 | (create_table_stmt 91 | (CREATE) 92 | (TEMPORARY) 93 | (TABLE) 94 | (IF) 95 | (NOT) 96 | (EXISTS) 97 | (identifier) 98 | (column_def 99 | (identifier)) 100 | (column_def 101 | (identifier)) 102 | (column_def 103 | (identifier)))) 104 | (sql_stmt 105 | (create_table_stmt 106 | (CREATE) 107 | (TABLE) 108 | (identifier) 109 | (identifier) 110 | (column_def 111 | (identifier)) 112 | (column_def 113 | (identifier)) 114 | (column_def 115 | (identifier)))) 116 | (sql_stmt 117 | (create_table_stmt 118 | (CREATE) 119 | (TEMP) 120 | (TABLE) 121 | (identifier) 122 | (identifier) 123 | (column_def 124 | (identifier)) 125 | (column_def 126 | (identifier)) 127 | (column_def 128 | (identifier)))) 129 | (sql_stmt 130 | (create_table_stmt 131 | (CREATE) 132 | (TEMPORARY) 133 | (TABLE) 134 | (identifier) 135 | (identifier) 136 | (column_def 137 | (identifier)) 138 | (column_def 139 | (identifier)) 140 | (column_def 141 | (identifier)))) 142 | (sql_stmt 143 | (create_table_stmt 144 | (CREATE) 145 | (TABLE) 146 | (IF) 147 | (NOT) 148 | (EXISTS) 149 | (identifier) 150 | (identifier) 151 | (column_def 152 | (identifier)) 153 | (column_def 154 | (identifier)) 155 | (column_def 156 | (identifier)))) 157 | (sql_stmt 158 | (create_table_stmt 159 | (CREATE) 160 | (TEMP) 161 | (TABLE) 162 | (IF) 163 | (NOT) 164 | (EXISTS) 165 | (identifier) 166 | (identifier) 167 | (column_def 168 | (identifier)) 169 | (column_def 170 | (identifier)) 171 | (column_def 172 | (identifier)))) 173 | (sql_stmt 174 | (create_table_stmt 175 | (CREATE) 176 | (TEMPORARY) 177 | (TABLE) 178 | (IF) 179 | (NOT) 180 | (EXISTS) 181 | (identifier) 182 | (identifier) 183 | (column_def 184 | (identifier)) 185 | (column_def 186 | (identifier)) 187 | (column_def 188 | (identifier)))) 189 | (sql_stmt 190 | (create_table_stmt 191 | (CREATE) 192 | (TABLE) 193 | (identifier) 194 | (AS) 195 | (select_stmt 196 | (SELECT) 197 | (from_clause 198 | (FROM) 199 | (table_or_subquery 200 | (identifier)))))) 201 | (sql_stmt 202 | (create_table_stmt 203 | (CREATE) 204 | (TEMP) 205 | (TABLE) 206 | (identifier) 207 | (AS) 208 | (select_stmt 209 | (SELECT) 210 | (identifier) 211 | (identifier) 212 | (identifier) 213 | (from_clause 214 | (FROM) 215 | (table_or_subquery 216 | (identifier)))))) 217 | (sql_stmt 218 | (create_table_stmt 219 | (CREATE) 220 | (TABLE) 221 | (identifier) 222 | (AS) 223 | (select_stmt 224 | (SELECT) 225 | (function_name 226 | (identifier)) 227 | (function_name 228 | (identifier)) 229 | (identifier) 230 | (function_name 231 | (identifier)) 232 | (identifier) 233 | (from_clause 234 | (FROM) 235 | (table_or_subquery 236 | (identifier)))))) 237 | (sql_stmt 238 | (create_table_stmt 239 | (CREATE) 240 | (TABLE) 241 | (identifier) 242 | (column_def 243 | (identifier)) 244 | (column_def 245 | (identifier) 246 | (type_name 247 | (identifier))) 248 | (column_def 249 | (identifier) 250 | (type_name 251 | (identifier)) 252 | (column_constraint 253 | (UNIQUE))) 254 | (column_def 255 | (identifier) 256 | (type_name 257 | (identifier) 258 | (signed_number 259 | (numeric_literal)) 260 | (signed_number 261 | (numeric_literal))) 262 | (column_constraint 263 | (PRIMARY) 264 | (KEY))) 265 | (column_def 266 | (identifier) 267 | (column_constraint 268 | (foreign_key_clause 269 | (REFERENCES) 270 | (identifier))))))) 271 | -------------------------------------------------------------------------------- /test/corpus/stmt.select.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.select 3 | ================================================================================ 4 | 5 | SELECT * FROM t1; 6 | SELECT * FROM t1 ORDER BY b; 7 | SELECT * FROM t1 ORDER BY b, a; 8 | SELECT * FROM t1 LIMIT 10; 9 | SELECT * FROM t1 LIMIT 10 OFFSET 5; 10 | SELECT * FROM t1 LIMIT 10, 5; 11 | SELECT * FROM t1 ORDER BY a LIMIT 10; 12 | SELECT * FROM t1 ORDER BY b LIMIT 10 OFFSET 5; 13 | SELECT * FROM t1 ORDER BY a,b LIMIT 10, 5; 14 | SELECT * FROM t1 UNION SELECT b, a FROM t1; 15 | SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b; 16 | SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b, a; 17 | SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10; 18 | SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10 OFFSET 5; 19 | SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10, 5; 20 | SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY a LIMIT 10; 21 | SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b LIMIT 10 OFFSET 5; 22 | SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY a,b LIMIT 10, 5; 23 | 24 | -------------------------------------------------------------------------------- 25 | 26 | (sql_stmt_list 27 | (sql_stmt 28 | (select_stmt 29 | (SELECT) 30 | (from_clause 31 | (FROM) 32 | (table_or_subquery 33 | (identifier))))) 34 | (sql_stmt 35 | (select_stmt 36 | (SELECT) 37 | (from_clause 38 | (FROM) 39 | (table_or_subquery 40 | (identifier))) 41 | (order_by_clause 42 | (ORDER) 43 | (BY) 44 | (ordering_term 45 | (identifier))))) 46 | (sql_stmt 47 | (select_stmt 48 | (SELECT) 49 | (from_clause 50 | (FROM) 51 | (table_or_subquery 52 | (identifier))) 53 | (order_by_clause 54 | (ORDER) 55 | (BY) 56 | (ordering_term 57 | (identifier)) 58 | (ordering_term 59 | (identifier))))) 60 | (sql_stmt 61 | (select_stmt 62 | (SELECT) 63 | (from_clause 64 | (FROM) 65 | (table_or_subquery 66 | (identifier))) 67 | (limit_clause 68 | (LIMIT) 69 | (numeric_literal)))) 70 | (sql_stmt 71 | (select_stmt 72 | (SELECT) 73 | (from_clause 74 | (FROM) 75 | (table_or_subquery 76 | (identifier))) 77 | (limit_clause 78 | (LIMIT) 79 | (numeric_literal) 80 | (OFFSET) 81 | (numeric_literal)))) 82 | (sql_stmt 83 | (select_stmt 84 | (SELECT) 85 | (from_clause 86 | (FROM) 87 | (table_or_subquery 88 | (identifier))) 89 | (limit_clause 90 | (LIMIT) 91 | (numeric_literal) 92 | (numeric_literal)))) 93 | (sql_stmt 94 | (select_stmt 95 | (SELECT) 96 | (from_clause 97 | (FROM) 98 | (table_or_subquery 99 | (identifier))) 100 | (order_by_clause 101 | (ORDER) 102 | (BY) 103 | (ordering_term 104 | (identifier))) 105 | (limit_clause 106 | (LIMIT) 107 | (numeric_literal)))) 108 | (sql_stmt 109 | (select_stmt 110 | (SELECT) 111 | (from_clause 112 | (FROM) 113 | (table_or_subquery 114 | (identifier))) 115 | (order_by_clause 116 | (ORDER) 117 | (BY) 118 | (ordering_term 119 | (identifier))) 120 | (limit_clause 121 | (LIMIT) 122 | (numeric_literal) 123 | (OFFSET) 124 | (numeric_literal)))) 125 | (sql_stmt 126 | (select_stmt 127 | (SELECT) 128 | (from_clause 129 | (FROM) 130 | (table_or_subquery 131 | (identifier))) 132 | (order_by_clause 133 | (ORDER) 134 | (BY) 135 | (ordering_term 136 | (identifier)) 137 | (ordering_term 138 | (identifier))) 139 | (limit_clause 140 | (LIMIT) 141 | (numeric_literal) 142 | (numeric_literal)))) 143 | (sql_stmt 144 | (select_stmt 145 | (SELECT) 146 | (from_clause 147 | (FROM) 148 | (table_or_subquery 149 | (identifier))) 150 | (UNION) 151 | (SELECT) 152 | (identifier) 153 | (identifier) 154 | (from_clause 155 | (FROM) 156 | (table_or_subquery 157 | (identifier))))) 158 | (sql_stmt 159 | (select_stmt 160 | (SELECT) 161 | (from_clause 162 | (FROM) 163 | (table_or_subquery 164 | (identifier))) 165 | (UNION) 166 | (SELECT) 167 | (identifier) 168 | (identifier) 169 | (from_clause 170 | (FROM) 171 | (table_or_subquery 172 | (identifier))) 173 | (order_by_clause 174 | (ORDER) 175 | (BY) 176 | (ordering_term 177 | (identifier))))) 178 | (sql_stmt 179 | (select_stmt 180 | (SELECT) 181 | (from_clause 182 | (FROM) 183 | (table_or_subquery 184 | (identifier))) 185 | (UNION) 186 | (SELECT) 187 | (identifier) 188 | (identifier) 189 | (from_clause 190 | (FROM) 191 | (table_or_subquery 192 | (identifier))) 193 | (order_by_clause 194 | (ORDER) 195 | (BY) 196 | (ordering_term 197 | (identifier)) 198 | (ordering_term 199 | (identifier))))) 200 | (sql_stmt 201 | (select_stmt 202 | (SELECT) 203 | (from_clause 204 | (FROM) 205 | (table_or_subquery 206 | (identifier))) 207 | (UNION) 208 | (SELECT) 209 | (identifier) 210 | (identifier) 211 | (from_clause 212 | (FROM) 213 | (table_or_subquery 214 | (identifier))) 215 | (limit_clause 216 | (LIMIT) 217 | (numeric_literal)))) 218 | (sql_stmt 219 | (select_stmt 220 | (SELECT) 221 | (from_clause 222 | (FROM) 223 | (table_or_subquery 224 | (identifier))) 225 | (UNION) 226 | (SELECT) 227 | (identifier) 228 | (identifier) 229 | (from_clause 230 | (FROM) 231 | (table_or_subquery 232 | (identifier))) 233 | (limit_clause 234 | (LIMIT) 235 | (numeric_literal) 236 | (OFFSET) 237 | (numeric_literal)))) 238 | (sql_stmt 239 | (select_stmt 240 | (SELECT) 241 | (from_clause 242 | (FROM) 243 | (table_or_subquery 244 | (identifier))) 245 | (UNION) 246 | (SELECT) 247 | (identifier) 248 | (identifier) 249 | (from_clause 250 | (FROM) 251 | (table_or_subquery 252 | (identifier))) 253 | (limit_clause 254 | (LIMIT) 255 | (numeric_literal) 256 | (numeric_literal)))) 257 | (sql_stmt 258 | (select_stmt 259 | (SELECT) 260 | (from_clause 261 | (FROM) 262 | (table_or_subquery 263 | (identifier))) 264 | (UNION) 265 | (SELECT) 266 | (identifier) 267 | (identifier) 268 | (from_clause 269 | (FROM) 270 | (table_or_subquery 271 | (identifier))) 272 | (order_by_clause 273 | (ORDER) 274 | (BY) 275 | (ordering_term 276 | (identifier))) 277 | (limit_clause 278 | (LIMIT) 279 | (numeric_literal)))) 280 | (sql_stmt 281 | (select_stmt 282 | (SELECT) 283 | (from_clause 284 | (FROM) 285 | (table_or_subquery 286 | (identifier))) 287 | (UNION) 288 | (SELECT) 289 | (identifier) 290 | (identifier) 291 | (from_clause 292 | (FROM) 293 | (table_or_subquery 294 | (identifier))) 295 | (order_by_clause 296 | (ORDER) 297 | (BY) 298 | (ordering_term 299 | (identifier))) 300 | (limit_clause 301 | (LIMIT) 302 | (numeric_literal) 303 | (OFFSET) 304 | (numeric_literal)))) 305 | (sql_stmt 306 | (select_stmt 307 | (SELECT) 308 | (from_clause 309 | (FROM) 310 | (table_or_subquery 311 | (identifier))) 312 | (UNION) 313 | (SELECT) 314 | (identifier) 315 | (identifier) 316 | (from_clause 317 | (FROM) 318 | (table_or_subquery 319 | (identifier))) 320 | (order_by_clause 321 | (ORDER) 322 | (BY) 323 | (ordering_term 324 | (identifier)) 325 | (ordering_term 326 | (identifier))) 327 | (limit_clause 328 | (LIMIT) 329 | (numeric_literal) 330 | (numeric_literal))))) 331 | -------------------------------------------------------------------------------- /test/corpus/stmt.create_table.column-constraint.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.create_table.column-constraint 3 | ================================================================================ 4 | 5 | CREATE TABLE t1(c1 text PRIMARY KEY); 6 | CREATE TABLE t1(c1 text PRIMARY KEY ASC); 7 | CREATE TABLE t1(c1 text PRIMARY KEY DESC); 8 | CREATE TABLE t1(c1 text CONSTRAINT cons PRIMARY KEY DESC); 9 | CREATE TABLE t1(c1 text NOT NULL); 10 | CREATE TABLE t1(c1 text CONSTRAINT nm NOT NULL); 11 | CREATE TABLE t1(c1 text NULL); 12 | CREATE TABLE t1(c1 text CONSTRAINT nm NULL); 13 | CREATE TABLE t1(c1 text UNIQUE); 14 | CREATE TABLE t1(c1 text CONSTRAINT un UNIQUE); 15 | CREATE TABLE t1(c1 text CHECK(c1!=0)); 16 | CREATE TABLE t1(c1 text CONSTRAINT chk CHECK(c1!=0)); 17 | CREATE TABLE t1(c1 text DEFAULT 1); 18 | CREATE TABLE t1(c1 text DEFAULT -1); 19 | CREATE TABLE t1(c1 text DEFAULT +1); 20 | CREATE TABLE t1(c1 text DEFAULT -45.8e22); 21 | CREATE TABLE t1(c1 text DEFAULT (1+1)); 22 | CREATE TABLE t1(c1 text CONSTRAINT "1 2" DEFAULT (1+1)); 23 | CREATE TABLE t1(c1 text COLLATE nocase); 24 | CREATE TABLE t1(c1 text CONSTRAINT 'a x' COLLATE nocase); 25 | CREATE TABLE t1(c1 REFERENCES t2); 26 | CREATE TABLE t1(c1 CONSTRAINT abc REFERENCES t2); 27 | CREATE TABLE t1(c1 PRIMARY KEY NOT NULL UNIQUE CHECK(c1 IS 'ten') DEFAULT 123 REFERENCES t1); 28 | CREATE TABLE t1(c1 REFERENCES t1 DEFAULT 123 CHECK(c1 IS 'ten') UNIQUE NOT NULL PRIMARY KEY); 29 | 30 | -------------------------------------------------------------------------------- 31 | 32 | (sql_stmt_list 33 | (sql_stmt 34 | (create_table_stmt 35 | (CREATE) 36 | (TABLE) 37 | (identifier) 38 | (column_def 39 | (identifier) 40 | (type_name 41 | (identifier)) 42 | (column_constraint 43 | (PRIMARY) 44 | (KEY))))) 45 | (sql_stmt 46 | (create_table_stmt 47 | (CREATE) 48 | (TABLE) 49 | (identifier) 50 | (column_def 51 | (identifier) 52 | (type_name 53 | (identifier)) 54 | (column_constraint 55 | (PRIMARY) 56 | (KEY) 57 | (ASC))))) 58 | (sql_stmt 59 | (create_table_stmt 60 | (CREATE) 61 | (TABLE) 62 | (identifier) 63 | (column_def 64 | (identifier) 65 | (type_name 66 | (identifier)) 67 | (column_constraint 68 | (PRIMARY) 69 | (KEY) 70 | (DESC))))) 71 | (sql_stmt 72 | (create_table_stmt 73 | (CREATE) 74 | (TABLE) 75 | (identifier) 76 | (column_def 77 | (identifier) 78 | (type_name 79 | (identifier)) 80 | (column_constraint 81 | (CONSTRAINT) 82 | (identifier) 83 | (PRIMARY) 84 | (KEY) 85 | (DESC))))) 86 | (sql_stmt 87 | (create_table_stmt 88 | (CREATE) 89 | (TABLE) 90 | (identifier) 91 | (column_def 92 | (identifier) 93 | (type_name 94 | (identifier)) 95 | (column_constraint 96 | (NOT) 97 | (NULL))))) 98 | (sql_stmt 99 | (create_table_stmt 100 | (CREATE) 101 | (TABLE) 102 | (identifier) 103 | (column_def 104 | (identifier) 105 | (type_name 106 | (identifier)) 107 | (column_constraint 108 | (CONSTRAINT) 109 | (identifier) 110 | (NOT) 111 | (NULL))))) 112 | (sql_stmt 113 | (create_table_stmt 114 | (CREATE) 115 | (TABLE) 116 | (identifier) 117 | (column_def 118 | (identifier) 119 | (type_name 120 | (identifier)) 121 | (column_constraint 122 | (NULL))))) 123 | (sql_stmt 124 | (create_table_stmt 125 | (CREATE) 126 | (TABLE) 127 | (identifier) 128 | (column_def 129 | (identifier) 130 | (type_name 131 | (identifier)) 132 | (column_constraint 133 | (CONSTRAINT) 134 | (identifier) 135 | (NULL))))) 136 | (sql_stmt 137 | (create_table_stmt 138 | (CREATE) 139 | (TABLE) 140 | (identifier) 141 | (column_def 142 | (identifier) 143 | (type_name 144 | (identifier)) 145 | (column_constraint 146 | (UNIQUE))))) 147 | (sql_stmt 148 | (create_table_stmt 149 | (CREATE) 150 | (TABLE) 151 | (identifier) 152 | (column_def 153 | (identifier) 154 | (type_name 155 | (identifier)) 156 | (column_constraint 157 | (CONSTRAINT) 158 | (identifier) 159 | (UNIQUE))))) 160 | (sql_stmt 161 | (create_table_stmt 162 | (CREATE) 163 | (TABLE) 164 | (identifier) 165 | (column_def 166 | (identifier) 167 | (type_name 168 | (identifier)) 169 | (column_constraint 170 | (CHECK) 171 | (identifier) 172 | (numeric_literal))))) 173 | (sql_stmt 174 | (create_table_stmt 175 | (CREATE) 176 | (TABLE) 177 | (identifier) 178 | (column_def 179 | (identifier) 180 | (type_name 181 | (identifier)) 182 | (column_constraint 183 | (CONSTRAINT) 184 | (identifier) 185 | (CHECK) 186 | (identifier) 187 | (numeric_literal))))) 188 | (sql_stmt 189 | (create_table_stmt 190 | (CREATE) 191 | (TABLE) 192 | (identifier) 193 | (column_def 194 | (identifier) 195 | (type_name 196 | (identifier)) 197 | (column_constraint 198 | (DEFAULT) 199 | (numeric_literal))))) 200 | (sql_stmt 201 | (create_table_stmt 202 | (CREATE) 203 | (TABLE) 204 | (identifier) 205 | (column_def 206 | (identifier) 207 | (type_name 208 | (identifier)) 209 | (column_constraint 210 | (DEFAULT) 211 | (signed_number 212 | (numeric_literal)))))) 213 | (sql_stmt 214 | (create_table_stmt 215 | (CREATE) 216 | (TABLE) 217 | (identifier) 218 | (column_def 219 | (identifier) 220 | (type_name 221 | (identifier)) 222 | (column_constraint 223 | (DEFAULT) 224 | (signed_number 225 | (numeric_literal)))))) 226 | (sql_stmt 227 | (create_table_stmt 228 | (CREATE) 229 | (TABLE) 230 | (identifier) 231 | (column_def 232 | (identifier) 233 | (type_name 234 | (identifier)) 235 | (column_constraint 236 | (DEFAULT) 237 | (signed_number 238 | (numeric_literal)))))) 239 | (sql_stmt 240 | (create_table_stmt 241 | (CREATE) 242 | (TABLE) 243 | (identifier) 244 | (column_def 245 | (identifier) 246 | (type_name 247 | (identifier)) 248 | (column_constraint 249 | (DEFAULT) 250 | (numeric_literal) 251 | (numeric_literal))))) 252 | (sql_stmt 253 | (create_table_stmt 254 | (CREATE) 255 | (TABLE) 256 | (identifier) 257 | (column_def 258 | (identifier) 259 | (type_name 260 | (identifier)) 261 | (column_constraint 262 | (CONSTRAINT) 263 | (identifier) 264 | (DEFAULT) 265 | (numeric_literal) 266 | (numeric_literal))))) 267 | (sql_stmt 268 | (create_table_stmt 269 | (CREATE) 270 | (TABLE) 271 | (identifier) 272 | (column_def 273 | (identifier) 274 | (type_name 275 | (identifier)) 276 | (column_constraint 277 | (COLLATE) 278 | (collation_name 279 | (identifier)))))) 280 | (sql_stmt 281 | (create_table_stmt 282 | (CREATE) 283 | (TABLE) 284 | (identifier) 285 | (column_def 286 | (identifier) 287 | (type_name 288 | (identifier)) 289 | (column_constraint 290 | (CONSTRAINT) 291 | (string_literal) 292 | (COLLATE) 293 | (collation_name 294 | (identifier)))))) 295 | (sql_stmt 296 | (create_table_stmt 297 | (CREATE) 298 | (TABLE) 299 | (identifier) 300 | (column_def 301 | (identifier) 302 | (column_constraint 303 | (foreign_key_clause 304 | (REFERENCES) 305 | (identifier)))))) 306 | (sql_stmt 307 | (create_table_stmt 308 | (CREATE) 309 | (TABLE) 310 | (identifier) 311 | (column_def 312 | (identifier) 313 | (column_constraint 314 | (CONSTRAINT) 315 | (identifier) 316 | (foreign_key_clause 317 | (REFERENCES) 318 | (identifier)))))) 319 | (sql_stmt 320 | (create_table_stmt 321 | (CREATE) 322 | (TABLE) 323 | (identifier) 324 | (column_def 325 | (identifier) 326 | (column_constraint 327 | (PRIMARY) 328 | (KEY)) 329 | (column_constraint 330 | (NOT) 331 | (NULL)) 332 | (column_constraint 333 | (UNIQUE)) 334 | (column_constraint 335 | (CHECK) 336 | (identifier) 337 | (IS) 338 | (string_literal)) 339 | (column_constraint 340 | (DEFAULT) 341 | (numeric_literal)) 342 | (column_constraint 343 | (foreign_key_clause 344 | (REFERENCES) 345 | (identifier)))))) 346 | (sql_stmt 347 | (create_table_stmt 348 | (CREATE) 349 | (TABLE) 350 | (identifier) 351 | (column_def 352 | (identifier) 353 | (column_constraint 354 | (foreign_key_clause 355 | (REFERENCES) 356 | (identifier))) 357 | (column_constraint 358 | (DEFAULT) 359 | (numeric_literal)) 360 | (column_constraint 361 | (CHECK) 362 | (identifier) 363 | (IS) 364 | (string_literal)) 365 | (column_constraint 366 | (UNIQUE)) 367 | (column_constraint 368 | (NOT) 369 | (NULL)) 370 | (column_constraint 371 | (PRIMARY) 372 | (KEY)))))) 373 | -------------------------------------------------------------------------------- /test/corpus/stmt.update.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.update 3 | ================================================================================ 4 | 5 | UPDATE t1 SET a=10; 6 | UPDATE t1 SET a=10, b=5; 7 | UPDATE t1 SET a=10 WHERE b=5; 8 | UPDATE t1 SET b=5,a=10 WHERE 1; 9 | UPDATE main.t1 SET a=10; 10 | UPDATE main.t1 SET a=10, b=5; 11 | UPDATE main.t1 SET a=10 WHERE b=5; 12 | UPDATE OR ROLLBACK t1 SET a=10; 13 | UPDATE OR ROLLBACK t1 SET a=10, b=5; 14 | UPDATE OR ROLLBACK t1 SET a=10 WHERE b=5; 15 | UPDATE OR ROLLBACK t1 SET b=5,a=10 WHERE 1; 16 | UPDATE OR ROLLBACK main.t1 SET a=10; 17 | UPDATE OR ROLLBACK main.t1 SET a=10, b=5; 18 | UPDATE OR ROLLBACK main.t1 SET a=10 WHERE b=5; 19 | UPDATE OR ROLLBACK main.t1 SET b=5,a=10 WHERE 1; 20 | UPDATE OR ABORT t1 SET a=10; 21 | UPDATE OR ABORT t1 SET a=10, b=5; 22 | UPDATE OR ABORT t1 SET a=10 WHERE b=5; 23 | UPDATE OR ABORT t1 SET b=5,a=10 WHERE 1; 24 | UPDATE OR ABORT main.t1 SET a=10; 25 | UPDATE OR ABORT main.t1 SET a=10, b=5; 26 | UPDATE OR ABORT main.t1 SET a=10 WHERE b=5; 27 | UPDATE OR ABORT main.t1 SET b=5,a=10 WHERE 1; 28 | UPDATE OR REPLACE t1 SET a=10; 29 | UPDATE OR REPLACE t1 SET a=10, b=5; 30 | UPDATE OR REPLACE t1 SET a=10 WHERE b=5; 31 | UPDATE OR REPLACE t1 SET b=5,a=10 WHERE 1; 32 | UPDATE OR REPLACE main.t1 SET a=10; 33 | UPDATE OR REPLACE main.t1 SET a=10, b=5; 34 | UPDATE OR REPLACE main.t1 SET a=10 WHERE b=5; 35 | UPDATE OR REPLACE main.t1 SET b=5,a=10 WHERE 1; 36 | UPDATE OR FAIL t1 SET a=10; 37 | UPDATE OR FAIL t1 SET a=10, b=5; 38 | UPDATE OR FAIL t1 SET a=10 WHERE b=5; 39 | UPDATE OR FAIL t1 SET b=5,a=10 WHERE 1; 40 | UPDATE OR FAIL main.t1 SET a=10; 41 | UPDATE OR FAIL main.t1 SET a=10, b=5; 42 | UPDATE OR FAIL main.t1 SET a=10 WHERE b=5; 43 | UPDATE OR FAIL main.t1 SET b=5,a=10 WHERE 1; 44 | UPDATE OR IGNORE t1 SET a=10; 45 | UPDATE OR IGNORE t1 SET a=10, b=5; 46 | UPDATE OR IGNORE t1 SET a=10 WHERE b=5; 47 | UPDATE OR IGNORE t1 SET b=5,a=10 WHERE 1; 48 | UPDATE OR IGNORE main.t1 SET a=10; 49 | UPDATE OR IGNORE main.t1 SET a=10, b=5; 50 | UPDATE OR IGNORE main.t1 SET a=10 WHERE b=5; 51 | UPDATE OR IGNORE main.t1 SET b=5,a=10 WHERE 1; 52 | 53 | -------------------------------------------------------------------------------- 54 | 55 | (sql_stmt_list 56 | (sql_stmt 57 | (update_stmt 58 | (UPDATE) 59 | (qualified_table_name 60 | (identifier)) 61 | (SET) 62 | (identifier) 63 | (numeric_literal))) 64 | (sql_stmt 65 | (update_stmt 66 | (UPDATE) 67 | (qualified_table_name 68 | (identifier)) 69 | (SET) 70 | (identifier) 71 | (numeric_literal) 72 | (identifier) 73 | (numeric_literal))) 74 | (sql_stmt 75 | (update_stmt 76 | (UPDATE) 77 | (qualified_table_name 78 | (identifier)) 79 | (SET) 80 | (identifier) 81 | (numeric_literal) 82 | (where_clause 83 | (WHERE) 84 | (identifier) 85 | (numeric_literal)))) 86 | (sql_stmt 87 | (update_stmt 88 | (UPDATE) 89 | (qualified_table_name 90 | (identifier)) 91 | (SET) 92 | (identifier) 93 | (numeric_literal) 94 | (identifier) 95 | (numeric_literal) 96 | (where_clause 97 | (WHERE) 98 | (numeric_literal)))) 99 | (sql_stmt 100 | (update_stmt 101 | (UPDATE) 102 | (qualified_table_name 103 | (identifier) 104 | (identifier)) 105 | (SET) 106 | (identifier) 107 | (numeric_literal))) 108 | (sql_stmt 109 | (update_stmt 110 | (UPDATE) 111 | (qualified_table_name 112 | (identifier) 113 | (identifier)) 114 | (SET) 115 | (identifier) 116 | (numeric_literal) 117 | (identifier) 118 | (numeric_literal))) 119 | (sql_stmt 120 | (update_stmt 121 | (UPDATE) 122 | (qualified_table_name 123 | (identifier) 124 | (identifier)) 125 | (SET) 126 | (identifier) 127 | (numeric_literal) 128 | (where_clause 129 | (WHERE) 130 | (identifier) 131 | (numeric_literal)))) 132 | (sql_stmt 133 | (update_stmt 134 | (UPDATE) 135 | (OR) 136 | (ROLLBACK) 137 | (qualified_table_name 138 | (identifier)) 139 | (SET) 140 | (identifier) 141 | (numeric_literal))) 142 | (sql_stmt 143 | (update_stmt 144 | (UPDATE) 145 | (OR) 146 | (ROLLBACK) 147 | (qualified_table_name 148 | (identifier)) 149 | (SET) 150 | (identifier) 151 | (numeric_literal) 152 | (identifier) 153 | (numeric_literal))) 154 | (sql_stmt 155 | (update_stmt 156 | (UPDATE) 157 | (OR) 158 | (ROLLBACK) 159 | (qualified_table_name 160 | (identifier)) 161 | (SET) 162 | (identifier) 163 | (numeric_literal) 164 | (where_clause 165 | (WHERE) 166 | (identifier) 167 | (numeric_literal)))) 168 | (sql_stmt 169 | (update_stmt 170 | (UPDATE) 171 | (OR) 172 | (ROLLBACK) 173 | (qualified_table_name 174 | (identifier)) 175 | (SET) 176 | (identifier) 177 | (numeric_literal) 178 | (identifier) 179 | (numeric_literal) 180 | (where_clause 181 | (WHERE) 182 | (numeric_literal)))) 183 | (sql_stmt 184 | (update_stmt 185 | (UPDATE) 186 | (OR) 187 | (ROLLBACK) 188 | (qualified_table_name 189 | (identifier) 190 | (identifier)) 191 | (SET) 192 | (identifier) 193 | (numeric_literal))) 194 | (sql_stmt 195 | (update_stmt 196 | (UPDATE) 197 | (OR) 198 | (ROLLBACK) 199 | (qualified_table_name 200 | (identifier) 201 | (identifier)) 202 | (SET) 203 | (identifier) 204 | (numeric_literal) 205 | (identifier) 206 | (numeric_literal))) 207 | (sql_stmt 208 | (update_stmt 209 | (UPDATE) 210 | (OR) 211 | (ROLLBACK) 212 | (qualified_table_name 213 | (identifier) 214 | (identifier)) 215 | (SET) 216 | (identifier) 217 | (numeric_literal) 218 | (where_clause 219 | (WHERE) 220 | (identifier) 221 | (numeric_literal)))) 222 | (sql_stmt 223 | (update_stmt 224 | (UPDATE) 225 | (OR) 226 | (ROLLBACK) 227 | (qualified_table_name 228 | (identifier) 229 | (identifier)) 230 | (SET) 231 | (identifier) 232 | (numeric_literal) 233 | (identifier) 234 | (numeric_literal) 235 | (where_clause 236 | (WHERE) 237 | (numeric_literal)))) 238 | (sql_stmt 239 | (update_stmt 240 | (UPDATE) 241 | (OR) 242 | (ABORT) 243 | (qualified_table_name 244 | (identifier)) 245 | (SET) 246 | (identifier) 247 | (numeric_literal))) 248 | (sql_stmt 249 | (update_stmt 250 | (UPDATE) 251 | (OR) 252 | (ABORT) 253 | (qualified_table_name 254 | (identifier)) 255 | (SET) 256 | (identifier) 257 | (numeric_literal) 258 | (identifier) 259 | (numeric_literal))) 260 | (sql_stmt 261 | (update_stmt 262 | (UPDATE) 263 | (OR) 264 | (ABORT) 265 | (qualified_table_name 266 | (identifier)) 267 | (SET) 268 | (identifier) 269 | (numeric_literal) 270 | (where_clause 271 | (WHERE) 272 | (identifier) 273 | (numeric_literal)))) 274 | (sql_stmt 275 | (update_stmt 276 | (UPDATE) 277 | (OR) 278 | (ABORT) 279 | (qualified_table_name 280 | (identifier)) 281 | (SET) 282 | (identifier) 283 | (numeric_literal) 284 | (identifier) 285 | (numeric_literal) 286 | (where_clause 287 | (WHERE) 288 | (numeric_literal)))) 289 | (sql_stmt 290 | (update_stmt 291 | (UPDATE) 292 | (OR) 293 | (ABORT) 294 | (qualified_table_name 295 | (identifier) 296 | (identifier)) 297 | (SET) 298 | (identifier) 299 | (numeric_literal))) 300 | (sql_stmt 301 | (update_stmt 302 | (UPDATE) 303 | (OR) 304 | (ABORT) 305 | (qualified_table_name 306 | (identifier) 307 | (identifier)) 308 | (SET) 309 | (identifier) 310 | (numeric_literal) 311 | (identifier) 312 | (numeric_literal))) 313 | (sql_stmt 314 | (update_stmt 315 | (UPDATE) 316 | (OR) 317 | (ABORT) 318 | (qualified_table_name 319 | (identifier) 320 | (identifier)) 321 | (SET) 322 | (identifier) 323 | (numeric_literal) 324 | (where_clause 325 | (WHERE) 326 | (identifier) 327 | (numeric_literal)))) 328 | (sql_stmt 329 | (update_stmt 330 | (UPDATE) 331 | (OR) 332 | (ABORT) 333 | (qualified_table_name 334 | (identifier) 335 | (identifier)) 336 | (SET) 337 | (identifier) 338 | (numeric_literal) 339 | (identifier) 340 | (numeric_literal) 341 | (where_clause 342 | (WHERE) 343 | (numeric_literal)))) 344 | (sql_stmt 345 | (update_stmt 346 | (UPDATE) 347 | (OR) 348 | (REPLACE) 349 | (qualified_table_name 350 | (identifier)) 351 | (SET) 352 | (identifier) 353 | (numeric_literal))) 354 | (sql_stmt 355 | (update_stmt 356 | (UPDATE) 357 | (OR) 358 | (REPLACE) 359 | (qualified_table_name 360 | (identifier)) 361 | (SET) 362 | (identifier) 363 | (numeric_literal) 364 | (identifier) 365 | (numeric_literal))) 366 | (sql_stmt 367 | (update_stmt 368 | (UPDATE) 369 | (OR) 370 | (REPLACE) 371 | (qualified_table_name 372 | (identifier)) 373 | (SET) 374 | (identifier) 375 | (numeric_literal) 376 | (where_clause 377 | (WHERE) 378 | (identifier) 379 | (numeric_literal)))) 380 | (sql_stmt 381 | (update_stmt 382 | (UPDATE) 383 | (OR) 384 | (REPLACE) 385 | (qualified_table_name 386 | (identifier)) 387 | (SET) 388 | (identifier) 389 | (numeric_literal) 390 | (identifier) 391 | (numeric_literal) 392 | (where_clause 393 | (WHERE) 394 | (numeric_literal)))) 395 | (sql_stmt 396 | (update_stmt 397 | (UPDATE) 398 | (OR) 399 | (REPLACE) 400 | (qualified_table_name 401 | (identifier) 402 | (identifier)) 403 | (SET) 404 | (identifier) 405 | (numeric_literal))) 406 | (sql_stmt 407 | (update_stmt 408 | (UPDATE) 409 | (OR) 410 | (REPLACE) 411 | (qualified_table_name 412 | (identifier) 413 | (identifier)) 414 | (SET) 415 | (identifier) 416 | (numeric_literal) 417 | (identifier) 418 | (numeric_literal))) 419 | (sql_stmt 420 | (update_stmt 421 | (UPDATE) 422 | (OR) 423 | (REPLACE) 424 | (qualified_table_name 425 | (identifier) 426 | (identifier)) 427 | (SET) 428 | (identifier) 429 | (numeric_literal) 430 | (where_clause 431 | (WHERE) 432 | (identifier) 433 | (numeric_literal)))) 434 | (sql_stmt 435 | (update_stmt 436 | (UPDATE) 437 | (OR) 438 | (REPLACE) 439 | (qualified_table_name 440 | (identifier) 441 | (identifier)) 442 | (SET) 443 | (identifier) 444 | (numeric_literal) 445 | (identifier) 446 | (numeric_literal) 447 | (where_clause 448 | (WHERE) 449 | (numeric_literal)))) 450 | (sql_stmt 451 | (update_stmt 452 | (UPDATE) 453 | (OR) 454 | (FAIL) 455 | (qualified_table_name 456 | (identifier)) 457 | (SET) 458 | (identifier) 459 | (numeric_literal))) 460 | (sql_stmt 461 | (update_stmt 462 | (UPDATE) 463 | (OR) 464 | (FAIL) 465 | (qualified_table_name 466 | (identifier)) 467 | (SET) 468 | (identifier) 469 | (numeric_literal) 470 | (identifier) 471 | (numeric_literal))) 472 | (sql_stmt 473 | (update_stmt 474 | (UPDATE) 475 | (OR) 476 | (FAIL) 477 | (qualified_table_name 478 | (identifier)) 479 | (SET) 480 | (identifier) 481 | (numeric_literal) 482 | (where_clause 483 | (WHERE) 484 | (identifier) 485 | (numeric_literal)))) 486 | (sql_stmt 487 | (update_stmt 488 | (UPDATE) 489 | (OR) 490 | (FAIL) 491 | (qualified_table_name 492 | (identifier)) 493 | (SET) 494 | (identifier) 495 | (numeric_literal) 496 | (identifier) 497 | (numeric_literal) 498 | (where_clause 499 | (WHERE) 500 | (numeric_literal)))) 501 | (sql_stmt 502 | (update_stmt 503 | (UPDATE) 504 | (OR) 505 | (FAIL) 506 | (qualified_table_name 507 | (identifier) 508 | (identifier)) 509 | (SET) 510 | (identifier) 511 | (numeric_literal))) 512 | (sql_stmt 513 | (update_stmt 514 | (UPDATE) 515 | (OR) 516 | (FAIL) 517 | (qualified_table_name 518 | (identifier) 519 | (identifier)) 520 | (SET) 521 | (identifier) 522 | (numeric_literal) 523 | (identifier) 524 | (numeric_literal))) 525 | (sql_stmt 526 | (update_stmt 527 | (UPDATE) 528 | (OR) 529 | (FAIL) 530 | (qualified_table_name 531 | (identifier) 532 | (identifier)) 533 | (SET) 534 | (identifier) 535 | (numeric_literal) 536 | (where_clause 537 | (WHERE) 538 | (identifier) 539 | (numeric_literal)))) 540 | (sql_stmt 541 | (update_stmt 542 | (UPDATE) 543 | (OR) 544 | (FAIL) 545 | (qualified_table_name 546 | (identifier) 547 | (identifier)) 548 | (SET) 549 | (identifier) 550 | (numeric_literal) 551 | (identifier) 552 | (numeric_literal) 553 | (where_clause 554 | (WHERE) 555 | (numeric_literal)))) 556 | (sql_stmt 557 | (update_stmt 558 | (UPDATE) 559 | (OR) 560 | (IGNORE) 561 | (qualified_table_name 562 | (identifier)) 563 | (SET) 564 | (identifier) 565 | (numeric_literal))) 566 | (sql_stmt 567 | (update_stmt 568 | (UPDATE) 569 | (OR) 570 | (IGNORE) 571 | (qualified_table_name 572 | (identifier)) 573 | (SET) 574 | (identifier) 575 | (numeric_literal) 576 | (identifier) 577 | (numeric_literal))) 578 | (sql_stmt 579 | (update_stmt 580 | (UPDATE) 581 | (OR) 582 | (IGNORE) 583 | (qualified_table_name 584 | (identifier)) 585 | (SET) 586 | (identifier) 587 | (numeric_literal) 588 | (where_clause 589 | (WHERE) 590 | (identifier) 591 | (numeric_literal)))) 592 | (sql_stmt 593 | (update_stmt 594 | (UPDATE) 595 | (OR) 596 | (IGNORE) 597 | (qualified_table_name 598 | (identifier)) 599 | (SET) 600 | (identifier) 601 | (numeric_literal) 602 | (identifier) 603 | (numeric_literal) 604 | (where_clause 605 | (WHERE) 606 | (numeric_literal)))) 607 | (sql_stmt 608 | (update_stmt 609 | (UPDATE) 610 | (OR) 611 | (IGNORE) 612 | (qualified_table_name 613 | (identifier) 614 | (identifier)) 615 | (SET) 616 | (identifier) 617 | (numeric_literal))) 618 | (sql_stmt 619 | (update_stmt 620 | (UPDATE) 621 | (OR) 622 | (IGNORE) 623 | (qualified_table_name 624 | (identifier) 625 | (identifier)) 626 | (SET) 627 | (identifier) 628 | (numeric_literal) 629 | (identifier) 630 | (numeric_literal))) 631 | (sql_stmt 632 | (update_stmt 633 | (UPDATE) 634 | (OR) 635 | (IGNORE) 636 | (qualified_table_name 637 | (identifier) 638 | (identifier)) 639 | (SET) 640 | (identifier) 641 | (numeric_literal) 642 | (where_clause 643 | (WHERE) 644 | (identifier) 645 | (numeric_literal)))) 646 | (sql_stmt 647 | (update_stmt 648 | (UPDATE) 649 | (OR) 650 | (IGNORE) 651 | (qualified_table_name 652 | (identifier) 653 | (identifier)) 654 | (SET) 655 | (identifier) 656 | (numeric_literal) 657 | (identifier) 658 | (numeric_literal) 659 | (where_clause 660 | (WHERE) 661 | (numeric_literal))))) 662 | -------------------------------------------------------------------------------- /test/corpus/stmt.create_table.reference.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.create_table.reference 3 | ================================================================================ 4 | 5 | CREATE TABLE t1(a 6 | REFERENCES t2(x) MATCH FULL 7 | ON DELETE SET NULL ON UPDATE RESTRICT DEFERRABLE 8 | ); 9 | CREATE TABLE t1(a 10 | REFERENCES t2(x) 11 | ON DELETE RESTRICT ON UPDATE SET NULL MATCH FULL 12 | NOT DEFERRABLE INITIALLY IMMEDIATE 13 | ); 14 | CREATE TABLE t1(a 15 | REFERENCES t2(x) MATCH PARTIAL 16 | ON DELETE SET NULL ON UPDATE CASCADE DEFERRABLE INITIALLY IMMEDIATE 17 | ); 18 | CREATE TABLE t1(a 19 | REFERENCES t2(x) MATCH PARTIAL 20 | ON DELETE RESTRICT ON UPDATE SET DEFAULT 21 | ); 22 | CREATE TABLE t1(a 23 | REFERENCES t2(x) MATCH PARTIAL 24 | ON DELETE RESTRICT ON UPDATE RESTRICT DEFERRABLE 25 | ); 26 | CREATE TABLE t1(a 27 | REFERENCES t2(x) MATCH PARTIAL 28 | ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY IMMEDIATE 29 | ); 30 | CREATE TABLE t1(a 31 | REFERENCES t2(x) MATCH SIMPLE 32 | ON DELETE SET NULL ON UPDATE CASCADE NOT DEFERRABLE 33 | ); 34 | CREATE TABLE t1(a 35 | REFERENCES t2(x) MATCH SIMPLE 36 | ON DELETE SET DEFAULT ON UPDATE SET NULL DEFERRABLE 37 | ); 38 | CREATE TABLE t1(a 39 | REFERENCES t2(x) MATCH SIMPLE 40 | ON DELETE SET DEFAULT NOT DEFERRABLE 41 | ); 42 | CREATE TABLE t1(a 43 | REFERENCES t2(x) MATCH SIMPLE 44 | ON DELETE RESTRICT ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY DEFERRED 45 | ); 46 | CREATE TABLE t1(a 47 | REFERENCES t2(x) MATCH SIMPLE 48 | ON DELETE RESTRICT ON UPDATE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE 49 | ); 50 | CREATE TABLE t1(a 51 | REFERENCES t2(x) MATCH SIMPLE 52 | ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE 53 | ); 54 | CREATE TABLE t1(a 55 | REFERENCES t2(x) MATCH STICK 56 | ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE 57 | ); 58 | CREATE TABLE t1(a 59 | REFERENCES t2(x) MATCH STICK 60 | ON UPDATE SET NULL NOT DEFERRABLE INITIALLY DEFERRED 61 | ); 62 | CREATE TABLE t1(a 63 | REFERENCES t2(x) 64 | ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY IMMEDIATE 65 | ); 66 | CREATE TABLE t1(a 67 | REFERENCES t2(x) ON DELETE RESTRICT ON UPDATE NO ACTION NOT DEFERRABLE 68 | ); 69 | CREATE TABLE t1(a 70 | REFERENCES t2(x) NOT DEFERRABLE INITIALLY DEFERRED 71 | ); 72 | CREATE TABLE t1(a 73 | REFERENCES t2 MATCH FULL 74 | ON DELETE SET NULL ON UPDATE SET NULL DEFERRABLE INITIALLY IMMEDIATE 75 | ); 76 | CREATE TABLE t1(a 77 | REFERENCES t2 MATCH FULL 78 | ON DELETE SET NULL ON UPDATE SET DEFAULT NOT DEFERRABLE 79 | ); 80 | CREATE TABLE t1(a 81 | REFERENCES t2 MATCH FULL ON DELETE SET DEFAULT ON UPDATE SET NULL 82 | ); 83 | CREATE TABLE t1(a 84 | REFERENCES t2 MATCH FULL 85 | ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE 86 | ); 87 | CREATE TABLE t1(a 88 | REFERENCES t2 MATCH PARTIAL 89 | ON DELETE SET NULL ON UPDATE RESTRICT NOT DEFERRABLE 90 | ); 91 | CREATE TABLE t1(a 92 | REFERENCES t2 MATCH PARTIAL 93 | ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE 94 | ); 95 | CREATE TABLE t1(a 96 | REFERENCES t2 MATCH PARTIAL ON DELETE CASCADE ON UPDATE SET DEFAULT 97 | ); 98 | CREATE TABLE t1(a 99 | REFERENCES t2 MATCH PARTIAL NOT DEFERRABLE 100 | ); 101 | CREATE TABLE t1(a 102 | REFERENCES t2 MATCH SIMPLE 103 | ON DELETE SET DEFAULT ON UPDATE CASCADE DEFERRABLE 104 | ); 105 | CREATE TABLE t1(a 106 | REFERENCES t2 MATCH STICK 107 | ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY IMMEDIATE 108 | ); 109 | CREATE TABLE t1(a 110 | REFERENCES t2 MATCH STICK 111 | ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY IMMEDIATE 112 | ); 113 | CREATE TABLE t1(a 114 | REFERENCES t2 MATCH STICK 115 | ON UPDATE SET DEFAULT DEFERRABLE INITIALLY IMMEDIATE 116 | ); 117 | CREATE TABLE t1(a 118 | REFERENCES t2 119 | ON DELETE RESTRICT ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED 120 | ); 121 | 122 | -------------------------------------------------------------------------------- 123 | 124 | (sql_stmt_list 125 | (sql_stmt 126 | (create_table_stmt 127 | (CREATE) 128 | (TABLE) 129 | (identifier) 130 | (column_def 131 | (identifier) 132 | (column_constraint 133 | (foreign_key_clause 134 | (REFERENCES) 135 | (identifier) 136 | (identifier) 137 | (MATCH) 138 | (identifier) 139 | (ON) 140 | (DELETE) 141 | (SET) 142 | (NULL) 143 | (ON) 144 | (UPDATE) 145 | (RESTRICT) 146 | (DEFERRABLE)))))) 147 | (sql_stmt 148 | (create_table_stmt 149 | (CREATE) 150 | (TABLE) 151 | (identifier) 152 | (column_def 153 | (identifier) 154 | (column_constraint 155 | (foreign_key_clause 156 | (REFERENCES) 157 | (identifier) 158 | (identifier) 159 | (ON) 160 | (DELETE) 161 | (RESTRICT) 162 | (ON) 163 | (UPDATE) 164 | (SET) 165 | (NULL) 166 | (MATCH) 167 | (identifier) 168 | (NOT) 169 | (DEFERRABLE) 170 | (INITIALLY) 171 | (IMMEDIATE)))))) 172 | (sql_stmt 173 | (create_table_stmt 174 | (CREATE) 175 | (TABLE) 176 | (identifier) 177 | (column_def 178 | (identifier) 179 | (column_constraint 180 | (foreign_key_clause 181 | (REFERENCES) 182 | (identifier) 183 | (identifier) 184 | (MATCH) 185 | (identifier) 186 | (ON) 187 | (DELETE) 188 | (SET) 189 | (NULL) 190 | (ON) 191 | (UPDATE) 192 | (CASCADE) 193 | (DEFERRABLE) 194 | (INITIALLY) 195 | (IMMEDIATE)))))) 196 | (sql_stmt 197 | (create_table_stmt 198 | (CREATE) 199 | (TABLE) 200 | (identifier) 201 | (column_def 202 | (identifier) 203 | (column_constraint 204 | (foreign_key_clause 205 | (REFERENCES) 206 | (identifier) 207 | (identifier) 208 | (MATCH) 209 | (identifier) 210 | (ON) 211 | (DELETE) 212 | (RESTRICT) 213 | (ON) 214 | (UPDATE) 215 | (SET) 216 | (DEFAULT)))))) 217 | (sql_stmt 218 | (create_table_stmt 219 | (CREATE) 220 | (TABLE) 221 | (identifier) 222 | (column_def 223 | (identifier) 224 | (column_constraint 225 | (foreign_key_clause 226 | (REFERENCES) 227 | (identifier) 228 | (identifier) 229 | (MATCH) 230 | (identifier) 231 | (ON) 232 | (DELETE) 233 | (RESTRICT) 234 | (ON) 235 | (UPDATE) 236 | (RESTRICT) 237 | (DEFERRABLE)))))) 238 | (sql_stmt 239 | (create_table_stmt 240 | (CREATE) 241 | (TABLE) 242 | (identifier) 243 | (column_def 244 | (identifier) 245 | (column_constraint 246 | (foreign_key_clause 247 | (REFERENCES) 248 | (identifier) 249 | (identifier) 250 | (MATCH) 251 | (identifier) 252 | (ON) 253 | (DELETE) 254 | (NO) 255 | (ACTION) 256 | (ON) 257 | (UPDATE) 258 | (SET) 259 | (DEFAULT) 260 | (NOT) 261 | (DEFERRABLE) 262 | (INITIALLY) 263 | (IMMEDIATE)))))) 264 | (sql_stmt 265 | (create_table_stmt 266 | (CREATE) 267 | (TABLE) 268 | (identifier) 269 | (column_def 270 | (identifier) 271 | (column_constraint 272 | (foreign_key_clause 273 | (REFERENCES) 274 | (identifier) 275 | (identifier) 276 | (MATCH) 277 | (identifier) 278 | (ON) 279 | (DELETE) 280 | (SET) 281 | (NULL) 282 | (ON) 283 | (UPDATE) 284 | (CASCADE) 285 | (NOT) 286 | (DEFERRABLE)))))) 287 | (sql_stmt 288 | (create_table_stmt 289 | (CREATE) 290 | (TABLE) 291 | (identifier) 292 | (column_def 293 | (identifier) 294 | (column_constraint 295 | (foreign_key_clause 296 | (REFERENCES) 297 | (identifier) 298 | (identifier) 299 | (MATCH) 300 | (identifier) 301 | (ON) 302 | (DELETE) 303 | (SET) 304 | (DEFAULT) 305 | (ON) 306 | (UPDATE) 307 | (SET) 308 | (NULL) 309 | (DEFERRABLE)))))) 310 | (sql_stmt 311 | (create_table_stmt 312 | (CREATE) 313 | (TABLE) 314 | (identifier) 315 | (column_def 316 | (identifier) 317 | (column_constraint 318 | (foreign_key_clause 319 | (REFERENCES) 320 | (identifier) 321 | (identifier) 322 | (MATCH) 323 | (identifier) 324 | (ON) 325 | (DELETE) 326 | (SET) 327 | (DEFAULT) 328 | (NOT) 329 | (DEFERRABLE)))))) 330 | (sql_stmt 331 | (create_table_stmt 332 | (CREATE) 333 | (TABLE) 334 | (identifier) 335 | (column_def 336 | (identifier) 337 | (column_constraint 338 | (foreign_key_clause 339 | (REFERENCES) 340 | (identifier) 341 | (identifier) 342 | (MATCH) 343 | (identifier) 344 | (ON) 345 | (DELETE) 346 | (RESTRICT) 347 | (ON) 348 | (UPDATE) 349 | (SET) 350 | (DEFAULT) 351 | (NOT) 352 | (DEFERRABLE) 353 | (INITIALLY) 354 | (DEFERRED)))))) 355 | (sql_stmt 356 | (create_table_stmt 357 | (CREATE) 358 | (TABLE) 359 | (identifier) 360 | (column_def 361 | (identifier) 362 | (column_constraint 363 | (foreign_key_clause 364 | (REFERENCES) 365 | (identifier) 366 | (identifier) 367 | (MATCH) 368 | (identifier) 369 | (ON) 370 | (DELETE) 371 | (RESTRICT) 372 | (ON) 373 | (UPDATE) 374 | (CASCADE) 375 | (NOT) 376 | (DEFERRABLE) 377 | (INITIALLY) 378 | (IMMEDIATE)))))) 379 | (sql_stmt 380 | (create_table_stmt 381 | (CREATE) 382 | (TABLE) 383 | (identifier) 384 | (column_def 385 | (identifier) 386 | (column_constraint 387 | (foreign_key_clause 388 | (REFERENCES) 389 | (identifier) 390 | (identifier) 391 | (MATCH) 392 | (identifier) 393 | (ON) 394 | (DELETE) 395 | (NO) 396 | (ACTION) 397 | (ON) 398 | (UPDATE) 399 | (SET) 400 | (DEFAULT) 401 | (NOT) 402 | (DEFERRABLE)))))) 403 | (sql_stmt 404 | (create_table_stmt 405 | (CREATE) 406 | (TABLE) 407 | (identifier) 408 | (column_def 409 | (identifier) 410 | (column_constraint 411 | (foreign_key_clause 412 | (REFERENCES) 413 | (identifier) 414 | (identifier) 415 | (MATCH) 416 | (identifier) 417 | (ON) 418 | (DELETE) 419 | (CASCADE) 420 | (ON) 421 | (UPDATE) 422 | (CASCADE) 423 | (DEFERRABLE)))))) 424 | (sql_stmt 425 | (create_table_stmt 426 | (CREATE) 427 | (TABLE) 428 | (identifier) 429 | (column_def 430 | (identifier) 431 | (column_constraint 432 | (foreign_key_clause 433 | (REFERENCES) 434 | (identifier) 435 | (identifier) 436 | (MATCH) 437 | (identifier) 438 | (ON) 439 | (UPDATE) 440 | (SET) 441 | (NULL) 442 | (NOT) 443 | (DEFERRABLE) 444 | (INITIALLY) 445 | (DEFERRED)))))) 446 | (sql_stmt 447 | (create_table_stmt 448 | (CREATE) 449 | (TABLE) 450 | (identifier) 451 | (column_def 452 | (identifier) 453 | (column_constraint 454 | (foreign_key_clause 455 | (REFERENCES) 456 | (identifier) 457 | (identifier) 458 | (ON) 459 | (DELETE) 460 | (SET) 461 | (NULL) 462 | (ON) 463 | (UPDATE) 464 | (NO) 465 | (ACTION) 466 | (DEFERRABLE) 467 | (INITIALLY) 468 | (IMMEDIATE)))))) 469 | (sql_stmt 470 | (create_table_stmt 471 | (CREATE) 472 | (TABLE) 473 | (identifier) 474 | (column_def 475 | (identifier) 476 | (column_constraint 477 | (foreign_key_clause 478 | (REFERENCES) 479 | (identifier) 480 | (identifier) 481 | (ON) 482 | (DELETE) 483 | (RESTRICT) 484 | (ON) 485 | (UPDATE) 486 | (NO) 487 | (ACTION) 488 | (NOT) 489 | (DEFERRABLE)))))) 490 | (sql_stmt 491 | (create_table_stmt 492 | (CREATE) 493 | (TABLE) 494 | (identifier) 495 | (column_def 496 | (identifier) 497 | (column_constraint 498 | (foreign_key_clause 499 | (REFERENCES) 500 | (identifier) 501 | (identifier) 502 | (NOT) 503 | (DEFERRABLE) 504 | (INITIALLY) 505 | (DEFERRED)))))) 506 | (sql_stmt 507 | (create_table_stmt 508 | (CREATE) 509 | (TABLE) 510 | (identifier) 511 | (column_def 512 | (identifier) 513 | (column_constraint 514 | (foreign_key_clause 515 | (REFERENCES) 516 | (identifier) 517 | (MATCH) 518 | (identifier) 519 | (ON) 520 | (DELETE) 521 | (SET) 522 | (NULL) 523 | (ON) 524 | (UPDATE) 525 | (SET) 526 | (NULL) 527 | (DEFERRABLE) 528 | (INITIALLY) 529 | (IMMEDIATE)))))) 530 | (sql_stmt 531 | (create_table_stmt 532 | (CREATE) 533 | (TABLE) 534 | (identifier) 535 | (column_def 536 | (identifier) 537 | (column_constraint 538 | (foreign_key_clause 539 | (REFERENCES) 540 | (identifier) 541 | (MATCH) 542 | (identifier) 543 | (ON) 544 | (DELETE) 545 | (SET) 546 | (NULL) 547 | (ON) 548 | (UPDATE) 549 | (SET) 550 | (DEFAULT) 551 | (NOT) 552 | (DEFERRABLE)))))) 553 | (sql_stmt 554 | (create_table_stmt 555 | (CREATE) 556 | (TABLE) 557 | (identifier) 558 | (column_def 559 | (identifier) 560 | (column_constraint 561 | (foreign_key_clause 562 | (REFERENCES) 563 | (identifier) 564 | (MATCH) 565 | (identifier) 566 | (ON) 567 | (DELETE) 568 | (SET) 569 | (DEFAULT) 570 | (ON) 571 | (UPDATE) 572 | (SET) 573 | (NULL)))))) 574 | (sql_stmt 575 | (create_table_stmt 576 | (CREATE) 577 | (TABLE) 578 | (identifier) 579 | (column_def 580 | (identifier) 581 | (column_constraint 582 | (foreign_key_clause 583 | (REFERENCES) 584 | (identifier) 585 | (MATCH) 586 | (identifier) 587 | (ON) 588 | (DELETE) 589 | (CASCADE) 590 | (NOT) 591 | (DEFERRABLE) 592 | (INITIALLY) 593 | (IMMEDIATE)))))) 594 | (sql_stmt 595 | (create_table_stmt 596 | (CREATE) 597 | (TABLE) 598 | (identifier) 599 | (column_def 600 | (identifier) 601 | (column_constraint 602 | (foreign_key_clause 603 | (REFERENCES) 604 | (identifier) 605 | (MATCH) 606 | (identifier) 607 | (ON) 608 | (DELETE) 609 | (SET) 610 | (NULL) 611 | (ON) 612 | (UPDATE) 613 | (RESTRICT) 614 | (NOT) 615 | (DEFERRABLE)))))) 616 | (sql_stmt 617 | (create_table_stmt 618 | (CREATE) 619 | (TABLE) 620 | (identifier) 621 | (column_def 622 | (identifier) 623 | (column_constraint 624 | (foreign_key_clause 625 | (REFERENCES) 626 | (identifier) 627 | (MATCH) 628 | (identifier) 629 | (ON) 630 | (DELETE) 631 | (SET) 632 | (NULL) 633 | (ON) 634 | (UPDATE) 635 | (NO) 636 | (ACTION) 637 | (DEFERRABLE)))))) 638 | (sql_stmt 639 | (create_table_stmt 640 | (CREATE) 641 | (TABLE) 642 | (identifier) 643 | (column_def 644 | (identifier) 645 | (column_constraint 646 | (foreign_key_clause 647 | (REFERENCES) 648 | (identifier) 649 | (MATCH) 650 | (identifier) 651 | (ON) 652 | (DELETE) 653 | (CASCADE) 654 | (ON) 655 | (UPDATE) 656 | (SET) 657 | (DEFAULT)))))) 658 | (sql_stmt 659 | (create_table_stmt 660 | (CREATE) 661 | (TABLE) 662 | (identifier) 663 | (column_def 664 | (identifier) 665 | (column_constraint 666 | (foreign_key_clause 667 | (REFERENCES) 668 | (identifier) 669 | (MATCH) 670 | (identifier) 671 | (NOT) 672 | (DEFERRABLE)))))) 673 | (sql_stmt 674 | (create_table_stmt 675 | (CREATE) 676 | (TABLE) 677 | (identifier) 678 | (column_def 679 | (identifier) 680 | (column_constraint 681 | (foreign_key_clause 682 | (REFERENCES) 683 | (identifier) 684 | (MATCH) 685 | (identifier) 686 | (ON) 687 | (DELETE) 688 | (SET) 689 | (DEFAULT) 690 | (ON) 691 | (UPDATE) 692 | (CASCADE) 693 | (DEFERRABLE)))))) 694 | (sql_stmt 695 | (create_table_stmt 696 | (CREATE) 697 | (TABLE) 698 | (identifier) 699 | (column_def 700 | (identifier) 701 | (column_constraint 702 | (foreign_key_clause 703 | (REFERENCES) 704 | (identifier) 705 | (MATCH) 706 | (identifier) 707 | (ON) 708 | (DELETE) 709 | (SET) 710 | (NULL) 711 | (ON) 712 | (UPDATE) 713 | (NO) 714 | (ACTION) 715 | (DEFERRABLE) 716 | (INITIALLY) 717 | (IMMEDIATE)))))) 718 | (sql_stmt 719 | (create_table_stmt 720 | (CREATE) 721 | (TABLE) 722 | (identifier) 723 | (column_def 724 | (identifier) 725 | (column_constraint 726 | (foreign_key_clause 727 | (REFERENCES) 728 | (identifier) 729 | (MATCH) 730 | (identifier) 731 | (ON) 732 | (DELETE) 733 | (NO) 734 | (ACTION) 735 | (ON) 736 | (UPDATE) 737 | (SET) 738 | (DEFAULT) 739 | (NOT) 740 | (DEFERRABLE) 741 | (INITIALLY) 742 | (IMMEDIATE)))))) 743 | (sql_stmt 744 | (create_table_stmt 745 | (CREATE) 746 | (TABLE) 747 | (identifier) 748 | (column_def 749 | (identifier) 750 | (column_constraint 751 | (foreign_key_clause 752 | (REFERENCES) 753 | (identifier) 754 | (MATCH) 755 | (identifier) 756 | (ON) 757 | (UPDATE) 758 | (SET) 759 | (DEFAULT) 760 | (DEFERRABLE) 761 | (INITIALLY) 762 | (IMMEDIATE)))))) 763 | (sql_stmt 764 | (create_table_stmt 765 | (CREATE) 766 | (TABLE) 767 | (identifier) 768 | (column_def 769 | (identifier) 770 | (column_constraint 771 | (foreign_key_clause 772 | (REFERENCES) 773 | (identifier) 774 | (ON) 775 | (DELETE) 776 | (RESTRICT) 777 | (ON) 778 | (UPDATE) 779 | (NO) 780 | (ACTION) 781 | (DEFERRABLE) 782 | (INITIALLY) 783 | (DEFERRED))))))) 784 | -------------------------------------------------------------------------------- /test/corpus/stmt.select.core.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | stmt.select.core 3 | ================================================================================ 4 | 5 | SELECT 1, 2, 3; 6 | SELECT DISTINCT 1, 2, 3; 7 | SELECT ALL 1, 2, 3; 8 | SELECT a, b, a||b FROM t1 ; 9 | SELECT DISTINCT a, b, a||b FROM t1; 10 | SELECT ALL a, b, a||b FROM t1; 11 | SELECT 1, 2, 3 WHERE 1; 12 | SELECT 1, 2, 3 WHERE 0; 13 | SELECT 1, 2, 3 WHERE NULL; 14 | SELECT DISTINCT 1, 2, 3 WHERE 1; 15 | SELECT ALL 1, 2, 3 WHERE 1; 16 | SELECT a, b, a||b FROM t1 WHERE a!='x'; 17 | SELECT a, b, a||b FROM t1 WHERE a=='x'; 18 | SELECT DISTINCT a, b, a||b FROM t1 WHERE a!='x'; 19 | SELECT ALL a, b, a||b FROM t1 WHERE a=='x'; 20 | SELECT 1, 2, 3 GROUP BY 2; 21 | SELECT 1, 2, 3 GROUP BY 2 HAVING count(*)=1; 22 | SELECT 1, 2, 3 GROUP BY 2 HAVING count(*)>1; 23 | SELECT DISTINCT 1, 2, 3 GROUP BY 2; 24 | SELECT DISTINCT 1, 2, 3 GROUP BY 2 HAVING count(*)=1; 25 | SELECT DISTINCT 1, 2, 3 GROUP BY 2 HAVING count(*)>1; 26 | SELECT ALL 1, 2, 3 GROUP BY 2; 27 | SELECT ALL 1, 2, 3 GROUP BY 2 HAVING count(*)=1; 28 | SELECT ALL 1, 2, 3 GROUP BY 2 HAVING count(*)>1; 29 | SELECT count(*), max(a) FROM t1 GROUP BY b; 30 | SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=1; 31 | SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=2; 32 | SELECT DISTINCT count(*), max(a) FROM t1 GROUP BY b; 33 | SELECT DISTINCT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=1; 34 | SELECT DISTINCT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=2; 35 | SELECT ALL count(*), max(a) FROM t1 GROUP BY b; 36 | SELECT ALL count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=1; 37 | SELECT ALL count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=2; 38 | SELECT 1, 2, 3 WHERE 1 GROUP BY 2; 39 | SELECT 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)=1; 40 | SELECT 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)>1; 41 | SELECT DISTINCT 1, 2, 3 WHERE 0 GROUP BY 2; 42 | SELECT DISTINCT 1, 2, 3 WHERE 1 GROUP BY 2 HAVING count(*)=1; 43 | SELECT DISTINCT 1, 2, 3 WHERE NULL GROUP BY 2 HAVING count(*)>1; 44 | SELECT ALL 1, 2, 3 WHERE 1 GROUP BY 2; 45 | SELECT ALL 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)=1; 46 | SELECT ALL 1, 2, 3 WHERE 'abc' GROUP BY 2 HAVING count(*)>1; 47 | SELECT count(*), max(a) FROM t1 WHERE a='a' GROUP BY b; 48 | SELECT count(*), max(a) FROM t1 WHERE a='c' GROUP BY b HAVING count(*)=1; 49 | SELECT count(*), max(a) FROM t1 WHERE 0 GROUP BY b HAVING count(*)=2; 50 | SELECT DISTINCT count(*), max(a) FROM t1 WHERE a<'c' GROUP BY b; 51 | SELECT DISTINCT count(*), max(a) FROM t1 WHERE a>'a' GROUP BY b HAVING count(*)=1; 52 | SELECT DISTINCT count(*), max(a) FROM t1 WHERE 0 GROUP BY b HAVING count(*)=2; 53 | SELECT ALL count(*), max(a) FROM t1 WHERE b>'one' GROUP BY b; 54 | SELECT ALL count(*), max(a) FROM t1 WHERE a!='b' GROUP BY b HAVING count(*)=1; 55 | SELECT ALL count(*), max(a) FROM t1 WHERE 0 GROUP BY b HAVING count(*)=2; 56 | 57 | -------------------------------------------------------------------------------- 58 | 59 | (sql_stmt_list 60 | (sql_stmt 61 | (select_stmt 62 | (SELECT) 63 | (numeric_literal) 64 | (numeric_literal) 65 | (numeric_literal))) 66 | (sql_stmt 67 | (select_stmt 68 | (SELECT) 69 | (DISTINCT) 70 | (numeric_literal) 71 | (numeric_literal) 72 | (numeric_literal))) 73 | (sql_stmt 74 | (select_stmt 75 | (SELECT) 76 | (ALL) 77 | (numeric_literal) 78 | (numeric_literal) 79 | (numeric_literal))) 80 | (sql_stmt 81 | (select_stmt 82 | (SELECT) 83 | (identifier) 84 | (identifier) 85 | (identifier) 86 | (identifier) 87 | (from_clause 88 | (FROM) 89 | (table_or_subquery 90 | (identifier))))) 91 | (sql_stmt 92 | (select_stmt 93 | (SELECT) 94 | (DISTINCT) 95 | (identifier) 96 | (identifier) 97 | (identifier) 98 | (identifier) 99 | (from_clause 100 | (FROM) 101 | (table_or_subquery 102 | (identifier))))) 103 | (sql_stmt 104 | (select_stmt 105 | (SELECT) 106 | (ALL) 107 | (identifier) 108 | (identifier) 109 | (identifier) 110 | (identifier) 111 | (from_clause 112 | (FROM) 113 | (table_or_subquery 114 | (identifier))))) 115 | (sql_stmt 116 | (select_stmt 117 | (SELECT) 118 | (numeric_literal) 119 | (numeric_literal) 120 | (numeric_literal) 121 | (where_clause 122 | (WHERE) 123 | (numeric_literal)))) 124 | (sql_stmt 125 | (select_stmt 126 | (SELECT) 127 | (numeric_literal) 128 | (numeric_literal) 129 | (numeric_literal) 130 | (where_clause 131 | (WHERE) 132 | (numeric_literal)))) 133 | (sql_stmt 134 | (select_stmt 135 | (SELECT) 136 | (numeric_literal) 137 | (numeric_literal) 138 | (numeric_literal) 139 | (where_clause 140 | (WHERE) 141 | (NULL)))) 142 | (sql_stmt 143 | (select_stmt 144 | (SELECT) 145 | (DISTINCT) 146 | (numeric_literal) 147 | (numeric_literal) 148 | (numeric_literal) 149 | (where_clause 150 | (WHERE) 151 | (numeric_literal)))) 152 | (sql_stmt 153 | (select_stmt 154 | (SELECT) 155 | (ALL) 156 | (numeric_literal) 157 | (numeric_literal) 158 | (numeric_literal) 159 | (where_clause 160 | (WHERE) 161 | (numeric_literal)))) 162 | (sql_stmt 163 | (select_stmt 164 | (SELECT) 165 | (identifier) 166 | (identifier) 167 | (identifier) 168 | (identifier) 169 | (from_clause 170 | (FROM) 171 | (table_or_subquery 172 | (identifier))) 173 | (where_clause 174 | (WHERE) 175 | (identifier) 176 | (string_literal)))) 177 | (sql_stmt 178 | (select_stmt 179 | (SELECT) 180 | (identifier) 181 | (identifier) 182 | (identifier) 183 | (identifier) 184 | (from_clause 185 | (FROM) 186 | (table_or_subquery 187 | (identifier))) 188 | (where_clause 189 | (WHERE) 190 | (identifier) 191 | (string_literal)))) 192 | (sql_stmt 193 | (select_stmt 194 | (SELECT) 195 | (DISTINCT) 196 | (identifier) 197 | (identifier) 198 | (identifier) 199 | (identifier) 200 | (from_clause 201 | (FROM) 202 | (table_or_subquery 203 | (identifier))) 204 | (where_clause 205 | (WHERE) 206 | (identifier) 207 | (string_literal)))) 208 | (sql_stmt 209 | (select_stmt 210 | (SELECT) 211 | (ALL) 212 | (identifier) 213 | (identifier) 214 | (identifier) 215 | (identifier) 216 | (from_clause 217 | (FROM) 218 | (table_or_subquery 219 | (identifier))) 220 | (where_clause 221 | (WHERE) 222 | (identifier) 223 | (string_literal)))) 224 | (sql_stmt 225 | (select_stmt 226 | (SELECT) 227 | (numeric_literal) 228 | (numeric_literal) 229 | (numeric_literal) 230 | (group_by_clause 231 | (GROUP) 232 | (BY) 233 | (numeric_literal)))) 234 | (sql_stmt 235 | (select_stmt 236 | (SELECT) 237 | (numeric_literal) 238 | (numeric_literal) 239 | (numeric_literal) 240 | (group_by_clause 241 | (GROUP) 242 | (BY) 243 | (numeric_literal) 244 | (HAVING) 245 | (function_name 246 | (identifier)) 247 | (numeric_literal)))) 248 | (sql_stmt 249 | (select_stmt 250 | (SELECT) 251 | (numeric_literal) 252 | (numeric_literal) 253 | (numeric_literal) 254 | (group_by_clause 255 | (GROUP) 256 | (BY) 257 | (numeric_literal) 258 | (HAVING) 259 | (function_name 260 | (identifier)) 261 | (numeric_literal)))) 262 | (sql_stmt 263 | (select_stmt 264 | (SELECT) 265 | (DISTINCT) 266 | (numeric_literal) 267 | (numeric_literal) 268 | (numeric_literal) 269 | (group_by_clause 270 | (GROUP) 271 | (BY) 272 | (numeric_literal)))) 273 | (sql_stmt 274 | (select_stmt 275 | (SELECT) 276 | (DISTINCT) 277 | (numeric_literal) 278 | (numeric_literal) 279 | (numeric_literal) 280 | (group_by_clause 281 | (GROUP) 282 | (BY) 283 | (numeric_literal) 284 | (HAVING) 285 | (function_name 286 | (identifier)) 287 | (numeric_literal)))) 288 | (sql_stmt 289 | (select_stmt 290 | (SELECT) 291 | (DISTINCT) 292 | (numeric_literal) 293 | (numeric_literal) 294 | (numeric_literal) 295 | (group_by_clause 296 | (GROUP) 297 | (BY) 298 | (numeric_literal) 299 | (HAVING) 300 | (function_name 301 | (identifier)) 302 | (numeric_literal)))) 303 | (sql_stmt 304 | (select_stmt 305 | (SELECT) 306 | (ALL) 307 | (numeric_literal) 308 | (numeric_literal) 309 | (numeric_literal) 310 | (group_by_clause 311 | (GROUP) 312 | (BY) 313 | (numeric_literal)))) 314 | (sql_stmt 315 | (select_stmt 316 | (SELECT) 317 | (ALL) 318 | (numeric_literal) 319 | (numeric_literal) 320 | (numeric_literal) 321 | (group_by_clause 322 | (GROUP) 323 | (BY) 324 | (numeric_literal) 325 | (HAVING) 326 | (function_name 327 | (identifier)) 328 | (numeric_literal)))) 329 | (sql_stmt 330 | (select_stmt 331 | (SELECT) 332 | (ALL) 333 | (numeric_literal) 334 | (numeric_literal) 335 | (numeric_literal) 336 | (group_by_clause 337 | (GROUP) 338 | (BY) 339 | (numeric_literal) 340 | (HAVING) 341 | (function_name 342 | (identifier)) 343 | (numeric_literal)))) 344 | (sql_stmt 345 | (select_stmt 346 | (SELECT) 347 | (function_name 348 | (identifier)) 349 | (function_name 350 | (identifier)) 351 | (identifier) 352 | (from_clause 353 | (FROM) 354 | (table_or_subquery 355 | (identifier))) 356 | (group_by_clause 357 | (GROUP) 358 | (BY) 359 | (identifier)))) 360 | (sql_stmt 361 | (select_stmt 362 | (SELECT) 363 | (function_name 364 | (identifier)) 365 | (function_name 366 | (identifier)) 367 | (identifier) 368 | (from_clause 369 | (FROM) 370 | (table_or_subquery 371 | (identifier))) 372 | (group_by_clause 373 | (GROUP) 374 | (BY) 375 | (identifier) 376 | (HAVING) 377 | (function_name 378 | (identifier)) 379 | (numeric_literal)))) 380 | (sql_stmt 381 | (select_stmt 382 | (SELECT) 383 | (function_name 384 | (identifier)) 385 | (function_name 386 | (identifier)) 387 | (identifier) 388 | (from_clause 389 | (FROM) 390 | (table_or_subquery 391 | (identifier))) 392 | (group_by_clause 393 | (GROUP) 394 | (BY) 395 | (identifier) 396 | (HAVING) 397 | (function_name 398 | (identifier)) 399 | (numeric_literal)))) 400 | (sql_stmt 401 | (select_stmt 402 | (SELECT) 403 | (DISTINCT) 404 | (function_name 405 | (identifier)) 406 | (function_name 407 | (identifier)) 408 | (identifier) 409 | (from_clause 410 | (FROM) 411 | (table_or_subquery 412 | (identifier))) 413 | (group_by_clause 414 | (GROUP) 415 | (BY) 416 | (identifier)))) 417 | (sql_stmt 418 | (select_stmt 419 | (SELECT) 420 | (DISTINCT) 421 | (function_name 422 | (identifier)) 423 | (function_name 424 | (identifier)) 425 | (identifier) 426 | (from_clause 427 | (FROM) 428 | (table_or_subquery 429 | (identifier))) 430 | (group_by_clause 431 | (GROUP) 432 | (BY) 433 | (identifier) 434 | (HAVING) 435 | (function_name 436 | (identifier)) 437 | (numeric_literal)))) 438 | (sql_stmt 439 | (select_stmt 440 | (SELECT) 441 | (DISTINCT) 442 | (function_name 443 | (identifier)) 444 | (function_name 445 | (identifier)) 446 | (identifier) 447 | (from_clause 448 | (FROM) 449 | (table_or_subquery 450 | (identifier))) 451 | (group_by_clause 452 | (GROUP) 453 | (BY) 454 | (identifier) 455 | (HAVING) 456 | (function_name 457 | (identifier)) 458 | (numeric_literal)))) 459 | (sql_stmt 460 | (select_stmt 461 | (SELECT) 462 | (ALL) 463 | (function_name 464 | (identifier)) 465 | (function_name 466 | (identifier)) 467 | (identifier) 468 | (from_clause 469 | (FROM) 470 | (table_or_subquery 471 | (identifier))) 472 | (group_by_clause 473 | (GROUP) 474 | (BY) 475 | (identifier)))) 476 | (sql_stmt 477 | (select_stmt 478 | (SELECT) 479 | (ALL) 480 | (function_name 481 | (identifier)) 482 | (function_name 483 | (identifier)) 484 | (identifier) 485 | (from_clause 486 | (FROM) 487 | (table_or_subquery 488 | (identifier))) 489 | (group_by_clause 490 | (GROUP) 491 | (BY) 492 | (identifier) 493 | (HAVING) 494 | (function_name 495 | (identifier)) 496 | (numeric_literal)))) 497 | (sql_stmt 498 | (select_stmt 499 | (SELECT) 500 | (ALL) 501 | (function_name 502 | (identifier)) 503 | (function_name 504 | (identifier)) 505 | (identifier) 506 | (from_clause 507 | (FROM) 508 | (table_or_subquery 509 | (identifier))) 510 | (group_by_clause 511 | (GROUP) 512 | (BY) 513 | (identifier) 514 | (HAVING) 515 | (function_name 516 | (identifier)) 517 | (numeric_literal)))) 518 | (sql_stmt 519 | (select_stmt 520 | (SELECT) 521 | (numeric_literal) 522 | (numeric_literal) 523 | (numeric_literal) 524 | (where_clause 525 | (WHERE) 526 | (numeric_literal)) 527 | (group_by_clause 528 | (GROUP) 529 | (BY) 530 | (numeric_literal)))) 531 | (sql_stmt 532 | (select_stmt 533 | (SELECT) 534 | (numeric_literal) 535 | (numeric_literal) 536 | (numeric_literal) 537 | (where_clause 538 | (WHERE) 539 | (numeric_literal)) 540 | (group_by_clause 541 | (GROUP) 542 | (BY) 543 | (numeric_literal) 544 | (HAVING) 545 | (function_name 546 | (identifier)) 547 | (numeric_literal)))) 548 | (sql_stmt 549 | (select_stmt 550 | (SELECT) 551 | (numeric_literal) 552 | (numeric_literal) 553 | (numeric_literal) 554 | (where_clause 555 | (WHERE) 556 | (numeric_literal)) 557 | (group_by_clause 558 | (GROUP) 559 | (BY) 560 | (numeric_literal) 561 | (HAVING) 562 | (function_name 563 | (identifier)) 564 | (numeric_literal)))) 565 | (sql_stmt 566 | (select_stmt 567 | (SELECT) 568 | (DISTINCT) 569 | (numeric_literal) 570 | (numeric_literal) 571 | (numeric_literal) 572 | (where_clause 573 | (WHERE) 574 | (numeric_literal)) 575 | (group_by_clause 576 | (GROUP) 577 | (BY) 578 | (numeric_literal)))) 579 | (sql_stmt 580 | (select_stmt 581 | (SELECT) 582 | (DISTINCT) 583 | (numeric_literal) 584 | (numeric_literal) 585 | (numeric_literal) 586 | (where_clause 587 | (WHERE) 588 | (numeric_literal)) 589 | (group_by_clause 590 | (GROUP) 591 | (BY) 592 | (numeric_literal) 593 | (HAVING) 594 | (function_name 595 | (identifier)) 596 | (numeric_literal)))) 597 | (sql_stmt 598 | (select_stmt 599 | (SELECT) 600 | (DISTINCT) 601 | (numeric_literal) 602 | (numeric_literal) 603 | (numeric_literal) 604 | (where_clause 605 | (WHERE) 606 | (NULL)) 607 | (group_by_clause 608 | (GROUP) 609 | (BY) 610 | (numeric_literal) 611 | (HAVING) 612 | (function_name 613 | (identifier)) 614 | (numeric_literal)))) 615 | (sql_stmt 616 | (select_stmt 617 | (SELECT) 618 | (ALL) 619 | (numeric_literal) 620 | (numeric_literal) 621 | (numeric_literal) 622 | (where_clause 623 | (WHERE) 624 | (numeric_literal)) 625 | (group_by_clause 626 | (GROUP) 627 | (BY) 628 | (numeric_literal)))) 629 | (sql_stmt 630 | (select_stmt 631 | (SELECT) 632 | (ALL) 633 | (numeric_literal) 634 | (numeric_literal) 635 | (numeric_literal) 636 | (where_clause 637 | (WHERE) 638 | (numeric_literal)) 639 | (group_by_clause 640 | (GROUP) 641 | (BY) 642 | (numeric_literal) 643 | (HAVING) 644 | (function_name 645 | (identifier)) 646 | (numeric_literal)))) 647 | (sql_stmt 648 | (select_stmt 649 | (SELECT) 650 | (ALL) 651 | (numeric_literal) 652 | (numeric_literal) 653 | (numeric_literal) 654 | (where_clause 655 | (WHERE) 656 | (string_literal)) 657 | (group_by_clause 658 | (GROUP) 659 | (BY) 660 | (numeric_literal) 661 | (HAVING) 662 | (function_name 663 | (identifier)) 664 | (numeric_literal)))) 665 | (sql_stmt 666 | (select_stmt 667 | (SELECT) 668 | (function_name 669 | (identifier)) 670 | (function_name 671 | (identifier)) 672 | (identifier) 673 | (from_clause 674 | (FROM) 675 | (table_or_subquery 676 | (identifier))) 677 | (where_clause 678 | (WHERE) 679 | (identifier) 680 | (string_literal)) 681 | (group_by_clause 682 | (GROUP) 683 | (BY) 684 | (identifier)))) 685 | (sql_stmt 686 | (select_stmt 687 | (SELECT) 688 | (function_name 689 | (identifier)) 690 | (function_name 691 | (identifier)) 692 | (identifier) 693 | (from_clause 694 | (FROM) 695 | (table_or_subquery 696 | (identifier))) 697 | (where_clause 698 | (WHERE) 699 | (identifier) 700 | (string_literal)) 701 | (group_by_clause 702 | (GROUP) 703 | (BY) 704 | (identifier) 705 | (HAVING) 706 | (function_name 707 | (identifier)) 708 | (numeric_literal)))) 709 | (sql_stmt 710 | (select_stmt 711 | (SELECT) 712 | (function_name 713 | (identifier)) 714 | (function_name 715 | (identifier)) 716 | (identifier) 717 | (from_clause 718 | (FROM) 719 | (table_or_subquery 720 | (identifier))) 721 | (where_clause 722 | (WHERE) 723 | (numeric_literal)) 724 | (group_by_clause 725 | (GROUP) 726 | (BY) 727 | (identifier) 728 | (HAVING) 729 | (function_name 730 | (identifier)) 731 | (numeric_literal)))) 732 | (sql_stmt 733 | (select_stmt 734 | (SELECT) 735 | (DISTINCT) 736 | (function_name 737 | (identifier)) 738 | (function_name 739 | (identifier)) 740 | (identifier) 741 | (from_clause 742 | (FROM) 743 | (table_or_subquery 744 | (identifier))) 745 | (where_clause 746 | (WHERE) 747 | (identifier) 748 | (string_literal)) 749 | (group_by_clause 750 | (GROUP) 751 | (BY) 752 | (identifier)))) 753 | (sql_stmt 754 | (select_stmt 755 | (SELECT) 756 | (DISTINCT) 757 | (function_name 758 | (identifier)) 759 | (function_name 760 | (identifier)) 761 | (identifier) 762 | (from_clause 763 | (FROM) 764 | (table_or_subquery 765 | (identifier))) 766 | (where_clause 767 | (WHERE) 768 | (identifier) 769 | (string_literal)) 770 | (group_by_clause 771 | (GROUP) 772 | (BY) 773 | (identifier) 774 | (HAVING) 775 | (function_name 776 | (identifier)) 777 | (numeric_literal)))) 778 | (sql_stmt 779 | (select_stmt 780 | (SELECT) 781 | (DISTINCT) 782 | (function_name 783 | (identifier)) 784 | (function_name 785 | (identifier)) 786 | (identifier) 787 | (from_clause 788 | (FROM) 789 | (table_or_subquery 790 | (identifier))) 791 | (where_clause 792 | (WHERE) 793 | (numeric_literal)) 794 | (group_by_clause 795 | (GROUP) 796 | (BY) 797 | (identifier) 798 | (HAVING) 799 | (function_name 800 | (identifier)) 801 | (numeric_literal)))) 802 | (sql_stmt 803 | (select_stmt 804 | (SELECT) 805 | (ALL) 806 | (function_name 807 | (identifier)) 808 | (function_name 809 | (identifier)) 810 | (identifier) 811 | (from_clause 812 | (FROM) 813 | (table_or_subquery 814 | (identifier))) 815 | (where_clause 816 | (WHERE) 817 | (identifier) 818 | (string_literal)) 819 | (group_by_clause 820 | (GROUP) 821 | (BY) 822 | (identifier)))) 823 | (sql_stmt 824 | (select_stmt 825 | (SELECT) 826 | (ALL) 827 | (function_name 828 | (identifier)) 829 | (function_name 830 | (identifier)) 831 | (identifier) 832 | (from_clause 833 | (FROM) 834 | (table_or_subquery 835 | (identifier))) 836 | (where_clause 837 | (WHERE) 838 | (identifier) 839 | (string_literal)) 840 | (group_by_clause 841 | (GROUP) 842 | (BY) 843 | (identifier) 844 | (HAVING) 845 | (function_name 846 | (identifier)) 847 | (numeric_literal)))) 848 | (sql_stmt 849 | (select_stmt 850 | (SELECT) 851 | (ALL) 852 | (function_name 853 | (identifier)) 854 | (function_name 855 | (identifier)) 856 | (identifier) 857 | (from_clause 858 | (FROM) 859 | (table_or_subquery 860 | (identifier))) 861 | (where_clause 862 | (WHERE) 863 | (numeric_literal)) 864 | (group_by_clause 865 | (GROUP) 866 | (BY) 867 | (identifier) 868 | (HAVING) 869 | (function_name 870 | (identifier)) 871 | (numeric_literal))))) 872 | -------------------------------------------------------------------------------- /grammar.js: -------------------------------------------------------------------------------- 1 | module.exports = grammar({ 2 | name: "sqlite", 3 | extras: ($) => [$._whitespace, $.comment], 4 | 5 | precedences: ($) => [ 6 | [ 7 | "unary_bitnot", 8 | "unary_plus", 9 | "expr_collate", 10 | "binary_concat", 11 | "binary_times", 12 | "binary_plus", 13 | "binary_bitwise", 14 | "binary_compare", 15 | "binary_relation", 16 | "expr_not_exists", 17 | "expr_exists", 18 | "unary_not", 19 | "binary_and", 20 | "binary_or", 21 | ], 22 | ], 23 | 24 | conflicts: ($) => [ 25 | [$._literal_value, $._name], 26 | [$._literal_value, $.signed_number], 27 | [$.insert_stmt, $._select_core], 28 | [$.foreign_key_clause], 29 | ], 30 | 31 | word: ($) => $._word, 32 | 33 | rules: { 34 | sql_stmt_list: ($) => 35 | seq(optional($.sql_stmt), repeat(seq(";", optional($.sql_stmt)))), 36 | 37 | /// keyword 38 | 39 | ...generateKeyword([ 40 | "ABORT", 41 | "ACTION", 42 | "ADD", 43 | "AFTER", 44 | "ALL", 45 | "ALTER", 46 | "ALWAYS", 47 | "ANALYZE", 48 | "AND", 49 | "AS", 50 | "ASC", 51 | "ATTACH", 52 | "AUTOINCREMENT", 53 | "BEFORE", 54 | "BEGIN", 55 | "BETWEEN", 56 | "BY", 57 | "CASCADE", 58 | "CASE", 59 | "CAST", 60 | "CHECK", 61 | "COLLATE", 62 | "COLUMN", 63 | "COMMIT", 64 | "CONFLICT", 65 | "CONSTRAINT", 66 | "CREATE", 67 | "CROSS", 68 | "CURRENT", 69 | "CURRENT_DATE", 70 | "CURRENT_TIME", 71 | "CURRENT_TIMESTAMP", 72 | "DATABASE", 73 | "DEFAULT", 74 | "DEFERRABLE", 75 | "DEFERRED", 76 | "DELETE", 77 | "DESC", 78 | "DETACH", 79 | "DISTINCT", 80 | "DO", 81 | "DROP", 82 | "EACH", 83 | "ELSE", 84 | "END", 85 | "ESCAPE", 86 | "EXCEPT", 87 | "EXCLUDE", 88 | "EXCLUSIVE", 89 | "EXISTS", 90 | "EXPLAIN", 91 | "FAIL", 92 | "FALSE", 93 | "FILTER", 94 | "FIRST", 95 | "FOLLOWING", 96 | "FOR", 97 | "FOREIGN", 98 | "FROM", 99 | "GENERATED", 100 | "GLOB", 101 | "GROUP", 102 | "GROUPS", 103 | "HAVING", 104 | "IF", 105 | "IGNORE", 106 | "IMMEDIATE", 107 | "IN", 108 | "INDEX", 109 | "INDEXED", 110 | "INITIALLY", 111 | "INNER", 112 | "INSERT", 113 | "INSTEAD", 114 | "INTERSECT", 115 | "INTO", 116 | "IS", 117 | "ISNULL", 118 | "JOIN", 119 | "KEY", 120 | "LAST", 121 | "LEFT", 122 | "LIKE", 123 | "LIMIT", 124 | "MATCH", 125 | "MATERIALIZED", 126 | "NATURAL", 127 | "NO", 128 | "NOT", 129 | "NOTHING", 130 | "NOTNULL", 131 | "NULL", 132 | "NULLS", 133 | "OF", 134 | "OFFSET", 135 | "ON", 136 | "OR", 137 | "ORDER", 138 | "OTHERS", 139 | "OUTER", 140 | "OVER", 141 | "PARTITION", 142 | "PLAN", 143 | "PRAGMA", 144 | "PRECEDING", 145 | "PRIMARY", 146 | "QUERY", 147 | "RAISE", 148 | "RANGE", 149 | "RECURSIVE", 150 | "REFERENCES", 151 | "REGEXP", 152 | "REINDEX", 153 | "RELEASE", 154 | "RENAME", 155 | "REPLACE", 156 | "RESTRICT", 157 | "RETURNING", 158 | "ROLLBACK", 159 | "ROW", 160 | "ROWID", 161 | "ROWS", 162 | "SAVEPOINT", 163 | "SELECT", 164 | "SET", 165 | "STORED", 166 | "STRICT", 167 | "TABLE", 168 | "TEMP", 169 | "TEMPORARY", 170 | "THEN", 171 | "TIES", 172 | "TO", 173 | "TRANSACTION", 174 | "TRIGGER", 175 | "TRUE", 176 | "UNBOUNDED", 177 | "UNION", 178 | "UNIQUE", 179 | "UPDATE", 180 | "USING", 181 | "VACUUM", 182 | "VALUES", 183 | "VIEW", 184 | "VIRTUAL", 185 | "WHEN", 186 | "WHERE", 187 | "WINDOW", 188 | "WITH", 189 | "WITHOUT", 190 | ]), 191 | 192 | /// token 193 | 194 | _whitespace: ($) => /[ \t\n\f\r]+/, 195 | 196 | numeric_literal: ($) => { 197 | const decimal_digit = /[0-9]+/ 198 | const exponent_part = seq( 199 | choice("e", "E"), 200 | optional(choice("-", "+")), 201 | decimal_digit, 202 | ) 203 | const decimal_integer_literal = choice( 204 | "0", 205 | seq(/[1-9]/, optional(decimal_digit)), 206 | ) 207 | const decimal_literal = choice( 208 | seq( 209 | decimal_integer_literal, 210 | optional(seq(".", optional(decimal_digit))), 211 | optional(exponent_part), 212 | ), 213 | seq(".", optional(decimal_digit), optional(exponent_part)), 214 | ) 215 | 216 | const hex_literal = seq(choice("0x", "0X"), /[0-9a-fA-F]+/) 217 | 218 | return token(choice(decimal_literal, hex_literal)) 219 | }, 220 | 221 | _string: ($) => seq("'", /(''|[^'])*/, "'"), 222 | 223 | string_literal: ($) => $._string, 224 | 225 | blob_literal: ($) => seq(choice("x'", "X'"), /(''|[^'])*/, "'"), 226 | 227 | identifier: ($) => 228 | choice( 229 | /[_a-zA-Z\x80-\xFF][$_0-9a-zA-Z\x80-\xFF]*/, 230 | seq('"', /(""|[^"])*/, '"'), 231 | seq("`", /(``|[^`])*/, "`"), 232 | seq("[", /[^\]]*/, "]"), 233 | ), 234 | 235 | bind_parameter: ($) => 236 | choice( 237 | seq("?", repeat(/[0-9]/)), 238 | seq(choice("@", "$", ":", "#"), /[$_0-9a-zA-Z\x80-\xFF]+/), 239 | ), 240 | 241 | // https://github.com/tree-sitter/tree-sitter-javascript/blob/v0.19.0/grammar.js#L888 242 | comment: ($) => 243 | choice(seq("--", /.*/), seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, "/")), 244 | 245 | /// statement 246 | 247 | sql_stmt: ($) => 248 | seq( 249 | optional(seq($.EXPLAIN, optional(seq($.QUERY, $.PLAN)))), 250 | choice( 251 | $.alter_table_stmt, 252 | $.analyze_stmt, 253 | $.attach_stmt, 254 | $.begin_stmt, 255 | $.commit_stmt, 256 | $.create_index_stmt, 257 | $.create_table_stmt, 258 | $.create_trigger_stmt, 259 | $.create_view_stmt, 260 | $.create_virtual_table_stmt, 261 | $.delete_stmt, 262 | $.detach_stmt, 263 | $.drop_index_stmt, 264 | $.drop_table_stmt, 265 | $.drop_trigger_stmt, 266 | $.drop_view_stmt, 267 | $.insert_stmt, 268 | $.pragma_stmt, 269 | $.reindex_stmt, 270 | $.release_stmt, 271 | $.rollback_stmt, 272 | $.savepoint_stmt, 273 | $.select_stmt, 274 | $.update_stmt, 275 | $.vacuum_stmt, 276 | ), 277 | ), 278 | 279 | alter_table_stmt: ($) => 280 | seq( 281 | $.ALTER, 282 | $.TABLE, 283 | $._name2, 284 | choice( 285 | seq($.RENAME, $.TO, $._name), 286 | seq($.RENAME, optional($.COLUMN), $._name, $.TO, $._name), 287 | seq($.ADD, optional($.COLUMN), $.column_def), 288 | seq($.DROP, optional($.COLUMN), $._name), 289 | ), 290 | ), 291 | 292 | analyze_stmt: ($) => seq($.ANALYZE, optional($._name2)), 293 | 294 | attach_stmt: ($) => 295 | seq($.ATTACH, optional($.DATABASE), $._expr, $.AS, $._name), 296 | 297 | begin_stmt: ($) => 298 | seq( 299 | $.BEGIN, 300 | optional(choice($.DEFERRED, $.IMMEDIATE, $.EXCLUSIVE)), 301 | optional(seq($.TRANSACTION, optional($._name))), 302 | ), 303 | 304 | commit_stmt: ($) => 305 | seq( 306 | choice($.COMMIT, $.END), 307 | optional(seq($.TRANSACTION, optional($._name))), 308 | ), 309 | 310 | create_index_stmt: ($) => 311 | seq( 312 | $.CREATE, 313 | optional($.UNIQUE), 314 | $.INDEX, 315 | optional(seq($.IF, $.NOT, $.EXISTS)), 316 | $._name2, 317 | $.ON, 318 | $._name, 319 | "(", 320 | commaSep($.indexed_column), 321 | ")", 322 | optional($.where_clause), 323 | ), 324 | 325 | create_table_stmt: ($) => 326 | seq( 327 | $.CREATE, 328 | optional(choice($.TEMP, $.TEMPORARY)), 329 | $.TABLE, 330 | optional(seq($.IF, $.NOT, $.EXISTS)), 331 | $._name2, 332 | choice( 333 | seq($.AS, $.select_stmt), 334 | seq( 335 | "(", 336 | commaSep($.column_def), 337 | repeat(seq(",", $.table_constraint)), 338 | ")", 339 | optional( 340 | commaSep(choice(seq($.WITHOUT, $.ROWID), $.STRICT)), 341 | ), 342 | ), 343 | ), 344 | ), 345 | 346 | create_trigger_stmt: ($) => 347 | seq( 348 | $.CREATE, 349 | optional(choice($.TEMP, $.TEMPORARY)), 350 | $.TRIGGER, 351 | optional(seq($.IF, $.NOT, $.EXISTS)), 352 | $._name2, 353 | optional(choice($.BEFORE, $.AFTER, seq($.INSTEAD, $.OF))), 354 | choice( 355 | $.DELETE, 356 | $.INSERT, 357 | seq($.UPDATE, optional(seq($.OF, commaSep($._name)))), 358 | ), 359 | $.ON, 360 | $._name, 361 | optional( 362 | choice( 363 | seq( 364 | $.FOR, 365 | $.EACH, 366 | $.ROW, 367 | optional(seq($.WHEN, $._expr)), 368 | ), 369 | seq($.WHEN, $._expr), 370 | ), 371 | ), 372 | $.BEGIN, 373 | repeat1( 374 | seq( 375 | choice( 376 | $.update_stmt, 377 | $.insert_stmt, 378 | $.delete_stmt, 379 | $.select_stmt, 380 | ), 381 | ";", 382 | ), 383 | ), 384 | $.END, 385 | ), 386 | 387 | create_view_stmt: ($) => 388 | seq( 389 | $.CREATE, 390 | optional(choice($.TEMP, $.TEMPORARY)), 391 | $.VIEW, 392 | optional(seq($.IF, $.NOT, $.EXISTS)), 393 | $._name2, 394 | optional(seq("(", commaSep($._name), ")")), 395 | $.AS, 396 | $.select_stmt, 397 | ), 398 | 399 | create_virtual_table_stmt: ($) => 400 | seq( 401 | $.CREATE, 402 | $.VIRTUAL, 403 | $.TABLE, 404 | optional(seq($.IF, $.NOT, $.EXISTS)), 405 | $._name2, 406 | $.USING, 407 | $._name, 408 | optional( 409 | // https://sqlite.org/lang_createvtab.html 410 | seq( 411 | "(", 412 | commaSep($.column_def), 413 | repeat(seq(",", $.table_constraint)), 414 | ")", 415 | ), 416 | ), 417 | ), 418 | 419 | delete_stmt: ($) => 420 | seq( 421 | optional($.with_clause), 422 | $.DELETE, 423 | $.FROM, 424 | $.qualified_table_name, 425 | optional($.where_clause), 426 | optional($.returning_clause), 427 | optional($.order_by_clause), 428 | optional($.limit_clause), 429 | ), 430 | 431 | detach_stmt: ($) => seq($.DETACH, optional($.DATABASE), $._name), 432 | 433 | drop_index_stmt: ($) => 434 | seq($.DROP, $.INDEX, optional(seq($.IF, $.EXISTS)), $._name2), 435 | 436 | drop_table_stmt: ($) => 437 | seq($.DROP, $.TABLE, optional(seq($.IF, $.EXISTS)), $._name2), 438 | 439 | drop_trigger_stmt: ($) => 440 | seq($.DROP, $.TRIGGER, optional(seq($.IF, $.EXISTS)), $._name2), 441 | 442 | drop_view_stmt: ($) => 443 | seq($.DROP, $.VIEW, optional(seq($.IF, $.EXISTS)), $._name2), 444 | 445 | insert_stmt: ($) => 446 | seq( 447 | optional($.with_clause), 448 | choice( 449 | $.REPLACE, 450 | seq( 451 | $.INSERT, 452 | optional( 453 | seq( 454 | $.OR, 455 | choice( 456 | $.ABORT, 457 | $.FAIL, 458 | $.IGNORE, 459 | $.REPLACE, 460 | $.ROLLBACK, 461 | ), 462 | ), 463 | ), 464 | ), 465 | ), 466 | $.INTO, 467 | $._name2, 468 | optional(seq($.AS, $._name)), 469 | optional(seq("(", commaSep($._name), ")")), 470 | choice( 471 | seq( 472 | $.VALUES, 473 | commaSep(seq("(", commaSep($._expr), ")")), 474 | optional($.upsert_clause), 475 | ), 476 | seq($.select_stmt, optional($.upsert_clause)), 477 | seq($.DEFAULT, $.VALUES), 478 | ), 479 | optional($.returning_clause), 480 | ), 481 | 482 | pragma_stmt: ($) => 483 | seq( 484 | $.PRAGMA, 485 | $._name2, 486 | optional( 487 | choice( 488 | seq("=", $.pragma_value), 489 | seq("(", $.pragma_value, ")"), 490 | ), 491 | ), 492 | ), 493 | 494 | reindex_stmt: ($) => seq($.REINDEX, optional($._name2)), 495 | 496 | release_stmt: ($) => seq($.RELEASE, optional($.SAVEPOINT), $._name), 497 | 498 | rollback_stmt: ($) => 499 | seq( 500 | $.ROLLBACK, 501 | optional(seq($.TRANSACTION, optional($._name))), 502 | optional(seq($.TO, optional($.SAVEPOINT), $._name)), 503 | ), 504 | 505 | savepoint_stmt: ($) => seq($.SAVEPOINT, $._name), 506 | 507 | select_stmt: ($) => 508 | seq( 509 | optional($.with_clause), 510 | $._select_core, 511 | repeat(seq($._compound_operator, $._select_core)), 512 | optional($.order_by_clause), 513 | optional($.limit_clause), 514 | ), 515 | 516 | update_stmt: ($) => 517 | seq( 518 | optional($.with_clause), 519 | $.UPDATE, 520 | optional( 521 | seq( 522 | $.OR, 523 | choice( 524 | $.ABORT, 525 | $.FAIL, 526 | $.IGNORE, 527 | $.REPLACE, 528 | $.ROLLBACK, 529 | ), 530 | ), 531 | ), 532 | $.qualified_table_name, 533 | $.SET, 534 | commaSep( 535 | seq(choice($._name, $._column_name_list), "=", $._expr), 536 | ), 537 | optional($.from_clause), 538 | optional($.where_clause), 539 | optional($.returning_clause), 540 | optional($.order_by_clause), 541 | optional($.limit_clause), 542 | ), 543 | 544 | vacuum_stmt: ($) => 545 | seq($.VACUUM, optional($._name), optional(seq($.INTO, $.filename))), 546 | 547 | /// part 548 | 549 | _name: ($) => choice($.string_literal, $.identifier), 550 | 551 | _name2: ($) => seq(optional(seq($._name, ".")), $._name), 552 | 553 | function_name: ($) => $.identifier, 554 | 555 | collation_name: ($) => choice($.string_literal, $.identifier), 556 | 557 | error_message: ($) => $._name, 558 | 559 | pragma_value: ($) => choice($.signed_number, $._name), 560 | 561 | filename: ($) => $._expr, 562 | 563 | _literal_value: ($) => 564 | choice( 565 | $.numeric_literal, 566 | $.string_literal, 567 | $.blob_literal, 568 | $.NULL, 569 | $.TRUE, 570 | $.FALSE, 571 | $.CURRENT_TIME, 572 | $.CURRENT_DATE, 573 | $.CURRENT_TIMESTAMP, 574 | ), 575 | 576 | _expr: ($) => 577 | choice( 578 | $._literal_value, 579 | $.bind_parameter, 580 | $._name, 581 | seq($._name, ".", $._name), 582 | seq($._name, ".", $._name, ".", $._name), 583 | prec.right("unary_bitnot", seq("~", $._expr)), 584 | prec.right("unary_plus", seq(choice("-", "+"), $._expr)), 585 | prec.right("unary_not", seq($.NOT, $._expr)), 586 | prec.left("binary_concat", seq($._expr, "||", $._expr)), 587 | prec.left("binary_concat", seq($._expr, "->", $._expr)), 588 | prec.left("binary_concat", seq($._expr, "->>", $._expr)), 589 | prec.left( 590 | "binary_times", 591 | seq($._expr, choice("*", "/", "%"), $._expr), 592 | ), 593 | prec.left( 594 | "binary_plus", 595 | seq($._expr, choice("+", "-"), $._expr), 596 | ), 597 | prec.left( 598 | "binary_bitwise", 599 | seq($._expr, choice("<<", ">>", "&", "|"), $._expr), 600 | ), 601 | prec.left( 602 | "binary_compare", 603 | seq($._expr, choice("<", "<=", ">", ">="), $._expr), 604 | ), 605 | prec.left( 606 | "binary_relation", 607 | seq($._expr, choice("=", "==", "!=", "<>"), $._expr), 608 | ), 609 | seq( 610 | $._expr, 611 | optional($.NOT), 612 | $.IN, 613 | choice( 614 | seq( 615 | "(", 616 | optional(choice($.select_stmt, commaSep($._expr))), 617 | ")", 618 | ), 619 | seq( 620 | $._name2, 621 | optional( 622 | seq("(", optional(commaSep($._expr)), ")"), 623 | ), 624 | ), 625 | ), 626 | ), 627 | prec.left("binary_and", seq($._expr, $.AND, $._expr)), 628 | prec.left("binary_or", seq($._expr, $.OR, $._expr)), 629 | seq( 630 | $.function_name, 631 | "(", 632 | optional( 633 | choice( 634 | seq(optional($.DISTINCT), commaSep($._expr)), 635 | "*", 636 | ), 637 | ), 638 | ")", 639 | optional($.filter_clause), 640 | optional($.over_clause), 641 | ), 642 | seq("(", commaSep($._expr), ")"), 643 | seq($.CAST, "(", $._expr, $.AS, $.type_name, ")"), 644 | prec("expr_collate", seq($._expr, $.COLLATE, $.collation_name)), 645 | prec.left( 646 | "binary_relation", 647 | seq( 648 | $._expr, 649 | optional($.NOT), 650 | choice($.LIKE, $.GLOB, $.REGEXP, $.MATCH), 651 | $._expr, 652 | optional(seq($.ESCAPE, $._expr)), 653 | ), 654 | ), 655 | seq($._expr, choice($.ISNULL, $.NOTNULL, seq($.NOT, $.NULL))), 656 | prec.left( 657 | "binary_relation", 658 | seq( 659 | $._expr, 660 | $.IS, 661 | optional($.NOT), 662 | optional(seq($.DISTINCT, $.FROM)), 663 | $._expr, 664 | ), 665 | ), 666 | prec.left( 667 | "binary_relation", 668 | seq( 669 | $._expr, 670 | optional($.NOT), 671 | $.BETWEEN, 672 | $._expr, 673 | $.AND, 674 | $._expr, 675 | ), 676 | ), 677 | seq("(", $.select_stmt, ")"), 678 | prec("expr_exists", seq($.EXISTS, "(", $.select_stmt, ")")), 679 | prec( 680 | "expr_not_exists", 681 | seq($.NOT, $.EXISTS, "(", $.select_stmt, ")"), 682 | ), 683 | seq( 684 | $.CASE, 685 | optional($._expr), 686 | repeat1(seq($.WHEN, $._expr, $.THEN, $._expr)), 687 | optional(seq($.ELSE, $._expr)), 688 | $.END, 689 | ), 690 | $.raise_function, 691 | ), 692 | 693 | signed_number: ($) => 694 | seq(optional(choice("+", "-")), $.numeric_literal), 695 | 696 | indexed_column: ($) => seq($._expr, optional(choice($.ASC, $.DESC))), 697 | 698 | column_def: ($) => 699 | seq($._name, optional($.type_name), repeat($.column_constraint)), 700 | 701 | type_name: ($) => 702 | seq( 703 | repeat1($._name), 704 | optional( 705 | choice( 706 | seq("(", $.signed_number, ")"), 707 | seq("(", $.signed_number, ",", $.signed_number, ")"), 708 | ), 709 | ), 710 | ), 711 | 712 | column_constraint: ($) => 713 | seq( 714 | optional(seq($.CONSTRAINT, $._name)), 715 | choice( 716 | seq( 717 | $.PRIMARY, 718 | $.KEY, 719 | optional(choice($.ASC, $.DESC)), 720 | optional($.conflict_clause), 721 | optional($.AUTOINCREMENT), 722 | ), 723 | seq(optional($.NOT), $.NULL, optional($.conflict_clause)), 724 | seq($.UNIQUE, optional($.conflict_clause)), 725 | seq($.CHECK, "(", $._expr, ")"), 726 | seq( 727 | $.DEFAULT, 728 | choice( 729 | seq("(", $._expr, ")"), 730 | $._literal_value, 731 | $.signed_number, 732 | ), 733 | ), 734 | seq($.COLLATE, $.collation_name), 735 | $.foreign_key_clause, 736 | seq( 737 | optional(seq($.GENERATED, $.ALWAYS)), 738 | $.AS, 739 | "(", 740 | $._expr, 741 | ")", 742 | optional(choice($.STORED, $.VIRTUAL)), 743 | ), 744 | ), 745 | ), 746 | 747 | table_constraint: ($) => 748 | seq( 749 | optional(seq($.CONSTRAINT, $._name)), 750 | choice( 751 | seq( 752 | choice(seq($.PRIMARY, $.KEY), $.UNIQUE), 753 | "(", 754 | commaSep($.indexed_column), 755 | ")", 756 | optional($.conflict_clause), 757 | ), 758 | seq($.CHECK, "(", $._expr, ")"), 759 | seq( 760 | $.FOREIGN, 761 | $.KEY, 762 | "(", 763 | commaSep($._name), 764 | ")", 765 | $.foreign_key_clause, 766 | ), 767 | ), 768 | ), 769 | 770 | where_clause: ($) => seq($.WHERE, $._expr), 771 | 772 | returning_clause: ($) => seq($.RETURNING, commaSep($._result_column)), 773 | 774 | order_by_clause: ($) => seq($.ORDER, $.BY, commaSep($.ordering_term)), 775 | 776 | limit_clause: ($) => 777 | seq( 778 | $.LIMIT, 779 | $._expr, 780 | optional(choice(seq($.OFFSET, $._expr), seq(",", $._expr))), 781 | ), 782 | 783 | group_by_clause: ($) => 784 | seq( 785 | $.GROUP, 786 | $.BY, 787 | commaSep($._expr), 788 | optional(seq($.HAVING, $._expr)), 789 | ), 790 | 791 | window_clause: ($) => 792 | seq($.WINDOW, commaSep(seq($._name, $.AS, $.window_defn))), 793 | 794 | window_defn: ($) => 795 | seq( 796 | "(", 797 | optional($._name), 798 | optional(seq($.PARTITION, $.BY, commaSep($._expr))), 799 | optional(seq($.ORDER, $.BY, commaSep($.ordering_term))), 800 | optional($.frame_spec), 801 | ")", 802 | ), 803 | 804 | _select_core: ($) => 805 | choice( 806 | seq( 807 | $.SELECT, 808 | optional(choice($.DISTINCT, $.ALL)), 809 | commaSep($._result_column), 810 | optional($.from_clause), 811 | optional($.where_clause), 812 | optional($.group_by_clause), 813 | optional($.window_clause), 814 | ), 815 | seq($.VALUES, commaSep(seq("(", commaSep($._expr), ")"))), 816 | ), 817 | 818 | _compound_operator: ($) => 819 | choice($.UNION, seq($.UNION, $.ALL), $.INTERSECT, $.EXCEPT), 820 | 821 | _result_column: ($) => 822 | choice( 823 | seq($._name, ".", "*"), 824 | "*", 825 | seq($._expr, optional(seq(optional($.AS), $._name))), 826 | ), 827 | 828 | with_clause: ($) => 829 | seq( 830 | $.WITH, 831 | optional($.RECURSIVE), 832 | commaSep($.common_table_expression), 833 | ), 834 | 835 | common_table_expression: ($) => 836 | seq( 837 | $._name, 838 | optional(seq("(", commaSep($._name), ")")), 839 | $.AS, 840 | optional(seq(optional($.NOT), $.MATERIALIZED)), 841 | "(", 842 | $.select_stmt, 843 | ")", 844 | ), 845 | 846 | conflict_clause: ($) => 847 | seq( 848 | $.ON, 849 | $.CONFLICT, 850 | choice($.ROLLBACK, $.ABORT, $.FAIL, $.IGNORE, $.REPLACE), 851 | ), 852 | 853 | foreign_key_clause: ($) => 854 | seq( 855 | $.REFERENCES, 856 | $._name, 857 | optional(seq("(", commaSep($._name), ")")), 858 | repeat( 859 | choice( 860 | seq( 861 | $.ON, 862 | choice($.DELETE, $.UPDATE), 863 | choice( 864 | seq($.SET, $.NULL), 865 | seq($.SET, $.DEFAULT), 866 | $.CASCADE, 867 | $.RESTRICT, 868 | seq($.NO, $.ACTION), 869 | ), 870 | ), 871 | seq($.MATCH, $._name), 872 | ), 873 | ), 874 | optional( 875 | seq( 876 | optional($.NOT), 877 | $.DEFERRABLE, 878 | optional( 879 | choice( 880 | seq($.INITIALLY, $.DEFERRED), 881 | seq($.INITIALLY, $.IMMEDIATE), 882 | ), 883 | ), 884 | ), 885 | ), 886 | ), 887 | 888 | filter_clause: ($) => seq($.FILTER, "(", $.WHERE, $._expr, ")"), 889 | 890 | over_clause: ($) => 891 | seq( 892 | $.OVER, 893 | choice( 894 | $._name, 895 | seq( 896 | "(", 897 | optional($._name), 898 | optional(seq($.PARTITION, $.BY, commaSep($._expr))), 899 | optional(seq($.ORDER, $.BY, commaSep($.ordering_term))), 900 | optional($.frame_spec), 901 | ")", 902 | ), 903 | ), 904 | ), 905 | 906 | raise_function: ($) => 907 | seq( 908 | $.RAISE, 909 | "(", 910 | choice( 911 | $.IGNORE, 912 | seq( 913 | choice($.ROLLBACK, $.ABORT, $.FAIL), 914 | ",", 915 | $.error_message, 916 | ), 917 | ), 918 | ")", 919 | ), 920 | 921 | ordering_term: ($) => 922 | seq( 923 | $._expr, 924 | optional(choice($.ASC, $.DESC)), 925 | optional(seq($.NULLS, choice($.FIRST, $.LAST))), 926 | ), 927 | 928 | frame_spec: ($) => 929 | seq( 930 | choice($.RANGE, $.ROWS, $.GROUPS), 931 | choice( 932 | seq( 933 | $.BETWEEN, 934 | choice( 935 | seq($.UNBOUNDED, $.PRECEDING), 936 | seq($._expr, $.PRECEDING), 937 | seq($.CURRENT, $.ROW), 938 | seq($._expr, $.FOLLOWING), 939 | ), 940 | $.AND, 941 | choice( 942 | seq($._expr, $.PRECEDING), 943 | seq($.CURRENT, $.ROW), 944 | seq($._expr, $.FOLLOWING), 945 | seq($.UNBOUNDED, $.FOLLOWING), 946 | ), 947 | ), 948 | seq($.UNBOUNDED, $.PRECEDING), 949 | seq($._expr, $.PRECEDING), 950 | seq($.CURRENT, $.ROW), 951 | ), 952 | optional( 953 | seq( 954 | $.EXCLUDE, 955 | choice( 956 | seq($.NOT, $.OTHERS), 957 | seq($.CURRENT, $.ROW), 958 | $.GROUP, 959 | $.TIES, 960 | ), 961 | ), 962 | ), 963 | ), 964 | 965 | _column_name_list: ($) => seq("(", commaSep($._name), ")"), 966 | 967 | qualified_table_name: ($) => 968 | seq( 969 | $._name2, 970 | optional(seq($.AS, $._name)), 971 | optional( 972 | choice( 973 | seq($.INDEXED, $.BY, $._name), 974 | seq($.NOT, $.INDEXED), 975 | ), 976 | ), 977 | ), 978 | 979 | from_clause: ($) => seq($.FROM, $._join_clause), 980 | 981 | _join_clause: ($) => 982 | seq( 983 | $.table_or_subquery, 984 | repeat( 985 | seq( 986 | $.join_operator, 987 | $.table_or_subquery, 988 | optional($.join_constraint), 989 | ), 990 | ), 991 | ), 992 | 993 | join_operator: ($) => 994 | choice( 995 | ",", 996 | seq( 997 | optional($.NATURAL), 998 | optional( 999 | choice( 1000 | seq($.LEFT, optional($.OUTER)), 1001 | $.INNER, 1002 | $.CROSS, 1003 | ), 1004 | ), 1005 | $.JOIN, 1006 | ), 1007 | ), 1008 | 1009 | join_constraint: ($) => 1010 | choice( 1011 | seq($.ON, $._expr), 1012 | seq($.USING, "(", commaSep($._name), ")"), 1013 | ), 1014 | 1015 | table_or_subquery: ($) => 1016 | choice( 1017 | prec.left( 1018 | 1, 1019 | seq( 1020 | $._name2, 1021 | optional(seq(optional($.AS), $._name)), 1022 | optional( 1023 | choice( 1024 | seq($.INDEXED, $.BY, $._name), 1025 | seq($.NOT, $.INDEXED), 1026 | ), 1027 | ), 1028 | optional($.join_constraint), 1029 | ), 1030 | ), 1031 | prec.left( 1032 | 1, 1033 | seq( 1034 | $._name2, 1035 | "(", 1036 | commaSep($._expr), 1037 | ")", 1038 | optional(seq(optional($.AS), $._name)), 1039 | optional($.join_constraint), 1040 | ), 1041 | ), 1042 | prec.left( 1043 | 1, 1044 | seq( 1045 | "(", 1046 | $.select_stmt, 1047 | ")", 1048 | optional(seq(optional($.AS), $._name)), 1049 | optional($.join_constraint), 1050 | ), 1051 | ), 1052 | seq("(", $._join_clause, ")"), 1053 | ), 1054 | 1055 | upsert_clause: ($) => 1056 | seq( 1057 | $.ON, 1058 | $.CONFLICT, 1059 | optional( 1060 | seq( 1061 | "(", 1062 | commaSep($.indexed_column), 1063 | ")", 1064 | optional($.where_clause), 1065 | ), 1066 | ), 1067 | $.DO, 1068 | choice( 1069 | $.NOTHING, 1070 | seq( 1071 | $.UPDATE, 1072 | $.SET, 1073 | commaSep( 1074 | seq( 1075 | choice($._name, $._column_name_list), 1076 | "=", 1077 | $._expr, 1078 | ), 1079 | ), 1080 | optional($.where_clause), 1081 | ), 1082 | ), 1083 | ), 1084 | 1085 | _word: ($) => /[_a-zA-Z\x80-\xFF$@#:?][$_0-9a-zA-Z\x80-\xFF]*/, 1086 | }, 1087 | }) 1088 | 1089 | function generateKeyword(keywords) { 1090 | const kw = {} 1091 | keywords.forEach((w) => { 1092 | kw[w.toUpperCase()] = ($) => 1093 | new RegExp( 1094 | Array.from(w) 1095 | .map((c) => "[" + c.toLowerCase() + c.toUpperCase() + "]") 1096 | .join(""), 1097 | ) 1098 | }) 1099 | return kw 1100 | } 1101 | 1102 | function commaSep(rule) { 1103 | return seq(rule, repeat(seq(",", rule))) 1104 | } 1105 | --------------------------------------------------------------------------------