@mermanjs/tree-sitter-mermaid 0.3.4 → 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,11 @@
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
+
3
9
  ## 0.3.4 - 2026-11-12
4
10
 
5
11
  - Keep generic suffixes attached to backtick-quoted Class names in declarations and compact relationship endpoints.
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.4"
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.4
8
+ VERSION := 0.3.5
9
9
 
10
10
  SRC_DIR := src
11
11
  PARSER := $(SRC_DIR)/parser.c
package/README.md CHANGED
@@ -29,7 +29,7 @@ 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.4`. The patch keeps generic suffixes attached to quoted Class names and recognizes compact Class relationship operators without consuming them as part of a class name. Check the [independent publication record](https://github.com/Latias94/merman/blob/main/docs/release/PUBLISH_ORDER.md#0100-preparation) for verified registry availability.
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
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
@@ -151,7 +151,7 @@ int main(void) {
151
151
  }
152
152
  ```
153
153
 
154
- Version 0.3.4 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
 
@@ -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
@@ -85,6 +85,8 @@ module.exports = grammar({
85
85
  $._end_of_input,
86
86
  $._directive_body,
87
87
  $._class_compact_identifier,
88
+ $._flowchart_group_separator,
89
+ $._flow_direction_prefix,
88
90
  ],
89
91
 
90
92
  conflicts: ($) => [
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "package": {
4
4
  "name": "tree-sitter-mermaid",
5
- "version": "0.3.4",
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.4",
3
+ "version": "0.3.5",
4
4
  "description": "Tolerant Tree-sitter grammar and editor queries for Mermaid",
5
5
  "license": "MIT",
6
6
  "repository": {