@mermanjs/tree-sitter-mermaid 0.1.0 → 0.2.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/CMakeLists.txt +1 -1
- package/Makefile +1 -1
- package/README.md +32 -10
- package/THIRD_PARTY_NOTICES.md +7 -0
- package/grammar/families/agentflow.js +121 -0
- package/grammar/families/usecase.js +263 -0
- package/grammar.js +8 -0
- package/metadata/derivations.json +57 -0
- package/metadata/provenance.json +14 -3
- package/package.json +7 -3
- package/prebuilds/darwin-arm64/@mermanjs+tree-sitter-mermaid.node +0 -0
- package/prebuilds/darwin-x64/@mermanjs+tree-sitter-mermaid.node +0 -0
- package/prebuilds/linux-x64/@mermanjs+tree-sitter-mermaid.node +0 -0
- package/prebuilds/win32-x64/@mermanjs+tree-sitter-mermaid.node +0 -0
- package/queries/portable/highlights.scm +71 -0
- package/queries/portable/tags.scm +21 -0
- package/queries/zed/highlights.scm +71 -0
- package/src/grammar.json +6750 -12
- package/src/node-types.json +6927 -3358
- package/src/parser.c +204468 -183432
- package/tree-sitter-mermaid.wasm +0 -0
- package/tree-sitter.json +1 -1
package/CMakeLists.txt
CHANGED
package/Makefile
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# tree-sitter-mermaid
|
|
2
2
|
|
|
3
|
+
[](https://crates.io/crates/tree-sitter-mermaid) [](https://www.npmjs.com/package/@mermanjs/tree-sitter-mermaid) [](#license-and-provenance)
|
|
4
|
+
|
|
3
5
|
A tolerant, incremental [Tree-sitter] grammar for Mermaid source. It provides structured concrete
|
|
4
|
-
syntax trees and editor queries for
|
|
5
|
-
|
|
6
|
+
syntax trees and editor queries for 37 public diagram families: the original 35-family Mermaid
|
|
7
|
+
11.16.1 syntax baseline, plus Agentflow and Usecase from Mermaid 12.0.0. The ZenUML integration
|
|
8
|
+
follows ZenUML Core 3.50.1.
|
|
6
9
|
|
|
7
10
|
Use this package for syntax highlighting, syntax-aware selection, folding, and other editor features
|
|
8
11
|
that must keep working while a document is incomplete. Use [`@mermanjs/web`] or the Merman Rust
|
|
@@ -17,18 +20,30 @@ accept or render the document.
|
|
|
17
20
|
| Node.js | [`@mermanjs/tree-sitter-mermaid`] | Native Node binding, TypeScript declarations, queries, and language WASM |
|
|
18
21
|
| Browser or Worker | [`@mermanjs/tree-sitter-mermaid`] + [`web-tree-sitter`] | Language WASM and portable queries for the generic browser runtime |
|
|
19
22
|
| Rust | [`tree-sitter-mermaid`] | `LANGUAGE`, `NODE_TYPES`, and the portable queries |
|
|
20
|
-
| C/C++ and editors | [GitHub Release]
|
|
23
|
+
| C/C++ and editors | Repository source, or a matching [GitHub Release] when available | Generated C parser/scanner, public header, Make, CMake, and pkg-config metadata |
|
|
21
24
|
|
|
22
25
|
The grammar has its own version line, independent of Merman. Its npm and Cargo artifacts share that
|
|
23
26
|
grammar version, but their registry names differ: the npm package is scoped under `@mermanjs`, while
|
|
24
27
|
the Rust crate and C library retain the standard `tree-sitter-mermaid` name.
|
|
25
28
|
|
|
29
|
+
The version-pinned examples below target `0.2.0`, which adds Agentflow and Usecase to the `0.1.0` family catalog. Custom query consumers should review the [migration guide](https://github.com/Latias94/merman/blob/main/distribution/tree-sitter-mermaid/docs/query-migration.md).
|
|
30
|
+
|
|
26
31
|
## Node.js
|
|
27
32
|
|
|
28
33
|
```console
|
|
29
|
-
npm install tree-sitter @mermanjs/tree-sitter-mermaid
|
|
34
|
+
npm install tree-sitter@0.25.1 @mermanjs/tree-sitter-mermaid@0.2.0
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
With npm 12 or later, review and approve the native install scripts, then rebuild:
|
|
38
|
+
|
|
39
|
+
```console
|
|
40
|
+
npm install-scripts approve tree-sitter @mermanjs/tree-sitter-mermaid
|
|
41
|
+
npm rebuild tree-sitter @mermanjs/tree-sitter-mermaid
|
|
30
42
|
```
|
|
31
43
|
|
|
44
|
+
Commit the resulting `allowScripts` entries in your application's `package.json` so subsequent
|
|
45
|
+
installs use the same version-specific approvals. Browser-only consumers do not need native scripts.
|
|
46
|
+
|
|
32
47
|
```js
|
|
33
48
|
const Parser = require('tree-sitter');
|
|
34
49
|
const Mermaid = require('@mermanjs/tree-sitter-mermaid');
|
|
@@ -53,7 +68,7 @@ import Mermaid from '@mermanjs/tree-sitter-mermaid';
|
|
|
53
68
|
## Browser and Workers
|
|
54
69
|
|
|
55
70
|
```console
|
|
56
|
-
npm install web-tree-sitter @mermanjs/tree-sitter-mermaid
|
|
71
|
+
npm install web-tree-sitter@0.27.0 @mermanjs/tree-sitter-mermaid@0.2.0
|
|
57
72
|
```
|
|
58
73
|
|
|
59
74
|
The package exports `@mermanjs/tree-sitter-mermaid/tree-sitter-mermaid.wasm`. Copy that asset to a
|
|
@@ -74,7 +89,7 @@ A no-build browser prototype can pin the exact grammar version on jsDelivr:
|
|
|
74
89
|
|
|
75
90
|
```js
|
|
76
91
|
const language = await Language.load(
|
|
77
|
-
'https://cdn.jsdelivr.net/npm/@mermanjs/tree-sitter-mermaid@0.
|
|
92
|
+
'https://cdn.jsdelivr.net/npm/@mermanjs/tree-sitter-mermaid@0.2.0/tree-sitter-mermaid.wasm',
|
|
78
93
|
);
|
|
79
94
|
```
|
|
80
95
|
|
|
@@ -86,7 +101,7 @@ diagnostics, completion, navigation, and rename.
|
|
|
86
101
|
## Rust
|
|
87
102
|
|
|
88
103
|
```console
|
|
89
|
-
cargo add tree-sitter tree-sitter-mermaid
|
|
104
|
+
cargo add tree-sitter@=0.26.12 tree-sitter-mermaid@=0.2.0
|
|
90
105
|
```
|
|
91
106
|
|
|
92
107
|
```rust
|
|
@@ -132,10 +147,12 @@ int main(void) {
|
|
|
132
147
|
|
|
133
148
|
| Contract | Version |
|
|
134
149
|
| --- | --- |
|
|
135
|
-
| Mermaid syntax baseline | 11.16.1 |
|
|
150
|
+
| Original 35-family Mermaid syntax baseline | 11.16.1 |
|
|
151
|
+
| Agentflow and Usecase syntax | 12.0.0 |
|
|
136
152
|
| ZenUML Core syntax baseline | 3.50.1 |
|
|
137
153
|
| Tree-sitter language ABI | 15 |
|
|
138
|
-
| Tested Rust
|
|
154
|
+
| Tested Rust runtime | 0.26.12 |
|
|
155
|
+
| Tested Web runtime | 0.27.0 |
|
|
139
156
|
| Native Node runtime contract | 0.25.x |
|
|
140
157
|
|
|
141
158
|
Before 1.0, a minor release may change named nodes, fields, canonical captures, the language ABI, or
|
|
@@ -165,6 +182,10 @@ npm ci --ignore-scripts --prefix distribution/tree-sitter-mermaid
|
|
|
165
182
|
npm rebuild tree-sitter-cli --prefix distribution/tree-sitter-mermaid
|
|
166
183
|
```
|
|
167
184
|
|
|
185
|
+
The package manifest approves only the pinned Tree-sitter CLI and native runtime install scripts.
|
|
186
|
+
`--ignore-scripts` still suppresses them during the initial install; the explicit rebuild downloads
|
|
187
|
+
the CLI executable.
|
|
188
|
+
|
|
168
189
|
Run the ordinary grammar and binding checks:
|
|
169
190
|
|
|
170
191
|
```console
|
|
@@ -189,7 +210,8 @@ publication details.
|
|
|
189
210
|
|
|
190
211
|
The package is MIT licensed. Source-derived syntax and template attributions are recorded in
|
|
191
212
|
`metadata/provenance.json`, `metadata/derivations.json`, `THIRD_PARTY_NOTICES.md`, and
|
|
192
|
-
`THIRD_PARTY_LICENSES/`.
|
|
213
|
+
`THIRD_PARTY_LICENSES/`. The added families have their own pinned source identity; adding them
|
|
214
|
+
does not relabel the existing family translations as Mermaid 12.0.0.
|
|
193
215
|
|
|
194
216
|
[Tree-sitter]: https://tree-sitter.github.io/tree-sitter/
|
|
195
217
|
[`@mermanjs/web`]: https://www.npmjs.com/package/@mermanjs/web
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -18,6 +18,13 @@ MIT-licensed projects. The corresponding license texts are included below
|
|
|
18
18
|
- Use: accepted Mermaid syntax, source-backed grammar translation, and representative fixtures
|
|
19
19
|
- License: `THIRD_PARTY_LICENSES/mermaid/LICENSE`
|
|
20
20
|
|
|
21
|
+
## Mermaid 12.0.0 (Agentflow and Usecase additions)
|
|
22
|
+
|
|
23
|
+
- Source: https://github.com/mermaid-js/mermaid.git
|
|
24
|
+
- Commit: `98a0945418c76238f15df2afaddbba4272656c3b`
|
|
25
|
+
- Use: Agentflow and Usecase grammar translation and source-backed editor corpus cases; existing families retain the Mermaid 11.16.1 source identity above
|
|
26
|
+
- License: `THIRD_PARTY_LICENSES/mermaid/LICENSE`
|
|
27
|
+
|
|
21
28
|
## ZenUML Core 3.50.1
|
|
22
29
|
|
|
23
30
|
- Source: https://github.com/mermaid-js/zenuml-core.git
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Source translation: Mermaid 12.0.0
|
|
2
|
+
// packages/mermaid/src/diagrams/agentflow/parser/agentflow.jison
|
|
3
|
+
// commit 98a0945418c76238f15df2afaddbba4272656c3b.
|
|
4
|
+
//
|
|
5
|
+
// Agentflow shares Flowchart's vertices and presentation commands, but owns its
|
|
6
|
+
// container vocabulary and edge operators. Shape data is YAML, including block
|
|
7
|
+
// scalars and indentation-sensitive mappings. Preserve that scoped payload without
|
|
8
|
+
// pretending to parse a subset of YAML; metadata and graph validation stay in Core.
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
createFlowFamilyConflicts,
|
|
12
|
+
createFlowFamilyRules,
|
|
13
|
+
} = require('./flowchart');
|
|
14
|
+
|
|
15
|
+
const sharedRules = createFlowFamilyRules({
|
|
16
|
+
prefix: 'agentflow',
|
|
17
|
+
diagram: 'agentflow_diagram',
|
|
18
|
+
header: 'agentflow_header',
|
|
19
|
+
headerEof: '_agentflow_header_eof',
|
|
20
|
+
keywords: ['agentflow-beta'],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const keyword = ($, value) => field(
|
|
24
|
+
'keyword',
|
|
25
|
+
alias(token(prec(30, value)), $.agentflow_statement_keyword),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const containerIdentity = ($) => seq(
|
|
29
|
+
field('id', choice(
|
|
30
|
+
alias($.agentflow_identifier, $.agentflow_node_id),
|
|
31
|
+
$.agentflow_quoted_label,
|
|
32
|
+
$.agentflow_markdown_label,
|
|
33
|
+
$.agentflow_container_title,
|
|
34
|
+
)),
|
|
35
|
+
optional(field('label', $.agentflow_square_label)),
|
|
36
|
+
optional(field('data', $.agentflow_shape_data)),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const agentflowRules = {
|
|
40
|
+
...sharedRules,
|
|
41
|
+
|
|
42
|
+
agentflow_statement: ($) => choice(
|
|
43
|
+
$.agentflow_flow_statement,
|
|
44
|
+
$.agentflow_global_statement,
|
|
45
|
+
$.agentflow_connector_statement,
|
|
46
|
+
$.agentflow_edge_statement,
|
|
47
|
+
$.agentflow_node_statement,
|
|
48
|
+
$.agentflow_direction_statement,
|
|
49
|
+
$.agentflow_class_definition_statement,
|
|
50
|
+
$.agentflow_class_assignment_statement,
|
|
51
|
+
$.agentflow_style_statement,
|
|
52
|
+
$.agentflow_link_style_statement,
|
|
53
|
+
$.agentflow_click_statement,
|
|
54
|
+
$.agentflow_accessibility_title_statement,
|
|
55
|
+
$.agentflow_accessibility_description_statement,
|
|
56
|
+
),
|
|
57
|
+
|
|
58
|
+
agentflow_flow_statement: ($) => prec.right(50, seq(
|
|
59
|
+
keyword($, 'flow'),
|
|
60
|
+
optional(containerIdentity($)),
|
|
61
|
+
field('terminator', $._statement_terminator),
|
|
62
|
+
repeat($.agentflow_line_item),
|
|
63
|
+
field('end', $.agentflow_end_statement),
|
|
64
|
+
)),
|
|
65
|
+
|
|
66
|
+
agentflow_global_statement: ($) => prec.right(50, seq(
|
|
67
|
+
keyword($, 'global'),
|
|
68
|
+
field('terminator', $._statement_terminator),
|
|
69
|
+
repeat($.agentflow_line_item),
|
|
70
|
+
field('end', $.agentflow_end_statement),
|
|
71
|
+
)),
|
|
72
|
+
|
|
73
|
+
agentflow_connector_statement: ($) => seq(
|
|
74
|
+
keyword($, 'connector'),
|
|
75
|
+
containerIdentity($),
|
|
76
|
+
),
|
|
77
|
+
|
|
78
|
+
agentflow_container_title: (_) => token(prec(
|
|
79
|
+
10,
|
|
80
|
+
/[^;%\[\]@\s\r\n](?:[^;%\[\]@\r\n]*[ \t][^;%\[\]@\s\r\n][^;%\[\]@\r\n]*)/,
|
|
81
|
+
)),
|
|
82
|
+
|
|
83
|
+
agentflow_end_statement: ($) => keyword($, 'end'),
|
|
84
|
+
|
|
85
|
+
agentflow_identifier: ($) => choice(
|
|
86
|
+
sharedRules.agentflow_identifier($),
|
|
87
|
+
token(prec(
|
|
88
|
+
40,
|
|
89
|
+
/(?:flow|connector|global)(?:[A-Za-z0-9_.!?$%#\u00c0-\uffff]|-[A-Za-z0-9_\u00c0-\uffff])+/,
|
|
90
|
+
)),
|
|
91
|
+
),
|
|
92
|
+
|
|
93
|
+
agentflow_arrow_start: (_) => token(prec(20, '--')),
|
|
94
|
+
agentflow_continued_arrow_start: (_) => token(prec(25, /(?:\r\n|\n|\r)[ \t]*--/)),
|
|
95
|
+
agentflow_arrow: (_) => token(prec(20, /(?:--+[x>]|-\.+-)/)),
|
|
96
|
+
agentflow_continued_arrow: (_) => token(prec(25, /(?:\r\n|\n|\r)[ \t]*(?:--+[x>]|-\.+-)/)),
|
|
97
|
+
|
|
98
|
+
agentflow_shape_data: ($) => seq(
|
|
99
|
+
field('open', '@{'),
|
|
100
|
+
optional(field('content', $.agentflow_metadata_yaml)),
|
|
101
|
+
field('close', '}'),
|
|
102
|
+
),
|
|
103
|
+
|
|
104
|
+
// The upstream shapeData/shapeDataStr lexer preserves the YAML buffer and
|
|
105
|
+
// protects closing braces inside double-quoted strings. Apostrophes remain
|
|
106
|
+
// ordinary payload characters, including in plain scalars such as "don't".
|
|
107
|
+
agentflow_metadata_yaml: ($) => repeat1(choice(
|
|
108
|
+
$.agentflow_metadata_string,
|
|
109
|
+
$.agentflow_metadata_content,
|
|
110
|
+
)),
|
|
111
|
+
|
|
112
|
+
agentflow_metadata_string: (_) => token(prec(30,
|
|
113
|
+
seq('"', /(?:[^"\\]|\\.)*/, '"'),
|
|
114
|
+
)),
|
|
115
|
+
|
|
116
|
+
agentflow_metadata_content: (_) => token(prec(-20, /[^}"]+/)),
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const agentflowConflicts = ($) => createFlowFamilyConflicts($, 'agentflow');
|
|
120
|
+
|
|
121
|
+
module.exports = { agentflowConflicts, agentflowRules };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// Source translation: Mermaid 12.0.0, commit 98a0945418c76238f15df2afaddbba4272656c3b.
|
|
2
|
+
// packages/mermaid/src/diagrams/usecase/parser/usecase.{parser,tokens}.ts
|
|
3
|
+
// Semantic resolution and validation remain owned by Merman Core.
|
|
4
|
+
|
|
5
|
+
// Equal lexical precedence preserves upstream longer_alt: actorUser is one id.
|
|
6
|
+
const keyword = ($, text) => field(
|
|
7
|
+
'keyword', alias(token(text), $.usecase_statement_keyword),
|
|
8
|
+
);
|
|
9
|
+
const identifier = ($, name = 'id') => field(name, $.usecase_identifier);
|
|
10
|
+
const terminator = ($) => choice($._line_ending, $._end_of_input);
|
|
11
|
+
const list = (rule) => seq(rule, repeat(seq(',', rule)));
|
|
12
|
+
const operator = (text) => token(prec(30, text));
|
|
13
|
+
|
|
14
|
+
const usecaseRules = {
|
|
15
|
+
usecase_diagram: ($) => seq(
|
|
16
|
+
field('header', $.usecase_header),
|
|
17
|
+
optional(field('body', $.usecase_body)),
|
|
18
|
+
),
|
|
19
|
+
|
|
20
|
+
usecase_header: ($) => seq(
|
|
21
|
+
field('keyword', alias(token(prec(50, 'usecase-beta')), $.diagram_keyword)),
|
|
22
|
+
terminator($),
|
|
23
|
+
),
|
|
24
|
+
|
|
25
|
+
usecase_body: ($) => repeat1(choice(
|
|
26
|
+
seq($._usecase_statement, terminator($)),
|
|
27
|
+
seq($.comment, terminator($)),
|
|
28
|
+
$._blank_line,
|
|
29
|
+
)),
|
|
30
|
+
|
|
31
|
+
_usecase_statement: ($) => choice(
|
|
32
|
+
$.usecase_actor_statement,
|
|
33
|
+
$.usecase_node_statement,
|
|
34
|
+
$.usecase_edge_statement,
|
|
35
|
+
$.usecase_boundary_statement,
|
|
36
|
+
$.usecase_note_statement,
|
|
37
|
+
$.usecase_json_statement,
|
|
38
|
+
$.usecase_direction_statement,
|
|
39
|
+
$.usecase_class_definition_statement,
|
|
40
|
+
$.usecase_class_statement,
|
|
41
|
+
$.usecase_style_statement,
|
|
42
|
+
$.usecase_accessibility_title_statement,
|
|
43
|
+
$.usecase_accessibility_description_statement,
|
|
44
|
+
),
|
|
45
|
+
|
|
46
|
+
// Upstream identifiers are ASCII word characters, including digit-leading ids.
|
|
47
|
+
usecase_identifier: (_) => token(/\w+/),
|
|
48
|
+
|
|
49
|
+
usecase_actor_statement: ($) => seq(
|
|
50
|
+
keyword($, 'actor'),
|
|
51
|
+
list($.usecase_actor),
|
|
52
|
+
),
|
|
53
|
+
|
|
54
|
+
usecase_actor: ($) => seq(
|
|
55
|
+
choice(
|
|
56
|
+
seq(identifier($), optional($.usecase_actor_label)),
|
|
57
|
+
field('label', $.usecase_string),
|
|
58
|
+
),
|
|
59
|
+
optional(field('metadata', $.usecase_metadata)),
|
|
60
|
+
optional(field('stereotype', $.usecase_stereotype)),
|
|
61
|
+
optional(field('classes', $.usecase_class_suffix)),
|
|
62
|
+
),
|
|
63
|
+
|
|
64
|
+
usecase_actor_label: ($) => seq('(', field('text', $.usecase_label), ')'),
|
|
65
|
+
|
|
66
|
+
usecase_node_statement: ($) => field('node', $.usecase_node),
|
|
67
|
+
|
|
68
|
+
usecase_node: ($) => seq(
|
|
69
|
+
$._usecase_node_name,
|
|
70
|
+
optional(field('metadata', $.usecase_metadata)),
|
|
71
|
+
optional(field('stereotype', $.usecase_stereotype)),
|
|
72
|
+
optional(field('classes', $.usecase_class_suffix)),
|
|
73
|
+
),
|
|
74
|
+
|
|
75
|
+
_usecase_node_name: ($) => choice(
|
|
76
|
+
seq(identifier($), optional(field('label', $.usecase_node_label))),
|
|
77
|
+
field('label', $.usecase_string),
|
|
78
|
+
),
|
|
79
|
+
|
|
80
|
+
usecase_node_label: ($) => choice(
|
|
81
|
+
seq('(', field('text', $.usecase_label), ')'),
|
|
82
|
+
seq('[', field('text', $.usecase_label), ']'),
|
|
83
|
+
),
|
|
84
|
+
|
|
85
|
+
usecase_label: ($) => choice(
|
|
86
|
+
$.usecase_string,
|
|
87
|
+
repeat1($._usecase_label_component),
|
|
88
|
+
),
|
|
89
|
+
|
|
90
|
+
_usecase_label_component: ($) => choice(
|
|
91
|
+
$.usecase_identifier,
|
|
92
|
+
alias(token(/[^\t\r\n !-~]+/), $.usecase_label_text),
|
|
93
|
+
alias(token(/(?:\d+\.\d+|\.\d+)(?:[A-Za-z]+)?/), $.usecase_label_text),
|
|
94
|
+
alias(token(/[!#$%&*+,./:;=?^_|~\\`-]/), $.usecase_label_text),
|
|
95
|
+
alias('@', $.usecase_label_text),
|
|
96
|
+
alias(token(prec(-1, choice('<', '>'))), $.usecase_label_text),
|
|
97
|
+
),
|
|
98
|
+
|
|
99
|
+
// Plain strings have no escape processing upstream; markdown strings may span lines.
|
|
100
|
+
usecase_string: (_) => token(choice(
|
|
101
|
+
/"[^"\r\n]*"/,
|
|
102
|
+
/'[^'\r\n]*'/,
|
|
103
|
+
/"`(?:[^`]|`[^"])*`"/,
|
|
104
|
+
)),
|
|
105
|
+
|
|
106
|
+
usecase_stereotype: ($) => seq(
|
|
107
|
+
'<<', field('text', alias(token(/(?:[^>\r\n]|>[^>\r\n])+/), $.usecase_stereotype_text)), '>>',
|
|
108
|
+
),
|
|
109
|
+
|
|
110
|
+
usecase_class_suffix: ($) => prec.right(seq(':::', list(identifier($, 'class')))),
|
|
111
|
+
|
|
112
|
+
usecase_metadata: ($) => seq(
|
|
113
|
+
'@{', repeat($._line_ending),
|
|
114
|
+
optional(seq(
|
|
115
|
+
$.usecase_metadata_property,
|
|
116
|
+
repeat(seq($._usecase_metadata_separator, $.usecase_metadata_property)),
|
|
117
|
+
optional(','), repeat($._line_ending),
|
|
118
|
+
)),
|
|
119
|
+
'}',
|
|
120
|
+
),
|
|
121
|
+
|
|
122
|
+
usecase_metadata_property: ($) => seq(
|
|
123
|
+
field('key', choice($.usecase_identifier, $.usecase_string)), ':',
|
|
124
|
+
field('value', choice($.usecase_identifier, $.usecase_string)),
|
|
125
|
+
),
|
|
126
|
+
|
|
127
|
+
_usecase_metadata_separator: ($) => choice(
|
|
128
|
+
seq(',', repeat($._line_ending)),
|
|
129
|
+
seq(repeat1($._line_ending), optional(seq(',', repeat($._line_ending)))),
|
|
130
|
+
),
|
|
131
|
+
|
|
132
|
+
usecase_edge_statement: ($) => seq(
|
|
133
|
+
choice(
|
|
134
|
+
field('source', $.usecase_node),
|
|
135
|
+
seq(keyword($, 'actor'), field('source', $.usecase_actor)),
|
|
136
|
+
),
|
|
137
|
+
optional(seq(identifier($, 'edge_id'), '@')),
|
|
138
|
+
field('operator', $.usecase_operator),
|
|
139
|
+
field('target', $.usecase_node),
|
|
140
|
+
),
|
|
141
|
+
|
|
142
|
+
usecase_operator: ($) => choice(
|
|
143
|
+
operator(/--+>/),
|
|
144
|
+
operator('<--'), operator(/<---+/),
|
|
145
|
+
operator('--'), operator(/---+/),
|
|
146
|
+
operator('--o'), operator('o--'), operator('--x'), operator('x--'), operator('--|>'),
|
|
147
|
+
seq(operator('..>'), ':', field('relation', alias(token(/include|extend/i), $.usecase_relation_kind))),
|
|
148
|
+
seq(
|
|
149
|
+
operator('--'), field('label', $.usecase_edge_label),
|
|
150
|
+
choice(operator(/--+>/), operator('--'), operator(/---+/), operator('--o'), operator('--x')),
|
|
151
|
+
),
|
|
152
|
+
seq(
|
|
153
|
+
choice(operator('<--'), operator('o--'), operator('x--')),
|
|
154
|
+
field('label', $.usecase_edge_label), choice(operator('--'), operator(/---+/)),
|
|
155
|
+
),
|
|
156
|
+
),
|
|
157
|
+
|
|
158
|
+
usecase_edge_label: ($) => $.usecase_label,
|
|
159
|
+
|
|
160
|
+
usecase_boundary_statement: ($) => seq(
|
|
161
|
+
keyword($, 'systemBoundary'),
|
|
162
|
+
$._usecase_node_name,
|
|
163
|
+
optional(field('metadata', $.usecase_metadata)),
|
|
164
|
+
optional(field('classes', $.usecase_class_suffix)),
|
|
165
|
+
$._line_ending,
|
|
166
|
+
optional(field('body', $.usecase_boundary_body)),
|
|
167
|
+
field('end', $.usecase_end_statement),
|
|
168
|
+
),
|
|
169
|
+
|
|
170
|
+
usecase_boundary_body: ($) => repeat1(choice(
|
|
171
|
+
seq(choice($.usecase_actor_statement, $.usecase_node_statement), $._line_ending),
|
|
172
|
+
seq($.comment, $._line_ending),
|
|
173
|
+
$._blank_line,
|
|
174
|
+
)),
|
|
175
|
+
|
|
176
|
+
usecase_end_statement: ($) => keyword($, 'end'),
|
|
177
|
+
|
|
178
|
+
usecase_note_statement: ($) => seq(
|
|
179
|
+
keyword($, 'note'), keyword($, 'for'), identifier($, 'target'),
|
|
180
|
+
field('label', $.usecase_label),
|
|
181
|
+
),
|
|
182
|
+
|
|
183
|
+
usecase_json_statement: ($) => seq(
|
|
184
|
+
keyword($, 'json'), identifier($), '@',
|
|
185
|
+
field('value', $.usecase_json_object),
|
|
186
|
+
optional(field('classes', $.usecase_class_suffix)),
|
|
187
|
+
),
|
|
188
|
+
|
|
189
|
+
// Keep nested JSON structural rather than consuming through the next closing brace.
|
|
190
|
+
usecase_json_object: ($) => seq(
|
|
191
|
+
'{', repeat($._line_ending),
|
|
192
|
+
optional(seq(
|
|
193
|
+
$.usecase_json_property,
|
|
194
|
+
repeat(seq(',', repeat($._line_ending), $.usecase_json_property)),
|
|
195
|
+
)), '}',
|
|
196
|
+
),
|
|
197
|
+
|
|
198
|
+
usecase_json_property: ($) => seq(
|
|
199
|
+
field('key', $.usecase_json_string), ':', repeat($._line_ending),
|
|
200
|
+
field('value', $._usecase_json_value), repeat($._line_ending),
|
|
201
|
+
),
|
|
202
|
+
|
|
203
|
+
_usecase_json_value: ($) => choice(
|
|
204
|
+
$.usecase_json_object, $.usecase_json_array, $.usecase_json_string,
|
|
205
|
+
$.usecase_json_number, $.usecase_json_literal,
|
|
206
|
+
),
|
|
207
|
+
|
|
208
|
+
usecase_json_string: (_) => token(/"(?:[^"\\\x00-\x1f]|\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4}))*"/),
|
|
209
|
+
usecase_json_number: (_) => token(/-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/),
|
|
210
|
+
usecase_json_literal: (_) => choice('true', 'false', 'null'),
|
|
211
|
+
|
|
212
|
+
usecase_json_array: ($) => seq(
|
|
213
|
+
'[', repeat($._line_ending),
|
|
214
|
+
optional(seq(
|
|
215
|
+
$._usecase_json_value, repeat($._line_ending),
|
|
216
|
+
repeat(seq(',', repeat($._line_ending), $._usecase_json_value, repeat($._line_ending))),
|
|
217
|
+
)), ']',
|
|
218
|
+
),
|
|
219
|
+
|
|
220
|
+
usecase_direction_statement: ($) => seq(
|
|
221
|
+
keyword($, 'direction'), field('direction', alias(choice('TD', 'TB', 'BT', 'LR', 'RL'), $.direction)),
|
|
222
|
+
),
|
|
223
|
+
|
|
224
|
+
usecase_class_definition_statement: ($) => seq(
|
|
225
|
+
keyword($, 'classDef'), list(identifier($, 'class')), $.usecase_styles,
|
|
226
|
+
),
|
|
227
|
+
|
|
228
|
+
usecase_class_statement: ($) => seq(
|
|
229
|
+
keyword($, 'class'), list(identifier($, 'target')), list(identifier($, 'class')),
|
|
230
|
+
),
|
|
231
|
+
|
|
232
|
+
usecase_style_statement: ($) => seq(
|
|
233
|
+
keyword($, 'style'), identifier($, 'target'), $.usecase_styles,
|
|
234
|
+
),
|
|
235
|
+
|
|
236
|
+
usecase_styles: ($) => list($.usecase_style_property),
|
|
237
|
+
|
|
238
|
+
usecase_style_property: ($) => seq(
|
|
239
|
+
field('key', alias(token(/(?:--)?[A-Za-z_][\w-]*/), $.usecase_style_name)), ':',
|
|
240
|
+
field('value', $.usecase_style_value),
|
|
241
|
+
),
|
|
242
|
+
|
|
243
|
+
usecase_style_value: (_) => token(/(?:\\,|[^,\r\n])+/),
|
|
244
|
+
|
|
245
|
+
usecase_accessibility_title_statement: ($) => seq(
|
|
246
|
+
keyword($, 'accTitle'), ':', optional(field('text', $.usecase_accessibility_text)),
|
|
247
|
+
),
|
|
248
|
+
|
|
249
|
+
usecase_accessibility_description_statement: ($) => seq(
|
|
250
|
+
keyword($, 'accDescr'), choice(
|
|
251
|
+
seq(':', optional(field('text', $.usecase_accessibility_text))),
|
|
252
|
+
seq('{', optional(field('text', alias(token(/[^}]+/), $.usecase_accessibility_text))), '}'),
|
|
253
|
+
),
|
|
254
|
+
),
|
|
255
|
+
|
|
256
|
+
usecase_accessibility_text: (_) => token(/[^\r\n]+/),
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const usecaseConflicts = ($) => [
|
|
260
|
+
[$.usecase_operator],
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
module.exports = { usecaseConflicts, usecaseRules };
|
package/grammar.js
CHANGED
|
@@ -69,6 +69,8 @@ const {
|
|
|
69
69
|
xyChartConflicts,
|
|
70
70
|
xyChartRules,
|
|
71
71
|
} = require('./grammar/families/xy-chart');
|
|
72
|
+
const { agentflowConflicts, agentflowRules } = require('./grammar/families/agentflow');
|
|
73
|
+
const { usecaseConflicts, usecaseRules } = require('./grammar/families/usecase');
|
|
72
74
|
const { indentationExternals } = require('./grammar/shared/indentation');
|
|
73
75
|
|
|
74
76
|
module.exports = grammar({
|
|
@@ -86,6 +88,8 @@ module.exports = grammar({
|
|
|
86
88
|
|
|
87
89
|
conflicts: ($) => [
|
|
88
90
|
...commonConflicts($),
|
|
91
|
+
...agentflowConflicts($),
|
|
92
|
+
...usecaseConflicts($),
|
|
89
93
|
...langiumConflicts($),
|
|
90
94
|
...architectureConflicts($),
|
|
91
95
|
...blockConflicts($),
|
|
@@ -142,6 +146,8 @@ module.exports = grammar({
|
|
|
142
146
|
$.timeline_diagram,
|
|
143
147
|
$.wardley_diagram,
|
|
144
148
|
$.xy_chart_diagram,
|
|
149
|
+
$.usecase_diagram,
|
|
150
|
+
$.agentflow_diagram,
|
|
145
151
|
)),
|
|
146
152
|
),
|
|
147
153
|
|
|
@@ -184,5 +190,7 @@ module.exports = grammar({
|
|
|
184
190
|
...kanbanRules,
|
|
185
191
|
...treemapRules,
|
|
186
192
|
...treeViewRules,
|
|
193
|
+
...agentflowRules,
|
|
194
|
+
...usecaseRules,
|
|
187
195
|
},
|
|
188
196
|
});
|
|
@@ -54,6 +54,63 @@
|
|
|
54
54
|
}
|
|
55
55
|
]
|
|
56
56
|
},
|
|
57
|
+
{
|
|
58
|
+
"localPaths": [
|
|
59
|
+
"grammar/families/agentflow.js",
|
|
60
|
+
"test/corpus/families/agentflow.txt"
|
|
61
|
+
],
|
|
62
|
+
"localSymbols": [
|
|
63
|
+
"agentflowRules",
|
|
64
|
+
"agentflowConflicts"
|
|
65
|
+
],
|
|
66
|
+
"sources": [
|
|
67
|
+
{
|
|
68
|
+
"sourceId": "mermaid-12-new-families",
|
|
69
|
+
"relationship": "translated",
|
|
70
|
+
"sourcePaths": [
|
|
71
|
+
"packages/mermaid/src/diagrams/agentflow/afDetector.ts",
|
|
72
|
+
"packages/mermaid/src/diagrams/agentflow/parser/agentflow.jison",
|
|
73
|
+
"packages/mermaid/src/diagrams/agentflow/parser/agentflowParser.ts"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"sourceId": "pappasam-tree-sitter-mermaid",
|
|
78
|
+
"relationship": "modified",
|
|
79
|
+
"sourcePaths": [
|
|
80
|
+
"grammar.js:369-622"
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"sourceId": "mermaid",
|
|
85
|
+
"relationship": "translated",
|
|
86
|
+
"sourcePaths": [
|
|
87
|
+
"packages/mermaid/src/diagrams/flowchart/parser/flow.jison:1-635"
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"localPaths": [
|
|
94
|
+
"grammar/families/usecase.js",
|
|
95
|
+
"test/corpus/families/usecase.txt"
|
|
96
|
+
],
|
|
97
|
+
"localSymbols": [
|
|
98
|
+
"usecaseRules",
|
|
99
|
+
"usecaseConflicts"
|
|
100
|
+
],
|
|
101
|
+
"sources": [
|
|
102
|
+
{
|
|
103
|
+
"sourceId": "mermaid-12-new-families",
|
|
104
|
+
"relationship": "translated",
|
|
105
|
+
"sourcePaths": [
|
|
106
|
+
"packages/mermaid/src/diagrams/usecase/usecaseDetector.ts",
|
|
107
|
+
"packages/mermaid/src/diagrams/usecase/parser/usecase.parser.ts",
|
|
108
|
+
"packages/mermaid/src/diagrams/usecase/parser/usecase.tokens.ts",
|
|
109
|
+
"packages/mermaid/src/diagrams/usecase/parser/usecase.lexer.ts"
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
},
|
|
57
114
|
{
|
|
58
115
|
"localPaths": [
|
|
59
116
|
"grammar/families/architecture.js",
|
package/metadata/provenance.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"package": {
|
|
4
4
|
"name": "tree-sitter-mermaid",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.2.0",
|
|
6
6
|
"releaseState": "candidate"
|
|
7
7
|
},
|
|
8
8
|
"language": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"treeSitterCli": "0.26.12",
|
|
16
16
|
"rustRuntime": "0.26.12",
|
|
17
17
|
"nodeRuntime": "0.25.1",
|
|
18
|
-
"webRuntime": "0.
|
|
18
|
+
"webRuntime": "0.27.0",
|
|
19
19
|
"wasiSdk": "29.0",
|
|
20
20
|
"wasiClang": "21.1.4-wasi-sdk"
|
|
21
21
|
},
|
|
@@ -46,10 +46,21 @@
|
|
|
46
46
|
"repository": "https://github.com/mermaid-js/mermaid.git",
|
|
47
47
|
"ref": "mermaid@11.16.1",
|
|
48
48
|
"commit": "7ecca0cd7f1658ef74f4e7e91f925724ef403bbf",
|
|
49
|
-
"usage": "Accepted source syntax and source-backed grammar translation",
|
|
49
|
+
"usage": "Accepted source syntax and source-backed grammar translation for the original 35 diagram families",
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"legalComponentId": "tree-sitter-mermaid-mermaid-baseline"
|
|
52
52
|
},
|
|
53
|
+
{
|
|
54
|
+
"id": "mermaid-12-new-families",
|
|
55
|
+
"kind": "syntax-authority",
|
|
56
|
+
"version": "12.0.0",
|
|
57
|
+
"repository": "https://github.com/mermaid-js/mermaid.git",
|
|
58
|
+
"ref": "mermaid@12.0.0",
|
|
59
|
+
"commit": "98a0945418c76238f15df2afaddbba4272656c3b",
|
|
60
|
+
"usage": "Agentflow and Usecase syntax additions; the original 35-family syntax baseline remains Mermaid 11.16.1",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"legalComponentId": "tree-sitter-mermaid-mermaid-12-new-families"
|
|
63
|
+
},
|
|
53
64
|
{
|
|
54
65
|
"id": "zenuml-core",
|
|
55
66
|
"kind": "companion-syntax-authority",
|