Skip to main content

ParsedFile

Struct ParsedFile 

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

An owned typed CST together with the source identity and original input.

ParsedFile::from_source selects the Tree-sitter adapter, while ParsedFile::from_source_native 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, Self::cell_stream, or Self::to_source.

The original string is retained as an immutable snapshot for diagnostics. Current emission is normalized by ToTokens; it will become lossless as trivia ownership is completed in the typed graph.

Implementations§

Source§

impl ParsedFile

Source

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

Parses source with the Tree-sitter adapter and a fresh source identity.

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_with_id( source: impl Into<String>, source_id: SourceId, ) -> Result<Self, ParseError>

Parses source with the Tree-sitter adapter and an explicit source id.

Source

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

Parses source with the native precedence parser and a fresh source identity.

Source

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

Parses source with the native precedence parser and an explicit source id.

Source

pub fn original_source(&self) -> &str

Returns the input snapshot exactly as supplied to the parser.

Source

pub fn source_id(&self) -> SourceId

Returns the source identity attached to parsed spans.

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

Flattens the current CST into its linearly ordered cells.

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.

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 Spanned for ParsedFile

Source§

fn span(&self) -> Span

Source§

impl ToCells for ParsedFile

Source§

fn to_cells(&self, output: &mut CellStream)

Appends this value’s global cells to output.
Source§

fn to_cell_stream(&self, source_id: SourceId) -> CellStream

Emits this value into a fresh cell stream with the requested identity.
Source§

impl ToTokens for ParsedFile

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 = Infallible

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.