Expand description
A lossless, typed syntax surface for R package NAMESPACE files.
R first parses a NAMESPACE file as R syntax, then interprets a deliberately
small set of calls, blocks, assignments, and conditional expressions. This
module mirrors that split: it reuses the lossless R CST and adds typed
namespace entries without evaluating conditions or assigning meaning to a
directive’s arguments.
use arity_parser::namespace::{self, DirectiveKind};
let source = "export(foo)\nimportFrom(stats, predict)\n";
let output = namespace::parse(source);
assert!(output.diagnostics.is_empty());
assert_eq!(
output
.document()
.directives()
.map(|directive| directive.kind())
.collect::<Vec<_>>(),
[DirectiveKind::Export, DirectiveKind::ImportFrom]
);
assert_eq!(namespace::reconstruct(source), source);Re-exports§
pub use crate::parser::ParseDiagnostic;
Structs§
- Argument
- One directive argument, retaining its raw CST and exact source ranges.
- Directive
- A named call in a namespace directive position.
- Document
- A typed view of a complete
NAMESPACEdocument. - Malformed
- An expression that occupies a directive position but is not a directive or supported namespace container.
- Parse
Output - A lossless
NAMESPACEparse and its recoverable diagnostics.
Enums§
- Directive
Kind - R’s recognized namespace directive names.
- Entry
- One flattened namespace entry.
Functions§
- parse
- Parse a
NAMESPACEbuffer without evaluating it. - reconstruct
- Round-trip
textthrough the namespace parser. Always equal totext.