Skip to main content

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;
38/// Value coercion for HEDL type system.
39pub mod coercion;
40/// Common conversion utilities and traits for HEDL format converters.
41pub mod convert;
42mod document;
43mod error;
44/// Error handling utilities and centralized error messages.
45pub mod errors;
46/// Header directive parsing for HEDL.
47pub mod header;
48/// Value inference ladder for HEDL.
49pub mod inference;
50
51// Re-export header types for convenience
52pub use header::{CountValue, ParseMode};
53/// Lexical analysis subsystem for HEDL.
54pub mod lex;
55mod limits;
56/// Parallel parsing infrastructure for hedl-core.
57#[cfg(feature = "parallel")]
58pub mod parallel;
59mod parser;
60/// Input preprocessing for HEDL parsing.
61pub mod preprocess;
62/// Reference resolution for HEDL.
63pub mod reference;
64/// Schema versioning for HEDL types.
65pub mod schema_version;
66/// Document traversal trait for format converters.
67pub mod traverse;
68/// Type system for bidirectional type checking in HEDL.
69pub mod types;
70/// Comprehensive validation framework for HEDL documents.
71pub mod validation;
72mod value;
73/// Comprehensive visitor pattern API for HEDL document traversal.
74pub mod visitor;
75
76pub use coercion::{
77    coerce, coerce_with_config, CoercionConfig, CoercionLevel, CoercionMode, CoercionResult,
78};
79pub use document::{Document, Item, MatrixList, Node};
80pub use error::{HedlError, HedlErrorKind, HedlResult};
81pub use inference::{
82    infer_value_synthesize, infer_value_with_type, InferenceConfidence, InferenceContext,
83    InferenceResult,
84};
85pub use limits::Limits;
86pub use parser::{parse, parse_with_limits, ParseOptions, ParseOptionsBuilder};
87pub use preprocess::preprocess;
88pub use reference::{resolve_references, resolve_references_with_limits, ReferenceMode};
89pub use schema_version::{FieldDef, Schema, SchemaVersion};
90pub use traverse::{traverse, DocumentVisitor, StatsCollector, VisitorContext};
91
92// Re-export visitor types for public API
93pub use types::{value_to_expected_type, ExpectedType, TensorDtype};
94pub use value::{Reference, Value};
95pub use visitor::{
96    transform, traverse as visitor_traverse, traverse_fallible, traverse_mut, DepthCounter,
97    FallibleVisitor, NodeCollector, PathCollector, PathSegment, ReferenceCollector, Transformer,
98    TraversalConfig, TraversalMode, TraversalOrder, TraversalResult, TraversalStats, VisitDecision,
99    Visitor, VisitorMut,
100};
101
102// Re-export useful types from the consolidated lex module
103pub use lex::{ExprLiteral, Expression, Reference as ReferenceToken, Tensor};
104
105// Re-export parallel types when feature is enabled
106#[cfg(feature = "parallel")]
107pub use parallel::{
108    collect_ids_parallel, identify_entity_boundaries, parse_matrix_rows_parallel,
109    validate_references_parallel, AtomicSecurityCounters, EntityBoundary, EntityType,
110    MatrixRowBatch, ParallelConfig,
111};