Skip to main content

ParsedDocument

Struct ParsedDocument 

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

A parsed .pactole source text, holding the original source, the tree-sitter concrete syntax tree, and any syntax diagnostics collected while walking the tree.

Parsing is tolerant: it always succeeds and produces a tree, even for invalid input. Errors are surfaced as SyntaxDiagnostics rather than as a Result::Err.

Implementations§

Source§

impl ParsedDocument

Source

pub fn source(&self) -> &str

The original source text that was parsed.

Source

pub fn tree(&self) -> &Tree

The tree-sitter concrete syntax tree produced for this document.

Source

pub fn root_node(&self) -> Node<'_>

The root node of the concrete syntax tree.

Source

pub fn has_errors(&self) -> bool

Whether the concrete syntax tree contains any ERROR or MISSING node.

Source

pub fn diagnostics(&self) -> &[SyntaxDiagnostic]

The syntax diagnostics collected while walking the tree, in document order.

Source

pub fn into_result(self) -> Result<Self, Vec<SyntaxDiagnostic>>

Converts this parsed document into a strict Result: Ok(self) if the concrete syntax tree contains no ERROR/MISSING node, or Err with the collected diagnostics otherwise.

This is a convenience for consumers (such as pactole-storage-fs) that only want to proceed on a syntactically clean document, without duplicating the has_errors check themselves.

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, 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, !>

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.