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.
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));Structs§
- Diagnostic
- LineCol
- Line
Index - Parser
Span ToText Range Error - Source
File - Source
Tokens - 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§
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.