@nvl/tree-sitter-sveltex 0.2.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/LICENSE +21 -0
- package/README.md +83 -0
- package/binding.gyp +30 -0
- package/bindings/node/binding.cc +19 -0
- package/bindings/node/index.js +13 -0
- package/grammar.js +264 -0
- package/package.json +76 -0
- package/queries/folds.scm +18 -0
- package/queries/highlights.scm +51 -0
- package/queries/injections.scm +97 -0
- package/src/grammar.json +742 -0
- package/src/node-types.json +331 -0
- package/src/parser.c +2007 -0
- package/src/scanner.c +847 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +330 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter.json +45 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
; Language injections for the SvelTeX (`.sveltex`) grammar.
|
|
2
|
+
;
|
|
3
|
+
; The `.sveltex` grammar parses only the top-level structure; every embedded
|
|
4
|
+
; language is delegated to an existing grammar through the injections below.
|
|
5
|
+
; This is the whole point of the grammar — Markdown, Svelte and LaTeX are NOT
|
|
6
|
+
; reimplemented here.
|
|
7
|
+
;
|
|
8
|
+
; Capture conventions (shared by tree-sitter, Zed, Neovim, Helix):
|
|
9
|
+
; * @injection.content — the node whose text is reparsed,
|
|
10
|
+
; * @injection.language — a node whose *text* names the language, or
|
|
11
|
+
; * (#set! injection.language "name") — a fixed language name.
|
|
12
|
+
; `injection.combined` joins several sibling content nodes into one virtual
|
|
13
|
+
; document before parsing (used so all Markdown chunks form one document).
|
|
14
|
+
|
|
15
|
+
; ── Markdown prose ───────────────────────────────────────────────────────
|
|
16
|
+
;
|
|
17
|
+
; Every `markdown_chunk` is delegated to the standard `markdown` grammar.
|
|
18
|
+
; `injection.combined` stitches all chunks of a document back together, so the
|
|
19
|
+
; embedded Markdown parser sees one continuous document and block constructs
|
|
20
|
+
; (lists, tables, reference links, ...) that happen to straddle a `.sveltex`
|
|
21
|
+
; construct still resolve correctly.
|
|
22
|
+
;
|
|
23
|
+
; The `markdown` grammar in turn injects `markdown_inline` for inline spans,
|
|
24
|
+
; the fenced-code languages for ``` blocks, and `html`/`svelte` for embedded
|
|
25
|
+
; markup — so Svelte `<script>`, logic blocks and mustache tags are handled by
|
|
26
|
+
; that downstream grammar, exactly as they are in a plain `.svelte`/`.md`
|
|
27
|
+
; setup.
|
|
28
|
+
((markdown_chunk) @injection.content
|
|
29
|
+
(#set! injection.language "markdown")
|
|
30
|
+
(#set! injection.combined))
|
|
31
|
+
|
|
32
|
+
; ── Frontmatter ──────────────────────────────────────────────────────────
|
|
33
|
+
;
|
|
34
|
+
; The fenced frontmatter block carries an optional language keyword
|
|
35
|
+
; (`yaml`/`toml`/`json`); when present, the keyword node's text names the
|
|
36
|
+
; embedded language directly.
|
|
37
|
+
(frontmatter
|
|
38
|
+
language: (frontmatter_language) @injection.language
|
|
39
|
+
content: (frontmatter_content) @injection.content)
|
|
40
|
+
|
|
41
|
+
; A `---`-fenced frontmatter block with no keyword defaults to YAML, matching
|
|
42
|
+
; SvelTeX's own default. The `!language` constraint keeps this from also
|
|
43
|
+
; matching the keyword form above; `#eq?` distinguishes it from the `+++`
|
|
44
|
+
; form below.
|
|
45
|
+
(frontmatter
|
|
46
|
+
open: (frontmatter_fence) @_fence
|
|
47
|
+
content: (frontmatter_content) @injection.content
|
|
48
|
+
!language
|
|
49
|
+
(#eq? @_fence "---")
|
|
50
|
+
(#set! injection.language "yaml"))
|
|
51
|
+
|
|
52
|
+
; A `+++`-fenced frontmatter block is always TOML (the SvelTeX shorthand); it
|
|
53
|
+
; never carries a language keyword.
|
|
54
|
+
(frontmatter
|
|
55
|
+
open: (frontmatter_fence) @_fence
|
|
56
|
+
content: (frontmatter_content) @injection.content
|
|
57
|
+
(#eq? @_fence "+++")
|
|
58
|
+
(#set! injection.language "toml"))
|
|
59
|
+
|
|
60
|
+
; ── Math ─────────────────────────────────────────────────────────────────
|
|
61
|
+
;
|
|
62
|
+
; All four delimiter styles carry LaTeX math. The `latex` grammar parses math
|
|
63
|
+
; mode happily even without the surrounding `$`/`\(` delimiters.
|
|
64
|
+
((math_content_display) @injection.content
|
|
65
|
+
(#set! injection.language "latex"))
|
|
66
|
+
|
|
67
|
+
((math_content_inline) @injection.content
|
|
68
|
+
(#set! injection.language "latex"))
|
|
69
|
+
|
|
70
|
+
((math_content_bracket) @injection.content
|
|
71
|
+
(#set! injection.language "latex"))
|
|
72
|
+
|
|
73
|
+
((math_content_paren) @injection.content
|
|
74
|
+
(#set! injection.language "latex"))
|
|
75
|
+
|
|
76
|
+
; ── Verbatim environments ────────────────────────────────────────────────
|
|
77
|
+
;
|
|
78
|
+
; A `<tex>`/`<latex>`/`<tikz>` environment holds a full LaTeX document
|
|
79
|
+
; fragment; delegate it to the `latex` grammar.
|
|
80
|
+
((tex_verbatim_body) @injection.content
|
|
81
|
+
(#set! injection.language "latex"))
|
|
82
|
+
|
|
83
|
+
; The opening/closing tags of every verbatim environment are HTML-like Svelte
|
|
84
|
+
; markup; hand them to the `svelte` grammar so attributes (which may contain
|
|
85
|
+
; Svelte expressions) are highlighted consistently with the rest of the file.
|
|
86
|
+
((verbatim_tex_open_tag) @injection.content
|
|
87
|
+
(#set! injection.language "svelte"))
|
|
88
|
+
|
|
89
|
+
((verbatim_plain_open_tag) @injection.content
|
|
90
|
+
(#set! injection.language "svelte"))
|
|
91
|
+
|
|
92
|
+
((verbatim_close_tag) @injection.content
|
|
93
|
+
(#set! injection.language "svelte"))
|
|
94
|
+
|
|
95
|
+
; A `<verb>`/`<verbatim>` environment is intentionally opaque (SvelTeX escapes
|
|
96
|
+
; its contents rather than rendering them), so `plain_verbatim_body` is left
|
|
97
|
+
; un-injected — it is plain text.
|