Skip to contents

[Experimental]

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-held ts_tree as Pandoc, render it first with to_qmd() and feed the result back in.

ast

The AST to return: "pd" (the default) for the Pandoc AST as a pandoc object, or "ts" for the tree-sitter AST as a ts_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. info and note diagnostics are never signalled regardless of quiet. If TRUE no signal is raised; diagnostics of every kind are still attached to the returned object's @diagnostics slot.

prune_errors

If TRUE (the default, matching the pampa CLI) parser-error diagnostics are deduplicated by tree-sitter ERROR node, keeping the earliest per node. Set to FALSE to 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.