tree-sitter-ucode 0.1.2 → 0.3.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.
package/tmpl/grammar.js CHANGED
@@ -33,6 +33,7 @@ module.exports = grammar({
33
33
  $._stmt_code, // content between {% ... %} (before the closer)
34
34
  $._expr_code, // content between {{ ... }} (before the closer)
35
35
  $._comment_body, // content between {# ... #} (before the closer)
36
+ $.eof_close, // emitted at EOF when inside a statement tag (implicit close)
36
37
  ],
37
38
 
38
39
  // The template scanner handles all whitespace explicitly; no implicit extras.
@@ -49,7 +50,7 @@ module.exports = grammar({
49
50
  statement_tag: $ => seq(
50
51
  field('open', choice('{%-', '{%+', '{%')),
51
52
  field('code', optional(alias($._stmt_code, $.code))),
52
- field('close', choice('-%}', '%}')),
53
+ field('close', choice('-%}', '%}', $.eof_close)),
53
54
  ),
54
55
 
55
56
  expression_tag: $ => seq(
@@ -0,0 +1,4 @@
1
+ ; Fold queries for ucode_tmpl.
2
+ ; Folds are not meaningful at the template document level since each tag is
3
+ ; typically one or a few lines. Folding inside code blocks is handled by the
4
+ ; injected ucode grammar.
@@ -0,0 +1,5 @@
1
+ ; Indentation queries for ucode_tmpl.
2
+ ; Raw text between tags is not indented by the template engine, so there are
3
+ ; no template-level indent rules. Code inside statement_tag and expression_tag
4
+ ; is parsed via language injection (see injections.scm) and indented according
5
+ ; to the injected ucode grammar's indents.scm.
@@ -89,6 +89,10 @@
89
89
  {
90
90
  "type": "STRING",
91
91
  "value": "%}"
92
+ },
93
+ {
94
+ "type": "SYMBOL",
95
+ "name": "eof_close"
92
96
  }
93
97
  ]
94
98
  }
@@ -235,6 +239,10 @@
235
239
  {
236
240
  "type": "SYMBOL",
237
241
  "name": "_comment_body"
242
+ },
243
+ {
244
+ "type": "SYMBOL",
245
+ "name": "eof_close"
238
246
  }
239
247
  ],
240
248
  "inline": [],
@@ -130,6 +130,10 @@
130
130
  {
131
131
  "type": "-%}",
132
132
  "named": false
133
+ },
134
+ {
135
+ "type": "eof_close",
136
+ "named": true
133
137
  }
134
138
  ]
135
139
  },
@@ -191,6 +195,10 @@
191
195
  "type": "comment_content",
192
196
  "named": true
193
197
  },
198
+ {
199
+ "type": "eof_close",
200
+ "named": true
201
+ },
194
202
  {
195
203
  "type": "raw_text",
196
204
  "named": true
package/tmpl/src/parser.c CHANGED
@@ -9,10 +9,10 @@
9
9
  #define LANGUAGE_VERSION 15
10
10
  #define STATE_COUNT 17
11
11
  #define LARGE_STATE_COUNT 4
12
- #define SYMBOL_COUNT 23
12
+ #define SYMBOL_COUNT 24
13
13
  #define ALIAS_COUNT 0
14
- #define TOKEN_COUNT 18
15
- #define EXTERNAL_TOKEN_COUNT 4
14
+ #define TOKEN_COUNT 19
15
+ #define EXTERNAL_TOKEN_COUNT 5
16
16
  #define FIELD_COUNT 4
17
17
  #define MAX_ALIAS_SEQUENCE_LENGTH 3
18
18
  #define MAX_RESERVED_WORD_SET_SIZE 0
@@ -37,11 +37,12 @@ enum ts_symbol_identifiers {
37
37
  sym__stmt_code = 15,
38
38
  sym__expr_code = 16,
39
39
  sym__comment_body = 17,
40
- sym_document = 18,
41
- sym_statement_tag = 19,
42
- sym_expression_tag = 20,
43
- sym_comment_tag = 21,
44
- aux_sym_document_repeat1 = 22,
40
+ sym_eof_close = 18,
41
+ sym_document = 19,
42
+ sym_statement_tag = 20,
43
+ sym_expression_tag = 21,
44
+ sym_comment_tag = 22,
45
+ aux_sym_document_repeat1 = 23,
45
46
  };
46
47
 
47
48
  static const char * const ts_symbol_names[] = {
@@ -63,6 +64,7 @@ static const char * const ts_symbol_names[] = {
63
64
  [sym__stmt_code] = "code",
64
65
  [sym__expr_code] = "code",
65
66
  [sym__comment_body] = "comment_content",
67
+ [sym_eof_close] = "eof_close",
66
68
  [sym_document] = "document",
67
69
  [sym_statement_tag] = "statement_tag",
68
70
  [sym_expression_tag] = "expression_tag",
@@ -89,6 +91,7 @@ static const TSSymbol ts_symbol_map[] = {
89
91
  [sym__stmt_code] = sym__stmt_code,
90
92
  [sym__expr_code] = sym__stmt_code,
91
93
  [sym__comment_body] = sym__comment_body,
94
+ [sym_eof_close] = sym_eof_close,
92
95
  [sym_document] = sym_document,
93
96
  [sym_statement_tag] = sym_statement_tag,
94
97
  [sym_expression_tag] = sym_expression_tag,
@@ -169,6 +172,10 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
169
172
  .visible = true,
170
173
  .named = true,
171
174
  },
175
+ [sym_eof_close] = {
176
+ .visible = true,
177
+ .named = true,
178
+ },
172
179
  [sym_document] = {
173
180
  .visible = true,
174
181
  .named = true,
@@ -359,7 +366,7 @@ static const TSLexerMode ts_lex_modes[STATE_COUNT] = {
359
366
  [10] = {.lex_state = 0, .external_lex_state = 3},
360
367
  [11] = {.lex_state = 0, .external_lex_state = 4},
361
368
  [12] = {.lex_state = 0, .external_lex_state = 5},
362
- [13] = {.lex_state = 0},
369
+ [13] = {.lex_state = 0, .external_lex_state = 6},
363
370
  [14] = {.lex_state = 0},
364
371
  [15] = {.lex_state = 0},
365
372
  [16] = {.lex_state = 0},
@@ -385,6 +392,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
385
392
  [sym__stmt_code] = ACTIONS(1),
386
393
  [sym__expr_code] = ACTIONS(1),
387
394
  [sym__comment_body] = ACTIONS(1),
395
+ [sym_eof_close] = ACTIONS(1),
388
396
  },
389
397
  [STATE(1)] = {
390
398
  [sym_document] = STATE(16),
@@ -510,34 +518,36 @@ static const uint16_t ts_small_parse_table[] = {
510
518
  [84] = 2,
511
519
  ACTIONS(72), 1,
512
520
  sym__stmt_code,
513
- ACTIONS(70), 2,
521
+ ACTIONS(70), 3,
522
+ sym_eof_close,
514
523
  anon_sym_DASH_PERCENT_RBRACE,
515
524
  anon_sym_PERCENT_RBRACE,
516
- [92] = 2,
525
+ [93] = 2,
517
526
  ACTIONS(76), 1,
518
527
  sym__expr_code,
519
528
  ACTIONS(74), 2,
520
529
  anon_sym_DASH_RBRACE_RBRACE,
521
530
  anon_sym_RBRACE_RBRACE,
522
- [100] = 2,
531
+ [101] = 2,
523
532
  ACTIONS(80), 1,
524
533
  sym__comment_body,
525
534
  ACTIONS(78), 2,
526
535
  anon_sym_DASH_POUND_RBRACE,
527
536
  anon_sym_POUND_RBRACE,
528
- [108] = 1,
529
- ACTIONS(82), 2,
537
+ [109] = 1,
538
+ ACTIONS(82), 3,
539
+ sym_eof_close,
530
540
  anon_sym_DASH_PERCENT_RBRACE,
531
541
  anon_sym_PERCENT_RBRACE,
532
- [113] = 1,
542
+ [115] = 1,
533
543
  ACTIONS(84), 2,
534
544
  anon_sym_DASH_RBRACE_RBRACE,
535
545
  anon_sym_RBRACE_RBRACE,
536
- [118] = 1,
546
+ [120] = 1,
537
547
  ACTIONS(86), 2,
538
548
  anon_sym_DASH_POUND_RBRACE,
539
549
  anon_sym_POUND_RBRACE,
540
- [123] = 1,
550
+ [125] = 1,
541
551
  ACTIONS(88), 1,
542
552
  ts_builtin_sym_end,
543
553
  };
@@ -550,12 +560,12 @@ static const uint32_t ts_small_parse_table_map[] = {
550
560
  [SMALL_STATE(8)] = 56,
551
561
  [SMALL_STATE(9)] = 70,
552
562
  [SMALL_STATE(10)] = 84,
553
- [SMALL_STATE(11)] = 92,
554
- [SMALL_STATE(12)] = 100,
555
- [SMALL_STATE(13)] = 108,
556
- [SMALL_STATE(14)] = 113,
557
- [SMALL_STATE(15)] = 118,
558
- [SMALL_STATE(16)] = 123,
563
+ [SMALL_STATE(11)] = 93,
564
+ [SMALL_STATE(12)] = 101,
565
+ [SMALL_STATE(13)] = 109,
566
+ [SMALL_STATE(14)] = 115,
567
+ [SMALL_STATE(15)] = 120,
568
+ [SMALL_STATE(16)] = 125,
559
569
  };
560
570
 
561
571
  static const TSParseActionEntry ts_parse_actions[] = {
@@ -608,6 +618,7 @@ enum ts_external_scanner_symbol_identifiers {
608
618
  ts_external_token__stmt_code = 1,
609
619
  ts_external_token__expr_code = 2,
610
620
  ts_external_token__comment_body = 3,
621
+ ts_external_token_eof_close = 4,
611
622
  };
612
623
 
613
624
  static const TSSymbol ts_external_scanner_symbol_map[EXTERNAL_TOKEN_COUNT] = {
@@ -615,20 +626,23 @@ static const TSSymbol ts_external_scanner_symbol_map[EXTERNAL_TOKEN_COUNT] = {
615
626
  [ts_external_token__stmt_code] = sym__stmt_code,
616
627
  [ts_external_token__expr_code] = sym__expr_code,
617
628
  [ts_external_token__comment_body] = sym__comment_body,
629
+ [ts_external_token_eof_close] = sym_eof_close,
618
630
  };
619
631
 
620
- static const bool ts_external_scanner_states[6][EXTERNAL_TOKEN_COUNT] = {
632
+ static const bool ts_external_scanner_states[7][EXTERNAL_TOKEN_COUNT] = {
621
633
  [1] = {
622
634
  [ts_external_token__raw_text] = true,
623
635
  [ts_external_token__stmt_code] = true,
624
636
  [ts_external_token__expr_code] = true,
625
637
  [ts_external_token__comment_body] = true,
638
+ [ts_external_token_eof_close] = true,
626
639
  },
627
640
  [2] = {
628
641
  [ts_external_token__raw_text] = true,
629
642
  },
630
643
  [3] = {
631
644
  [ts_external_token__stmt_code] = true,
645
+ [ts_external_token_eof_close] = true,
632
646
  },
633
647
  [4] = {
634
648
  [ts_external_token__expr_code] = true,
@@ -636,6 +650,9 @@ static const bool ts_external_scanner_states[6][EXTERNAL_TOKEN_COUNT] = {
636
650
  [5] = {
637
651
  [ts_external_token__comment_body] = true,
638
652
  },
653
+ [6] = {
654
+ [ts_external_token_eof_close] = true,
655
+ },
639
656
  };
640
657
 
641
658
  #ifdef __cplusplus
@@ -696,8 +713,8 @@ TS_PUBLIC const TSLanguage *tree_sitter_ucode_tmpl(void) {
696
713
  .max_reserved_word_set_size = 0,
697
714
  .metadata = {
698
715
  .major_version = 0,
699
- .minor_version = 1,
700
- .patch_version = 2,
716
+ .minor_version = 3,
717
+ .patch_version = 0,
701
718
  },
702
719
  };
703
720
  return &language;
@@ -6,6 +6,7 @@ enum TokenType {
6
6
  STMT_CODE,
7
7
  EXPR_CODE,
8
8
  COMMENT_BODY,
9
+ EOF_CLOSE,
9
10
  };
10
11
 
11
12
  void *tree_sitter_ucode_tmpl_external_scanner_create(void) { return NULL; }
@@ -160,6 +161,10 @@ bool tree_sitter_ucode_tmpl_external_scanner_scan(
160
161
  ) {
161
162
  (void)payload;
162
163
 
164
+ if (valid_symbols[EOF_CLOSE] && lexer->lookahead == '\0') {
165
+ lexer->result_symbol = EOF_CLOSE;
166
+ return true;
167
+ }
163
168
  if (valid_symbols[RAW_TEXT]) return scan_raw_text(lexer);
164
169
  if (valid_symbols[STMT_CODE]) return scan_stmt_code(lexer);
165
170
  if (valid_symbols[EXPR_CODE]) return scan_expr_code(lexer);
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -1,33 +1,15 @@
1
1
  {
2
2
  "grammars": [
3
- {
4
- "name": "ucode",
5
- "camelcase": "Ucode",
6
- "scope": "source.uc",
7
- "path": ".",
8
- "file-types": [
9
- "uc"
10
- ],
11
- "highlights": [
12
- "queries/highlights.scm"
13
- ],
14
- "locals": [
15
- "queries/locals.scm"
16
- ],
17
- "tags": [
18
- "queries/tags.scm"
19
- ],
20
- "injection-regex": "^ucode$"
21
- },
22
3
  {
23
4
  "name": "ucode_tmpl",
24
5
  "camelcase": "UcodeTmpl",
25
6
  "scope": "source.uc.tmpl",
26
7
  "path": "./tmpl",
27
8
  "file-types": [
28
- "uc.tmpl",
9
+ "uc",
29
10
  "utpl"
30
11
  ],
12
+ "content-regex": "(?m)^\\s*\\{[%{#]",
31
13
  "highlights": [
32
14
  "tmpl/queries/highlights.scm"
33
15
  ],
@@ -38,10 +20,29 @@
38
20
  "tmpl/queries/injections.scm"
39
21
  ],
40
22
  "injection-regex": "^ucode_tmpl$"
23
+ },
24
+ {
25
+ "name": "ucode",
26
+ "camelcase": "Ucode",
27
+ "scope": "source.uc",
28
+ "path": ".",
29
+ "file-types": [
30
+ "uc"
31
+ ],
32
+ "highlights": [
33
+ "queries/highlights.scm"
34
+ ],
35
+ "locals": [
36
+ "queries/locals.scm"
37
+ ],
38
+ "tags": [
39
+ "queries/tags.scm"
40
+ ],
41
+ "injection-regex": "^ucode$"
41
42
  }
42
43
  ],
43
44
  "metadata": {
44
- "version": "0.1.2",
45
+ "version": "0.3.0",
45
46
  "license": "MIT",
46
47
  "description": "Ucode grammar for tree-sitter",
47
48
  "links": {