arity-parser
The lossless CST parser, typed AST wrappers, and incremental reparser for the R language, extracted from arity.
This crate is the parsing engine behind the arity CLI and language server. It
is published so that other tools can build on it, but its API surface is still
early and may change between releases; it is versioned independently of the
arity CLI.
use ;
let text = "f <- function(x) x + 1\n";
let output = parse;
assert!;
assert_eq!;
The parser preserves all source text (whitespace, comments, roxygen structure), so reconstructing any parse tree yields the input byte-for-byte.
Package NAMESPACE files use the same lossless CST through a typed surface that
finds directives only where R permits them and never evaluates conditional
expressions:
use ;
let text = "export(foo)\nimportFrom(stats, predict)\n";
let output = parse;
assert!;
assert_eq!;
assert_eq!;
Rd help files have an independent lossless grammar:
use rd;
let text = "\\title{An example}\n\\description{Use \\code{foo()}.}\n";
let output = parse;
assert!;
assert_eq!;
assert_eq!;
The Rd parser models standard sections, nested markup, links, lists, tables, conditionals, and prose, R-like, and verbatim arguments. It preserves macro definitions and calls without expansion or evaluation. Unrecognized macro names remain in the tree without a diagnostic. Malformed syntax produces byte-ranged diagnostics and a recovered, lossless CST. Input is UTF-8; the initial API parses complete documents and does not provide incremental Rd reparsing.