Skip to main content

ParsedFile

Struct ParsedFile 

Source
pub struct ParsedFile { /* private fields */ }
Expand description

An owned typed CST together with the original input.

With the tree-sitter feature, from_source selects that adapter; ParsedFile::from_source_native always selects the direct precedence parser. After parsing, callers may mutate Self::cst_mut or use Self::edit, then project the resulting tree through Self::token_stream or Self::to_source.

The original string is retained as an immutable snapshot for diagnostics. Cell and source-file comment ownership is retained by the typed graph; source-backed layout is recovered from spans during emission.

Implementations§

Source§

impl ParsedFile

Source

pub fn from_source(source: impl Into<String>) -> Result<Self, ParseError>

Parses source with the Tree-sitter adapter.

§Errors

Returns ParseError when Tree-sitter rejects the source or typed migration fails.

Examples found in repository?
examples/inspect.rs (line 15)
10fn main() -> Result<(), Box<dyn Error>> {
11    let source = match std::env::args_os().nth(1) {
12        Some(path) => fs::read_to_string(path)?,
13        None => SAMPLE.to_owned(),
14    };
15    ParsedFile::from_source(source)?.print_pretty()?;
16    Ok(())
17}
Source

pub fn from_source_native( source: impl Into<String>, ) -> Result<Self, NativeParseError>

Parses source with the native precedence parser.

§Errors

Returns NativeParseError when lexing or native parsing fails.

Source

pub fn original_source(&self) -> &str

Returns the input snapshot exactly as supplied to the parser.

Source

pub fn cst(&self) -> &SourceFile

Borrows the generated typed CST root.

Source

pub fn cst_mut(&mut self) -> &mut SourceFile

Mutably borrows the generated typed CST root.

Source

pub fn edit(self, edit: impl FnOnce(&mut SourceFile)) -> Self

Applies an edit and returns the file for further method chaining.

Source

pub fn into_cst(self) -> SourceFile

Consumes the facade and returns its generated typed CST.

Source

pub fn token_stream(&self) -> TokenStream

Flattens the current CST into one token stream.

Source

pub fn cell_stream(&self) -> CellStream

Projects the current CST as independently parseable cells.

This is the normal macro-facing representation after tokenisation. Use Self::token_stream when a function-like transformation intentionally needs the less structured lexical representation.

Source

pub fn to_source(&self) -> String

Emits the current CST as normalized Macaulay2 source.

Source

pub fn pretty_tokens(&self) -> String

Formats the current raw token representation as a recursively flattened table with explicit group boundaries.

Source

pub fn pretty_cst(&self) -> String

Formats the complete generated typed CST as a Unicode tree.

Source

pub fn pretty_report(&self) -> PrettyReport<'_>

Builds a combined source, flat-token, and typed-CST inspection report.

Source

pub fn print_pretty(&self) -> Result<()>

Prints the combined report to standard output, enabling ANSI styling only when standard output is an interactive terminal.

§Errors

Returns an I/O error when standard output cannot be written.

Examples found in repository?
examples/inspect.rs (line 15)
10fn main() -> Result<(), Box<dyn Error>> {
11    let source = match std::env::args_os().nth(1) {
12        Some(path) => fs::read_to_string(path)?,
13        None => SAMPLE.to_owned(),
14    };
15    ParsedFile::from_source(source)?.print_pretty()?;
16    Ok(())
17}

Trait Implementations§

Source§

impl AsMut<SourceFile> for ParsedFile

Source§

fn as_mut(&mut self) -> &mut SourceFile

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<SourceFile> for ParsedFile

Source§

fn as_ref(&self) -> &SourceFile

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for ParsedFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ParsedFile

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Lex for ParsedFile

Source§

fn to_tokens(&self, output: &mut TokenStream)

Appends this value’s token trees to output.
Source§

fn to_token_stream(&self) -> TokenStream

Emits this value into a fresh token stream.
Source§

fn to_m2(&self) -> String

Renders this value as normalized Macaulay2 source.
Source§

impl Spanned for ParsedFile

Source§

fn span(&self) -> Span

Returns the smallest span covering this value. Read more
Source§

fn try_span(&self) -> Option<Span>

Returns the smallest span covering this value, when its constituents share one source snapshot.
Source§

fn expect_span(&self) -> Span

Returns this value’s span when one source snapshot covers it. Read more
Source§

impl Tokenize for ParsedFile

Source§

fn tokenize(&self, output: &mut CellStream) -> Result<(), CellStreamError>

Appends this value’s independently parseable cells to output. Read more
Source§

fn to_cell_stream(&self) -> Result<CellStream, CellStreamError>

Tokenizes this value into a fresh cell stream. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.