hedl_core/
lib.rs

1// Dweve HEDL - Hierarchical Entity Data Language
2//
3// Copyright (c) 2025 Dweve IP B.V. and individual contributors.
4//
5// SPDX-License-Identifier: Apache-2.0
6//
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License in the LICENSE file at the
10// root of this repository or at: http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Core parser and data model for HEDL format.
19//!
20//! This crate provides the main parsing functionality for HEDL documents,
21//! including header directives, body parsing, and reference resolution.
22//!
23//! # Lexical Analysis
24//!
25//! The [`lex`] module provides the complete lexical analysis infrastructure,
26//! consolidating functionality from `hedl-lex`, `hedl-row`, and `hedl-tensor`:
27//!
28//! - Token validation (key tokens, type names, ID tokens, references)
29//! - CSV/matrix row parsing with expression and tensor support
30//! - Multi-dimensional tensor literal parsing
31//! - Incremental parsing for IDE integration
32//! - Source position and span tracking for error reporting
33//!
34//! See [`lex`] module documentation for more details and examples.
35
36#![cfg_attr(not(test), warn(missing_docs))]
37mod block_string;
38pub mod coercion;
39pub mod convert;
40mod document;
41mod error;
42pub mod errors;
43pub mod header;
44pub mod inference;
45pub mod lex;
46mod limits;
47#[cfg(feature = "parallel")]
48pub mod parallel;
49mod parser;
50pub mod preprocess;
51pub mod reference;
52pub mod schema_version;
53pub mod traverse;
54pub mod types;
55pub mod validation;
56mod value;
57pub mod visitor;
58
59pub use coercion::{
60    coerce, coerce_with_config, CoercionConfig, CoercionLevel, CoercionMode, CoercionResult,
61};
62pub use document::{Document, Item, MatrixList, Node};
63pub use error::{HedlError, HedlErrorKind, HedlResult};
64pub use inference::{
65    infer_value_synthesize, infer_value_with_type, InferenceConfidence, InferenceContext,
66    InferenceResult,
67};
68pub use limits::Limits;
69pub use parser::{parse, parse_with_limits, ParseOptions, ParseOptionsBuilder};
70pub use preprocess::preprocess;
71pub use reference::{resolve_references, resolve_references_with_limits, ReferenceMode};
72pub use schema_version::{FieldDef, Schema, SchemaVersion};
73pub use traverse::{traverse, DocumentVisitor, StatsCollector, VisitorContext};
74
75// Re-export visitor types for public API
76pub use types::{value_to_expected_type, ExpectedType, TensorDtype};
77pub use value::{Reference, Value};
78pub use visitor::{
79    transform, traverse as visitor_traverse, traverse_fallible, traverse_mut, DepthCounter,
80    FallibleVisitor, NodeCollector, PathCollector, PathSegment, ReferenceCollector, Transformer,
81    TraversalConfig, TraversalMode, TraversalOrder, TraversalResult, TraversalStats, VisitDecision,
82    Visitor, VisitorMut,
83};
84
85// Re-export useful types from the consolidated lex module
86pub use lex::{ExprLiteral, Expression, Reference as ReferenceToken, Tensor};
87
88// Re-export parallel types when feature is enabled
89#[cfg(feature = "parallel")]
90pub use parallel::{
91    collect_ids_parallel, identify_entity_boundaries, parse_matrix_rows_parallel,
92    validate_references_parallel, AtomicSecurityCounters, EntityBoundary, EntityType,
93    MatrixRowBatch, ParallelConfig,
94};