@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,460 @@
1
+ // Source translation: Mermaid 11.16.1
2
+ // packages/mermaid/src/diagrams/xychart/parser/xychart.jison and
3
+ // packages/mermaid/src/diagrams/xychart/parser/xychart.jison.spec.ts at
4
+ // commit 7ecca0cd7f1658ef74f4e7e91f925724ef403bbf.
5
+
6
+ const caseVariants = (value) => [...value].reduce(
7
+ (variants, character) => {
8
+ const lower = character.toLowerCase();
9
+ const upper = character.toUpperCase();
10
+ if (lower === upper) return variants.map((prefix) => prefix + character);
11
+ return variants.flatMap((prefix) => [prefix + lower, prefix + upper]);
12
+ },
13
+ [''],
14
+ );
15
+
16
+ const caseInsensitiveChoice = (...values) => choice(
17
+ ...values.flatMap(caseVariants),
18
+ );
19
+
20
+ const diagramKeyword = ($) => field(
21
+ 'keyword',
22
+ alias(caseInsensitiveChoice('xychart'), $.diagram_keyword),
23
+ );
24
+
25
+ const statementKeyword = ($, ...keywords) => field(
26
+ 'keyword',
27
+ alias(caseInsensitiveChoice(...keywords), $.statement_keyword),
28
+ );
29
+
30
+ const seriesStatement = ($, keyword) => prec.right(30, seq(
31
+ statementKeyword($, keyword),
32
+ $._xy_chart_inline_space,
33
+ optional(field('title', $.xy_chart_text)),
34
+ field('data', $.xy_chart_series_array),
35
+ ));
36
+
37
+ const xyChartRules = {
38
+ xy_chart_diagram: ($) => choice(
39
+ seq(
40
+ field('header', $.xy_chart_header),
41
+ optional(field('comment', choice($.comment, $.directive))),
42
+ field('terminator', $._line_ending),
43
+ optional(field('body', $.xy_chart_body)),
44
+ ),
45
+ seq(
46
+ field('header', $.xy_chart_header),
47
+ field(
48
+ 'terminator',
49
+ alias(';', $.xy_chart_statement_delimiter),
50
+ ),
51
+ optional(field('body', $.xy_chart_body)),
52
+ ),
53
+ prec(30, seq(
54
+ field('header', $.xy_chart_header),
55
+ $._xy_chart_trailing_space,
56
+ optional(field('comment', choice($.comment, $.directive))),
57
+ )),
58
+ seq(
59
+ field('header', $.xy_chart_header),
60
+ optional(field('comment', choice($.comment, $.directive))),
61
+ ),
62
+ ),
63
+
64
+ xy_chart_header: ($) => seq(
65
+ diagramKeyword($),
66
+ optional(field(
67
+ 'beta',
68
+ alias(token.immediate(/-beta/i), $.xy_chart_beta_marker),
69
+ )),
70
+ optional(seq(
71
+ $._xy_chart_inline_space,
72
+ field('orientation', $.xy_chart_orientation),
73
+ )),
74
+ ),
75
+
76
+ xy_chart_orientation: (_) => token.immediate(/(?:vertical|horizontal)/i),
77
+
78
+ xy_chart_body: ($) => choice(
79
+ repeat1($._xy_chart_terminated_body_item),
80
+ seq(
81
+ repeat($._xy_chart_terminated_body_item),
82
+ $._xy_chart_eof_body_item,
83
+ ),
84
+ ),
85
+
86
+ _xy_chart_terminated_body_item: ($) => choice(
87
+ $._blank_line,
88
+ seq(choice($.comment, $.directive), $._line_ending),
89
+ seq(
90
+ $._xy_chart_statement,
91
+ optional(choice($.comment, $.directive)),
92
+ $._line_ending,
93
+ ),
94
+ seq(
95
+ $._xy_chart_statement,
96
+ alias(';', $.xy_chart_statement_delimiter),
97
+ ),
98
+ ),
99
+
100
+ _xy_chart_eof_body_item: ($) => choice(
101
+ seq(
102
+ $._xy_chart_statement,
103
+ optional(choice($.comment, $.directive)),
104
+ ),
105
+ $.comment,
106
+ $.directive,
107
+ ),
108
+
109
+ _xy_chart_statement: ($) => choice(
110
+ $.xy_chart_malformed_statement_sequence,
111
+ $._xy_chart_complete_statement,
112
+ $.xy_chart_incomplete_x_axis_statement,
113
+ $.xy_chart_incomplete_y_axis_statement,
114
+ $.xy_chart_malformed_y_axis_categories_statement,
115
+ $.xy_chart_malformed_title_statement,
116
+ $.xy_chart_malformed_axis_statement,
117
+ $.xy_chart_malformed_series_statement,
118
+ $.xy_chart_malformed_accessibility_statement,
119
+ $.xy_chart_malformed_statement,
120
+ ),
121
+
122
+ _xy_chart_complete_statement: ($) => choice(
123
+ $.xy_chart_title_statement,
124
+ $.xy_chart_x_axis_statement,
125
+ $.xy_chart_y_axis_statement,
126
+ $.xy_chart_line_statement,
127
+ $.xy_chart_bar_statement,
128
+ $.xy_chart_accessibility_title_statement,
129
+ $.xy_chart_accessibility_description_statement,
130
+ ),
131
+
132
+ xy_chart_malformed_statement_sequence: ($) => prec.right(-40, seq(
133
+ field('statement', choice(
134
+ $.xy_chart_line_statement,
135
+ $.xy_chart_bar_statement,
136
+ )),
137
+ field('trailing', $.xy_chart_trailing_text),
138
+ )),
139
+
140
+ xy_chart_title_statement: ($) => prec.right(30, seq(
141
+ statementKeyword($, 'title'),
142
+ $._xy_chart_inline_space,
143
+ field('title', $.xy_chart_text),
144
+ )),
145
+
146
+ xy_chart_x_axis_statement: ($) => prec.right(30, seq(
147
+ statementKeyword($, 'x-axis'),
148
+ $._xy_chart_inline_space,
149
+ choice(
150
+ seq(
151
+ optional(field('title', $.xy_chart_text)),
152
+ field('categories', $.xy_chart_category_array),
153
+ ),
154
+ seq(
155
+ optional(field('title', $.xy_chart_text)),
156
+ field('range', $.xy_chart_axis_range),
157
+ ),
158
+ field('title', $.xy_chart_text),
159
+ ),
160
+ )),
161
+
162
+ xy_chart_y_axis_statement: ($) => prec.right(30, seq(
163
+ statementKeyword($, 'y-axis'),
164
+ $._xy_chart_inline_space,
165
+ choice(
166
+ seq(
167
+ optional(field('title', $.xy_chart_text)),
168
+ field('range', $.xy_chart_axis_range),
169
+ ),
170
+ field('title', $.xy_chart_text),
171
+ ),
172
+ )),
173
+
174
+ xy_chart_line_statement: ($) => seriesStatement(
175
+ $,
176
+ 'line',
177
+ ),
178
+
179
+ xy_chart_bar_statement: ($) => seriesStatement(
180
+ $,
181
+ 'bar',
182
+ ),
183
+
184
+ xy_chart_axis_range: ($) => seq(
185
+ field('minimum', $.xy_chart_number),
186
+ field(
187
+ 'delimiter',
188
+ alias('-->', $.xy_chart_range_delimiter),
189
+ ),
190
+ field('maximum', $.xy_chart_number),
191
+ ),
192
+
193
+ xy_chart_category_array: ($) => seq(
194
+ field('open', alias('[', $.xy_chart_array_open)),
195
+ field('category', $.xy_chart_text),
196
+ repeat(seq(
197
+ field('delimiter', alias(',', $.xy_chart_array_delimiter)),
198
+ field('category', $.xy_chart_text),
199
+ )),
200
+ field('close', alias(']', $.xy_chart_array_close)),
201
+ ),
202
+
203
+ xy_chart_series_array: ($) => seq(
204
+ field('open', alias('[', $.xy_chart_array_open)),
205
+ field('point', $.xy_chart_data_point),
206
+ repeat(seq(
207
+ field('delimiter', alias(',', $.xy_chart_array_delimiter)),
208
+ field('point', $.xy_chart_data_point),
209
+ )),
210
+ field('close', alias(']', $.xy_chart_array_close)),
211
+ ),
212
+
213
+ xy_chart_data_point: ($) => seq(
214
+ field('value', $.xy_chart_number),
215
+ optional(field('label', $.xy_chart_quoted_text)),
216
+ ),
217
+
218
+ xy_chart_unclosed_category_array: ($) => prec.dynamic(-10, seq(
219
+ field('open', alias('[', $.xy_chart_array_open)),
220
+ field('category', $.xy_chart_text),
221
+ repeat(seq(
222
+ field('delimiter', alias(',', $.xy_chart_array_delimiter)),
223
+ field('category', $.xy_chart_text),
224
+ )),
225
+ )),
226
+
227
+ xy_chart_unclosed_series_array: ($) => prec.dynamic(-10, seq(
228
+ field('open', alias('[', $.xy_chart_array_open)),
229
+ field('point', $.xy_chart_data_point),
230
+ repeat(seq(
231
+ field('delimiter', alias(',', $.xy_chart_array_delimiter)),
232
+ field('point', $.xy_chart_data_point),
233
+ )),
234
+ )),
235
+
236
+ xy_chart_empty_series_array: ($) => seq(
237
+ field('open', alias('[', $.xy_chart_array_open)),
238
+ field('close', alias(']', $.xy_chart_array_close)),
239
+ ),
240
+
241
+ xy_chart_incomplete_axis_range: ($) => seq(
242
+ field('minimum', $.xy_chart_number),
243
+ field(
244
+ 'delimiter',
245
+ alias('-->', $.xy_chart_range_delimiter),
246
+ ),
247
+ ),
248
+
249
+ xy_chart_incomplete_x_axis_statement: ($) => prec.right(-20, seq(
250
+ statementKeyword($, 'x-axis'),
251
+ $._xy_chart_inline_space,
252
+ choice(
253
+ seq(
254
+ optional(field('title', $.xy_chart_text)),
255
+ field('categories', $.xy_chart_unclosed_category_array),
256
+ ),
257
+ seq(
258
+ optional(field('title', $.xy_chart_text)),
259
+ field('range', $.xy_chart_incomplete_axis_range),
260
+ ),
261
+ ),
262
+ )),
263
+
264
+ xy_chart_incomplete_y_axis_statement: ($) => prec.right(-20, seq(
265
+ statementKeyword($, 'y-axis'),
266
+ $._xy_chart_inline_space,
267
+ optional(field('title', $.xy_chart_text)),
268
+ field('range', $.xy_chart_incomplete_axis_range),
269
+ )),
270
+
271
+ xy_chart_malformed_y_axis_categories_statement: ($) => prec.right(-20, seq(
272
+ statementKeyword($, 'y-axis'),
273
+ $._xy_chart_inline_space,
274
+ optional(field('title', $.xy_chart_text)),
275
+ field('categories', $.xy_chart_category_array),
276
+ )),
277
+
278
+ xy_chart_accessibility_title_statement: ($) => prec.right(30, seq(
279
+ statementKeyword($, 'accTitle'),
280
+ optional($._xy_chart_inline_space),
281
+ field(
282
+ 'delimiter',
283
+ alias(token.immediate(':'), $.xy_chart_accessibility_delimiter),
284
+ ),
285
+ optional($._xy_chart_inline_space),
286
+ optional(field('text', $.xy_chart_accessibility_text)),
287
+ )),
288
+
289
+ xy_chart_accessibility_description_statement: ($) => prec.right(30, seq(
290
+ statementKeyword($, 'accDescr'),
291
+ optional($._xy_chart_inline_space),
292
+ choice(
293
+ seq(
294
+ field(
295
+ 'delimiter',
296
+ alias(token.immediate(':'), $.xy_chart_accessibility_delimiter),
297
+ ),
298
+ optional($._xy_chart_inline_space),
299
+ optional(field('text', $.xy_chart_accessibility_text)),
300
+ ),
301
+ field(
302
+ 'description',
303
+ choice(
304
+ $.xy_chart_accessibility_description_block,
305
+ $.xy_chart_unclosed_accessibility_description_block,
306
+ ),
307
+ ),
308
+ ),
309
+ )),
310
+
311
+ xy_chart_accessibility_description_block: ($) => field(
312
+ 'text',
313
+ $.xy_chart_accessibility_block_text,
314
+ ),
315
+
316
+ xy_chart_unclosed_accessibility_description_block: ($) => field(
317
+ 'text',
318
+ $.xy_chart_unclosed_accessibility_block_text,
319
+ ),
320
+
321
+ xy_chart_text: ($) => choice(
322
+ $.xy_chart_markdown_text,
323
+ $.xy_chart_quoted_text,
324
+ $.xy_chart_unclosed_markdown_text,
325
+ $.xy_chart_unclosed_quoted_text,
326
+ $.xy_chart_bare_text,
327
+ ),
328
+
329
+ xy_chart_quoted_text: ($) => prec.dynamic(10, seq(
330
+ field('open', alias('"', $.xy_chart_quote_delimiter)),
331
+ optional(field('content', $.xy_chart_quoted_content)),
332
+ field(
333
+ 'close',
334
+ alias(token.immediate('"'), $.xy_chart_quote_delimiter),
335
+ ),
336
+ )),
337
+
338
+ xy_chart_unclosed_quoted_text: ($) => prec.dynamic(-10, seq(
339
+ field('open', alias('"', $.xy_chart_quote_delimiter)),
340
+ optional(field('content', $.xy_chart_quoted_content)),
341
+ )),
342
+
343
+ xy_chart_markdown_text: ($) => prec.dynamic(10, seq(
344
+ field('open', alias('"`', $.xy_chart_markdown_delimiter)),
345
+ repeat(choice(
346
+ field('content', $.xy_chart_markdown_content),
347
+ field('content', $.xy_chart_markdown_backtick_content),
348
+ )),
349
+ field(
350
+ 'close',
351
+ alias(token.immediate('`"'), $.xy_chart_markdown_delimiter),
352
+ ),
353
+ )),
354
+
355
+ xy_chart_unclosed_markdown_text: ($) => prec.dynamic(-10, seq(
356
+ field('open', alias('"`', $.xy_chart_markdown_delimiter)),
357
+ repeat(choice(
358
+ field('content', $.xy_chart_markdown_content),
359
+ field('content', $.xy_chart_markdown_backtick_content),
360
+ )),
361
+ )),
362
+
363
+ xy_chart_bare_text: ($) => repeat1(field('part', choice(
364
+ $.xy_chart_text_atom,
365
+ $.xy_chart_number,
366
+ ))),
367
+
368
+ xy_chart_number: (_) => token(prec(
369
+ 10,
370
+ /[+-]?(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)/,
371
+ )),
372
+
373
+ xy_chart_text_atom: (_) => token(prec(-1, /[A-Za-z&=*.#_+\-]+/)),
374
+
375
+ xy_chart_quoted_content: (_) => token.immediate(/[^"\r\n]+/),
376
+
377
+ xy_chart_markdown_content: (_) => token.immediate(/[^`\r\n]+/),
378
+
379
+ xy_chart_markdown_backtick_content: (_) => token.immediate(/`[^"\r\n]/),
380
+
381
+ xy_chart_accessibility_text: (_) => token.immediate(prec(
382
+ 5,
383
+ /[^\s%\r\n](?:(?:[^%\r\n]|%[^%\r\n])*[^\s%\r\n])?/,
384
+ )),
385
+
386
+ xy_chart_accessibility_block_text: (_) => token(prec(
387
+ 10,
388
+ seq('{', /[^}]*/, '}'),
389
+ )),
390
+
391
+ xy_chart_unclosed_accessibility_block_text: (_) => token(prec(
392
+ -10,
393
+ seq('{', /[^}\r\n]*/),
394
+ )),
395
+
396
+ xy_chart_malformed_title_statement: ($) => prec.right(-50, seq(
397
+ statementKeyword($, 'title'),
398
+ )),
399
+
400
+ xy_chart_malformed_axis_statement: ($) => prec.right(-50, seq(
401
+ statementKeyword($, 'x-axis', 'y-axis'),
402
+ )),
403
+
404
+ xy_chart_malformed_series_statement: ($) => prec.right(-50, seq(
405
+ statementKeyword($, 'line', 'bar'),
406
+ optional(seq(
407
+ $._xy_chart_inline_space,
408
+ choice(
409
+ field('title', $.xy_chart_text),
410
+ seq(
411
+ optional(field('title', $.xy_chart_text)),
412
+ field('data', $.xy_chart_unclosed_series_array),
413
+ ),
414
+ seq(
415
+ optional(field('title', $.xy_chart_text)),
416
+ field('data', $.xy_chart_empty_series_array),
417
+ ),
418
+ ),
419
+ )),
420
+ )),
421
+
422
+ xy_chart_malformed_accessibility_statement: ($) => prec.right(-50, seq(
423
+ statementKeyword($, 'accTitle', 'accDescr'),
424
+ optional(seq(
425
+ $._xy_chart_inline_space,
426
+ optional(field('text', $.xy_chart_text)),
427
+ )),
428
+ )),
429
+
430
+ xy_chart_malformed_statement: ($) => prec.right(-100, choice(
431
+ seq(
432
+ field('keyword', alias($.identifier, $.xy_chart_unknown_keyword)),
433
+ optional(field('text', $.xy_chart_unknown_tail)),
434
+ ),
435
+ field('text', $.xy_chart_malformed_text),
436
+ )),
437
+
438
+ xy_chart_unknown_tail: (_) => token(prec(-100, /[^;\r\n]+/)),
439
+
440
+ xy_chart_trailing_text: (_) => token.immediate(prec(
441
+ -100,
442
+ /[ \t]+[^ \t%;\r\n][^;\r\n]*/,
443
+ )),
444
+
445
+ xy_chart_malformed_text: (_) => token(prec(
446
+ -100,
447
+ /[^%;\r\n][^;\r\n]*/,
448
+ )),
449
+
450
+ _xy_chart_inline_space: (_) => token.immediate(/[ \t]+/),
451
+
452
+ _xy_chart_trailing_space: (_) => token.immediate(/[ \t]+/),
453
+ };
454
+
455
+ const xyChartConflicts = ($) => [
456
+ [$.xy_chart_header],
457
+ [$.xy_chart_bare_text],
458
+ ];
459
+
460
+ module.exports = { xyChartConflicts, xyChartRules };