@mermanjs/tree-sitter-mermaid 0.3.3 → 0.3.4

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/src/scanner.c CHANGED
@@ -28,6 +28,7 @@ enum TokenType {
28
28
  KANBAN_INDENTATION_OVERFLOW,
29
29
  END_OF_INPUT,
30
30
  DIRECTIVE_BODY,
31
+ CLASS_COMPACT_IDENTIFIER,
31
32
  };
32
33
 
33
34
  enum ScannerMode {
@@ -191,6 +192,51 @@ static bool is_horizontal_space(int32_t lookahead) {
191
192
  lookahead == 0xa0;
192
193
  }
193
194
 
195
+ static bool is_ascii_word_character(int32_t value) {
196
+ return (value >= 'A' && value <= 'Z') ||
197
+ (value >= 'a' && value <= 'z') ||
198
+ (value >= '0' && value <= '9') || value == '_';
199
+ }
200
+
201
+ static bool is_class_identifier_character(int32_t value) {
202
+ return is_ascii_word_character(value) ||
203
+ (value >= 0xc0 && value <= 0xffff);
204
+ }
205
+
206
+ // Jison recognizes LINE and DOTTED_LINE before the single MINUS and DOT
207
+ // tokens in class names. Preserve that boundary without changing identifier
208
+ // leaves or rejecting names containing an ordinary or trailing hyphen.
209
+ static bool scan_class_compact_identifier(TSLexer *lexer) {
210
+ while (is_horizontal_space(lexer->lookahead)) {
211
+ lexer->advance(lexer, true);
212
+ }
213
+ if (!is_class_identifier_character(lexer->lookahead)) {
214
+ return false;
215
+ }
216
+
217
+ bool have_name = false;
218
+ bool previous_is_word = false;
219
+ bool aggregation_prefix = false;
220
+ while (is_class_identifier_character(lexer->lookahead) ||
221
+ lexer->lookahead == '-' || lexer->lookahead == '.') {
222
+ int32_t current = lexer->lookahead;
223
+ if (!aggregation_prefix) {
224
+ lexer->mark_end(lexer);
225
+ }
226
+ lexer->advance(lexer, false);
227
+ if ((current == '-' || current == '.') && lexer->lookahead == current) {
228
+ lexer->result_symbol = CLASS_COMPACT_IDENTIFIER;
229
+ return true;
230
+ }
231
+ // An o starting a new Jison word can own the following line operator.
232
+ // Retain the end before it until the next character resolves that choice.
233
+ aggregation_prefix = have_name && !previous_is_word && current == 'o';
234
+ previous_is_word = is_ascii_word_character(current);
235
+ have_name = true;
236
+ }
237
+ return false;
238
+ }
239
+
194
240
  static bool scan_directive_body(TSLexer *lexer) {
195
241
  bool consumed = false;
196
242
 
@@ -430,6 +476,10 @@ bool tree_sitter_mermaid_external_scanner_scan(void *payload, TSLexer *lexer,
430
476
  }
431
477
 
432
478
  const TokenGroup *group = requested_group(valid_symbols);
479
+ if (valid_symbols[CLASS_COMPACT_IDENTIFIER] &&
480
+ !valid_symbols[DIRECTIVE_BODY] && group == NULL) {
481
+ return scan_class_compact_identifier(lexer);
482
+ }
433
483
  if (group == NULL) {
434
484
  return false;
435
485
  }
Binary file
package/tree-sitter.json CHANGED
@@ -17,7 +17,7 @@
17
17
  }
18
18
  ],
19
19
  "metadata": {
20
- "version": "0.3.3",
20
+ "version": "0.3.4",
21
21
  "license": "MIT",
22
22
  "description": "Tolerant Tree-sitter grammar and editor queries for Mermaid",
23
23
  "authors": [