octofhir_fhirpath_parser/lib.rs
1// Copyright 2024 OctoFHIR Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Parser and tokenizer for FHIRPath expressions
16//!
17//! This crate provides parsing capabilities for FHIRPath expressions,
18//! converting text into abstract syntax trees.
19
20pub mod ast_cache;
21pub mod error;
22pub mod error_recovery;
23pub mod lexer;
24pub mod pratt;
25pub mod span;
26pub mod tokenizer;
27
28// Re-export main types
29pub use error::{ParseError, ParseResult};
30pub use tokenizer::{Token, Tokenizer};
31// pub use lexer::FhirPathParser; // May not exist
32pub use ast_cache::{cache_ast, get_cached_ast};
33pub use pratt::parse_expression_pratt;
34pub use span::{Span, Spanned};
35
36// Re-export from workspace crates for convenience
37pub use octofhir_fhirpath_ast::{ExpressionNode, LiteralValue};
38pub use octofhir_fhirpath_core::{FhirPathError, Result};
39pub use octofhir_fhirpath_diagnostics::{Diagnostic, DiagnosticBuilder};
40
41/// Parse a FHIRPath expression from a string
42pub fn parse_expression(input: &str) -> Result<ExpressionNode> {
43 pratt::parse_expression_pratt(input)
44 .map_err(|e| octofhir_fhirpath_core::FhirPathError::parse_error(0, e.to_string()))
45}
46
47/// Alias for parse_expression for convenience
48pub fn parse(input: &str) -> Result<ExpressionNode> {
49 parse_expression(input)
50}