Expand description
Lossless syntax tree, error-tolerant parser and formatter for the FHIR Mapping Language.
let parse = fml_syntax::parse(r#"
uses "http://hl7.org/fhir/StructureDefinition/Patient" as source
uses "http://hl7.org/fhir/StructureDefinition/Patient" as target
group Copy(source src : Patient, target tgt : Patient) {
src.name -> tgt.name;
}
"#);
assert!(parse.diagnostics().is_empty());
let file = parse.tree();
let group = file.groups().next().unwrap();
assert_eq!(group.name().as_deref(), Some("Copy"));The tree keeps every byte of the input, comments and whitespace included, so
parse(text).syntax().to_string() == text for any input.
Re-exports§
pub use ast::AstNode;
Modules§
- ast
- Typed views over the syntax tree.
Structs§
- Diagnostic
- A problem found in the source, located by byte range.
- Format
Options - LineCol
- A position in the source: zero-based line, and zero-based column counted both in UTF-8 bytes and in UTF-16 code units (the unit LSP and the Mapping Language debug trace use).
- Line
Index - Converts byte offsets to line and column.
- Parse
- The result of parsing: a syntax tree that covers the whole input, plus the problems found.
- 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.
- Token
- A token: its kind and where it is in the source.
Enums§
- Direction
- FmlLanguage
- The rowan language tag for FML trees.
- Format
Error - Node
OrToken - Severity
- Syntax
Kind - Every token and node kind in an FML syntax tree.
Functions§
- expression_
text - Renders a FHIRPath expression in canonical form: one space around binary operators, none inside paths and calls, comments dropped, strings single-quoted. This is the form StructureMap stores expressions in, and the one the HL7 reference compiler produces.
- format
- Formats FML source text.
- format_
tree - Formats a parsed tree without checking it first. Prefer [
format], which refuses trees with syntax errors and verifies the result. - parse
- Parses FML source text. Never fails; see
Parse::diagnostics. - quote_
fhirpath_ string - Writes
valueas a single-quoted FHIRPath string literal. - tokenize
- Splits
sourceinto tokens. Every byte of the source belongs to exactly one token, so the concatenated token texts always equal the source. Malformed input producesSyntaxKind::Unknowntokens and a diagnostic for each.