Skip to main content

Parse

Trait Parse 

Source
pub trait Parse: Clone {
    // Required methods
    fn parse_document(
        &mut self,
        input: impl Read,
        path: Option<impl AsRef<Path>>,
        keep_contents: bool,
    ) -> Result<ParsedDocument>;
    fn get_sources(self) -> Result<HashMap<DocumentId, String>>;
}
Expand description

The trait implemented by all parsers

Ideally, cloning a parser should not duplicate the contents of the sources. The underlying data should be wrapped in an Arc, so that the last clone of a parser is able to retrieve the sources’ contents for all files.

Required Methods§

Source

fn parse_document( &mut self, input: impl Read, path: Option<impl AsRef<Path>>, keep_contents: bool, ) -> Result<ParsedDocument>

Parse a document from a reader and identify the relevant source items

If a path is provided, then this can be used to enrich diagnostics. The fact that this takes in a mutable reference to the parser allows for stateful parsers.

Source

fn get_sources(self) -> Result<HashMap<DocumentId, String>>

Retrieve the contents of the source files after parsing is done

This consumes the parser, so that ownership of the contents can be retrieved safely. Note that documents which were parsed with keep_contents to false will no be present in the map.

This can return an error if there are more than one clone of the parser.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Parse for SlangParser

Available on crate feature slang only.
Source§

impl Parse for SolarParser

Available on crate feature solar only.

A parser using the solar_parse crate