@willbooster/tree-sitter-python 2.1.0 → 2.1.2

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/grammar.js CHANGED
@@ -6,9 +6,11 @@
6
6
  * @see {@link https://docs.python.org/3/reference/grammar.html|Python 3 grammar}
7
7
  */
8
8
 
9
- /// <reference types="tree-sitter-cli/dsl" />
10
9
  // @ts-check
11
10
 
11
+ const { grammar, seq, choice, repeat, repeat1, optional, token, prec, alias, field, sym } =
12
+ /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
13
+
12
14
  const PREC = {
13
15
  // this resolves a conflict between the usage of ':' in a lambda vs in a
14
16
  // typed parameter. In the case of a lambda, we don't allow typed parameters.
@@ -60,21 +62,21 @@ module.exports = grammar({
60
62
  $.parameter,
61
63
  ],
62
64
 
63
- externals: ($) => [
64
- $._newline,
65
- $._indent,
66
- $._dedent,
67
- $.string_start,
68
- $._string_content,
69
- $.escape_interpolation,
70
- $.string_end,
65
+ externals: () => [
66
+ sym('_newline'),
67
+ sym('_indent'),
68
+ sym('_dedent'),
69
+ sym('string_start'),
70
+ sym('_string_content'),
71
+ sym('escape_interpolation'),
72
+ sym('string_end'),
71
73
 
72
74
  // Mark comments as external tokens so that the external scanner is always
73
75
  // invoked, even if no external token is expected. This allows for better
74
76
  // error recovery, because the external scanner can maintain the overall
75
77
  // structure by returning dedent tokens whenever a dedent occurs, even
76
78
  // if no dedent is expected.
77
- $.comment,
79
+ sym('comment'),
78
80
 
79
81
  // Allow the external scanner to check for the validity of closing brackets
80
82
  // so that it can avoid returning dedent tokens between brackets.
@@ -144,7 +146,7 @@ module.exports = grammar({
144
146
 
145
147
  // Simple statements
146
148
 
147
- _simple_statements: ($) => seq(sep1($._simple_statement, SEMICOLON), optional(SEMICOLON), $._newline),
149
+ _simple_statements: ($) => seq(sep1($._simple_statement, SEMICOLON), optional(SEMICOLON), sym('_newline')),
148
150
 
149
151
  _simple_statement: ($) =>
150
152
  choice(
@@ -278,7 +280,8 @@ module.exports = grammar({
278
280
  );
279
281
  },
280
282
 
281
- _match_block: ($) => choice(seq($._indent, repeat(field('alternative', $.case_clause)), $._dedent), $._newline),
283
+ _match_block: ($) =>
284
+ choice(seq(sym('_indent'), repeat(field('alternative', $.case_clause)), sym('_dedent')), sym('_newline')),
282
285
 
283
286
  case_clause: ($) =>
284
287
  seq(
@@ -416,11 +419,12 @@ module.exports = grammar({
416
419
  decorated_definition: ($) =>
417
420
  seq(repeat1($.decorator), field('definition', choice($.class_definition, $.function_definition))),
418
421
 
419
- decorator: ($) => seq('@', $.expression, $._newline),
422
+ decorator: ($) => seq('@', $.expression, sym('_newline')),
420
423
 
421
- _suite: ($) => choice(alias($._simple_statements, $.block), seq($._indent, $.block), alias($._newline, $.block)),
424
+ _suite: ($) =>
425
+ choice(alias($._simple_statements, $.block), seq(sym('_indent'), $.block), alias(sym('_newline'), $.block)),
422
426
 
423
- block: ($) => seq(repeat($._statement), $._dedent),
427
+ block: ($) => seq(repeat($._statement), sym('_dedent')),
424
428
 
425
429
  expression_list: ($) =>
426
430
  prec.dynamic(1, prec.right(seq(choice($.expression, $.list_splat), ',', optional($._collection_elements)))),
@@ -524,7 +528,8 @@ module.exports = grammar({
524
528
 
525
529
  // Extended patterns (patterns allowed in match statement are far more flexible than simple patterns though still a subset of "expression")
526
530
 
527
- as_pattern: ($) => prec.left(seq($.expression, 'as', field('alias', alias($.expression, $.as_pattern_target)))),
531
+ as_pattern: ($) =>
532
+ prec.left(seq($.expression, 'as', field('alias', alias($.expression, sym('as_pattern_target'))))),
528
533
 
529
534
  // Expressions
530
535
 
@@ -594,8 +599,7 @@ module.exports = grammar({
594
599
  ),
595
600
 
596
601
  binary_operator: ($) => {
597
- /* oxlint-disable typescript/unbound-method -- prec.left and prec.right do not use `this`. */
598
- /** @type {[typeof prec.left | typeof prec.right, string, number][]} */
602
+ /** @type {[import('@willbooster/web-tree-sitter/dsl').DSL['prec']['left' | 'right'], string, number][]} */
599
603
  const table = [
600
604
  [prec.left, '+', PREC.plus],
601
605
  [prec.left, '-', PREC.plus],
@@ -611,7 +615,6 @@ module.exports = grammar({
611
615
  [prec.left, '<<', PREC.shift],
612
616
  [prec.left, '>>', PREC.shift],
613
617
  ];
614
- /* oxlint-enable typescript/unbound-method */
615
618
 
616
619
  return choice(
617
620
  ...table.map(([fn, operator, precedence]) =>
@@ -823,10 +826,12 @@ module.exports = grammar({
823
826
 
824
827
  concatenated_string: ($) => seq($.string, repeat1($.string)),
825
828
 
826
- string: ($) => seq($.string_start, repeat(choice($.interpolation, $.string_content)), $.string_end),
829
+ string: ($) => seq(sym('string_start'), repeat(choice($.interpolation, $.string_content)), sym('string_end')),
827
830
 
828
831
  string_content: ($) =>
829
- prec.right(repeat1(choice($.escape_interpolation, $.escape_sequence, $._not_escape_sequence, $._string_content))),
832
+ prec.right(
833
+ repeat1(choice(sym('escape_interpolation'), $.escape_sequence, $._not_escape_sequence, sym('_string_content')))
834
+ ),
830
835
 
831
836
  interpolation: ($) =>
832
837
  seq(
@@ -862,7 +867,10 @@ module.exports = grammar({
862
867
  _not_escape_sequence: () => token.immediate('\\'),
863
868
 
864
869
  format_specifier: ($) =>
865
- seq(':', repeat(choice(token(prec(1, /[^{}\n]+/)), alias($.interpolation, $.format_expression)))),
870
+ seq(
871
+ token(prec(1, ':')),
872
+ repeat(choice(token(prec(1, /[^{}\n]+/)), alias($.interpolation, sym('format_expression'))))
873
+ ),
866
874
 
867
875
  type_conversion: () => /![a-z]/,
868
876
 
@@ -931,9 +939,9 @@ Object.assign(module.exports, { PREC });
931
939
  /**
932
940
  * Creates a rule to match one or more of the rules separated by a comma
933
941
  *
934
- * @param {RuleOrLiteral} rule
942
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
935
943
  *
936
- * @returns {SeqRule}
944
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
937
945
  */
938
946
  function commaSep1(rule) {
939
947
  return sep1(rule, ',');
@@ -942,11 +950,11 @@ function commaSep1(rule) {
942
950
  /**
943
951
  * Creates a rule to match one or more occurrences of `rule` separated by `sep`
944
952
  *
945
- * @param {RuleOrLiteral} rule
953
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
946
954
  *
947
- * @param {RuleOrLiteral} separator
955
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} separator
948
956
  *
949
- * @returns {SeqRule}
957
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
950
958
  */
951
959
  function sep1(rule, separator) {
952
960
  return seq(rule, repeat(seq(separator, rule)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-python",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "Python grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -56,7 +56,6 @@
56
56
  "playwright": "1.64.0",
57
57
  "semantic-release": "25.0.9",
58
58
  "sort-package-json": "4.0.0",
59
- "tree-sitter-cli": "0.27.1",
60
59
  "vite": "8.3.4",
61
60
  "vitest": "5.0.3",
62
61
  "wrangler": "4.149.0"
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "2.1.0",
22
+ "version": "2.1.2",
23
23
  "license": "MIT",
24
24
  "description": "Python grammar for tree-sitter",
25
25
  "authors": [