@willbooster/tree-sitter-sql 2.0.0 → 3.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 +6 -8
- package/package.json +3 -3
- package/sqlite/grammar.js +46 -25
- package/tree-sitter-sqlite.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -9,10 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
SQL grammars for [tree-sitter](https://github.com/tree-sitter/tree-sitter), generated with the
|
|
11
11
|
[WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. Each generated `TSLanguage` carries
|
|
12
|
-
the WillBooster ABI (`
|
|
13
|
-
|
|
14
|
-
before 19.1.0 read despite sharing ABI `0x5742000c`. The supported WillBooster runtime is version 20.0.0 or later in the
|
|
15
|
-
20.x series.
|
|
12
|
+
the WillBooster ABI (`0x5742000d`), which upstream `tree-sitter` runtimes and WillBooster runtimes prior to 22.0.0
|
|
13
|
+
reject. The supported WillBooster runtime is version 23.0.0 or later in the 23.x series.
|
|
16
14
|
|
|
17
15
|
The `sqlite` grammar parses the SQL dialect of [SQLite](https://sqlite.org/lang.html) 3.54 in its default build. Its
|
|
18
16
|
rules follow SQLite's own grammar (`src/parse.y`) and tokenizer (`src/tokenize.c`), which are in the public domain:
|
|
@@ -42,8 +40,8 @@ produces may change; such changes are released as new major versions.
|
|
|
42
40
|
## Usage
|
|
43
41
|
|
|
44
42
|
The npm package ships `tree-sitter-sqlite.wasm` for
|
|
45
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version
|
|
46
|
-
the
|
|
43
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 23.0.0 or later in
|
|
44
|
+
the 23.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from
|
|
47
45
|
its path:
|
|
48
46
|
|
|
49
47
|
```js
|
|
@@ -87,11 +85,11 @@ The package also ships the grammar definitions (`common/common.mjs` and `sqlite/
|
|
|
87
85
|
file that marks the latter as an ES module) and the node types in `sqlite/src/node-types.json`.
|
|
88
86
|
|
|
89
87
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-sql) and on
|
|
90
|
-
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) version
|
|
88
|
+
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) version 23.0.0 or later in the 23.x series,
|
|
91
89
|
the runtime this package is tested and fuzzed with:
|
|
92
90
|
|
|
93
91
|
```sh
|
|
94
|
-
cargo add willbooster-tree-sitter@
|
|
92
|
+
cargo add willbooster-tree-sitter@23.0.0 --rename tree-sitter
|
|
95
93
|
cargo add willbooster-tree-sitter-sql --rename tree-sitter-sql
|
|
96
94
|
```
|
|
97
95
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-sql",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "SQL grammars (SQLite) for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"parsing",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@vitest/browser-playwright": "5.0.5",
|
|
52
52
|
"@willbooster/oxlint-config": "1.4.9",
|
|
53
53
|
"@willbooster/wb": "23.3.0",
|
|
54
|
-
"@willbooster/web-tree-sitter": "
|
|
54
|
+
"@willbooster/web-tree-sitter": "23.0.0",
|
|
55
55
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
56
56
|
"lefthook": "2.2.2",
|
|
57
57
|
"oxlint": "1.90.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"wrangler": "4.156.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@willbooster/web-tree-sitter": "^
|
|
65
|
+
"@willbooster/web-tree-sitter": "^23.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependenciesMeta": {
|
|
68
68
|
"@willbooster/web-tree-sitter": {
|
package/sqlite/grammar.js
CHANGED
|
@@ -101,23 +101,6 @@ const RESERVED = [
|
|
|
101
101
|
// Names (`nm` in parse.y) may also be these, but an identifier in a narrower position (`id` and `ids`) may not.
|
|
102
102
|
const JOIN_KEYWORDS = ['CROSS', 'FULL', 'INNER', 'LEFT', 'NATURAL', 'OUTER', 'RIGHT'];
|
|
103
103
|
|
|
104
|
-
// SQLite accepts any sequence of one to three join keywords whose combination is not contradictory
|
|
105
|
-
// (`sqlite3JoinType` in src/select.c): `INNER` or `CROSS` with an outer join, or `OUTER` without a side, is an error.
|
|
106
|
-
/** @type {string[][]} */
|
|
107
|
-
const JOIN_TYPES = [];
|
|
108
|
-
/** @param {string[]} words */
|
|
109
|
-
const isJoinType = (words) => {
|
|
110
|
-
const inner = words.some((word) => word === 'INNER' || word === 'CROSS');
|
|
111
|
-
const side = words.some((word) => word === 'LEFT' || word === 'RIGHT' || word === 'FULL');
|
|
112
|
-
return !(inner && (side || words.includes('OUTER'))) && !(words.includes('OUTER') && !side);
|
|
113
|
-
};
|
|
114
|
-
/** @param {string[]} words */
|
|
115
|
-
const addJoinTypes = (words) => {
|
|
116
|
-
if (words.length > 0 && isJoinType(words)) JOIN_TYPES.push(words);
|
|
117
|
-
if (words.length < 3) for (const word of JOIN_KEYWORDS) addJoinTypes([...words, word]);
|
|
118
|
-
};
|
|
119
|
-
addJoinTypes([]);
|
|
120
|
-
|
|
121
104
|
// SQLite's identifier characters: ASCII letters, digits, `_`, `$`, and every non-ASCII character. A byte order mark
|
|
122
105
|
// before an identifier is white space instead.
|
|
123
106
|
const IDENTIFIER_START = String.raw`A-Za-z_\u0080-\uFEFE\uFF00-\u{10FFFF}`;
|
|
@@ -878,23 +861,61 @@ export default grammar({
|
|
|
878
861
|
|
|
879
862
|
indexed_clause: ($) => choice(seq(keywords('INDEXED BY'), field('index', $._name)), keywords('NOT INDEXED')),
|
|
880
863
|
|
|
881
|
-
|
|
864
|
+
// SQLite accepts any sequence of one to three join keywords whose combination is not contradictory
|
|
865
|
+
// (`sqlite3JoinType` in src/select.c): `INNER` or `CROSS` with an outer join, or `OUTER` without a side, is an
|
|
866
|
+
// error. Partitioning by the leading keyword avoids unrolling all 180 combinations into grammar.json.
|
|
867
|
+
join_operator: ($) =>
|
|
882
868
|
choice(
|
|
883
869
|
',',
|
|
884
|
-
|
|
885
|
-
|
|
870
|
+
seq(
|
|
871
|
+
choice(
|
|
872
|
+
seq($._join_inner, optional(seq($._join_inner, optional($._join_inner)))),
|
|
873
|
+
seq($._join_side, optional(seq($._join_side_or_outer, optional($._join_side_or_outer)))),
|
|
874
|
+
seq(keyword('OUTER'), $._join_side, optional($._join_side_or_outer)),
|
|
875
|
+
seq(keyword('OUTER'), keyword('OUTER'), $._join_side)
|
|
876
|
+
),
|
|
877
|
+
keyword('JOIN')
|
|
886
878
|
),
|
|
887
879
|
keyword('JOIN')
|
|
888
880
|
),
|
|
889
881
|
|
|
890
882
|
// A natural join may not have an ON or USING clause.
|
|
891
|
-
_natural_join_operator: () =>
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
seq(
|
|
895
|
-
|
|
883
|
+
_natural_join_operator: ($) =>
|
|
884
|
+
seq(
|
|
885
|
+
choice(
|
|
886
|
+
seq(
|
|
887
|
+
$._join_inner,
|
|
888
|
+
choice(seq(keyword('NATURAL'), optional($._join_inner_or_natural)), seq($._join_inner, keyword('NATURAL')))
|
|
889
|
+
),
|
|
890
|
+
seq(
|
|
891
|
+
$._join_side,
|
|
892
|
+
choice(
|
|
893
|
+
seq(keyword('NATURAL'), optional($._join_outer_word)),
|
|
894
|
+
seq($._join_side_or_outer, keyword('NATURAL'))
|
|
895
|
+
)
|
|
896
|
+
),
|
|
897
|
+
seq(keyword('OUTER'), choice(seq($._join_side, keyword('NATURAL')), seq(keyword('NATURAL'), $._join_side))),
|
|
898
|
+
seq(
|
|
899
|
+
keyword('NATURAL'),
|
|
900
|
+
optional(
|
|
901
|
+
choice(
|
|
902
|
+
seq(keyword('NATURAL'), optional(choice(keyword('NATURAL'), $._join_inner, $._join_side))),
|
|
903
|
+
seq($._join_inner, optional($._join_inner_or_natural)),
|
|
904
|
+
seq($._join_side, optional($._join_outer_word)),
|
|
905
|
+
seq(keyword('OUTER'), $._join_side)
|
|
906
|
+
)
|
|
907
|
+
)
|
|
908
|
+
)
|
|
909
|
+
),
|
|
910
|
+
keyword('JOIN')
|
|
896
911
|
),
|
|
897
912
|
|
|
913
|
+
_join_inner: () => choice(keyword('INNER'), keyword('CROSS')),
|
|
914
|
+
_join_side: () => choice(keyword('LEFT'), keyword('RIGHT'), keyword('FULL')),
|
|
915
|
+
_join_side_or_outer: ($) => choice($._join_side, keyword('OUTER')),
|
|
916
|
+
_join_inner_or_natural: ($) => choice($._join_inner, keyword('NATURAL')),
|
|
917
|
+
_join_outer_word: ($) => choice($._join_side, keyword('OUTER'), keyword('NATURAL')),
|
|
918
|
+
|
|
898
919
|
join_constraint: ($) =>
|
|
899
920
|
choice(seq(keyword('ON'), field('condition', $._expression)), seq(keyword('USING'), $.column_list)),
|
|
900
921
|
|
package/tree-sitter-sqlite.wasm
CHANGED
|
Binary file
|