pub struct DocumentLoader { /* private fields */ }Expand description
Document loader with transform shortcuts
DocumentLoader provides a convenient API for loading source text and running
transforms on it. It’s used by both production code (CLI, libraries) and tests.
§Example
use lex_parser::lex::loader::DocumentLoader;
// Load from file and parse
let doc = DocumentLoader::from_path("example.lex")
.unwrap()
.parse()
.unwrap();
// Load from string and get tokens
let tokens = DocumentLoader::from_string("Hello world\n")
.tokenize()
.unwrap();Implementations§
Source§impl DocumentLoader
impl DocumentLoader
Sourcepub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, LoaderError>
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, LoaderError>
Load from a file path
§Example
use lex_parser::lex::loader::DocumentLoader;
let loader = DocumentLoader::from_path("example.lex").unwrap();Sourcepub fn from_string<S: Into<String>>(source: S) -> Self
pub fn from_string<S: Into<String>>(source: S) -> Self
Load from a string
§Example
use lex_parser::lex::loader::DocumentLoader;
let loader = DocumentLoader::from_string("Hello world\n");Sourcepub fn with<O: 'static>(
&self,
transform: &Transform<String, O>,
) -> Result<O, LoaderError>
pub fn with<O: 'static>( &self, transform: &Transform<String, O>, ) -> Result<O, LoaderError>
Run a custom transform on the source
This is the generic method that all shortcuts use internally.
§Example
use lex_parser::lex::loader::DocumentLoader;
use lex_parser::lex::transforms::standard::LEXING;
let loader = DocumentLoader::from_string("Hello\n");
let tokens = loader.with(&*LEXING).unwrap();Sourcepub fn parse(&self) -> Result<Document, LoaderError>
pub fn parse(&self) -> Result<Document, LoaderError>
Parse the source into a Document AST
This is a shortcut for .with(&STRING_TO_AST).
§Example
use lex_parser::lex::loader::DocumentLoader;
let doc = DocumentLoader::from_string("Hello world\n")
.parse()
.unwrap();Sourcepub fn tokenize(&self) -> Result<TokenStream, LoaderError>
pub fn tokenize(&self) -> Result<TokenStream, LoaderError>
Tokenize the source with full lexing (including semantic indentation)
This is a shortcut for .with(&LEXING).
§Example
use lex_parser::lex::loader::DocumentLoader;
let tokens = DocumentLoader::from_string("Session:\n Content\n")
.tokenize()
.unwrap();
// tokens include Indent/DedentSourcepub fn base_tokens(&self) -> Result<TokenStream, LoaderError>
pub fn base_tokens(&self) -> Result<TokenStream, LoaderError>
Get base tokens (core tokenization only, no semantic indentation)
This is a shortcut for .with(&CORE_TOKENIZATION).
§Example
use lex_parser::lex::loader::DocumentLoader;
let tokens = DocumentLoader::from_string("Hello\n")
.base_tokens()
.unwrap();
// tokens include raw Indentation tokens, not Indent/DedentSourcepub fn source(&self) -> String
pub fn source(&self) -> String
Get the raw source string
§Example
use lex_parser::lex::loader::DocumentLoader;
let loader = DocumentLoader::from_string("Hello\n");
assert_eq!(loader.source(), "Hello\n");Sourcepub fn source_ref(&self) -> &str
pub fn source_ref(&self) -> &str
Get a reference to the raw source string
Use this when you don’t need an owned copy.
Auto Trait Implementations§
impl Freeze for DocumentLoader
impl RefUnwindSafe for DocumentLoader
impl Send for DocumentLoader
impl Sync for DocumentLoader
impl Unpin for DocumentLoader
impl UnsafeUnpin for DocumentLoader
impl UnwindSafe for DocumentLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more