panache_parser/syntax/kind.rs
1//! Syntax kinds and language definition for the Quarto/Pandoc CST.
2
3use rowan::Language;
4
5#[allow(non_camel_case_types)]
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7#[repr(u16)]
8pub enum SyntaxKind {
9 // Tokens
10 WHITESPACE = 0,
11 NEWLINE,
12 TEXT,
13 BACKSLASH, // \ (for escaping)
14 ESCAPED_CHAR, // Any escaped character
15 NONBREAKING_SPACE, // \<space>
16 HARD_LINE_BREAK, // \<newline>
17 DIV_MARKER, // :::
18
19 // YAML tokens (metadata and in-tree YAML CST parser)
20 YAML_METADATA_DELIM, // --- or ... (for YAML blocks)
21 YAML_KEY, // YAML mapping key token
22 YAML_COLON, // YAML mapping key-value separator
23 YAML_TAG, // YAML explicit tag token (e.g. !!str)
24 YAML_ANCHOR, // YAML anchor token (e.g. &name)
25 YAML_ALIAS, // YAML alias token (e.g. *name)
26 YAML_SCALAR_TEXT, // YAML scalar content fragment (one physical line of a scalar)
27 YAML_FLOW_INDICATOR, // YAML flow structural punctuation ([ ] { } ,)
28 YAML_DIRECTIVE, // YAML directive line (%YAML, %TAG)
29 YAML_COMMENT, // YAML inline comment token
30 YAML_LINE_PREFIX, // Embedded-YAML per-line prefix trivia (hashpipe `#|`)
31 YAML_DOCUMENT_START, // YAML document start marker (---)
32 YAML_DOCUMENT_END, // YAML document end marker (...)
33
34 BLOCK_QUOTE_MARKER, // >
35 ALERT_MARKER, // [!NOTE], [!TIP], etc.
36 IMAGE_LINK_START, // ![
37 LIST_MARKER, // - + *
38 TASK_CHECKBOX, // [ ] or [x] or [X]
39 COMMENT_START, // <!--
40 COMMENT_END, // -->
41 ATTRIBUTE, // {#label} for headings, math, etc.
42 // Structured children of a Pandoc `{...}` ATTRIBUTE. Each wraps the
43 // existing source bytes (markers/quotes included); the projector strips
44 // them. Absent on opaque ATTRIBUTE forms (MMD `[#id]`, raw-inline
45 // `{=format}`, fallback), which keep a single inner ATTRIBUTE token.
46 ATTR_ID, // #id (token text includes the leading '#')
47 ATTR_CLASS, // .class (token text includes the leading '.')
48 ATTR_KEY_VALUE, // key=value (node grouping the pieces below)
49 ATTR_KEY, // key (token, no '=')
50 ATTR_VALUE, // value or "value"/'value' (token text includes quotes)
51 HORIZONTAL_RULE, // --- or *** or ___
52 BLANK_LINE,
53
54 // Links and images
55 LINK_START, // [
56 LINK, // [text](url)
57 LINK_TEXT, // text part of link
58 LINK_TEXT_END, // ] closing link text
59 LINK_DEST_START, // ( opening link destination
60 LINK_DEST, // (url) or (url "title")
61 LINK_DEST_END, // ) closing link destination
62 LINK_REF, // [ref] in reference links
63 IMAGE_LINK, // 
64 IMAGE_ALT, // alt text in image
65 IMAGE_ALT_END, // ] closing image alt
66 IMAGE_DEST_START, // ( opening image destination
67 IMAGE_DEST_END, // ) closing image destination
68 AUTO_LINK, // <http://example.com>
69 AUTO_LINK_MARKER, // < and >
70 REFERENCE_DEFINITION, // [label]: url "title"
71 FOOTNOTE_DEFINITION, // [^id]: content
72 FOOTNOTE_REFERENCE, // [^id]
73 FOOTNOTE_LABEL_START, // [^
74 FOOTNOTE_LABEL_ID, // id in [^id] or [^id]:
75 FOOTNOTE_LABEL_END, // ]
76 FOOTNOTE_LABEL_COLON, // :
77 REFERENCE_LABEL, // [label] part
78 REFERENCE_URL, // url part
79 REFERENCE_TITLE, // "title" part
80
81 // Wikilinks (Pandoc `wikilinks_title_{after,before}_pipe` extensions)
82 WIKI_LINK, // [[url]] or [[url|title]]
83 IMAGE_WIKI_LINK, // ![[url]] or ![[url|title]]
84 WIKI_LINK_OPEN, // [[ or ![[
85 WIKI_LINK_URL, // URL slot (raw TEXT child, no inline parsing)
86 WIKI_LINK_PIPE, // | separator
87 WIKI_LINK_TITLE, // title slot (raw TEXT child, no inline parsing)
88 WIKI_LINK_CLOSE, // ]]
89
90 // Math
91 INLINE_MATH_MARKER, // $
92 DISPLAY_MATH_MARKER, // $$
93 INLINE_MATH,
94 DISPLAY_MATH,
95 MATH_CONTENT, // wrapper node for parsed TeX math content (subtree root)
96
97 // Math content (structural TeX CST under MATH_CONTENT)
98 MATH_GROUP, // { ... } brace group (node)
99 MATH_ENVIRONMENT, // \begin{env} ... \end{env} (node)
100 MATH_GROUP_OPEN, // {
101 MATH_GROUP_CLOSE, // }
102 MATH_COMMAND, // \foo control word or \% control symbol
103 MATH_LINE_BREAK, // \\
104 MATH_ALIGN, // & alignment tab
105 MATH_SCRIPT, // ^ or _
106 MATH_COMMENT, // % to end of line (TeX comment)
107 // `+ - * = < >` operator atom; one token per char. Class/precedence are
108 // contextual (unary minus, `\mathbin`) and deferred to the formatter.
109 MATH_OPERATOR,
110 // Delimiters and punctuation whose TeX mathcode class is fixed at the
111 // character level (unlike operator class, which is contextual): `( [` open,
112 // `) ]` close, `, ;` punctuation. One token per char. The ambiguous `| . /`
113 // stay in MATH_TEXT — their class needs macro context.
114 MATH_OPEN, // ( or [
115 MATH_CLOSE, // ) or ]
116 MATH_PUNCT, // , or ;
117 MATH_TEXT, // run of ordinary atoms
118 MATH_SPACE, // run of spaces/tabs
119 MATH_NEWLINE, // newline within math content
120 // Bookdown equation label `(\#eq:label)`, recognized only when the
121 // `bookdown_equation_references` extension is enabled. A single token over
122 // the whole `(\#eq:...)` span so the indexer/LSP can target it precisely.
123 MATH_EQUATION_LABEL,
124
125 // Footnotes
126 INLINE_FOOTNOTE_START, // ^[
127 INLINE_FOOTNOTE_END, // ]
128 INLINE_FOOTNOTE, // ^[text]
129
130 // Citations
131 CITATION, // [@key] or @key
132 CITATION_MARKER, // @ or -@
133 CITATION_KEY, // The citation key identifier
134 CITATION_BRACE_OPEN, // { for complex keys
135 CITATION_BRACE_CLOSE, // } for complex keys
136 CITATION_CONTENT, // Text content in bracketed citations
137 CITATION_SEPARATOR, // ; between multiple citations
138 CROSSREF, // Quarto cross-reference: @fig-*, @eq-*, etc.
139 CROSSREF_MARKER, // @ or -@ for cross-references
140 CROSSREF_KEY, // Cross-reference key identifier
141 CROSSREF_BRACE_OPEN, // { for braced cross-reference keys
142 CROSSREF_BRACE_CLOSE, // } for braced cross-reference keys
143 CROSSREF_BOOKDOWN_OPEN, // \@ref(
144 CROSSREF_BOOKDOWN_CLOSE, // )
145
146 // Spans
147 BRACKETED_SPAN, // [text]{.class}
148 SPAN_CONTENT, // text inside span
149 SPAN_ATTRIBUTES, // {.class key="val"}
150 SPAN_BRACKET_OPEN, // [
151 SPAN_BRACKET_CLOSE, // ]
152
153 // Shortcodes (Quarto)
154 SHORTCODE, // {{< name args >}} or {{{< name args >}}}
155 SHORTCODE_MARKER_OPEN, // {{< or {{{<
156 SHORTCODE_MARKER_CLOSE, // >}} or >}}}
157 SHORTCODE_CONTENT, // content between markers
158
159 // Code
160 INLINE_CODE,
161 INLINE_CODE_MARKER, // ` or `` or ```
162 INLINE_CODE_CONTENT, // Literal inline code content
163 INLINE_EXEC, // Inline executable code span variants
164 INLINE_EXEC_MARKER, // Backtick markers delimiting inline executable code
165 INLINE_EXEC_LANG, // Runtime marker (`r` or `{r}`)
166 INLINE_EXEC_CONTENT, // Executable inline code expression
167 CODE_FENCE_MARKER, // ``` or ~~~
168 CODE_BLOCK,
169
170 // Raw inline spans
171 RAW_INLINE, // `content`{=format}
172 RAW_INLINE_MARKER, // ` markers
173 RAW_INLINE_FORMAT, // format name (html, latex, etc.)
174 RAW_INLINE_CONTENT, // raw content
175
176 // Inline emphasis and formatting
177 EMPHASIS, // *text* or _text_
178 STRONG, // **text** or __text__
179 STRIKEOUT, // ~~text~~
180 MARK, // ==text==
181 SUPERSCRIPT, // ^text^
182 SUBSCRIPT, // ~text~
183 EMPHASIS_MARKER, // * or _ (for emphasis)
184 STRONG_MARKER, // ** or __ (for strong)
185 STRIKEOUT_MARKER, // ~~ (for strikeout)
186 MARK_MARKER, // == (for mark/highlight)
187 SUPERSCRIPT_MARKER, // ^ (for superscript)
188 SUBSCRIPT_MARKER, // ~ (for subscript)
189
190 // Composite nodes
191 DOCUMENT,
192
193 // YAML nodes
194 YAML_METADATA,
195 YAML_METADATA_CONTENT, // Content lines inside YAML metadata block
196 YAML_STREAM, // YAML 1.2 stream wrapper (zero or more YAML_DOCUMENT children + trivia)
197 YAML_DOCUMENT, // a single YAML document (markers + body)
198 YAML_SCALAR, // YAML scalar value node (wraps YAML_SCALAR_TEXT content + NEWLINE/prefix leaves)
199 YAML_BLOCK_MAP, // YAML block mapping container
200 YAML_BLOCK_MAP_ENTRY, // YAML block mapping entry (key: value)
201 YAML_BLOCK_MAP_KEY, // YAML block mapping key wrapper
202 YAML_BLOCK_MAP_VALUE, // YAML block mapping value wrapper
203 YAML_FLOW_MAP, // YAML flow mapping container ({key: value, ...})
204 YAML_FLOW_MAP_ENTRY, // YAML flow mapping entry
205 YAML_FLOW_MAP_KEY, // YAML flow mapping key wrapper
206 YAML_FLOW_MAP_VALUE, // YAML flow mapping value wrapper
207 YAML_FLOW_SEQUENCE, // YAML flow sequence container ([a, b, ...])
208 YAML_FLOW_SEQUENCE_ITEM, // YAML flow sequence item wrapper
209 YAML_BLOCK_SEQUENCE, // YAML block sequence container (- item ...)
210 YAML_BLOCK_SEQUENCE_ITEM, // YAML block sequence item wrapper
211 YAML_BLOCK_SEQ_ENTRY, // YAML block sequence entry marker (-)
212
213 PANDOC_TITLE_BLOCK,
214 MMD_TITLE_BLOCK,
215 FENCED_DIV,
216 PARAGRAPH,
217 PLAIN, // Inline content without paragraph break (tight lists, definition lists, table cells)
218 BLOCK_QUOTE,
219 ALERT,
220 LIST,
221 LIST_ITEM,
222 DEFINITION_LIST,
223 DEFINITION_ITEM,
224 TERM,
225 DEFINITION,
226 DEFINITION_MARKER, // : or ~
227 LINE_BLOCK,
228 LINE_BLOCK_LINE,
229 LINE_BLOCK_MARKER, // |
230 COMMENT,
231 FIGURE, // Standalone image (Pandoc figure)
232
233 // HTML blocks
234 HTML_BLOCK, // Generic HTML block
235 HTML_BLOCK_TAG, // Opening/closing tags
236 HTML_BLOCK_CONTENT, // Content between tags
237 // Pandoc-dialect lift: a matched <div ...>...</div> block.
238 HTML_BLOCK_DIV,
239 // Structural region inside an HTML opening tag holding the
240 // attribute-list bytes — i.e. everything between the tag name and
241 // the closing `>`, exclusive. Recognized by `AttributeNode::cast`,
242 // so the salsa anchor index sees `id`/`class`/key=val attrs from
243 // `<div id="x">` blocks via the same walk that handles fenced-div
244 // and heading attributes.
245 HTML_ATTRS,
246
247 // Inline raw HTML (CommonMark §6.6 / Pandoc raw_html). One node per HTML
248 // tag/comment/declaration/PI/CDATA span; child token holds the verbatim
249 // bytes of the span.
250 INLINE_HTML,
251 INLINE_HTML_CONTENT,
252 // Pandoc-dialect inline lift: a matched <span ...>...</span> tag pair,
253 // mirroring HTML_BLOCK_DIV at the inline level. The open tag's
254 // attribute region is exposed structurally as HTML_ATTRS so the
255 // existing AttributeNode walk picks up `<span id>` ids automatically.
256 INLINE_HTML_SPAN,
257
258 // TeX blocks
259 TEX_BLOCK, // Raw tex block (e.g., LaTeX commands)
260
261 // Headings
262 HEADING,
263 HEADING_CONTENT,
264 ATX_HEADING_MARKER, // leading #####
265 SETEXT_HEADING_UNDERLINE, // ===== or -----
266
267 // LaTeX inline commands
268 LATEX_COMMAND, // \command{...}
269
270 // Tables
271 SIMPLE_TABLE,
272 MULTILINE_TABLE,
273 PIPE_TABLE,
274 GRID_TABLE,
275 TABLE_HEADER,
276 TABLE_FOOTER,
277 TABLE_SEPARATOR,
278 TABLE_ROW,
279 TABLE_CELL,
280 TABLE_CAPTION,
281 TABLE_CAPTION_PREFIX, // "Table: ", "table: ", or ": "
282
283 // Code block parts
284 CODE_FENCE_OPEN,
285 CODE_FENCE_CLOSE,
286 CODE_INFO, // Raw info string (preserved for lossless formatting)
287 CODE_LANGUAGE, // Parsed language identifier (r, python, etc.)
288
289 // Chunk options (for executable chunks like {r, echo=TRUE})
290 CHUNK_OPTIONS, // Container for all chunk options
291 CHUNK_OPTION, // Single option (key=value pair)
292 CHUNK_OPTION_KEY, // Option name (e.g., echo, fig.cap)
293 CHUNK_OPTION_VALUE, // Option value (e.g., TRUE, "text")
294 CHUNK_OPTION_QUOTE, // Quote character (" or ') if present
295 CHUNK_LABEL, // Special case: unlabeled first option in {r mylabel}
296 HASHPIPE_YAML_PREAMBLE, // Hashpipe YAML option preamble region inside CODE_CONTENT
297 HASHPIPE_YAML_CONTENT, // Content lines belonging to hashpipe YAML preamble
298 HASHPIPE_PREFIX, // Hashpipe option marker prefix (e.g., #|, //|, --|)
299
300 CODE_CONTENT,
301
302 // Div parts
303 DIV_FENCE_OPEN,
304 DIV_FENCE_CLOSE,
305 DIV_INFO,
306 DIV_CONTENT,
307 EMOJI, // :alias:
308
309 // Bracket-shape pattern that did not resolve as a link/image.
310 // Distinct from LINK/IMAGE_LINK so downstream tools (linter, LSP) can
311 // walk a typed wrapper without the parser having to lie about
312 // resolution. `is_image()` on the typed wrapper distinguishes
313 // `[foo]` from `![foo]` shapes.
314 UNRESOLVED_REFERENCE,
315}
316
317impl From<SyntaxKind> for rowan::SyntaxKind {
318 fn from(kind: SyntaxKind) -> Self {
319 Self(kind as u16)
320 }
321}
322
323#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
324pub enum PanacheLanguage {}
325
326impl Language for PanacheLanguage {
327 type Kind = SyntaxKind;
328
329 fn kind_from_raw(raw: rowan::SyntaxKind) -> Self::Kind {
330 unsafe { std::mem::transmute::<u16, SyntaxKind>(raw.0) }
331 }
332
333 fn kind_to_raw(kind: Self::Kind) -> rowan::SyntaxKind {
334 kind.into()
335 }
336}