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