pub struct SourceFile { /* private fields */ }Expand description
Parsed Daml module with diagnostics, line index, and lazy token access.
Implementations§
Source§impl SourceFile
impl SourceFile
Sourcepub fn parse(source: &str) -> Self
pub fn parse(source: &str) -> Self
Parses source into a module AST and source-facing presentation data.
Malformed input still returns a partial module and surfaces diagnostics;
this function does not fail with Result.
Sourcepub fn diagnostics(&self) -> &[Diagnostic]
pub fn diagnostics(&self) -> &[Diagnostic]
Parse and lexer diagnostics anchored in source text.
Sourcepub const fn line_index(&self) -> &LineIndex
pub const fn line_index(&self) -> &LineIndex
Line, column, and UTF-16 lookup tables for this source.
Sourcepub fn laid_out_tokens(&self) -> &[Token]
pub fn laid_out_tokens(&self) -> &[Token]
Layout-resolved tokens for this source.
Sourcepub fn parser_span_to_text_range(&self, span: ParserSpan) -> TextRange
pub fn parser_span_to_text_range(&self, span: ParserSpan) -> TextRange
Convert a parser span from this source into a text-size byte range.
This is the convenience API for spans that originate from this source file and are expected to be valid.
§Panics
Panics when span does not map to valid UTF-8 source bytes in this
source.
Sourcepub fn try_parser_span_to_text_range(
&self,
span: ParserSpan,
) -> Result<TextRange, ParserSpanToTextRangeError>
pub fn try_parser_span_to_text_range( &self, span: ParserSpan, ) -> Result<TextRange, ParserSpanToTextRangeError>
Try to convert a parser span from this source into a text-size byte
range.
This fallible API is the preferred choice for spans from external or
untrusted sources where offsets may be invalid. Use
SourceFile::parser_span_to_text_range for spans that originate from
this source and are expected to map to valid UTF-8 bytes.