pub mod ast;
mod diagnostic;
mod format;
mod kind;
mod lexer;
mod parser;
use rowan::GreenNode;
pub use diagnostic::{Diagnostic, LineCol, LineIndex, Severity};
pub use format::{
FormatError, FormatOptions, expression_text, format, format_tree, quote_fhirpath_string,
};
pub use kind::{FmlLanguage, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken};
pub use lexer::{Token, tokenize};
pub use rowan::{Direction, NodeOrToken, TextRange, TextSize};
#[derive(Debug, Clone)]
pub struct Parse {
green: GreenNode,
diagnostics: Vec<Diagnostic>,
}
impl Parse {
pub fn syntax(&self) -> SyntaxNode {
SyntaxNode::new_root(self.green.clone())
}
pub fn tree(&self) -> ast::SourceFile {
ast::SourceFile::cast(self.syntax()).expect("the root is always a source file")
}
pub fn diagnostics(&self) -> &[Diagnostic] {
&self.diagnostics
}
pub fn has_errors(&self) -> bool {
self.diagnostics
.iter()
.any(|d| d.severity == Severity::Error)
}
}
pub fn parse(text: &str) -> Parse {
let (green, diagnostics) = parser::parse_source(text);
Parse { green, diagnostics }
}
pub use ast::AstNode;