@willbooster/tree-sitter-haskell 7.0.2 → 8.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.
@@ -169,6 +169,8 @@ module.exports = {
169
169
  $._varsym,
170
170
  $._consym,
171
171
 
172
+ $._unboxed_label_start,
173
+
172
174
  // The newline is used as a dummy symbol that is emitted whenever the scanner has to update its state even though
173
175
  // the current position must be parsed by the grammar.
174
176
  /\n/,
package/grammar/lexeme.js CHANGED
@@ -1,3 +1,5 @@
1
+ const { quoted_string } = require('./util.js')
2
+
1
3
  const id_char = /[\pL\p{Mn}\pN_']*/
2
4
 
3
5
  const varid_start_char = /[_\p{Ll}\p{Lo}]/
@@ -12,7 +14,10 @@ module.exports = {
12
14
 
13
15
  name: _ => token(seq(conid_start_char, id_char, /#*/)),
14
16
 
15
- label: _ => token(seq('#', varid_start_char, id_char)),
17
+ label: _ => token(seq('#', choice(/[\pL\p{Mn}\pN_']+/, quoted_string(
18
+ /[^\p{C}\p{Zl}\p{Zp}\\"]/,
19
+ /\\(?:[abfnrtv\\"'&]|\^[@-_]|[0-9]+|o[0-7]+|x[0-9a-fA-F]+|NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC[1-4]|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL)/,
20
+ )))),
16
21
 
17
22
  _carrow: _ => choice('=>', '⇒'),
18
23
  _arrow: _ => choice('->', '→'),
@@ -47,8 +52,7 @@ module.exports = {
47
52
  _bracket_open: $ => seq('[', $._cmd_texp_start),
48
53
  _bracket_close: $ => seq(']', $._cmd_texp_end),
49
54
 
50
- // Sadly, this does not have the effect of creating a single terminal for the bracket :'(
51
- _unboxed_open: $ => alias(seq($._paren_open, token.immediate('#')), '(#'),
55
+ _unboxed_open: $ => seq(optional($._unboxed_label_start), alias(seq($._paren_open, token.immediate('#')), '(#')),
52
56
  _unboxed_close: $ => seq('#)', $._cmd_texp_end),
53
57
  _unboxed_bar: _ => choice('|', token.immediate('|')),
54
58
 
@@ -2,18 +2,17 @@ const {
2
2
  parens,
3
3
  brackets,
4
4
  unboxed,
5
+ quoted_string,
6
+ string_gap,
5
7
  } = require('./util.js')
6
8
 
7
9
  const decimal = /[0-9][0-9_]*/
8
10
  const exponent = /[eE][+-]?[0-9_]+/
9
11
  const hex_exponent = /[pP][+-]?[0-9a-fA-F_]+/
10
- const escaped = /\\(\^)?./
11
- const string_gap = /\\\p{White_Space}+\\/
12
12
  const magic_hash = rule => token(seq(rule, optional(token.immediate(/##?/))))
13
13
 
14
14
  module.exports = {
15
15
 
16
- // the `choice` here is necessary to avoid integers being parsed as floats
17
16
  float: _ => magic_hash(
18
17
  seq(
19
18
  decimal,
@@ -33,15 +32,7 @@ module.exports = {
33
32
 
34
33
  string: _ => magic_hash(
35
34
  choice(
36
- seq(
37
- '"',
38
- repeat(choice(
39
- /[^\\"\n]/,
40
- escaped,
41
- /\\\n\s*\\/,
42
- )),
43
- '"',
44
- ),
35
+ quoted_string(/[^\\"\n]/, /\\(\^)?./),
45
36
  seq(
46
37
  '"""',
47
38
  repeat(seq(
package/grammar/util.js CHANGED
@@ -1,16 +1,16 @@
1
- // ------------------------------------------------------------------------
2
- // structure
3
- // ------------------------------------------------------------------------
4
-
5
1
  const sep1 = (s, rule) => seq(rule, repeat(seq(s, rule)))
6
2
 
7
3
  const sep2 = (s, rule) => seq(rule, repeat1(seq(s, rule)))
8
4
 
9
5
  const sep = (s, rule) => optional(sep1(s, rule))
10
6
 
11
- // ------------------------------------------------------------------------
12
- // syntax
13
- // ------------------------------------------------------------------------
7
+ const string_gap = /\\\p{White_Space}+\\/
8
+
9
+ const quoted_string = (character, escape) => seq(
10
+ '"',
11
+ repeat(choice(character, escape, string_gap)),
12
+ '"',
13
+ )
14
14
 
15
15
  const parens = ($, ...rule) => seq($._paren_open, ...rule, $._paren_close)
16
16
 
@@ -30,13 +30,6 @@ const semi_opt = $ => optional(semi($))
30
30
 
31
31
  const semis = ($, rule) => sep1(semi($), rule)
32
32
 
33
- // ------------------------------------------------------------------------
34
- // layout
35
- // ------------------------------------------------------------------------
36
-
37
- /**
38
- * More general variant of `layout_sort`.
39
- */
40
33
  const layout_sort_single = ($, start, rule) => seq(
41
34
  choice(start, alias($._cmd_layout_start_explicit, '{')),
42
35
  rule,
@@ -44,12 +37,8 @@ const layout_sort_single = ($, start, rule) => seq(
44
37
  )
45
38
 
46
39
  /**
47
- * Wrap a repeated rule in a layout.
48
- * This is used for `where`, `let`, `of`, `if` and `do`, and the toplevel module.
49
- * The `start` rule must be one of the externals starting with `_cmd_layout_<type>`, which instruct the scanner to push
50
- * a layout context with the current column as its indentation.
51
- * When a `_cond_layout_end` or `_cond_layout_semicolon` is encountered by the scanner, the recorded indent is compared
52
- * to the current one to make a decision.
40
+ * The start rule must be a `_cmd_layout_<type>` external so the scanner can push a layout context.
41
+ * Layout-start externals make the scanner record the current column; conditional end and semicolon tokens compare it.
53
42
  */
54
43
  const layout_sort = ($, start, rule) => seq(
55
44
  choice(start, alias($._cmd_layout_start_explicit, '{')),
@@ -62,29 +51,14 @@ const layout_sort = ($, start, rule) => seq(
62
51
  )
63
52
 
64
53
  /**
65
- * Same as `layout`, but using `layout_sort_single`.
66
- * This is necessary for braces without repeating layout elements.
67
- * Usually it is enough to just use `braces` for this (e.g. records), but if the rule is in a choice with a full
68
- * layout, we need to allow the layout start token since the scanner emits that unconditionally based on preceding
69
- * tokens.
54
+ * The scanner emits a layout-start token unconditionally after layout introducers, including single-element alternatives.
70
55
  */
71
56
  const layout_single = ($, rule) => layout_sort_single($, $._cmd_layout_start, rule)
72
57
 
73
- /**
74
- * Alias for `layout_sort` using the common layout type for the start token, which corresponds to declarations and GADT
75
- * constructors.
76
- */
77
58
  const layout = ($, rule) => layout_sort($, $._cmd_layout_start, rule)
78
59
 
79
- // ------------------------------------------------------------------------
80
- // unboxed
81
- // ------------------------------------------------------------------------
82
-
83
60
  const unboxed = ($, ...rules) => seq($._unboxed_open, ...rules, $._unboxed_close)
84
61
 
85
- /**
86
- * At least one element is filled, for expressions.
87
- */
88
62
  const unboxed_tuple_nonempty = ($, rule) => unboxed(
89
63
  $,
90
64
  repeat(','),
@@ -92,14 +66,8 @@ const unboxed_tuple_nonempty = ($, rule) => unboxed(
92
66
  repeat(seq(',', optional(field('element', rule))))
93
67
  )
94
68
 
95
- /**
96
- * All elements are filled in, for types and patterns.
97
- */
98
69
  const unboxed_tuple_full = ($, rule) => unboxed($, sep1(',', field('element', rule)))
99
70
 
100
- /**
101
- * Exactly one element is filled in, used by expressions, patterns and the special data constructors.
102
- */
103
71
  const unboxed_sum_single = ($, rule) => unboxed(
104
72
  $,
105
73
  choice(
@@ -109,21 +77,10 @@ const unboxed_sum_single = ($, rule) => unboxed(
109
77
  repeat($._unboxed_bar),
110
78
  )
111
79
 
112
- /**
113
- * All elements are filled in, for types.
114
- */
115
80
  const unboxed_sum_full = ($, rule) => unboxed($, sep2($._unboxed_bar, field('element', rule)))
116
81
 
117
- // ------------------------------------------------------------------------
118
- // where
119
- // ------------------------------------------------------------------------
120
-
121
82
  const optional_where = ($, rule) => optional(seq($._where, optional(rule)))
122
83
 
123
- // ------------------------------------------------------------------------
124
- // misc
125
- // ------------------------------------------------------------------------
126
-
127
84
  const qualified = ($, id) => prec('qualified-id', seq(
128
85
  field('module', alias($._qualifying_module, $.module)),
129
86
  field('id', id),
@@ -137,6 +94,8 @@ module.exports = {
137
94
  sep1,
138
95
  sep2,
139
96
  sep,
97
+ quoted_string,
98
+ string_gap,
140
99
  parens,
141
100
  braces,
142
101
  brackets,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-haskell",
3
- "version": "7.0.2",
3
+ "version": "8.0.0",
4
4
  "description": "Haskell grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "7.0.2",
19
+ "version": "8.0.0",
20
20
  "license": "MIT",
21
21
  "description": "Haskell grammar for tree-sitter",
22
22
  "authors": [