@mermanjs/tree-sitter-mermaid 0.3.3 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.5 - Unreleased
4
+
5
+ - Highlight node IDs that start with a dot, including `...`, in Flowchart, Swimlane, and Agentflow. Compact edges such as `.a-.->.b` in Flowchart keep the full operator highlighted.
6
+ - Preserve literal ampersands in Flowchart node IDs and keep surrounding whitespace outside arrow and edge-label captures. Recognize compact arrows in additional endpoint and label forms.
7
+ - Parse and highlight `direction` as a node ID in Flowchart, Swimlane, and Agentflow. Direction statements recognize value prefixes such as `LR` in `LRfoo` across line breaks and whole-line comments. When a statement contains several `direction` pairs, highlight the last pair at the highest matching priority (`TB`, `BT`, `RL`, `LR`, `TD`).
8
+
9
+ ## 0.3.4 - 2026-11-12
10
+
11
+ - Keep generic suffixes attached to backtick-quoted Class names in declarations and compact relationship endpoints.
12
+ - Recognize compact Class relationship operators without consuming their hyphens or dots as part of the source name. Ordinary and trailing hyphens remain valid in class names.
13
+
3
14
  ## 0.3.3 - 2026-11-06
4
15
 
5
16
  - Refresh the npm development-tool lockfile to semver 7.8.6 and undici 8.12.4.
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.3.3"
4
+ VERSION "0.3.5"
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.3.3
8
+ VERSION := 0.3.5
9
9
 
10
10
  SRC_DIR := src
11
11
  PARSER := $(SRC_DIR)/parser.c
package/README.md CHANGED
@@ -29,8 +29,8 @@ The grammar has its own version line, independent of Merman. Its npm and Cargo a
29
29
  grammar version, but their registry names differ: the npm package is scoped under `@mermanjs`, while
30
30
  the Rust crate and C library retain the standard `tree-sitter-mermaid` name.
31
31
 
32
- This guide targets `0.3.3`. The patch refreshes the npm development-tool lockfile (`semver` 7.8.5 to 7.8.6 and `undici` 8.12.3 to 8.12.4). Check the [independent publication record](https://github.com/Latias94/merman/blob/main/docs/release/PUBLISH_ORDER.md#0100-alpha2-preparation) for verified registry availability.
33
- Accepted syntax, queries, Mermaid/ZenUML baselines, language ABI 15, runtime versions, and the Rust
32
+ Version `0.3.5` improves highlighting for dot-prefixed node IDs and compact Flowchart-style edges. The installation examples below use the published `0.3.4` packages. Check [Publish Order](https://github.com/Latias94/merman/blob/main/docs/release/PUBLISH_ORDER.md) for current registry availability.
33
+ Portable queries, Mermaid/ZenUML baselines, language ABI 15, runtime versions, and the Rust
34
34
  `cc` minimum of `1.10.0` remain unchanged. See [CHANGELOG.md](CHANGELOG.md) for package changes.
35
35
  Match the examples to the version installed in your project; earlier versions have their own tagged
36
36
  documentation. Custom query consumers should review the
@@ -39,7 +39,7 @@ documentation. Custom query consumers should review the
39
39
  ## Node.js
40
40
 
41
41
  ```console
42
- npm install tree-sitter@0.25.1 @mermanjs/tree-sitter-mermaid@0.3.3
42
+ npm install tree-sitter@0.25.1 @mermanjs/tree-sitter-mermaid@0.3.4
43
43
  ```
44
44
 
45
45
  With npm 12 or later, review and approve the native install scripts, then rebuild:
@@ -76,7 +76,7 @@ import Mermaid from '@mermanjs/tree-sitter-mermaid';
76
76
  ## Browser and Workers
77
77
 
78
78
  ```console
79
- npm install web-tree-sitter@0.27.1 @mermanjs/tree-sitter-mermaid@0.3.3
79
+ npm install web-tree-sitter@0.27.1 @mermanjs/tree-sitter-mermaid@0.3.4
80
80
  ```
81
81
 
82
82
  The package exports `@mermanjs/tree-sitter-mermaid/tree-sitter-mermaid.wasm`. Copy that asset to a
@@ -97,7 +97,7 @@ A no-build browser prototype can pin the exact grammar version on jsDelivr:
97
97
 
98
98
  ```js
99
99
  const language = await Language.load(
100
- 'https://cdn.jsdelivr.net/npm/@mermanjs/tree-sitter-mermaid@0.3.3/tree-sitter-mermaid.wasm',
100
+ 'https://cdn.jsdelivr.net/npm/@mermanjs/tree-sitter-mermaid@0.3.4/tree-sitter-mermaid.wasm',
101
101
  );
102
102
  ```
103
103
 
@@ -151,7 +151,7 @@ int main(void) {
151
151
  }
152
152
  ```
153
153
 
154
- The 0.3.3 candidate pairs with Tree-sitter CLI, Rust, and Web runtime 0.27.1; the Rust language adapter uses compatible `^0.1.9`, and the generated language ABI remains 15. See [query migration](docs/query-migration.md) when upgrading queries and the [grammar release guide](../../docs/release/TREE_SITTER_MERMAID.md) when maintaining the package.
154
+ The grammar pairs with Tree-sitter CLI, Rust, and Web runtime 0.27.1. The Rust language adapter uses compatible `^0.1.9` and the generated language ABI remains 15. See [query migration](docs/query-migration.md) when upgrading queries and the [grammar release guide](../../docs/release/TREE_SITTER_MERMAID.md) when maintaining the package.
155
155
 
156
156
  ## Compatibility
157
157
 
@@ -403,8 +403,9 @@ const classRules = {
403
403
 
404
404
  _class_identifier: ($) => choice(
405
405
  $.identifier,
406
+ alias($._class_compact_identifier, $.identifier),
406
407
  token(prec(5, choice(
407
- seq('`', /[^`]+/, '`'),
408
+ seq('`', /[^`]+/, '`', optional(/~[^~\r\n]+~/)),
408
409
  /[0-9][A-Za-z0-9_.\-\u00c0-\uffff]*(?:~[^~\r\n]+~)?/,
409
410
  /[A-Za-z_\u00c0-\uffff][A-Za-z0-9_\-\u00c0-\uffff]*\.[A-Za-z0-9_.\-\u00c0-\uffff]+(?:~[^~\r\n]+~)?/,
410
411
  /[A-Za-z_\u00c0-\uffff][A-Za-z0-9_.\-\u00c0-\uffff]*~[^~\r\n]+~/,
@@ -416,8 +417,9 @@ const classRules = {
416
417
  token.immediate(/[A-Za-z_\u00c0-\uffff][A-Za-z0-9_\-\u00c0-\uffff]*/),
417
418
  $.identifier,
418
419
  ),
420
+ alias($._class_compact_identifier, $.identifier),
419
421
  token.immediate(prec(5, choice(
420
- seq('`', /[^`]+/, '`'),
422
+ seq('`', /[^`]+/, '`', optional(/~[^~\r\n]+~/)),
421
423
  /[0-9][A-Za-z0-9_.\-\u00c0-\uffff]*(?:~[^~\r\n]+~)?/,
422
424
  /[A-Za-z_\u00c0-\uffff][A-Za-z0-9_\-\u00c0-\uffff]*\.[A-Za-z0-9_.\-\u00c0-\uffff]+(?:~[^~\r\n]+~)?/,
423
425
  /[A-Za-z_\u00c0-\uffff][A-Za-z0-9_.\-\u00c0-\uffff]*~[^~\r\n]+~/,
@@ -26,16 +26,30 @@ const statementKeyword = ($, prefix, keyword) => field(
26
26
 
27
27
  const optionalInlineGap = () => optional(token.immediate(/[ \t]+/));
28
28
 
29
- const keywordPrefixedIdentifier = () => choice(
30
- token(prec(
31
- 60,
32
- /classDef(?:[A-Za-z0-9_.!?$%#\u00c0-\uffff]|-[A-Za-z0-9_\u00c0-\uffff])+/
33
- )),
34
- token(prec(
35
- 40,
36
- /(?:subgraph|direction|class|style|linkStyle|click|accTitle|accDescr|end)(?:[A-Za-z0-9_.!?$%#\u00c0-\uffff]|-[A-Za-z0-9_\u00c0-\uffff])+/
37
- )),
38
- );
29
+ const identifierPrecedence = -5;
30
+
31
+ // At identifier precedence, a longer name such as `directionLR` wins the whole token.
32
+ const directionKeyword = () => token(prec(identifierPrecedence, /direction/));
33
+
34
+ const identifier = (flowchartLexing) => {
35
+ const unicode = String.raw`\u00c0-\uffff`;
36
+ const head = flowchartLexing ? 'A-Za-z_./&' : 'A-Za-z0-9_.';
37
+ const part = (flowchartLexing ? 'A-Za-z0-9_/&' : 'A-Za-z0-9_') + unicode;
38
+ const tail = `(?:[${part}.!?$%#]|-[${part}])+`;
39
+ const variants = [
40
+ token(prec(60, new RegExp(`classDef${tail}`))),
41
+ token(prec(40, new RegExp(
42
+ `(?:subgraph|class|style|linkStyle|click|accTitle|accDescr|end)${tail}`,
43
+ ))),
44
+ directionKeyword(),
45
+ token(prec(identifierPrecedence, new RegExp(`[${head}${unicode}](?:${tail})?`))),
46
+ ];
47
+ if (flowchartLexing) {
48
+ // Jison lexes NUM first, so a dashless dotted arrow can follow it immediately.
49
+ variants.push(seq(/[0-9]+/, optional(token.immediate(prec(identifierPrecedence, new RegExp(tail))))));
50
+ }
51
+ return choice(...variants);
52
+ };
39
53
 
40
54
  const headerDirection = ($) => seq(
41
55
  token.immediate(/[ \t]+/),
@@ -112,6 +126,7 @@ const createFlowFamilyRules = ({
112
126
  header,
113
127
  headerEof,
114
128
  keywords,
129
+ flowchartLexing = false,
115
130
  }) => ({
116
131
  [diagram]: ($) => choice(
117
132
  seq(
@@ -219,14 +234,21 @@ const createFlowFamilyRules = ({
219
234
 
220
235
  [familyRule(prefix, 'subgraph_end')]: (_) => token(prec(30, 'end')),
221
236
 
222
- [familyRule(prefix, 'direction_statement')]: ($) => seq(
223
- statementKeyword($, prefix, 'direction'),
224
- token.immediate(/[ \t]+/),
237
+ // flow.jison matches a value by prefix. Keep the selected pair and any
238
+ // whole-line comments that Mermaid removes between its keyword and value.
239
+ [familyRule(prefix, 'direction_statement')]: ($) => prec.dynamic(1, seq(
240
+ repeat($._flow_direction_prefix),
241
+ field('keyword', alias(directionKeyword(), ref($, prefix, 'statement_keyword'))),
242
+ repeat(seq(
243
+ $._line_ending,
244
+ optional(alias(token(/%%[^{\r\n][^\r\n]*/), $.comment)),
245
+ )),
225
246
  field('direction', alias(
226
- token.immediate(/(?:LR|RL|TB|BT|TD)/),
247
+ token(prec(1, /(?:LR|RL|TB|BT|TD)/)),
227
248
  ref($, prefix, 'direction'),
228
249
  )),
229
- ),
250
+ optional(token.immediate(/[^;\r\n]+/)),
251
+ )),
230
252
 
231
253
  [familyRule(prefix, 'edge_statement')]: ($) => prec.right(60, seq(
232
254
  field('source', ref($, prefix, 'node')),
@@ -253,7 +275,7 @@ const createFlowFamilyRules = ({
253
275
  [familyRule(prefix, 'node')]: ($) => seq(
254
276
  field('vertex', ref($, prefix, 'vertex')),
255
277
  repeat(seq(
256
- field('separator', '&'),
278
+ field('separator', flowchartLexing ? alias($._flowchart_group_separator, '&') : '&'),
257
279
  field('vertex', ref($, prefix, 'vertex')),
258
280
  )),
259
281
  ),
@@ -450,7 +472,10 @@ const createFlowFamilyRules = ({
450
472
  token.immediate('='),
451
473
  token.immediate('.'),
452
474
  )),
453
- [familyRule(prefix, 'middle_edge_label_fragment')]: (_) => token.immediate(/[^-=.\r\n]+/),
475
+ // A trailing x, o, or < can belong to the closing arrow.
476
+ [familyRule(prefix, 'middle_edge_label_fragment')]: (_) => token.immediate(flowchartLexing
477
+ ? /(?:[xo<]?[^-=.xo<\r\n])+|[xo<]/
478
+ : /[^-=.\r\n]+/),
454
479
 
455
480
  [familyRule(prefix, 'arrow_start')]: (_) => token(prec(
456
481
  20,
@@ -652,16 +677,12 @@ const createFlowFamilyRules = ({
652
677
 
653
678
  [familyRule(prefix, 'accessibility_block_text')]: (_) => token.immediate(/[^}]+/),
654
679
 
655
- [familyRule(prefix, 'identifier')]: (_) => choice(
656
- keywordPrefixedIdentifier(),
657
- token(prec(
658
- -5,
659
- /[A-Za-z0-9_\u00c0-\uffff][A-Za-z0-9_.!?$%#\u00c0-\uffff]*(?:-[A-Za-z0-9_\u00c0-\uffff][A-Za-z0-9_.!?$%#\u00c0-\uffff]*)*/,
660
- )),
661
- ),
680
+ [familyRule(prefix, 'identifier')]: (_) => identifier(flowchartLexing),
662
681
  });
663
682
 
664
683
  const createFlowFamilyConflicts = ($, prefix) => [
684
+ // A newline after `direction` can terminate a node or precede a direction value.
685
+ [ref($, prefix, 'direction_statement'), ref($, prefix, 'identifier')],
665
686
  [
666
687
  privateRef($, prefix, 'labeled_edge'),
667
688
  privateRef($, prefix, 'unlabeled_edge'),
@@ -678,6 +699,7 @@ const flowchartRules = createFlowFamilyRules({
678
699
  header: 'flowchart_header',
679
700
  headerEof: '_flowchart_header_eof',
680
701
  keywords: ['flowchart-elk', 'flowchart', 'graph'],
702
+ flowchartLexing: true,
681
703
  });
682
704
 
683
705
  const flowchartConflicts = ($) => createFlowFamilyConflicts($, 'flow');
@@ -18,6 +18,7 @@ const swimlaneRules = createFlowFamilyRules({
18
18
  header: 'swimlane_header',
19
19
  headerEof: '_swimlane_header_eof',
20
20
  keywords: ['swimlane-beta'],
21
+ flowchartLexing: true,
21
22
  });
22
23
 
23
24
  const swimlaneConflicts = ($) => createFlowFamilyConflicts($, 'swimlane');
package/grammar.js CHANGED
@@ -84,6 +84,9 @@ module.exports = grammar({
84
84
  ...indentationExternals($),
85
85
  $._end_of_input,
86
86
  $._directive_body,
87
+ $._class_compact_identifier,
88
+ $._flowchart_group_separator,
89
+ $._flow_direction_prefix,
87
90
  ],
88
91
 
89
92
  conflicts: ($) => [
@@ -461,6 +461,25 @@
461
461
  }
462
462
  ]
463
463
  },
464
+ {
465
+ "localPaths": [
466
+ "src/scanner.c",
467
+ "grammar/families/class.js"
468
+ ],
469
+ "localSymbols": [
470
+ "scan_class_compact_identifier",
471
+ "_class_compact_identifier"
472
+ ],
473
+ "sources": [
474
+ {
475
+ "sourceId": "mermaid",
476
+ "relationship": "translated",
477
+ "sourcePaths": [
478
+ "packages/mermaid/src/diagrams/class/parser/classDiagram.jison:1-440"
479
+ ]
480
+ }
481
+ ]
482
+ },
464
483
  {
465
484
  "localPaths": [
466
485
  "src/scanner.c",
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "package": {
4
4
  "name": "tree-sitter-mermaid",
5
- "version": "0.3.3",
5
+ "version": "0.3.5",
6
6
  "releaseState": "candidate"
7
7
  },
8
8
  "language": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mermanjs/tree-sitter-mermaid",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Tolerant Tree-sitter grammar and editor queries for Mermaid",
5
5
  "license": "MIT",
6
6
  "repository": {