@willbooster/tree-sitter-zig 13.0.0 → 14.0.1

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
@@ -23,8 +23,9 @@ exceptions:
23
23
  `for (0..&x) |i| {}`), is the right operand of a `range_expression`. Upstream's packaged parser, generated by
24
24
  tree-sitter CLI 0.24, lets that token continue the expression instead, on a range without an end: a call, an index,
25
25
  a field access, a binary expression, and so on. tree-sitter CLI 0.27 generates this fork's reading from the same
26
- grammar. Every other range end reads the same in both, whether its first token can only start an expression (`n`,
27
- `~x`) or only continue one (`+`, `orelse`), and so do ranges outside `for` loops.
26
+ grammar. This generator difference applies only to those `for`-loop range ends.
27
+ - Labeled blocks used as indices or slice bounds retain their `block_label` inside the expression,
28
+ instead of splitting the label colon into an index and a sentinel.
28
29
  - A NUL character inside a token such as a string or a comment is part of that token, where upstream's lexer reports
29
30
  an error.
30
31
  - Multiline strings expose each `\\` line delimiter and nonempty `string_content` children. Line endings are outside
package/grammar.js CHANGED
@@ -54,9 +54,10 @@ const builtinTypes = [
54
54
  module.exports = grammar({
55
55
  name: 'zig',
56
56
 
57
- externals: $ => [$.doc_comment_content, $._empty_doc_comment_content, $._error_sentinel],
57
+ externals: $ => [$.doc_comment_content, $._empty_doc_comment_content, $._error_sentinel, $._declaration_name_colon],
58
58
 
59
59
  conflicts: $ => [
60
+ [$.block_label, $.primary_type_expression],
60
61
  [$.for_expression],
61
62
  [$.while_expression],
62
63
 
@@ -128,7 +129,7 @@ module.exports = grammar({
128
129
  choice(
129
130
  seq(
130
131
  field('name', choice($.identifier, $._reserved_identifier, alias($.builtin_type, $.identifier))),
131
- ':',
132
+ alias($._declaration_name_colon, ':'),
132
133
  field('type', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression, $.error_set_declaration)),
133
134
  ),
134
135
  field('name', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression, $.error_set_declaration)),
@@ -226,7 +227,7 @@ module.exports = grammar({
226
227
  optional(choice('noalias', 'comptime')),
227
228
  optional(seq(
228
229
  field('name', choice($.identifier, alias($.builtin_type, $.identifier))),
229
- ':',
230
+ alias($._declaration_name_colon, ':'),
230
231
  )),
231
232
  field('type', choice($.type_expression, $.if_type_expression, $.comptime_type_expression)),
232
233
  ),
@@ -772,7 +773,7 @@ module.exports = grammar({
772
773
 
773
774
  parenthesized_expression: $ => seq('(', $.expression, ')'),
774
775
 
775
- block_label: $ => prec(-1, seq(
776
+ block_label: $ => prec.dynamic(1, seq(
776
777
  choice($.identifier, alias($.builtin_type, $.identifier)),
777
778
  ':',
778
779
  )),
@@ -882,37 +883,14 @@ module.exports = grammar({
882
883
  },
883
884
  });
884
885
 
885
- /**
886
- * Creates a rule to match optionally match one or more of the rules
887
- * separated by a comma and optionally ending with a comma
888
- *
889
- * @param {RuleOrLiteral} rule
890
- *
891
- * @returns {ChoiceRule}
892
- */
893
886
  function optionalCommaSep(rule) {
894
887
  return optional(optionalCommaSep1(rule));
895
888
  }
896
889
 
897
- /**
898
- * Creates a rule to match one or more of the rules separated by a comma
899
- * and optionally ending with a comma
900
- *
901
- * @param {RuleOrLiteral} rule
902
- *
903
- * @returns {SeqRule}
904
- */
905
890
  function optionalCommaSep1(rule) {
906
891
  return seq(commaSep1(rule), optional(','));
907
892
  }
908
893
 
909
- /**
910
- * Creates a rule to match one or more of the rules separated by a comma
911
- *
912
- * @param {RuleOrLiteral} rule
913
- *
914
- * @returns {SeqRule}
915
- */
916
894
  function commaSep1(rule) {
917
895
  return seq(rule, repeat(seq(',', rule)));
918
896
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-zig",
3
- "version": "13.0.0",
3
+ "version": "14.0.1",
4
4
  "description": "Zig grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "parsing",
package/src/scanner.c CHANGED
@@ -4,6 +4,7 @@ enum TokenType {
4
4
  DOC_COMMENT_CONTENT,
5
5
  EMPTY_DOC_COMMENT_CONTENT,
6
6
  ERROR_SENTINEL,
7
+ DECLARATION_NAME_COLON,
7
8
  };
8
9
 
9
10
  void *tree_sitter_zig_external_scanner_create(void) { return NULL; }
@@ -24,10 +25,22 @@ void tree_sitter_zig_external_scanner_deserialize(void *payload, const char *buf
24
25
 
25
26
  static inline bool at_eof(const TSLexer *lexer) { return lexer->lookahead == 0 && lexer->eof(lexer); }
26
27
 
28
+ static bool scan_declaration_name_colon(TSLexer *lexer) {
29
+ while (lexer->lookahead == ' ' || lexer->lookahead == '\t' || lexer->lookahead == '\n' ||
30
+ lexer->lookahead == '\r' || lexer->lookahead == '\f') {
31
+ lexer->advance(lexer, true);
32
+ }
33
+ if (lexer->lookahead != ':') return false;
34
+ lexer->advance(lexer, false);
35
+ lexer->result_symbol = DECLARATION_NAME_COLON;
36
+ return true;
37
+ }
38
+
27
39
  bool tree_sitter_zig_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
28
40
  (void)payload;
29
- if (valid_symbols[ERROR_SENTINEL] ||
30
- (!valid_symbols[DOC_COMMENT_CONTENT] && !valid_symbols[EMPTY_DOC_COMMENT_CONTENT])) {
41
+ if (valid_symbols[ERROR_SENTINEL]) return false;
42
+ if (valid_symbols[DECLARATION_NAME_COLON]) return scan_declaration_name_colon(lexer);
43
+ if (!valid_symbols[DOC_COMMENT_CONTENT] && !valid_symbols[EMPTY_DOC_COMMENT_CONTENT]) {
31
44
  return false;
32
45
  }
33
46
  if (at_eof(lexer)) {
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "13.0.0",
16
+ "version": "14.0.1",
17
17
  "license": "MIT",
18
18
  "description": "Zig grammar for tree-sitter",
19
19
  "authors": [