@willbooster/tree-sitter-haskell 3.0.0 → 4.1.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 CHANGED
@@ -13,7 +13,7 @@ Haskell grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), f
13
13
  to its authors and contributors. This is not an official release of that project.
14
14
 
15
15
  This fork is based on upstream's version 0.23.1 grammar and generates the parser with the
16
- [WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser carries that fork's own ABI number, so it loads only with that fork's runtime, version 4.0.2 or later in the 4.x series; upstream's runtime rejects it.
16
+ [WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser carries that fork's own ABI number, so it loads only with that fork's runtime, version 6.0.0 or later in the 6.x series; upstream's runtime rejects it.
17
17
  [Upstream's README at that version](https://github.com/tree-sitter/tree-sitter-haskell/blob/v0.23.1/README.md) lists
18
18
  the supported language extensions and, under "Querying", explains how to query the grammar's supertypes; it is the
19
19
  readme that the comments in `grammar.js` refer to.
@@ -22,6 +22,7 @@ readme that the comments in `grammar.js` refer to.
22
22
 
23
23
  The fork's main differences from upstream 0.23.1 are:
24
24
 
25
+ - **Whitespace**: horizontal tabs separate tokens, are accepted before Haddock markers, and advance layout to the next eight-column tab stop.
25
26
  - **MultilineStrings**: triple-quoted literals retain their complete source as a single `string` node, including embedded quotes, escapes, and string gaps.
26
27
  - **Comment scanning**: empty block comments such as `{--}` terminate at their closing delimiter and preserve following code.
27
28
  An ordinary line comment does not absorb a following marked Haddock comment.
@@ -42,7 +43,7 @@ reports an error: the lexers of the WillBooster/tree-sitter generator let charac
42
43
  ## Usage
43
44
 
44
45
  The npm package ships `tree-sitter-haskell.wasm` for
45
- [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 4.0.2 or later in the 4.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
46
+ [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 6.0.0 or later in the 6.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
46
47
 
47
48
  ```js
48
49
  import { fileURLToPath } from 'node:url';
@@ -82,14 +83,20 @@ parser.setLanguage(await Language.load(haskell));
82
83
 
83
84
  The package also ships `grammar.js` with the files in `grammar/` it loads, the queries in `queries/`, and the node types in `src/node-types.json`.
84
85
 
86
+ For code navigation, use `queries/tags.scm` (or `TAGS_QUERY` in Rust). It indexes module headers, top-level named functions and simple named bindings, named types and classes, class and instance methods, and syntactic variable/operator calls. A signature and each equation have separate definition locations. Call references identify the called name without resolving its binding.
87
+
88
+ Extra parentheses around a function or type declaration's head are not indexed; parenthesized operator identifiers such as `(:+:)` are supported. Call-name matching supports one extra expression-parenthesis wrapper; deeper wrappers are not indexed. Destructuring bindings, local pattern bindings and constructors (including pattern synonyms) are not indexed.
89
+
90
+ In a repository checkout, configure the CLI parser directories to include the grammar, then run `script/tree-sitter tags file.hs` to inspect the tags.
91
+
85
92
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-haskell) and on
86
93
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
87
94
  fuzzed with:
88
95
 
89
96
  ```toml
90
97
  [dependencies]
91
- tree-sitter = { package = "willbooster-tree-sitter", version = "4.0.2" }
92
- tree-sitter-haskell = { package = "willbooster-tree-sitter-haskell", version = "3" }
98
+ tree-sitter = { package = "willbooster-tree-sitter", version = "6.0.0" }
99
+ tree-sitter-haskell = { package = "willbooster-tree-sitter-haskell", version = "4" }
93
100
  ```
94
101
 
95
102
  ```rust
@@ -129,7 +136,7 @@ and the release build regenerate the parsers before compiling them.
129
136
  edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
130
137
  `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
131
138
  - a check that the real-world Haskell files in `examples/`, the checked-in ones and those of the cloned repositories, fail to
132
- parse exactly as listed in `script/known-failures.txt`; upstream's prebuilt parser fails on the same files. The first run clones the repositories. The example repositories are pinned to commits in
139
+ parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example repositories are pinned to commits in
133
140
  `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites it;
134
141
  review its diff before committing;
135
142
  - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes linear
@@ -26,8 +26,8 @@ module.exports = {
26
26
 
27
27
  char: _ => magic_hash(
28
28
  choice(
29
- /'[^']'/,
30
- /'\\[^ ]*'/,
29
+ /'[^'\r\n\f]'/,
30
+ seq("'\\", choice("'", /[^'\p{White_Space}]+/), "'"),
31
31
  ),
32
32
  ),
33
33
 
package/grammar.js CHANGED
@@ -51,11 +51,9 @@ module.exports = grammar({
51
51
  ...inline,
52
52
  ...conflicts,
53
53
 
54
- /**
55
- * These rules may occur anywhere in the grammar and don't have to be specified in productions.
56
- */
57
54
  extras: $ => [
58
55
  /\p{Zs}/,
56
+ /\t/,
59
57
  /\n/,
60
58
  /\r/,
61
59
  $.cpp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-haskell",
3
- "version": "3.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Haskell grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -48,7 +48,7 @@
48
48
  "@willbooster/oxfmt-config": "1.2.2",
49
49
  "@willbooster/oxlint-config": "1.4.8",
50
50
  "@willbooster/wb": "22.26.1",
51
- "@willbooster/web-tree-sitter": "4.0.2",
51
+ "@willbooster/web-tree-sitter": "6.0.0",
52
52
  "conventional-changelog-conventionalcommits": "10.4.0",
53
53
  "lefthook": "2.2.1",
54
54
  "oxfmt": "0.72.0",
@@ -61,7 +61,7 @@
61
61
  "wrangler": "4.147.0"
62
62
  },
63
63
  "peerDependencies": {
64
- "@willbooster/web-tree-sitter": "^4.0.2"
64
+ "@willbooster/web-tree-sitter": "^6.0.0"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@willbooster/web-tree-sitter": {
@@ -0,0 +1,140 @@
1
+ (header module: (module) @name) @definition.module
2
+
3
+ (declarations
4
+ [
5
+ (function name: [(variable) @name (prefix_id (operator) @name)])
6
+ (function (infix operator: [(operator) @name (infix_id (variable) @name)]))
7
+ (signature name: [(variable) @name (prefix_id (operator) @name)])
8
+ (signature names: (binding_list name: [(variable) @name (prefix_id (operator) @name)]))
9
+ ] @definition.function)
10
+
11
+ (declarations
12
+ (bind name: [(variable) @name (prefix_id (operator) @name)]) @definition.variable)
13
+
14
+ [
15
+ (class_declarations
16
+ [
17
+ (function name: [(variable) @name (prefix_id (operator) @name)])
18
+ (function (infix operator: [(operator) @name (infix_id (variable) @name)]))
19
+ (signature name: [(variable) @name (prefix_id (operator) @name)])
20
+ (signature names: (binding_list name: [(variable) @name (prefix_id (operator) @name)]))
21
+ (default_signature signature: (signature name: [(variable) @name (prefix_id (operator) @name)]))
22
+ (default_signature signature: (signature names: (binding_list name: [(variable) @name (prefix_id (operator) @name)])))
23
+ (bind name: [(variable) @name (prefix_id (operator) @name)])
24
+ ] @definition.method)
25
+ (instance_declarations
26
+ [
27
+ (function name: [(variable) @name (prefix_id (operator) @name)])
28
+ (function (infix operator: [(operator) @name (infix_id (variable) @name)]))
29
+ (signature name: [(variable) @name (prefix_id (operator) @name)])
30
+ (signature names: (binding_list name: [(variable) @name (prefix_id (operator) @name)]))
31
+ (bind name: [(variable) @name (prefix_id (operator) @name)])
32
+ ] @definition.method)
33
+ ]
34
+
35
+ [
36
+ (type_synonym name: [
37
+ (name) @name
38
+ (qualified id: (name) @name)
39
+ (prefix_id [(operator) @name (constructor_operator) @name])
40
+ (prefix_id (qualified id: [(operator) @name (constructor_operator) @name]))
41
+ ])
42
+ (type_family name: [
43
+ (name) @name
44
+ (qualified id: (name) @name)
45
+ (prefix_id [(operator) @name (constructor_operator) @name])
46
+ (prefix_id (qualified id: [(operator) @name (constructor_operator) @name]))
47
+ ])
48
+ (data_family name: [
49
+ (name) @name
50
+ (qualified id: (name) @name)
51
+ (prefix_id [(operator) @name (constructor_operator) @name])
52
+ (prefix_id (qualified id: [(operator) @name (constructor_operator) @name]))
53
+ ])
54
+ ] @definition.class
55
+
56
+ [
57
+ (type_synonym (infix operator: [(constructor_operator) @name (operator) @name (infix_id (name) @name)]) "=")
58
+ (type_family . [(cpp) (comment) (haddock) (pragma)]* . (infix operator: [(constructor_operator) @name (operator) @name (infix_id (name) @name)]))
59
+ (data_family . [(cpp) (comment) (haddock) (pragma)]* . (infix operator: [(constructor_operator) @name (operator) @name (infix_id (name) @name)]))
60
+ ] @definition.class
61
+
62
+ (declarations
63
+ [
64
+ (data_type name: [
65
+ (name) @name
66
+ (qualified id: (name) @name)
67
+ (prefix_id [(operator) @name (constructor_operator) @name])
68
+ (prefix_id (qualified id: [(operator) @name (constructor_operator) @name]))
69
+ ])
70
+ (newtype name: [
71
+ (name) @name
72
+ (qualified id: (name) @name)
73
+ (prefix_id [(operator) @name (constructor_operator) @name])
74
+ (prefix_id (qualified id: [(operator) @name (constructor_operator) @name]))
75
+ ])
76
+ (data_type . [(cpp) (comment) (haddock) (pragma)]* . (infix operator: [(constructor_operator) @name (operator) @name (infix_id (name) @name)]))
77
+ (data_type . [(cpp) (comment) (haddock) (pragma)]* . (context) . [(cpp) (comment) (haddock) (pragma)]* . (infix operator: [(constructor_operator) @name (operator) @name (infix_id (name) @name)]))
78
+ (newtype . [(cpp) (comment) (haddock) (pragma)]* . (infix operator: [(constructor_operator) @name (operator) @name (infix_id (name) @name)]))
79
+ (newtype . [(cpp) (comment) (haddock) (pragma)]* . (context) . [(cpp) (comment) (haddock) (pragma)]* . (infix operator: [(constructor_operator) @name (operator) @name (infix_id (name) @name)]))
80
+ ] @definition.class)
81
+
82
+ (class name: [
83
+ (name) @name
84
+ (qualified id: (name) @name)
85
+ (prefix_id [(operator) @name (constructor_operator) @name])
86
+ (prefix_id (qualified id: [(operator) @name (constructor_operator) @name]))
87
+ ]) @definition.interface
88
+ (class (infix operator: [(constructor_operator) @name (operator) @name (infix_id (name) @name)])) @definition.interface
89
+ (instance name: [
90
+ (name) @name
91
+ (qualified id: (name) @name)
92
+ (prefix_id [(operator) @name (constructor_operator) @name])
93
+ (prefix_id (qualified id: [(operator) @name (constructor_operator) @name]))
94
+ ]) @reference.implementation
95
+ (instance (infix operator: [
96
+ (constructor_operator) @name
97
+ (operator) @name
98
+ (infix_id (name) @name)
99
+ (qualified id: [(constructor_operator) @name (operator) @name])
100
+ (infix_id (qualified id: (name) @name))
101
+ ])) @reference.implementation
102
+
103
+ (deriving_instance name: [
104
+ (name) @name
105
+ (qualified id: (name) @name)
106
+ (prefix_id [(operator) @name (constructor_operator) @name])
107
+ (prefix_id (qualified id: [(operator) @name (constructor_operator) @name]))
108
+ ]) @reference.implementation
109
+ (deriving_instance (infix operator: [
110
+ (constructor_operator) @name
111
+ (operator) @name
112
+ (infix_id (name) @name)
113
+ (qualified id: [(constructor_operator) @name (operator) @name])
114
+ (infix_id (qualified id: (name) @name))
115
+ ])) @reference.implementation
116
+
117
+ (foreign_import
118
+ signature: (signature name: [(variable) @name (prefix_id (operator) @name)])) @definition.function
119
+
120
+ (expression/apply
121
+ function: [
122
+ (variable) @name
123
+ (qualified id: (variable) @name)
124
+ (prefix_id (operator) @name)
125
+ (prefix_id (qualified id: (operator) @name))
126
+ (parens expression: [
127
+ (variable) @name
128
+ (qualified id: (variable) @name)
129
+ (prefix_id (operator) @name)
130
+ (prefix_id (qualified id: (operator) @name))
131
+ ])
132
+ ]) @reference.call
133
+
134
+ (expression/infix
135
+ operator: [
136
+ (operator) @name
137
+ (infix_id (variable) @name)
138
+ (infix_id (qualified id: (variable) @name))
139
+ (qualified id: (operator) @name)
140
+ ]) @reference.call
@@ -827,6 +827,16 @@
827
827
  "type": "annotated",
828
828
  "named": true,
829
829
  "fields": {
830
+ "bind": {
831
+ "multiple": false,
832
+ "required": false,
833
+ "types": [
834
+ {
835
+ "type": "variable",
836
+ "named": true
837
+ }
838
+ ]
839
+ },
830
840
  "kind": {
831
841
  "multiple": false,
832
842
  "required": true,
@@ -840,10 +850,18 @@
840
850
  },
841
851
  "children": {
842
852
  "multiple": false,
843
- "required": true,
853
+ "required": false,
844
854
  "types": [
845
855
  {
846
- "type": "type_param",
856
+ "type": "invisible",
857
+ "named": true
858
+ },
859
+ {
860
+ "type": "parens",
861
+ "named": true
862
+ },
863
+ {
864
+ "type": "wildcard",
847
865
  "named": true
848
866
  }
849
867
  ]
@@ -3341,17 +3359,36 @@
3341
3359
  {
3342
3360
  "type": "inferred",
3343
3361
  "named": true,
3344
- "fields": {},
3362
+ "fields": {
3363
+ "bind": {
3364
+ "multiple": false,
3365
+ "required": false,
3366
+ "types": [
3367
+ {
3368
+ "type": "variable",
3369
+ "named": true
3370
+ }
3371
+ ]
3372
+ }
3373
+ },
3345
3374
  "children": {
3346
3375
  "multiple": false,
3347
- "required": true,
3376
+ "required": false,
3348
3377
  "types": [
3349
3378
  {
3350
3379
  "type": "annotated",
3351
3380
  "named": true
3352
3381
  },
3353
3382
  {
3354
- "type": "type_param",
3383
+ "type": "invisible",
3384
+ "named": true
3385
+ },
3386
+ {
3387
+ "type": "parens",
3388
+ "named": true
3389
+ },
3390
+ {
3391
+ "type": "wildcard",
3355
3392
  "named": true
3356
3393
  }
3357
3394
  ]
@@ -3361,6 +3398,16 @@
3361
3398
  "type": "infix",
3362
3399
  "named": true,
3363
3400
  "fields": {
3401
+ "bind": {
3402
+ "multiple": true,
3403
+ "required": false,
3404
+ "types": [
3405
+ {
3406
+ "type": "variable",
3407
+ "named": true
3408
+ }
3409
+ ]
3410
+ },
3364
3411
  "left_operand": {
3365
3412
  "multiple": false,
3366
3413
  "required": true,
@@ -4330,6 +4377,16 @@
4330
4377
  "type": "parens",
4331
4378
  "named": true,
4332
4379
  "fields": {
4380
+ "bind": {
4381
+ "multiple": false,
4382
+ "required": false,
4383
+ "types": [
4384
+ {
4385
+ "type": "variable",
4386
+ "named": true
4387
+ }
4388
+ ]
4389
+ },
4333
4390
  "expression": {
4334
4391
  "multiple": false,
4335
4392
  "required": false,
@@ -4444,7 +4501,15 @@
4444
4501
  "named": true
4445
4502
  },
4446
4503
  {
4447
- "type": "type_param",
4504
+ "type": "invisible",
4505
+ "named": true
4506
+ },
4507
+ {
4508
+ "type": "parens",
4509
+ "named": true
4510
+ },
4511
+ {
4512
+ "type": "wildcard",
4448
4513
  "named": true
4449
4514
  }
4450
4515
  ]
@@ -4793,17 +4858,36 @@
4793
4858
  {
4794
4859
  "type": "quantified_variables",
4795
4860
  "named": true,
4796
- "fields": {},
4861
+ "fields": {
4862
+ "bind": {
4863
+ "multiple": true,
4864
+ "required": false,
4865
+ "types": [
4866
+ {
4867
+ "type": "variable",
4868
+ "named": true
4869
+ }
4870
+ ]
4871
+ }
4872
+ },
4797
4873
  "children": {
4798
4874
  "multiple": true,
4799
- "required": true,
4875
+ "required": false,
4800
4876
  "types": [
4801
4877
  {
4802
4878
  "type": "inferred",
4803
4879
  "named": true
4804
4880
  },
4805
4881
  {
4806
- "type": "type_param",
4882
+ "type": "invisible",
4883
+ "named": true
4884
+ },
4885
+ {
4886
+ "type": "parens",
4887
+ "named": true
4888
+ },
4889
+ {
4890
+ "type": "wildcard",
4807
4891
  "named": true
4808
4892
  }
4809
4893
  ]
@@ -4998,7 +5082,7 @@
4998
5082
  "named": true,
4999
5083
  "fields": {
5000
5084
  "arrow": {
5001
- "multiple": true,
5085
+ "multiple": false,
5002
5086
  "required": false,
5003
5087
  "types": [
5004
5088
  {
@@ -5723,13 +5807,32 @@
5723
5807
  {
5724
5808
  "type": "type_params",
5725
5809
  "named": true,
5726
- "fields": {},
5810
+ "fields": {
5811
+ "bind": {
5812
+ "multiple": true,
5813
+ "required": false,
5814
+ "types": [
5815
+ {
5816
+ "type": "variable",
5817
+ "named": true
5818
+ }
5819
+ ]
5820
+ }
5821
+ },
5727
5822
  "children": {
5728
5823
  "multiple": true,
5729
- "required": true,
5824
+ "required": false,
5730
5825
  "types": [
5731
5826
  {
5732
- "type": "type_param",
5827
+ "type": "invisible",
5828
+ "named": true
5829
+ },
5830
+ {
5831
+ "type": "parens",
5832
+ "named": true
5833
+ },
5834
+ {
5835
+ "type": "wildcard",
5733
5836
  "named": true
5734
5837
  }
5735
5838
  ]
Binary file
package/tree-sitter.json CHANGED
@@ -11,11 +11,12 @@
11
11
  "hs-boot"
12
12
  ],
13
13
  "highlights": "queries/highlights.scm",
14
+ "tags": "queries/tags.scm",
14
15
  "injection-regex": "^(hs|haskell)$"
15
16
  }
16
17
  ],
17
18
  "metadata": {
18
- "version": "3.0.0",
19
+ "version": "4.1.0",
19
20
  "license": "MIT",
20
21
  "description": "Haskell grammar for tree-sitter",
21
22
  "authors": [