@mermanjs/tree-sitter-mermaid 0.1.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.
Files changed (101) hide show
  1. package/CMakeLists.txt +44 -0
  2. package/LICENSE +22 -0
  3. package/Makefile +80 -0
  4. package/README.md +201 -0
  5. package/THIRD_PARTY_LICENSES/mermaid/LICENSE +21 -0
  6. package/THIRD_PARTY_LICENSES/monaqa-tree-sitter-mermaid/LICENSE +21 -0
  7. package/THIRD_PARTY_LICENSES/pappasam-tree-sitter-mermaid/LICENSE +21 -0
  8. package/THIRD_PARTY_LICENSES/singularity-tree-sitter-mermaid/LICENSE +22 -0
  9. package/THIRD_PARTY_LICENSES/tree-sitter/LICENSE +21 -0
  10. package/THIRD_PARTY_LICENSES/zenuml-core/LICENSE +21 -0
  11. package/THIRD_PARTY_NOTICES.md +47 -0
  12. package/binding.gyp +56 -0
  13. package/bindings/c/tree-sitter-mermaid.pc.in +10 -0
  14. package/bindings/c/tree_sitter/tree-sitter-mermaid.h +16 -0
  15. package/bindings/node/binding.cc +25 -0
  16. package/bindings/node/index.d.ts +5 -0
  17. package/bindings/node/index.js +10 -0
  18. package/grammar/families/architecture.js +361 -0
  19. package/grammar/families/block.js +370 -0
  20. package/grammar/families/c4.js +394 -0
  21. package/grammar/families/class.js +441 -0
  22. package/grammar/families/cynefin.js +127 -0
  23. package/grammar/families/entity-relationship.js +408 -0
  24. package/grammar/families/event-modeling.js +307 -0
  25. package/grammar/families/flowchart.js +690 -0
  26. package/grammar/families/gantt.js +445 -0
  27. package/grammar/families/git-graph.js +326 -0
  28. package/grammar/families/info.js +77 -0
  29. package/grammar/families/ishikawa.js +103 -0
  30. package/grammar/families/journey.js +221 -0
  31. package/grammar/families/kanban.js +264 -0
  32. package/grammar/families/mindmap.js +221 -0
  33. package/grammar/families/packet.js +108 -0
  34. package/grammar/families/pie.js +118 -0
  35. package/grammar/families/quadrant-chart.js +385 -0
  36. package/grammar/families/radar.js +286 -0
  37. package/grammar/families/railroad-abnf.js +124 -0
  38. package/grammar/families/railroad-ebnf.js +179 -0
  39. package/grammar/families/railroad-peg.js +128 -0
  40. package/grammar/families/railroad-shared.js +114 -0
  41. package/grammar/families/railroad.js +143 -0
  42. package/grammar/families/requirement.js +475 -0
  43. package/grammar/families/sankey.js +139 -0
  44. package/grammar/families/sequence.js +437 -0
  45. package/grammar/families/state.js +400 -0
  46. package/grammar/families/swimlane.js +25 -0
  47. package/grammar/families/timeline.js +251 -0
  48. package/grammar/families/tree-view.js +189 -0
  49. package/grammar/families/treemap.js +146 -0
  50. package/grammar/families/venn.js +256 -0
  51. package/grammar/families/wardley.js +530 -0
  52. package/grammar/families/xy-chart.js +460 -0
  53. package/grammar/families/zenuml.js +725 -0
  54. package/grammar/shared/common.js +78 -0
  55. package/grammar/shared/header.js +16 -0
  56. package/grammar/shared/indentation.js +22 -0
  57. package/grammar/shared/langium.js +166 -0
  58. package/grammar/shared/preamble.js +26 -0
  59. package/grammar.js +188 -0
  60. package/metadata/derivations.json +519 -0
  61. package/metadata/provenance.json +98 -0
  62. package/package.json +107 -0
  63. package/prebuilds/darwin-arm64/@mermanjs+tree-sitter-mermaid.node +0 -0
  64. package/prebuilds/darwin-x64/@mermanjs+tree-sitter-mermaid.node +0 -0
  65. package/prebuilds/linux-x64/@mermanjs+tree-sitter-mermaid.node +0 -0
  66. package/prebuilds/win32-x64/@mermanjs+tree-sitter-mermaid.node +0 -0
  67. package/queries/helix/highlights.scm +960 -0
  68. package/queries/helix/indents.scm +45 -0
  69. package/queries/helix/injections.scm +15 -0
  70. package/queries/helix/locals.scm +134 -0
  71. package/queries/helix/textobjects.scm +264 -0
  72. package/queries/neovim/README.md +28 -0
  73. package/queries/neovim/brackets.scm +65 -0
  74. package/queries/neovim/folds.scm +53 -0
  75. package/queries/neovim/highlights.scm +121 -0
  76. package/queries/neovim/indents.scm +110 -0
  77. package/queries/neovim/injections.scm +86 -0
  78. package/queries/neovim/locals.scm +277 -0
  79. package/queries/neovim/outline.scm +117 -0
  80. package/queries/neovim/tags.scm +149 -0
  81. package/queries/neovim/textobjects.scm +97 -0
  82. package/queries/portable/highlights.scm +961 -0
  83. package/queries/portable/injections.scm +45 -0
  84. package/queries/portable/locals.scm +290 -0
  85. package/queries/portable/tags.scm +182 -0
  86. package/queries/zed/README.md +48 -0
  87. package/queries/zed/brackets.scm +111 -0
  88. package/queries/zed/highlights.scm +961 -0
  89. package/queries/zed/indents.scm +111 -0
  90. package/queries/zed/injections.scm +11 -0
  91. package/queries/zed/outline.scm +167 -0
  92. package/queries/zed/textobjects.scm +68 -0
  93. package/src/grammar.json +71138 -0
  94. package/src/node-types.json +34871 -0
  95. package/src/parser.c +321353 -0
  96. package/src/scanner.c +462 -0
  97. package/src/tree_sitter/alloc.h +54 -0
  98. package/src/tree_sitter/array.h +336 -0
  99. package/src/tree_sitter/parser.h +286 -0
  100. package/tree-sitter-mermaid.wasm +0 -0
  101. package/tree-sitter.json +40 -0
@@ -0,0 +1,114 @@
1
+ // The metadata rules below translate TITLE, ACC_TITLE, and ACC_DESCR from
2
+ // lines 3-5 of all four Mermaid 11.16.1 railroad*.langium grammars. Those
3
+ // token languages are identical at commit
4
+ // 7ecca0cd7f1658ef74f4e7e91f925724ef403bbf.
5
+
6
+ const statementKeyword = ($, keyword) => field(
7
+ 'keyword',
8
+ alias(token(prec(50, keyword)), $.railroad_statement_keyword),
9
+ );
10
+
11
+ const inlineSpacing = () => optional(token.immediate(prec(100, /[ \t]+/)));
12
+
13
+ // IR RR_ID/RR_STRING (lines 7-8), EBNF EBNF_ID/EBNF_STRING (lines 7-8),
14
+ // and PEG PEG_ID/PEG_STRING (lines 7-8) use identical terminal languages.
15
+ // The named CST nodes remain dialect-local.
16
+ const railroadIdentifierToken = () => token(
17
+ prec(20, /[A-Z_a-z][A-Za-z0-9_-]*/),
18
+ );
19
+
20
+ const railroadEscapedStringToken = () => token(prec(10, choice(
21
+ seq('"', /(?:[^"\\]|\\.)*/, '"'),
22
+ seq("'", /(?:[^'\\]|\\.)*/, "'"),
23
+ )));
24
+
25
+ // Editing recovery derived from the shared STRING terminal. All three
26
+ // dialects stop an unclosed quote at the same CR/LF boundary.
27
+ const railroadUnclosedEscapedStringToken = () => token(prec(-20, choice(
28
+ seq('"', /(?:[^"\\\r\n]|\\[^\r\n])*/),
29
+ seq("'", /(?:[^'\\\r\n]|\\[^\r\n])*/),
30
+ )));
31
+
32
+ // IR RR_BLOCK_COMMENT (line 14) and EBNF EBNF_BLOCK_COMMENT (line 19)
33
+ // define the same C-style block-comment terminal.
34
+ const railroadCStyleBlockCommentToken = () => token(prec(
35
+ 40,
36
+ /\/\*[^*]*(?:\*+[^*/][^*]*)*\*+\//,
37
+ ));
38
+
39
+ // EBNF postfix rules (lines 152-161) and PEG suffix operators (line 87)
40
+ // share this token set.
41
+ const railroadSuffixQuantifierToken = () => token(
42
+ prec(20, choice('?', '*', '+')),
43
+ );
44
+
45
+ const railroadSharedRules = {
46
+ railroad_title_statement: ($) => prec.right(40, seq(
47
+ statementKeyword($, 'title'),
48
+ optional(seq(
49
+ token.immediate(prec(100, /[ \t]+/)),
50
+ optional(field('text', $.railroad_line_text)),
51
+ )),
52
+ )),
53
+
54
+ railroad_acc_title_statement: ($) => prec.right(40, seq(
55
+ statementKeyword($, 'accTitle'),
56
+ inlineSpacing(),
57
+ field('delimiter', token.immediate(':')),
58
+ inlineSpacing(),
59
+ optional(field('text', $.railroad_line_text)),
60
+ )),
61
+
62
+ railroad_acc_descr_statement: ($) => prec.right(40, seq(
63
+ statementKeyword($, 'accDescr'),
64
+ choice(
65
+ seq(
66
+ inlineSpacing(),
67
+ field('delimiter', token.immediate(':')),
68
+ inlineSpacing(),
69
+ optional(field('text', $.railroad_line_text)),
70
+ ),
71
+ seq(
72
+ repeat($._line_ending),
73
+ field('description', choice(
74
+ $.railroad_acc_descr_block,
75
+ $.railroad_unclosed_acc_descr_block,
76
+ )),
77
+ ),
78
+ ),
79
+ )),
80
+
81
+ railroad_acc_descr_block: ($) => seq(
82
+ field('open', '{'),
83
+ optional(field('text', $.railroad_acc_descr_block_text)),
84
+ field('close', '}'),
85
+ ),
86
+
87
+ railroad_unclosed_acc_descr_block: ($) => seq(
88
+ field('open', '{'),
89
+ optional(field('text', $.railroad_unclosed_acc_descr_block_text)),
90
+ ),
91
+
92
+ // These line payloads intentionally stop before Mermaid's `%%` comment.
93
+ railroad_line_text: (_) => token(prec(60, /(?:[^%\r\n]|%[^%])+/)),
94
+
95
+ railroad_acc_descr_block_text: (_) => token.immediate(/[^}]+/),
96
+
97
+ railroad_unclosed_acc_descr_block_text: (_) => token.immediate(/[^}\r\n]+/),
98
+ };
99
+
100
+ const railroadMetadataStatements = ($) => choice(
101
+ $.railroad_title_statement,
102
+ $.railroad_acc_title_statement,
103
+ $.railroad_acc_descr_statement,
104
+ );
105
+
106
+ module.exports = {
107
+ railroadCStyleBlockCommentToken,
108
+ railroadEscapedStringToken,
109
+ railroadIdentifierToken,
110
+ railroadMetadataStatements,
111
+ railroadSharedRules,
112
+ railroadSuffixQuantifierToken,
113
+ railroadUnclosedEscapedStringToken,
114
+ };
@@ -0,0 +1,143 @@
1
+ // Source translation: Mermaid 11.16.1
2
+ // packages/parser/src/language/railroad/railroad.langium
3
+ // commit 7ecca0cd7f1658ef74f4e7e91f925724ef403bbf.
4
+
5
+ const {
6
+ railroadCStyleBlockCommentToken,
7
+ railroadEscapedStringToken,
8
+ railroadIdentifierToken,
9
+ railroadMetadataStatements,
10
+ railroadUnclosedEscapedStringToken,
11
+ } = require('./railroad-shared');
12
+
13
+ const diagramKeyword = ($) => field(
14
+ 'keyword',
15
+ alias(token(prec(40, 'railroad-beta')), $.diagram_keyword),
16
+ );
17
+
18
+ const constructorKeyword = ($, keyword) => field(
19
+ 'kind',
20
+ alias(token(prec(30, keyword)), $.railroad_constructor_keyword),
21
+ );
22
+
23
+ const layout = ($) => optional($._railroad_layout);
24
+
25
+ const unaryConstructor = ($, keyword) => seq(
26
+ constructorKeyword($, keyword),
27
+ layout($),
28
+ field('open', '('),
29
+ layout($),
30
+ field('element', $.railroad_expression),
31
+ layout($),
32
+ field('close', ')'),
33
+ );
34
+
35
+ const stringConstructor = ($, keyword, fieldName) => seq(
36
+ constructorKeyword($, keyword),
37
+ layout($),
38
+ field('open', '('),
39
+ layout($),
40
+ field(fieldName, choice($.railroad_string, $.railroad_unclosed_string)),
41
+ layout($),
42
+ field('close', ')'),
43
+ );
44
+
45
+ const variadicConstructor = ($, keyword, fieldName) => seq(
46
+ constructorKeyword($, keyword),
47
+ layout($),
48
+ field('open', '('),
49
+ layout($),
50
+ field(fieldName, $.railroad_expression),
51
+ repeat(seq(
52
+ layout($),
53
+ field('delimiter', ','),
54
+ layout($),
55
+ field(fieldName, $.railroad_expression),
56
+ )),
57
+ layout($),
58
+ field('close', ')'),
59
+ );
60
+
61
+ const railroadRules = {
62
+ _railroad_layout: ($) => repeat1(choice(
63
+ $._line_ending,
64
+ $.comment,
65
+ $.directive,
66
+ $.railroad_block_comment,
67
+ )),
68
+
69
+ railroad_diagram: ($) => seq(
70
+ field('header', $.railroad_header),
71
+ optional(field('body', $.railroad_body)),
72
+ ),
73
+
74
+ railroad_header: ($) => diagramKeyword($),
75
+
76
+ railroad_body: ($) => repeat1(choice(
77
+ railroadMetadataStatements($),
78
+ $.railroad_rule,
79
+ $.railroad_incomplete_rule,
80
+ $.comment,
81
+ $.directive,
82
+ $.railroad_block_comment,
83
+ $._line_ending,
84
+ )),
85
+
86
+ railroad_rule: ($) => prec(20, seq(
87
+ field('name', $.railroad_identifier),
88
+ layout($),
89
+ field('operator', alias('=', $.railroad_assignment_operator)),
90
+ layout($),
91
+ field('definition', $.railroad_expression),
92
+ layout($),
93
+ field('terminator', ';'),
94
+ )),
95
+
96
+ // A missing definition is a common editing intermediate. Keep the recovery
97
+ // anchored by the normal rule name, assignment, and semicolon instead of
98
+ // accepting the rest of the line as an opaque fallback.
99
+ railroad_incomplete_rule: ($) => prec(-30, seq(
100
+ field('name', $.railroad_identifier),
101
+ layout($),
102
+ field('operator', alias('=', $.railroad_assignment_operator)),
103
+ layout($),
104
+ field('terminator', ';'),
105
+ )),
106
+
107
+ railroad_expression: ($) => choice(
108
+ $.railroad_sequence,
109
+ $.railroad_choice,
110
+ $.railroad_optional,
111
+ $.railroad_repetition,
112
+ $.railroad_terminal,
113
+ $.railroad_reference,
114
+ $.railroad_special,
115
+ ),
116
+
117
+ railroad_sequence: ($) => variadicConstructor($, 'sequence', 'element'),
118
+
119
+ railroad_choice: ($) => variadicConstructor($, 'choice', 'alternative'),
120
+
121
+ railroad_optional: ($) => unaryConstructor($, 'optional'),
122
+
123
+ railroad_repetition: ($) => unaryConstructor(
124
+ $,
125
+ choice('zeroOrMore', 'oneOrMore'),
126
+ ),
127
+
128
+ railroad_terminal: ($) => stringConstructor($, 'terminal', 'value'),
129
+
130
+ railroad_reference: ($) => stringConstructor($, 'nonterminal', 'name'),
131
+
132
+ railroad_special: ($) => stringConstructor($, 'special', 'text'),
133
+
134
+ railroad_identifier: (_) => railroadIdentifierToken(),
135
+
136
+ railroad_string: (_) => railroadEscapedStringToken(),
137
+
138
+ railroad_unclosed_string: (_) => railroadUnclosedEscapedStringToken(),
139
+
140
+ railroad_block_comment: (_) => railroadCStyleBlockCommentToken(),
141
+ };
142
+
143
+ module.exports = { railroadRules };