Skip to main content

Crate fml_syntax

Crate fml_syntax 

Source
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.
FormatOptions
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).
LineIndex
Converts byte offsets to line and column.
Parse
The result of parsing: a syntax tree that covers the whole input, plus the problems found.
TextRange
A range in text, represented as a pair of TextSize.
TextSize
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.
FormatError
NodeOrToken
Severity
SyntaxKind
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 value as a single-quoted FHIRPath string literal.
tokenize
Splits source into tokens. Every byte of the source belongs to exactly one token, so the concatenated token texts always equal the source. Malformed input produces SyntaxKind::Unknown tokens and a diagnostic for each.

Type Aliases§

SyntaxElement
SyntaxNode
SyntaxToken