tree-sitter-flow 0.0.0-stage → 0.1.0-rc.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024 The Flow contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # Flow
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/buttercrab/flow/actions/workflows/ci.yml/badge.svg?branch=main&event=push)](https://github.com/buttercrab/flow/actions/workflows/ci.yml?query=branch%3Amain+event%3Apush)
4
+
5
+ **A typed language that records the answers its programs get from outside, so a run can be replayed or picked up later.**
6
+
7
+ Programs that call models, services and people are mostly glue code today:
8
+ replies nobody checks, failures silently swallowed, runs nobody can reproduce.
9
+ In Flow, a run can wait for days, replay without calling anything, and be
10
+ inspected step by step.
11
+
12
+ ```flow
13
+ use "github.com/example/agents@v1/model" // Tools: functions whose bodies the host supplies
14
+ use "github.com/example/agents@v1/person"
15
+
16
+ pub flow main(ticket: Text) -> Outcome = {
17
+ let plan: Plan = match model.extract("Plan a reply to: ${ticket}") {
18
+ Ok(Ok(plan)) => plan, // the Tool returned a plan
19
+ Ok(Err(error)) => return PlanRefused(error), // the Tool returned its own ModelError
20
+ Err(problem) => return PlanFailed(problem), // the call got no value back
21
+ }
22
+ guard let Ok(Yes) = person.ask("Send this reply? ${plan.reply}") else { return Declined }
23
+ Sent(plan.reply)
24
+ }
25
+ ```
26
+
27
+ Flow is pre-release, and nothing here carries a compatibility promise.
28
+
29
+ ## Install and run
30
+
31
+ The [installation guide](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/docs/guides/installation.md) installs a release
32
+ bundle. To build from source instead, follow
33
+ [Build from a checkout](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/docs/guides/installation.md#build-from-a-checkout),
34
+ then run a program that needs no model account. It checks a successful effect,
35
+ a typed failure, an uncertain outcome, continuing in a fresh process, and
36
+ replay after the implementation is removed:
37
+
38
+ ```bash
39
+ cargo xtask flow tests/examples/verify_lifecycle.flow output="$(mktemp -d)/lifecycle"
40
+ ```
41
+
42
+ Tools are typed Python or Rust functions, or an MCP server's tools, kept in a
43
+ library that a program imports like any module. Start with the
44
+ [two-language projects](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/examples/function-tools/README.md), the
45
+ [library guide](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/docs/guides/writing-a-library.md) and the
46
+ [maintained examples](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/examples/README.md). `flow <command> --help` lists each
47
+ command's arguments.
48
+
49
+ ## Documentation
50
+
51
+ The [documentation index](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/docs/README.md) says where to start, from the Flow
52
+ Book to the design, and maps everything else.
53
+
54
+ ## Contributing
55
+
56
+ [CONTRIBUTING.md](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/CONTRIBUTING.md) says where a change belongs and how to check
57
+ it, and [AGENTS.md](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/AGENTS.md) holds the working rules for human and automated
58
+ contributors alike.
59
+
60
+ ## Project
61
+
62
+ - [Code of Conduct](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/CODE_OF_CONDUCT.md)
63
+ - [License](https://github.com/buttercrab/flow/blob/13a1f8183b4a856c4d8b98666695893e643fe4ef/LICENSE) — Apache-2.0
package/grammar.js ADDED
@@ -0,0 +1,105 @@
1
+ // Editor syntax follows docs/language/spec/grammar.md. The Flow compiler owns
2
+ // acceptance, including significant newline and block-margin validation.
3
+ const commaSep = rule => seq(rule, repeat(seq(',', rule)), optional(','));
4
+ const commaSep0 = rule => optional(commaSep(rule));
5
+
6
+ module.exports = grammar({
7
+ name: 'flow',
8
+ extras: $ => [/[ \t\r\n]/, $.comment, $.doc_comment],
9
+ word: $ => $.lower_identifier,
10
+ // src/scanner.c: a doc comment's text runs from its `///` through its line
11
+ // end, and a `///` that ends the file is a doc comment with no text. The
12
+ // sentinel is in no rule, so it is valid only during error recovery.
13
+ externals: $ => [$._error_sentinel, $.doc_text, $._final_doc_marker],
14
+ conflicts: $ => [
15
+ [$._name, $.constructor_path],
16
+ [$.tuple_type]
17
+ ],
18
+ rules: {
19
+ source_file: $ => repeat(choice($.import_declaration, $.reexport_declaration, $._item)),
20
+ comment: _ => token(seq('//', /[^\r\n]*/)),
21
+ // `///` and the text after it are separate tokens so an editor can read the
22
+ // text as Markdown. The text keeps its line end: Markdown needs the lines
23
+ // apart, and an injection skips every character outside its ranges. An
24
+ // extra must end unambiguously, so the text is not optional: a `///` with
25
+ // nothing after it but the end of the file is a token of its own.
26
+ doc_comment: $ => choice(seq(token(prec(1, '///')), $.doc_text), alias($._final_doc_marker, '///')),
27
+ lower_identifier: _ => /[a-z][a-z0-9_]*/,
28
+ upper_identifier: _ => /[A-Z][A-Za-z0-9]*/,
29
+ _name: $ => choice($.lower_identifier, $.upper_identifier),
30
+ import_declaration: $ => seq('use', field('path', $.text), optional(seq('as', field('name', $.lower_identifier)))),
31
+ reexport_declaration: $ => seq('pub', 'use', field('module', $.lower_identifier), '.', choice('*', $.reexport_entry, seq('{', commaSep($.reexport_entry), '}'))),
32
+ reexport_entry: $ => choice(
33
+ seq(field('name', $.lower_identifier), optional(seq('as', field('alias', $.lower_identifier)))),
34
+ seq(field('name', $.upper_identifier), optional(seq('as', field('alias', $.upper_identifier))))
35
+ ),
36
+ _item: $ => seq(repeat($.annotation), optional('pub'), choice($.function_declaration, $.type_declaration, $.let_declaration)),
37
+ annotation: $ => seq('@', $.lower_identifier, optional(seq('(', commaSep($.annotation_argument), ')'))),
38
+ annotation_argument: $ => seq($.lower_identifier, repeat(seq('.', $.lower_identifier))),
39
+ type_parameters: $ => seq('<', commaSep($.upper_identifier), '>'),
40
+ function_declaration: $ => seq('flow', field('name', $.lower_identifier), optional($.type_parameters), '(', commaSep0($.typed_parameter), ')', '->', field('result', $._type), optional(seq('=', field('body', $._expression)))),
41
+ typed_parameter: $ => seq(field('pattern', $._pattern), ':', field('type', $._type), optional(seq('=', field('default', $._expression)))),
42
+ parameter: $ => seq(field('pattern', $._pattern), optional(seq(':', field('type', $._type))), optional(seq('=', field('default', $._expression)))),
43
+ type_declaration: $ => seq(optional('opaque'), 'type', field('name', $.upper_identifier), optional($.type_parameters), optional($.type_body)),
44
+ type_body: $ => choice(seq('=', $._type), seq('{', commaSep(choice($.field_declaration, $.constructor_declaration)), '}'), seq('(', optional('pub'), $._type, optional(','), ')')),
45
+ field_declaration: $ => seq(optional('pub'), field('name', $.lower_identifier), ':', $._type),
46
+ constructor_declaration: $ => seq(field('name', $.upper_identifier), optional(choice(seq('(', commaSep($._type), ')'), seq('{', commaSep($.payload_field), '}')))),
47
+ payload_field: $ => seq(field('name', $.lower_identifier), ':', $._type),
48
+ _type: $ => choice($.type_reference, $.function_type, $.tuple_type, $.parenthesized_type),
49
+ type_reference: $ => seq(optional(seq($.lower_identifier, '.')), $.upper_identifier, optional($.type_arguments)),
50
+ type_arguments: $ => seq('<', commaSep($._type), '>'),
51
+ parenthesized_type: $ => seq('(', $._type, optional(','), ')'),
52
+ tuple_type: $ => seq('(', $._type, ',', commaSep($._type), ')'),
53
+ function_type: $ => prec.right(seq('(', commaSep0($._type), ')', '->', $._type)),
54
+ let_declaration: $ => seq('let', field('pattern', $._pattern), optional(seq(':', $._type)), '=', field('value', $._expression)),
55
+ block: $ => seq('{', repeat(choice($.let_declaration, $.guard_statement, $.local_function, $.local_type, $._expression)), '}'),
56
+ local_function: $ => seq('flow', field('name', $.lower_identifier), optional($.type_parameters), '(', commaSep0($.parameter), ')', optional(seq('->', $._type)), '=', field('body', $._expression)),
57
+ local_type: $ => seq('type', field('name', $.upper_identifier), optional($.type_parameters), $.type_body),
58
+ guard_statement: $ => seq('guard', optional(seq('let', $._pattern, '=')), $._expression, 'else', $.block),
59
+ _expression: $ => choice($._name, $._literal, $.block, $.list_expression, $.dict_expression, $.unit_expression, $.parenthesized_expression, $.tuple_expression, $.record_expression, $.anonymous_function, $.return_expression, $.unary_expression, $.binary_expression, $.call_expression, $.member_expression, $.try_expression, $.if_expression, $.match_expression),
60
+ _literal: $ => choice($.integer, $.decimal, $.boolean, $.text, $.raw_text, $.block_text, $.raw_block_text),
61
+ integer: _ => token(choice(/0x[0-9a-fA-F](_?[0-9a-fA-F])*/, /0o[0-7](_?[0-7])*/, /0b[01](_?[01])*/, /0|[1-9](_?[0-9])*/)),
62
+ decimal: _ => token(/(0|[1-9](_?[0-9])*)\.[0-9](_?[0-9])*/),
63
+ boolean: _ => choice('true', 'false'),
64
+ text: $ => seq('"', repeat(choice($.text_content, $.escape, $.interpolation)), '"'),
65
+ text_content: _ => token.immediate(prec(1, /[^"\\$\r\n]+|\$[^{$"\\\r\n]?/)),
66
+ escape: _ => token.immediate(/\\([nrt\\"]|\$\{|u\{[0-9a-fA-F]{1,6}\})/),
67
+ interpolation: $ => seq(token.immediate(prec(2, '${')), $._expression, '}'),
68
+ raw_text: _ => token(seq('r"', /[^"\r\n]*/, '"')),
69
+ block_text: $ => seq('"""', repeat(choice($.block_text_content, $.escape, $.interpolation)), '"""'),
70
+ block_text_content: _ => token.immediate(prec(1, /[^"\\$]+|"[^"\\$]?|""[^"\\$]|\$[^{$"\\]?/)),
71
+ raw_block_text: _ => token(seq('r"""', repeat(choice(/[^"]+/, /"[^"]/, /""[^"]/)), '"""')),
72
+ unit_expression: _ => seq('(', ')'),
73
+ parenthesized_expression: $ => seq('(', $._expression, optional(','), ')'),
74
+ tuple_expression: $ => seq('(', $._expression, ',', commaSep($._expression), ')'),
75
+ list_expression: $ => seq('[', commaSep0($._expression), ']'),
76
+ dict_expression: $ => seq('[', choice(':', commaSep($.dict_entry)), ']'),
77
+ dict_entry: $ => seq($._expression, ':', $._expression),
78
+ constructor_path: $ => seq(optional(seq($.lower_identifier, '.')), $.upper_identifier, optional(seq('.', $.upper_identifier))),
79
+ record_expression: $ => seq($.constructor_path, '{', commaSep0(choice($.record_entry, $.spread_expression)), '}'),
80
+ record_entry: $ => seq(field('name', $.lower_identifier), repeat(seq('.', $.lower_identifier)), optional(seq(':', $._expression))),
81
+ spread_expression: $ => seq('..', $._expression),
82
+ anonymous_function: $ => prec.right(seq('flow', '(', commaSep0($.parameter), ')', optional(seq('->', $._type)), '=', $._expression)),
83
+ return_expression: $ => prec.right(seq('return', $._expression)),
84
+ unary_expression: $ => prec(7, seq(field('operator', choice('!', '-')), $._expression)),
85
+ binary_expression: $ => choice(...[['||', 1], ['&&', 2], ['==', 3], ['!=', 3], ['<', 3], ['<=', 3], ['>', 3], ['>=', 3], ['+', 4], ['-', 4], ['*', 5], ['/', 5], ['%', 5]].map(([op, precedence]) => prec.left(precedence, seq(field('left', $._expression), field('operator', op), field('right', $._expression))))),
86
+ call_expression: $ => prec.left(9, seq(field('function', $._expression), '(', commaSep0(choice($._expression, $.named_argument)), ')')),
87
+ named_argument: $ => seq(field('name', $.lower_identifier), ':', field('value', $._expression)),
88
+ member_expression: $ => prec.left(9, seq(field('object', $._expression), '.', field('member', $._name))),
89
+ try_expression: $ => prec.left(8, seq($._expression, '?')),
90
+ if_expression: $ => prec.right(seq('if', field('condition', $._expression), field('consequence', $.block), optional(seq('else', field('alternative', choice($.block, $.if_expression)))))),
91
+ match_expression: $ => seq('match', $._expression, '{', commaSep($.match_arm), '}'),
92
+ match_arm: $ => seq($._pattern, optional(seq('if', $._expression)), '=>', $._expression),
93
+ _pattern: $ => choice($._simple_pattern, $.or_pattern, $.as_pattern),
94
+ _simple_pattern: $ => choice('_', $.lower_identifier, $._literal, $.negative_pattern, $.unit_expression, $.parenthesized_pattern, $.tuple_pattern, $.list_pattern, $.constructor_pattern),
95
+ negative_pattern: $ => seq('-', choice($.integer, $.decimal)),
96
+ parenthesized_pattern: $ => seq('(', $._pattern, optional(','), ')'),
97
+ tuple_pattern: $ => seq('(', $._pattern, ',', commaSep($._pattern), ')'),
98
+ list_pattern: $ => seq('[', commaSep0(choice($._pattern, $.rest_pattern)), ']'),
99
+ rest_pattern: $ => seq('..', optional($.lower_identifier)),
100
+ constructor_pattern: $ => seq($.constructor_path, optional(choice(seq('(', commaSep($._pattern), ')'), seq('{', commaSep(choice($.field_pattern, $.rest_pattern)), '}')))),
101
+ field_pattern: $ => seq($.lower_identifier, optional(seq(':', $._pattern))),
102
+ or_pattern: $ => prec.left(1, seq($._pattern, '|', $._pattern)),
103
+ as_pattern: $ => prec.left(0, seq($._pattern, 'as', $.lower_identifier))
104
+ }
105
+ });
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "tree-sitter-flow",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-rc.5",
4
+ "description": "Tree-sitter grammar for the Flow orchestration language",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/buttercrab/flow.git",
9
+ "directory": "tools/tree-sitter-flow"
10
+ },
11
+ "homepage": "https://github.com/buttercrab/flow/tree/main/tools/tree-sitter-flow",
12
+ "keywords": ["tree-sitter", "parser", "flow", "incremental", "syntax"],
13
+ "files": [
14
+ "grammar.js",
15
+ "tree-sitter.json",
16
+ "src/**",
17
+ "queries/*.scm",
18
+ "tree-sitter-flow.wasm",
19
+ "LICENSE",
20
+ "README.md"
21
+ ],
22
+ "scripts": {
23
+ "generate": "tree-sitter generate",
24
+ "test": "tree-sitter test && node --test test/*.test.js"
25
+ },
26
+ "devDependencies": { "tree-sitter-cli": "0.27.2" }
27
+ }
@@ -0,0 +1,6 @@
1
+ ("(" @open ")" @close)
2
+ ("[" @open "]" @close)
3
+ ("{" @open "}" @close)
4
+ (interpolation "${" @open "}" @close)
5
+ ((text "\"" @open "\"" @close) (#set! rainbow.exclude))
6
+ ((block_text "\"\"\"" @open "\"\"\"" @close) (#set! rainbow.exclude))
@@ -0,0 +1,77 @@
1
+ ; Later patterns take precedence over earlier ones. Where a capture names
2
+ ; two styles, `@type @constructor`, an editor that resolves fallbacks (Zed)
3
+ ; uses the last one the theme defines; the language server's semantic tokens
4
+ ; refine these by resolved identity (editors/README.md).
5
+
6
+ (comment) @comment
7
+ (doc_comment) @comment.doc
8
+ (integer) @number
9
+ (decimal) @number
10
+ (boolean) @boolean
11
+ [(text) (raw_text) (block_text) (raw_block_text)] @string
12
+ (escape) @string.escape
13
+
14
+ ; Names by case: a lowercase name is a value, an uppercase name in an
15
+ ; expression or a pattern is a constructor, and one in a type is a type.
16
+ (lower_identifier) @variable
17
+ (upper_identifier) @type @constructor
18
+
19
+ (type_reference (upper_identifier) @type)
20
+ (type_reference (lower_identifier) @namespace)
21
+ (type_parameters (upper_identifier) @type)
22
+ (type_declaration name: (upper_identifier) @type)
23
+ (local_type name: (upper_identifier) @type)
24
+ (constructor_declaration name: (upper_identifier) @type @constructor)
25
+
26
+ ; `module.Type.Constructor` and `Type.Constructor`: the qualifiers are a
27
+ ; module and a type.
28
+ (constructor_path (lower_identifier) @namespace)
29
+ (constructor_path (upper_identifier) @type . (upper_identifier))
30
+ (member_expression object: (upper_identifier) @type member: (upper_identifier))
31
+ (member_expression
32
+ object: (member_expression member: (upper_identifier) @type)
33
+ member: (upper_identifier))
34
+ (import_declaration name: (lower_identifier) @namespace)
35
+ (reexport_declaration module: (lower_identifier) @namespace)
36
+ (reexport_entry (upper_identifier) @type)
37
+ ; A module is used only qualified, `list.map(items, f)`, and a name before a
38
+ ; `.` is a module exactly when an import binds it. A query cannot see the
39
+ ; imports, so it names std's modules; the language server marks every module
40
+ ; qualifier, a library's too, and a local value that shadows one of these.
41
+ ((member_expression object: (lower_identifier) @namespace)
42
+ (#any-of? @namespace "bytes" "clock" "code" "decimal" "dict" "duration" "int" "json" "list" "media" "option" "path" "result" "runs" "set" "task" "test" "text" "time" "tool" "url"))
43
+ ; `Point { x: 1 }` may name a record type or a constructor with record
44
+ ; fields; without the language server it keeps the type's style.
45
+ (record_expression (constructor_path (upper_identifier) @type .))
46
+
47
+ (function_declaration name: (lower_identifier) @function)
48
+ (local_function name: (lower_identifier) @function)
49
+ (call_expression function: (lower_identifier) @function)
50
+ (member_expression member: (lower_identifier) @property)
51
+ (call_expression function: (member_expression member: (lower_identifier) @function.method))
52
+ (field_declaration name: (lower_identifier) @property)
53
+ (payload_field name: (lower_identifier) @property)
54
+ (record_entry name: (lower_identifier) @property)
55
+ (field_pattern . (lower_identifier) @property)
56
+ (typed_parameter pattern: (lower_identifier) @variable.parameter)
57
+ (parameter pattern: (lower_identifier) @variable.parameter)
58
+ (named_argument name: (lower_identifier) @variable.parameter)
59
+ (annotation "@" @attribute (lower_identifier) @attribute)
60
+ ; `@lang(int, data)` names lang keys; `@fake(model.chat)` names a Tool by its
61
+ ; module.
62
+ (annotation_argument (lower_identifier) @attribute)
63
+ (annotation_argument (lower_identifier) @namespace . (lower_identifier))
64
+ (annotation_argument (lower_identifier) (lower_identifier) @function .)
65
+
66
+ ["flow" "type" "pub" "opaque" "let" "use" "as"] @keyword
67
+ ["match" "if" "else" "guard" "return"] @keyword.control
68
+ ["=" "=>" "->" "?" "!" "|" "+" "-" "*" "/" "%" "==" "!=" "<" "<=" ">" ">=" "&&" "||" ".."] @operator
69
+ ["(" ")" "[" "]" "{" "}"] @punctuation.bracket
70
+ ["," ":" "."] @punctuation.delimiter
71
+ (type_parameters ["<" ">"] @punctuation.bracket)
72
+ (type_arguments ["<" ">"] @punctuation.bracket)
73
+ ; The wildcard pattern binds nothing, and `()` is the unit value, a literal.
74
+ "_" @variable.special
75
+ (unit_expression ["(" ")"] @constant.builtin)
76
+ ; After the bracket rules, so the braces of `${…}` keep this style.
77
+ (interpolation "${" @punctuation.special "}" @punctuation.special)
@@ -0,0 +1,2 @@
1
+ [(block) (type_body) (record_expression) (match_expression) (list_expression) (dict_expression)] @indent
2
+ ["}" "]" ")"] @outdent
@@ -0,0 +1,5 @@
1
+ ; A doc comment's text is Markdown. Its lines form one document, so a fenced
2
+ ; ```flow block across them is highlighted as Flow.
3
+ ((doc_text) @injection.content
4
+ (#set! injection.language "markdown")
5
+ (#set! injection.combined))
@@ -0,0 +1,4 @@
1
+ (function_declaration "flow" @context name: (lower_identifier) @name) @item
2
+ (local_function "flow" @context name: (lower_identifier) @name) @item
3
+ (type_declaration "type" @context name: (upper_identifier) @name) @item
4
+ (local_type "type" @context name: (upper_identifier) @name) @item
@@ -0,0 +1,23 @@
1
+ ; Run buttons for Zed's gutter. Each tag names the tasks
2
+ ; editors/zed/languages/flow/tasks.json binds to it.
3
+
4
+ ; The program's entry: `flow run` starts at `main`.
5
+ ((source_file
6
+ (function_declaration
7
+ name: (lower_identifier) @run @_entry))
8
+ (#eq? @_entry "main")
9
+ (#set! tag flow-main))
10
+
11
+ ; A `@test` function, after any other annotations and comments between them.
12
+ ; `@flow_test` is its name, which Zed gives the task as $ZED_CUSTOM_flow_test,
13
+ ; so the button runs this test alone.
14
+ ((source_file
15
+ (annotation
16
+ (lower_identifier) @_annotation)
17
+ .
18
+ [(annotation) (comment)]*
19
+ .
20
+ (function_declaration
21
+ name: (lower_identifier) @run @flow_test))
22
+ (#eq? @_annotation "test")
23
+ (#set! tag flow-test))
@@ -0,0 +1,37 @@
1
+ ; Text objects for Zed's vim mode: `af`/`if` select a function, `ac`/`ic` a
2
+ ; type declaration, `gc` a run of comments, and `]m`/`[m`, `]]`/`[[` move
3
+ ; between them.
4
+
5
+ ; A function's body is one expression. A block's inside is what its braces
6
+ ; hold; any other body is its own inside. Only a block starts with `{`.
7
+ (function_declaration
8
+ body: (block "{" (_)* @function.inside "}")) @function.around
9
+ (function_declaration
10
+ body: (_) @function.inside
11
+ (#not-match? @function.inside "^\\{")) @function.around
12
+ ; A Tool or `@lang` declaration has no body.
13
+ (function_declaration) @function.around
14
+ (local_function
15
+ body: (block "{" (_)* @function.inside "}")) @function.around
16
+ (local_function
17
+ body: (_) @function.inside
18
+ (#not-match? @function.inside "^\\{")) @function.around
19
+ ; An anonymous function's body is its last child.
20
+ (anonymous_function
21
+ (block "{" (_)* @function.inside "}") .) @function.around
22
+ (anonymous_function
23
+ (_) @function.inside .
24
+ (#not-match? @function.inside "^\\{")) @function.around
25
+ (anonymous_function) @function.around
26
+
27
+ ; A type's inside is what its braces or parentheses hold; an alias has none.
28
+ (type_declaration
29
+ (type_body ["{" "("] (_)* @class.inside ["}" ")"])) @class.around
30
+ (type_declaration) @class.around
31
+ (local_type
32
+ (type_body ["{" "("] (_)* @class.inside ["}" ")"])) @class.around
33
+ (local_type) @class.around
34
+
35
+ (comment)+ @comment.around
36
+ (doc_comment)+ @comment.around
37
+ (doc_comment (doc_text) @comment.inside)