Skip to main content

Crate daml_syntax

Crate daml_syntax 

Source
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
LineIndex
ParserSpanToTextRangeError
SourceFile
SourceTokens
TextRange
A range in text, represented as a pair of TextSize.
TextSize
A measure of text length. Also, equivalently, an index into text.

Functions§

parser_span_to_text_range
Convert a parser span into a text-size byte range for an arbitrary source string.
try_parser_span_to_text_range
Try to convert a parser span into a text-size byte range.