Skip to main content

Module namespace

Module namespace 

Source
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 NAMESPACE document.
Malformed
An expression that occupies a directive position but is not a directive or supported namespace container.
ParseOutput
A lossless NAMESPACE parse and its recoverable diagnostics.

Enums§

DirectiveKind
R’s recognized namespace directive names.
Entry
One flattened namespace entry.

Functions§

parse
Parse a NAMESPACE buffer without evaluating it.
reconstruct
Round-trip text through the namespace parser. Always equal to text.