tree-sitter-postgres 1.1.1 → 1.1.5

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/package.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "name": "tree-sitter-postgres",
3
- "version": "1.1.1",
3
+ "version": "1.1.5",
4
4
  "description": "PostgreSQL grammar for tree-sitter, generated from Postgres source",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/gmr/tree-sitter-postgres.git"
8
+ },
9
+ "homepage": "https://github.com/gmr/tree-sitter-postgres",
10
+ "bugs": {
11
+ "url": "https://github.com/gmr/tree-sitter-postgres/issues"
12
+ },
5
13
  "main": "bindings/node",
6
14
  "types": "bindings/node",
7
15
  "keywords": [
@@ -12,7 +12,6 @@
12
12
  #include "tree_sitter/parser.h"
13
13
 
14
14
  #include <string.h>
15
- #include <ctype.h>
16
15
 
17
16
  enum TokenType {
18
17
  SQL_BODY,
@@ -30,6 +29,35 @@ static void skip_whitespace(TSLexer *lexer) {
30
29
  }
31
30
  }
32
31
 
32
+ /*
33
+ * Keep the scanner self-contained for WebAssembly builds.
34
+ *
35
+ * Zed loads tree-sitter grammars as Wasm modules. If this scanner calls
36
+ * libc ctype helpers like isalpha/isalnum/tolower, the compiled Wasm can
37
+ * contain imports named "isalpha", "isalnum", or "tolower". Zed's grammar
38
+ * runtime does not provide those imports, causing errors like:
39
+ *
40
+ * Failed to instantiate Wasm module: invalid import 'isalnum'
41
+ *
42
+ * For delimiter keyword detection we only need ASCII PL/pgSQL keywords, so
43
+ * small local helpers are sufficient and avoid external libc imports.
44
+ */
45
+ static bool is_ascii_alpha(int c) {
46
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
47
+ }
48
+
49
+ static bool is_ascii_digit(int c) {
50
+ return c >= '0' && c <= '9';
51
+ }
52
+
53
+ static bool is_ascii_alnum(int c) {
54
+ return is_ascii_alpha(c) || is_ascii_digit(c);
55
+ }
56
+
57
+ static char ascii_tolower(int c) {
58
+ return (c >= 'A' && c <= 'Z') ? (char)(c + ('a' - 'A')) : (char)c;
59
+ }
60
+
33
61
  bool tree_sitter_plpgsql_external_scanner_scan(
34
62
  void *payload, TSLexer *lexer, const bool *valid_symbols
35
63
  ) {
@@ -196,13 +224,13 @@ bool tree_sitter_plpgsql_external_scanner_scan(
196
224
 
197
225
  /* At depth 0, check for PL/pgSQL delimiter keywords.
198
226
  * We mark the position before checking, and if it's a delimiter, we stop. */
199
- if (depth == 0 && isalpha(lexer->lookahead)) {
227
+ if (depth == 0 && is_ascii_alpha(lexer->lookahead)) {
200
228
  lexer->mark_end(lexer);
201
229
  /* Read the identifier */
202
230
  char word[32];
203
231
  int len = 0;
204
- while (isalnum(lexer->lookahead) || lexer->lookahead == '_') {
205
- if (len < 30) word[len++] = tolower(lexer->lookahead);
232
+ while (is_ascii_alnum(lexer->lookahead) || lexer->lookahead == '_') {
233
+ if (len < 30) word[len++] = ascii_tolower(lexer->lookahead);
206
234
  lexer->advance(lexer, false);
207
235
  }
208
236
  word[len] = '\0';
@@ -276,7 +304,7 @@ bool tree_sitter_plpgsql_external_scanner_scan(
276
304
 
277
305
  /* Identifiers starting with underscore or non-ASCII */
278
306
  if (depth == 0 && (lexer->lookahead == '_' || (lexer->lookahead >= 0x80))) {
279
- while (isalnum(lexer->lookahead) || lexer->lookahead == '_' ||
307
+ while (is_ascii_alnum(lexer->lookahead) || lexer->lookahead == '_' ||
280
308
  lexer->lookahead == '$' || lexer->lookahead >= 0x80) {
281
309
  lexer->advance(lexer, false);
282
310
  }
@@ -285,8 +313,8 @@ bool tree_sitter_plpgsql_external_scanner_scan(
285
313
  continue;
286
314
  }
287
315
  /* Inside parens, consume identifiers without keyword checking */
288
- if (depth > 0 && (isalpha(lexer->lookahead) || lexer->lookahead == '_')) {
289
- while (isalnum(lexer->lookahead) || lexer->lookahead == '_' ||
316
+ if (depth > 0 && (is_ascii_alpha(lexer->lookahead) || lexer->lookahead == '_')) {
317
+ while (is_ascii_alnum(lexer->lookahead) || lexer->lookahead == '_' ||
290
318
  lexer->lookahead == '$') {
291
319
  lexer->advance(lexer, false);
292
320
  }
@@ -26,7 +26,7 @@
26
26
  (func_as
27
27
  (Sconst
28
28
  (dollar_quoted_string) @injection.content))))))
29
- (#eq? @_lang "plpgsql")
29
+ (?i)^plpgsql$
30
30
  (#set! injection.language "plpgsql")
31
31
  (#set! injection.include-children))
32
32
 
@@ -44,7 +44,7 @@
44
44
  (NonReservedWord_or_Sconst
45
45
  (NonReservedWord
46
46
  (identifier) @_lang))))))
47
- (#eq? @_lang "plpgsql")
47
+ (?i)^plpgsql$
48
48
  (#set! injection.language "plpgsql")
49
49
  (#set! injection.include-children))
50
50
 
@@ -63,7 +63,7 @@
63
63
  (func_as
64
64
  (Sconst
65
65
  (dollar_quoted_string) @injection.content))))))
66
- (#eq? @_lang "plpgsql")
66
+ (?i)^plpgsql$
67
67
  (#set! injection.language "plpgsql")
68
68
  (#set! injection.include-children))
69
69
 
@@ -82,7 +82,7 @@
82
82
  (NonReservedWord_or_Sconst
83
83
  (NonReservedWord
84
84
  (identifier) @_lang))))))
85
- (#eq? @_lang "plpgsql")
85
+ (?i)^plpgsql$
86
86
  (#set! injection.language "plpgsql")
87
87
  (#set! injection.include-children))
88
88
 
@@ -102,7 +102,7 @@
102
102
  (func_as
103
103
  (Sconst
104
104
  (dollar_quoted_string) @injection.content))))))
105
- (#eq? @_lang "plpgsql")
105
+ (?i)^plpgsql$
106
106
  (#set! injection.language "plpgsql")
107
107
  (#set! injection.include-children))
108
108
 
@@ -122,7 +122,7 @@
122
122
  (NonReservedWord_or_Sconst
123
123
  (NonReservedWord
124
124
  (identifier) @_lang))))))
125
- (#eq? @_lang "plpgsql")
125
+ (?i)^plpgsql$
126
126
  (#set! injection.language "plpgsql")
127
127
  (#set! injection.include-children))
128
128
 
@@ -143,7 +143,7 @@
143
143
  (func_as
144
144
  (Sconst
145
145
  (dollar_quoted_string) @injection.content))))))
146
- (#eq? @_lang "plpgsql")
146
+ (?i)^plpgsql$
147
147
  (#set! injection.language "plpgsql")
148
148
  (#set! injection.include-children))
149
149
 
@@ -164,7 +164,7 @@
164
164
  (NonReservedWord_or_Sconst
165
165
  (NonReservedWord
166
166
  (identifier) @_lang))))))
167
- (#eq? @_lang "plpgsql")
167
+ (?i)^plpgsql$
168
168
  (#set! injection.language "plpgsql")
169
169
  (#set! injection.include-children))
170
170
 
@@ -186,7 +186,7 @@
186
186
  (func_as
187
187
  (Sconst
188
188
  (dollar_quoted_string) @injection.content))))))
189
- (#eq? @_lang "plpgsql")
189
+ (?i)^plpgsql$
190
190
  (#set! injection.language "plpgsql")
191
191
  (#set! injection.include-children))
192
192
 
@@ -208,7 +208,7 @@
208
208
  (NonReservedWord_or_Sconst
209
209
  (NonReservedWord
210
210
  (identifier) @_lang))))))
211
- (#eq? @_lang "plpgsql")
211
+ (?i)^plpgsql$
212
212
  (#set! injection.language "plpgsql")
213
213
  (#set! injection.include-children))
214
214
 
@@ -231,7 +231,7 @@
231
231
  (func_as
232
232
  (Sconst
233
233
  (dollar_quoted_string) @injection.content))))))
234
- (#eq? @_lang "plpgsql")
234
+ (?i)^plpgsql$
235
235
  (#set! injection.language "plpgsql")
236
236
  (#set! injection.include-children))
237
237
 
@@ -254,7 +254,7 @@
254
254
  (NonReservedWord_or_Sconst
255
255
  (NonReservedWord
256
256
  (identifier) @_lang))))))
257
- (#eq? @_lang "plpgsql")
257
+ (?i)^plpgsql$
258
258
  (#set! injection.language "plpgsql")
259
259
  (#set! injection.include-children))
260
260
 
Binary file