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 shadow 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_SCALAR, // YAML scalar value token
25 YAML_COMMENT, // YAML inline comment token
26 YAML_DOCUMENT_START, // YAML document start marker (---) in shadow parser
27 YAML_DOCUMENT_END, // YAML document end marker (...) in shadow parser
28
29 BLOCK_QUOTE_MARKER, // >
30 ALERT_MARKER, // [!NOTE], [!TIP], etc.
31 IMAGE_LINK_START, // ![
32 LIST_MARKER, // - + *
33 TASK_CHECKBOX, // [ ] or [x] or [X]
34 COMMENT_START, // <!--
35 COMMENT_END, // -->
36 ATTRIBUTE, // {#label} for headings, math, etc.
37 HORIZONTAL_RULE, // --- or *** or ___
38 BLANK_LINE,
39
40 // Links and images
41 LINK_START, // [
42 LINK, // [text](url)
43 LINK_TEXT, // text part of link
44 LINK_TEXT_END, // ] closing link text
45 LINK_DEST_START, // ( opening link destination
46 LINK_DEST, // (url) or (url "title")
47 LINK_DEST_END, // ) closing link destination
48 LINK_REF, // [ref] in reference links
49 IMAGE_LINK, // 
50 IMAGE_ALT, // alt text in image
51 IMAGE_ALT_END, // ] closing image alt
52 IMAGE_DEST_START, // ( opening image destination
53 IMAGE_DEST_END, // ) closing image destination
54 AUTO_LINK, // <http://example.com>
55 AUTO_LINK_MARKER, // < and >
56 REFERENCE_DEFINITION, // [label]: url "title"
57 FOOTNOTE_DEFINITION, // [^id]: content
58 FOOTNOTE_REFERENCE, // [^id]
59 FOOTNOTE_LABEL_START, // [^
60 FOOTNOTE_LABEL_ID, // id in [^id] or [^id]:
61 FOOTNOTE_LABEL_END, // ]
62 FOOTNOTE_LABEL_COLON, // :
63 REFERENCE_LABEL, // [label] part
64 REFERENCE_URL, // url part
65 REFERENCE_TITLE, // "title" part
66
67 // Math
68 INLINE_MATH_MARKER, // $
69 DISPLAY_MATH_MARKER, // $$
70 INLINE_MATH,
71 DISPLAY_MATH,
72 MATH_CONTENT,
73
74 // Footnotes
75 INLINE_FOOTNOTE_START, // ^[
76 INLINE_FOOTNOTE_END, // ]
77 INLINE_FOOTNOTE, // ^[text]
78
79 // Citations
80 CITATION, // [@key] or @key
81 CITATION_MARKER, // @ or -@
82 CITATION_KEY, // The citation key identifier
83 CITATION_BRACE_OPEN, // { for complex keys
84 CITATION_BRACE_CLOSE, // } for complex keys
85 CITATION_CONTENT, // Text content in bracketed citations
86 CITATION_SEPARATOR, // ; between multiple citations
87 CROSSREF, // Quarto cross-reference: @fig-*, @eq-*, etc.
88 CROSSREF_MARKER, // @ or -@ for cross-references
89 CROSSREF_KEY, // Cross-reference key identifier
90 CROSSREF_BRACE_OPEN, // { for braced cross-reference keys
91 CROSSREF_BRACE_CLOSE, // } for braced cross-reference keys
92 CROSSREF_BOOKDOWN_OPEN, // \@ref(
93 CROSSREF_BOOKDOWN_CLOSE, // )
94
95 // Spans
96 BRACKETED_SPAN, // [text]{.class}
97 SPAN_CONTENT, // text inside span
98 SPAN_ATTRIBUTES, // {.class key="val"}
99 SPAN_BRACKET_OPEN, // [
100 SPAN_BRACKET_CLOSE, // ]
101
102 // Shortcodes (Quarto)
103 SHORTCODE, // {{< name args >}} or {{{< name args >}}}
104 SHORTCODE_MARKER_OPEN, // {{< or {{{<
105 SHORTCODE_MARKER_CLOSE, // >}} or >}}}
106 SHORTCODE_CONTENT, // content between markers
107
108 // Code
109 INLINE_CODE,
110 INLINE_CODE_MARKER, // ` or `` or ```
111 INLINE_CODE_CONTENT, // Literal inline code content
112 INLINE_EXEC, // Inline executable code span variants
113 INLINE_EXEC_MARKER, // Backtick markers delimiting inline executable code
114 INLINE_EXEC_LANG, // Runtime marker (`r` or `{r}`)
115 INLINE_EXEC_CONTENT, // Executable inline code expression
116 CODE_FENCE_MARKER, // ``` or ~~~
117 CODE_BLOCK,
118
119 // Raw inline spans
120 RAW_INLINE, // `content`{=format}
121 RAW_INLINE_MARKER, // ` markers
122 RAW_INLINE_FORMAT, // format name (html, latex, etc.)
123 RAW_INLINE_CONTENT, // raw content
124
125 // Inline emphasis and formatting
126 EMPHASIS, // *text* or _text_
127 STRONG, // **text** or __text__
128 STRIKEOUT, // ~~text~~
129 MARK, // ==text==
130 SUPERSCRIPT, // ^text^
131 SUBSCRIPT, // ~text~
132 EMPHASIS_MARKER, // * or _ (for emphasis)
133 STRONG_MARKER, // ** or __ (for strong)
134 STRIKEOUT_MARKER, // ~~ (for strikeout)
135 MARK_MARKER, // == (for mark/highlight)
136 SUPERSCRIPT_MARKER, // ^ (for superscript)
137 SUBSCRIPT_MARKER, // ~ (for subscript)
138
139 // Composite nodes
140 DOCUMENT,
141
142 // YAML nodes
143 YAML_METADATA,
144 YAML_METADATA_CONTENT, // Content lines inside YAML metadata block
145 YAML_STREAM, // Shadow parser only: YAML 1.2 stream wrapper (zero or more YAML_DOCUMENT children + trivia)
146 YAML_DOCUMENT, // Shadow parser only: a single YAML document (markers + body)
147 YAML_BLOCK_MAP, // YAML block mapping container (prototype shadow parser)
148 YAML_BLOCK_MAP_ENTRY, // YAML block mapping entry (key: value)
149 YAML_BLOCK_MAP_KEY, // YAML block mapping key wrapper
150 YAML_BLOCK_MAP_VALUE, // YAML block mapping value wrapper
151 YAML_FLOW_MAP, // YAML flow mapping container ({key: value, ...})
152 YAML_FLOW_MAP_ENTRY, // YAML flow mapping entry
153 YAML_FLOW_MAP_KEY, // YAML flow mapping key wrapper
154 YAML_FLOW_MAP_VALUE, // YAML flow mapping value wrapper
155 YAML_FLOW_SEQUENCE, // YAML flow sequence container ([a, b, ...])
156 YAML_FLOW_SEQUENCE_ITEM, // YAML flow sequence item wrapper
157 YAML_BLOCK_SEQUENCE, // YAML block sequence container (- item ...)
158 YAML_BLOCK_SEQUENCE_ITEM, // YAML block sequence item wrapper
159 YAML_BLOCK_SEQ_ENTRY, // YAML block sequence entry marker (-)
160
161 PANDOC_TITLE_BLOCK,
162 MMD_TITLE_BLOCK,
163 FENCED_DIV,
164 PARAGRAPH,
165 PLAIN, // Inline content without paragraph break (tight lists, definition lists, table cells)
166 BLOCK_QUOTE,
167 ALERT,
168 LIST,
169 LIST_ITEM,
170 DEFINITION_LIST,
171 DEFINITION_ITEM,
172 TERM,
173 DEFINITION,
174 DEFINITION_MARKER, // : or ~
175 LINE_BLOCK,
176 LINE_BLOCK_LINE,
177 LINE_BLOCK_MARKER, // |
178 COMMENT,
179 FIGURE, // Standalone image (Pandoc figure)
180
181 // HTML blocks
182 HTML_BLOCK, // Generic HTML block
183 HTML_BLOCK_TAG, // Opening/closing tags
184 HTML_BLOCK_CONTENT, // Content between tags
185 // Pandoc-dialect lift: a matched <div ...>...</div> block.
186 HTML_BLOCK_DIV,
187 // Structural region inside an HTML opening tag holding the
188 // attribute-list bytes — i.e. everything between the tag name and
189 // the closing `>`, exclusive. Recognized by `AttributeNode::cast`,
190 // so the salsa anchor index sees `id`/`class`/key=val attrs from
191 // `<div id="x">` blocks via the same walk that handles fenced-div
192 // and heading attributes.
193 HTML_ATTRS,
194
195 // Inline raw HTML (CommonMark §6.6 / Pandoc raw_html). One node per HTML
196 // tag/comment/declaration/PI/CDATA span; child token holds the verbatim
197 // bytes of the span.
198 INLINE_HTML,
199 INLINE_HTML_CONTENT,
200 // Pandoc-dialect inline lift: a matched <span ...>...</span> tag pair,
201 // mirroring HTML_BLOCK_DIV at the inline level. The open tag's
202 // attribute region is exposed structurally as HTML_ATTRS so the
203 // existing AttributeNode walk picks up `<span id>` ids automatically.
204 INLINE_HTML_SPAN,
205
206 // TeX blocks
207 TEX_BLOCK, // Raw tex block (e.g., LaTeX commands)
208
209 // Headings
210 HEADING,
211 HEADING_CONTENT,
212 ATX_HEADING_MARKER, // leading #####
213 SETEXT_HEADING_UNDERLINE, // ===== or -----
214
215 // LaTeX inline commands
216 LATEX_COMMAND, // \command{...}
217
218 // Tables
219 SIMPLE_TABLE,
220 MULTILINE_TABLE,
221 PIPE_TABLE,
222 GRID_TABLE,
223 TABLE_HEADER,
224 TABLE_FOOTER,
225 TABLE_SEPARATOR,
226 TABLE_ROW,
227 TABLE_CELL,
228 TABLE_CAPTION,
229 TABLE_CAPTION_PREFIX, // "Table: ", "table: ", or ": "
230
231 // Code block parts
232 CODE_FENCE_OPEN,
233 CODE_FENCE_CLOSE,
234 CODE_INFO, // Raw info string (preserved for lossless formatting)
235 CODE_LANGUAGE, // Parsed language identifier (r, python, etc.)
236
237 // Chunk options (for executable chunks like {r, echo=TRUE})
238 CHUNK_OPTIONS, // Container for all chunk options
239 CHUNK_OPTION, // Single option (key=value pair)
240 CHUNK_OPTION_KEY, // Option name (e.g., echo, fig.cap)
241 CHUNK_OPTION_VALUE, // Option value (e.g., TRUE, "text")
242 CHUNK_OPTION_QUOTE, // Quote character (" or ') if present
243 CHUNK_LABEL, // Special case: unlabeled first option in {r mylabel}
244 HASHPIPE_YAML_PREAMBLE, // Hashpipe YAML option preamble region inside CODE_CONTENT
245 HASHPIPE_YAML_CONTENT, // Content lines belonging to hashpipe YAML preamble
246 HASHPIPE_PREFIX, // Hashpipe option marker prefix (e.g., #|, //|, --|)
247
248 CODE_CONTENT,
249
250 // Div parts
251 DIV_FENCE_OPEN,
252 DIV_FENCE_CLOSE,
253 DIV_INFO,
254 DIV_CONTENT,
255 EMOJI, // :alias:
256
257 // Bracket-shape pattern that did not resolve as a link/image.
258 // Distinct from LINK/IMAGE_LINK so downstream tools (linter, LSP) can
259 // walk a typed wrapper without the parser having to lie about
260 // resolution. `is_image()` on the typed wrapper distinguishes
261 // `[foo]` from `![foo]` shapes.
262 UNRESOLVED_REFERENCE,
263}
264
265impl From<SyntaxKind> for rowan::SyntaxKind {
266 fn from(kind: SyntaxKind) -> Self {
267 Self(kind as u16)
268 }
269}
270
271#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
272pub enum PanacheLanguage {}
273
274impl Language for PanacheLanguage {
275 type Kind = SyntaxKind;
276
277 fn kind_from_raw(raw: rowan::SyntaxKind) -> Self::Kind {
278 unsafe { std::mem::transmute::<u16, SyntaxKind>(raw.0) }
279 }
280
281 fn kind_to_raw(kind: Self::Kind) -> rowan::SyntaxKind {
282 kind.into()
283 }
284}