@willbooster/tree-sitter-sql 4.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -29
- package/common/common.mjs +2 -9
- package/mysql/src/node-types.json +5361 -19850
- package/oracle/src/node-types.json +8786 -48891
- package/package.json +6 -7
- package/postgresql/src/node-types.json +8543 -23838
- package/sqlite/grammar.js +6 -5
- package/tree-sitter-mysql.wasm +0 -0
- package/tree-sitter-oracle.wasm +0 -0
- package/tree-sitter-postgresql.wasm +0 -0
- package/tree-sitter-sqlite.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-sql/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-sql/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](https://crates.io/crates/willbooster-tree-sitter-sql)
|
|
10
10
|
|
|
11
11
|
SQL grammars for [tree-sitter](https://github.com/tree-sitter/tree-sitter), generated with the
|
|
12
12
|
[WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. Each generated `TSLanguage` carries
|
|
13
|
-
the WillBooster ABI (`
|
|
14
|
-
reject. The supported WillBooster runtime is version
|
|
13
|
+
the WillBooster ABI (`0x5742000e`), which upstream `tree-sitter` runtimes and WillBooster runtimes prior to 23.1.0
|
|
14
|
+
reject. The supported WillBooster runtime is version 26.3.0 through 27.x.
|
|
15
15
|
|
|
16
16
|
## Dialects
|
|
17
17
|
|
|
18
|
-
Each dialect has its own grammar and external scanner in `<dialect>/`, built independently on top of
|
|
19
|
-
helpers in `common/common.mjs`:
|
|
18
|
+
Each dialect has its own grammar and, except MySQL, an external scanner in `<dialect>/`, built independently on top of
|
|
19
|
+
the small DSL helpers in `common/common.mjs`:
|
|
20
20
|
|
|
21
21
|
| Dialect | Directory | Wasm file | Rust constants | Cargo feature |
|
|
22
22
|
| -------------------------------------------------------------------------------------------- | ------------- | ----------------------------- | ---------------------------------------------- | ------------- |
|
|
@@ -25,35 +25,30 @@ helpers in `common/common.mjs`:
|
|
|
25
25
|
| [MySQL](https://dev.mysql.com/doc/refman/8.4/en/sql-statements.html) 8.4 | `mysql/` | `tree-sitter-mysql.wasm` | `LANGUAGE_MYSQL`, `MYSQL_NODE_TYPES` | `mysql` |
|
|
26
26
|
| [Oracle Database](https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/) 23ai | `oracle/` | `tree-sitter-oracle.wasm` | `LANGUAGE_ORACLE`, `ORACLE_NODE_TYPES` | `oracle` |
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
programs (`CREATE PROCEDURE`, `CREATE FUNCTION`, `CREATE TRIGGER`, `CREATE EVENT`) and executable versioned comments
|
|
39
|
-
(`/*! ... */` and `/*!50700 ... */`). Client `mysql` directives (`DELIMITER`, `SOURCE`) yield syntax errors.
|
|
40
|
-
- `oracle` follows Oracle Database 23ai's documented SQL and embedded PL/SQL syntax (`CREATE TRIGGER`, `CREATE FUNCTION`,
|
|
41
|
-
`CREATE PROCEDURE`, `CREATE PACKAGE`, `CREATE TYPE`, anonymous `DECLARE`/`BEGIN` blocks, and inline `WITH` functions
|
|
42
|
-
and procedures). Client SQL*Plus directives (`REM`, `SET`, `CONNECT`, `PROMPT`, `SPOOL`, `@`, standalone `/`) yield
|
|
43
|
-
syntax errors.
|
|
28
|
+
`sqlite` follows SQLite's parser (`src/parse.y`) and tokenizer (`src/tokenize.c`) in its default build, except for
|
|
29
|
+
`OVER` as an alias without `AS` before `WINDOW` after a non-call closing parenthesis (such as
|
|
30
|
+
`SELECT (1) OVER WINDOW w AS ()`), a NUL character (which ends input for SQLite's C parser), and invalid UTF-8/UTF-16.
|
|
31
|
+
It rejects what SQLite's parser grammar and tokenizer reject, plus single-clause shape checks; semantic, compile-time,
|
|
32
|
+
scope, label, numeric-range, limit, catalog, and cross-clause errors are accepted without `ERROR` nodes.
|
|
33
|
+
|
|
34
|
+
The other three grammars favor size and speed over completeness: they target the SQL found in application code and
|
|
35
|
+
schema scripts, give structured trees to its common statements, and parse most other statements as a
|
|
36
|
+
`generic_statement` of words, literals, operators, and parenthesized groups up to the next statement terminator.
|
|
37
|
+
Rarely written clauses inside structured statements yield `ERROR` nodes, and some invalid input parses without them.
|
|
44
38
|
|
|
45
39
|
## Support Scope
|
|
46
40
|
|
|
47
|
-
This repository maintains only full parsing
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
This repository maintains only full parsing, optimized for binary size and parse speed: valid code as found in
|
|
42
|
+
real-world projects yields a correct tree, other valid code yields a correct tree or one with `ERROR` or `MISSING`
|
|
43
|
+
nodes, and any input parses without crashing, hanging, or taking more than linear time. Invalid input may parse without
|
|
44
|
+
`ERROR` or `MISSING` nodes. Incremental parsing is not supported, and no queries (highlights, locals, injections, tags)
|
|
45
|
+
are shipped. Node types, field names, and the trees that error recovery produces may change; such changes are released
|
|
46
|
+
as new major versions.
|
|
51
47
|
|
|
52
48
|
## Usage
|
|
53
49
|
|
|
54
50
|
The npm package ships one `.wasm` file per dialect for
|
|
55
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version
|
|
56
|
-
the 23.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers. Replace `tree-sitter-sqlite.wasm` in the
|
|
51
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 26.3.0 through 27.x, which runs in Node.js, Bun, browsers, and Cloudflare Workers. Replace `tree-sitter-sqlite.wasm` in the
|
|
57
52
|
examples below with `tree-sitter-postgresql.wasm`, `tree-sitter-mysql.wasm`, or `tree-sitter-oracle.wasm` for another
|
|
58
53
|
dialect.
|
|
59
54
|
|
|
@@ -100,10 +95,10 @@ The package also ships each dialect's `src/node-types.json`, `sqlite/grammar.js`
|
|
|
100
95
|
`common/common.mjs`, and `tree-sitter.json`.
|
|
101
96
|
|
|
102
97
|
In Rust, depend on [willbooster-tree-sitter-sql](https://crates.io/crates/willbooster-tree-sitter-sql) and on
|
|
103
|
-
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) version
|
|
98
|
+
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) version 26.3.0 through 27.x:
|
|
104
99
|
|
|
105
100
|
```sh
|
|
106
|
-
cargo add willbooster-tree-sitter@
|
|
101
|
+
cargo add willbooster-tree-sitter@27.0.0 --rename tree-sitter
|
|
107
102
|
cargo add willbooster-tree-sitter-sql --rename tree-sitter-sql
|
|
108
103
|
```
|
|
109
104
|
|
package/common/common.mjs
CHANGED
|
@@ -3,23 +3,16 @@
|
|
|
3
3
|
/** @import {RuleOrLiteral} from '@willbooster/web-tree-sitter/dsl' */
|
|
4
4
|
|
|
5
5
|
// The CLI injects the DSL before loading the grammar that imports this module.
|
|
6
|
-
const {
|
|
6
|
+
const { optional, repeat, seq } = /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (
|
|
7
7
|
globalThis
|
|
8
8
|
);
|
|
9
9
|
|
|
10
|
-
// SQL keywords are ASCII words that match without regard to case. A pattern with the `i` flag would also match the
|
|
11
|
-
// Unicode characters that fold to an ASCII letter (e.g. U+212A KELVIN SIGN for `k`), which SQL dialects read as an
|
|
12
|
-
// identifier, so each letter lists its two ASCII cases instead.
|
|
13
|
-
/** @param {string} word */
|
|
14
|
-
export const keywordPattern = (word) =>
|
|
15
|
-
new RegExp(word.replaceAll(/[A-Za-z]/g, (letter) => `[${letter.toUpperCase()}${letter.toLowerCase()}]`));
|
|
16
|
-
|
|
17
10
|
/**
|
|
18
11
|
* A keyword token, which appears in the tree as an anonymous node named after the keyword in upper case.
|
|
19
12
|
*
|
|
20
13
|
* @param {string} word
|
|
21
14
|
*/
|
|
22
|
-
export const keyword = (word) =>
|
|
15
|
+
export const keyword = (word) => word.toUpperCase();
|
|
23
16
|
|
|
24
17
|
/**
|
|
25
18
|
* A sequence of keywords separated by spaces in `phrase`, such as `'PRIMARY KEY'`.
|