Usage
parse_qmd(input, ast = c("pd", "ts"), quiet = FALSE, prune_errors = TRUE)Arguments
- input
A single string. Treated as a file path if it does not contain newlines and names an existing file (
file.exists()is TRUE and it is not a directory); otherwise treated as raw text. To parse an R-heldts_treeas Pandoc, render it first withto_qmd()and feed the result back in.- ast
The AST to return:
"pd"(the default) for the Pandoc AST as apandocobject, or"ts"for the tree-sitter AST as ats_tree.- quiet
If
FALSE(the default) any error-kind diagnostics are raised as R errors (after attaching diagnostics to the result), and warning-kind diagnostics are emitted as R warnings.infoandnotediagnostics are never signalled regardless ofquiet. IfTRUEno signal is raised; diagnostics of every kind are still attached to the returned object's@diagnosticsslot.- prune_errors
If
TRUE(the default, matching the pampa CLI) parser-error diagnostics are deduplicated by tree-sitterERRORnode, keeping the earliest per node. Set toFALSEto see every raw diagnostic pampa produces (useful for debugging the parser).
Value
For ast = "pd" a pandoc object, for ast = "ts" a
ts_tree object, with any parse diagnostics attached in the
@diagnostics slot. If pampa fails to produce a Pandoc AST the
returned pandoc has an empty @blocks; the diagnostics explain
why. Tree-sitter parsing itself never fails.
Details
Parses QMD text or a file with pampa and returns the requested AST.
With ast = "pd" (the default) the Pandoc AST is returned as a
pandoc object; with ast = "ts" the tree-sitter concrete syntax
tree is returned as a ts_tree. Either way any parse diagnostics are
attached to the returned object's @diagnostics slot.