@mermanjs/tree-sitter-mermaid 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  cmake_minimum_required(VERSION 3.13)
2
2
 
3
3
  project(tree-sitter-mermaid
4
- VERSION "0.1.0"
4
+ VERSION "0.3.0"
5
5
  DESCRIPTION "Tolerant Tree-sitter grammar and editor queries for Mermaid"
6
6
  HOMEPAGE_URL "https://github.com/Latias94/merman"
7
7
  LANGUAGES C)
package/Makefile CHANGED
@@ -5,7 +5,7 @@ endif
5
5
  LANGUAGE_NAME := tree-sitter-mermaid
6
6
  DESCRIPTION := Tolerant Tree-sitter grammar and editor queries for Mermaid
7
7
  HOMEPAGE_URL := https://github.com/Latias94/merman
8
- VERSION := 0.1.0
8
+ VERSION := 0.3.0
9
9
 
10
10
  SRC_DIR := src
11
11
  PARSER := $(SRC_DIR)/parser.c
package/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # tree-sitter-mermaid
2
2
 
3
+ [![crates.io](https://img.shields.io/crates/v/tree-sitter-mermaid.svg)](https://crates.io/crates/tree-sitter-mermaid) [![npm](https://img.shields.io/npm/v/%40mermanjs%2Ftree-sitter-mermaid.svg)](https://www.npmjs.com/package/@mermanjs/tree-sitter-mermaid) [![MIT license](https://img.shields.io/badge/license-MIT-59636e.svg)](#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 all 35 public diagram families in Mermaid 11.16.1, including
5
- the ZenUML integration backed by ZenUML Core 3.50.1.
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.
9
+ Sequence actor-menu names (`link`, `links`, `properties`, and `details`) also work as message
10
+ endpoints, following the focused Mermaid 12.1.0 lexer fix without changing the other families'
11
+ syntax baseline.
6
12
 
7
13
  Use this package for syntax highlighting, syntax-aware selection, folding, and other editor features
8
14
  that must keep working while a document is incomplete. Use [`@mermanjs/web`] or the Merman Rust
@@ -17,18 +23,30 @@ accept or render the document.
17
23
  | Node.js | [`@mermanjs/tree-sitter-mermaid`] | Native Node binding, TypeScript declarations, queries, and language WASM |
18
24
  | Browser or Worker | [`@mermanjs/tree-sitter-mermaid`] + [`web-tree-sitter`] | Language WASM and portable queries for the generic browser runtime |
19
25
  | Rust | [`tree-sitter-mermaid`] | `LANGUAGE`, `NODE_TYPES`, and the portable queries |
20
- | C/C++ and editors | [GitHub Release] or repository source | Generated C parser/scanner, public header, Make, CMake, and pkg-config metadata |
26
+ | 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
27
 
22
28
  The grammar has its own version line, independent of Merman. Its npm and Cargo artifacts share that
23
29
  grammar version, but their registry names differ: the npm package is scoped under `@mermanjs`, while
24
30
  the Rust crate and C library retain the standard `tree-sitter-mermaid` name.
25
31
 
32
+ This guide documents `0.3.0`, including the Mermaid 12.1 sequence endpoint fix and updated generator/runtime contract. Match the examples to the version installed in your project; earlier versions have their own tagged documentation. Custom query consumers should review the [migration guide](https://github.com/Latias94/merman/blob/main/distribution/tree-sitter-mermaid/docs/query-migration.md).
33
+
26
34
  ## Node.js
27
35
 
28
36
  ```console
29
- npm install tree-sitter @mermanjs/tree-sitter-mermaid
37
+ npm install tree-sitter@0.25.1 @mermanjs/tree-sitter-mermaid@0.3.0
38
+ ```
39
+
40
+ With npm 12 or later, review and approve the native install scripts, then rebuild:
41
+
42
+ ```console
43
+ npm install-scripts approve tree-sitter @mermanjs/tree-sitter-mermaid
44
+ npm rebuild tree-sitter @mermanjs/tree-sitter-mermaid
30
45
  ```
31
46
 
47
+ Commit the resulting `allowScripts` entries in your application's `package.json` so subsequent
48
+ installs use the same version-specific approvals. Browser-only consumers do not need native scripts.
49
+
32
50
  ```js
33
51
  const Parser = require('tree-sitter');
34
52
  const Mermaid = require('@mermanjs/tree-sitter-mermaid');
@@ -53,7 +71,7 @@ import Mermaid from '@mermanjs/tree-sitter-mermaid';
53
71
  ## Browser and Workers
54
72
 
55
73
  ```console
56
- npm install web-tree-sitter @mermanjs/tree-sitter-mermaid
74
+ npm install web-tree-sitter@0.27.0 @mermanjs/tree-sitter-mermaid@0.3.0
57
75
  ```
58
76
 
59
77
  The package exports `@mermanjs/tree-sitter-mermaid/tree-sitter-mermaid.wasm`. Copy that asset to a
@@ -74,7 +92,7 @@ A no-build browser prototype can pin the exact grammar version on jsDelivr:
74
92
 
75
93
  ```js
76
94
  const language = await Language.load(
77
- 'https://cdn.jsdelivr.net/npm/@mermanjs/tree-sitter-mermaid@0.1.0/tree-sitter-mermaid.wasm',
95
+ 'https://cdn.jsdelivr.net/npm/@mermanjs/tree-sitter-mermaid@0.3.0/tree-sitter-mermaid.wasm',
78
96
  );
79
97
  ```
80
98
 
@@ -86,7 +104,7 @@ diagnostics, completion, navigation, and rename.
86
104
  ## Rust
87
105
 
88
106
  ```console
89
- cargo add tree-sitter tree-sitter-mermaid
107
+ cargo add tree-sitter@=0.27.0 tree-sitter-mermaid@=0.3.0
90
108
  ```
91
109
 
92
110
  ```rust
@@ -132,10 +150,12 @@ int main(void) {
132
150
 
133
151
  | Contract | Version |
134
152
  | --- | --- |
135
- | Mermaid syntax baseline | 11.16.1 |
153
+ | Original 35-family Mermaid syntax baseline | 11.16.1 |
154
+ | Agentflow and Usecase syntax | 12.0.0 |
136
155
  | ZenUML Core syntax baseline | 3.50.1 |
137
156
  | Tree-sitter language ABI | 15 |
138
- | Tested Rust and Web runtime | 0.26.12 |
157
+ | Tested Rust runtime | 0.27.0 |
158
+ | Tested Web runtime | 0.27.0 |
139
159
  | Native Node runtime contract | 0.25.x |
140
160
 
141
161
  Before 1.0, a minor release may change named nodes, fields, canonical captures, the language ABI, or
@@ -165,6 +185,10 @@ npm ci --ignore-scripts --prefix distribution/tree-sitter-mermaid
165
185
  npm rebuild tree-sitter-cli --prefix distribution/tree-sitter-mermaid
166
186
  ```
167
187
 
188
+ The package manifest approves only the pinned Tree-sitter CLI and native runtime install scripts.
189
+ `--ignore-scripts` still suppresses them during the initial install; the explicit rebuild downloads
190
+ the CLI executable.
191
+
168
192
  Run the ordinary grammar and binding checks:
169
193
 
170
194
  ```console
@@ -189,7 +213,8 @@ publication details.
189
213
 
190
214
  The package is MIT licensed. Source-derived syntax and template attributions are recorded in
191
215
  `metadata/provenance.json`, `metadata/derivations.json`, `THIRD_PARTY_NOTICES.md`, and
192
- `THIRD_PARTY_LICENSES/`.
216
+ `THIRD_PARTY_LICENSES/`. The added families have their own pinned source identity; adding them
217
+ does not relabel the existing family translations as Mermaid 12.0.0.
193
218
 
194
219
  [Tree-sitter]: https://tree-sitter.github.io/tree-sitter/
195
220
  [`@mermanjs/web`]: https://www.npmjs.com/package/@mermanjs/web
@@ -4,11 +4,18 @@ This source distribution derives syntax behavior or compatibility evidence from
4
4
  MIT-licensed projects. The corresponding license texts are included below
5
5
  `THIRD_PARTY_LICENSES/`.
6
6
 
7
- ## Tree-sitter 0.26.12
7
+ ## Tree-sitter 0.27.0 (generator and support headers)
8
+
9
+ - Source: https://github.com/tree-sitter/tree-sitter.git
10
+ - Commit: `6070dbfefd326bd735e5683eb128cc1b57dad0c0`
11
+ - Use: pinned generator and copied generated support headers
12
+ - License: `THIRD_PARTY_LICENSES/tree-sitter/LICENSE`
13
+
14
+ ## Tree-sitter 0.26.12 (retained implementation templates)
8
15
 
9
16
  - Source: https://github.com/tree-sitter/tree-sitter.git
10
17
  - Commit: `808e4b1fc06e269a107c4bd8bd936cc6fde18b00`
11
- - Use: pinned generator, copied generated support headers, and modified C, Rust, and Node binding templates
18
+ - Use: modified C, Rust, and Node binding templates and WASM build helper retained from the original implementation
12
19
  - License: `THIRD_PARTY_LICENSES/tree-sitter/LICENSE`
13
20
 
14
21
  ## Mermaid 11.16.1
@@ -18,6 +25,13 @@ MIT-licensed projects. The corresponding license texts are included below
18
25
  - Use: accepted Mermaid syntax, source-backed grammar translation, and representative fixtures
19
26
  - License: `THIRD_PARTY_LICENSES/mermaid/LICENSE`
20
27
 
28
+ ## Mermaid 12.0.0 (Agentflow and Usecase additions)
29
+
30
+ - Source: https://github.com/mermaid-js/mermaid.git
31
+ - Commit: `98a0945418c76238f15df2afaddbba4272656c3b`
32
+ - Use: Agentflow and Usecase grammar translation and source-backed editor corpus cases; existing families retain the Mermaid 11.16.1 source identity above
33
+ - License: `THIRD_PARTY_LICENSES/mermaid/LICENSE`
34
+
21
35
  ## ZenUML Core 3.50.1
22
36
 
23
37
  - 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 };
@@ -1,6 +1,8 @@
1
1
  // Source translation: Mermaid 11.16.1
2
2
  // packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison
3
3
  // commit 7ecca0cd7f1658ef74f4e7e91f925724ef403bbf.
4
+ // Actor-menu keyword endpoints also follow Mermaid 12.1.0,
5
+ // commit 21f72f07ea22c0af48a3149c550654e80d8e40cb (same Jison source).
4
6
 
5
7
  const diagramKeyword = ($) => field(
6
8
  'keyword',
@@ -167,6 +169,7 @@ const sequenceRules = {
167
169
 
168
170
  _sequence_actor_identifier: ($) => choice(
169
171
  $._sequence_keyword_prefixed_actor_identifier,
172
+ $._sequence_actor_menu_keyword,
170
173
  token(prec(30, choice(
171
174
  // Reserve `-x` for cross arrows while retaining ordinary hyphenated ids.
172
175
  /[A-Za-z0-9_\u00c0-\uffff](?:[A-Za-z0-9_=.\u00c0-\uffff]|-[A-WYZa-wyz0-9_=.\u00c0-\uffff])*/,
@@ -175,12 +178,17 @@ const sequenceRules = {
175
178
  ))),
176
179
  ),
177
180
 
178
- // Jison only recognizes block keywords at word boundaries. Give a longer
179
- // actor such as `Parser` priority over the shorter `par` token.
180
- _sequence_keyword_prefixed_actor_identifier: (_) => token(prec(
181
- 50,
182
- /(?:loop|rect|opt|alt|else|par_over|par|and|critical|option|break|box|end)(?:[A-Za-z0-9_=.\u00c0-\uffff]|-[A-WYZa-wyz0-9_=.\u00c0-\uffff])(?:[A-Za-z0-9_=.\u00c0-\uffff]|-[A-WYZa-wyz0-9_=.\u00c0-\uffff])*/i,
183
- )),
181
+ // Give longer actor ids priority over shorter keyword tokens. Keep bare
182
+ // `links` out of the `link` prefix branch so it remains a shared menu token.
183
+ _sequence_keyword_prefixed_actor_identifier: (_) => token(prec(50, choice(
184
+ /(?:loop|rect|opt|alt|else|par_over|par|and|critical|option|break|box|end)(?:[A-Za-z0-9_=.\u00c0-\uffff]|-[A-WYZa-wyz0-9_=.\u00c0-\uffff])+/i,
185
+ /(?:links|properties|details)(?:[A-Za-z0-9_=.\u00c0-\uffff]|-[A-WYZa-wyz0-9_=.\u00c0-\uffff])+/i,
186
+ /link(?:[A-RT-Za-rt-z0-9_=.\u00c0-\uffff]|-[A-WYZa-wyz0-9_=.\u00c0-\uffff])(?:[A-Za-z0-9_=.\u00c0-\uffff]|-[A-WYZa-wyz0-9_=.\u00c0-\uffff])*/i,
187
+ ))),
188
+
189
+ // Share the lexical token between metadata and endpoints. The following
190
+ // actor or arrow chooses the statement without consuming an endpoint as a directive.
191
+ _sequence_actor_menu_keyword: (_) => token(prec(40, /(?:links|link|properties|details)/i)),
184
192
 
185
193
  sequence_participant_config: (_) => token(prec(30, /@\{[^}\r\n]*\}/)),
186
194
 
@@ -381,11 +389,9 @@ const sequenceRules = {
381
389
  ),
382
390
 
383
391
  sequence_actor_metadata_statement: ($) => seq(
384
- field('kind', choice(
385
- statementKeyword($, /links/i),
386
- statementKeyword($, /link/i),
387
- statementKeyword($, /properties/i),
388
- statementKeyword($, /details/i),
392
+ field('keyword', alias(
393
+ $._sequence_actor_menu_keyword,
394
+ $.sequence_statement_keyword,
389
395
  )),
390
396
  actorReference($, 'participant'),
391
397
  field('delimiter', ':'),
@@ -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
  });