Expand description
Shared parsed-source surface for Daml tools.
daml-parser stays the low-level lexer/layout/parser implementation.
This crate owns the source-facing facts tools need around that parser:
diagnostics, line/UTF-16 mapping, tokens, trivia, laid-out tokens, and
conversion from parser byte spans to text-size ranges.
§Public dependencies
This crate intentionally exposes types from daml-parser and the
text-size crate in its public API. Downstream SemVer expectations include
compatible major versions of those dependencies when their types appear in
function signatures or re-exports:
daml_parser::ast,daml_parser::lexer, and related parser types used bySourceFileand span conversion helpers.TextRangeandTextSize, re-exported fromtext-sizefor source ranges and offsets.
Coordinate newtypes such as LineNumber, ByteColumn, and
CharColumn are 1-based and reject zero via LineNumber::try_new and
siblings; 0-based offsets use ByteOffset and Utf16Offset.
use daml_syntax::{parser_span_to_text_range, SourceFile};
let source = "module M where\nfoo : Int\nfoo = 1\n";
let file = SourceFile::parse(source);
assert_eq!(file.module().name, "M");
assert!(file.diagnostics().is_empty());
assert!(!file.tokens().is_empty());
assert!(!file.laid_out_tokens().is_empty());
let header_range = parser_span_to_text_range(source, file.module().header);
assert_eq!(usize::from(header_range.start()), 0);
assert_eq!(header_range, file.parser_span_to_text_range(file.module().header));Re-exports§
pub use coordinate::ByteColumn;pub use coordinate::ByteLineCol;pub use coordinate::ByteOffset;pub use coordinate::CharColumn;pub use coordinate::CharLineCol;pub use coordinate::Coordinate;pub use coordinate::LineNumber;pub use coordinate::Utf16Offset;
Modules§
- coordinate
- Domain-specific source coordinates.
Structs§
- Diagnostic
- A parser or lexer diagnostic anchored in source text.
- Line
Index - Precomputed line, character, and UTF-16 offset tables for a source string.
- Parser
Span ToText Range Error - Error returned when a parser span cannot be converted to a
TextRange. - Source
File - Parsed Daml module with diagnostics, line index, and lazy token access.
- Source
Tokens - Lexer output for a source string without running the full module parser.
- Text
Range - A range in text, represented as a pair of
TextSize. - Text
Size - A measure of text length. Also, equivalently, an index into text.
Enums§
- Parser
Span ToText Range Error Kind - Failure kind when converting a parser span to a
TextRange.
Functions§
- parser_
span_ to_ text_ range - Convert a parser span into a
text-sizebyte range for an arbitrary source string. - try_
parser_ span_ to_ text_ range - Try to convert a parser span into a
text-sizebyte range.