ifc_lite_core/
lib.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! # IFC-Lite Core Parser
6//!
7//! High-performance STEP/IFC parser built with [nom](https://docs.rs/nom).
8//! Provides zero-copy tokenization and fast entity scanning for IFC files.
9//!
10//! ## Overview
11//!
12//! This crate provides the core parsing functionality for IFC-Lite:
13//!
14//! - **STEP Tokenization**: Zero-copy parsing of STEP file format
15//! - **Entity Scanning**: SIMD-accelerated entity discovery using [memchr](https://docs.rs/memchr)
16//! - **Lazy Decoding**: On-demand attribute parsing for memory efficiency
17//! - **Streaming Parser**: Event-based parsing for large files
18//!
19//! ## Quick Start
20//!
21//! ```rust,ignore
22//! use ifc_lite_core::{EntityScanner, parse_entity, IfcType};
23//!
24//! // Scan for entities
25//! let content = br#"#1=IFCPROJECT('guid',$,$,$,$,$,$,$,$);"#;
26//! let mut scanner = EntityScanner::new(content);
27//!
28//! while let Some((id, type_name, start, end)) = scanner.next_entity() {
29//!     println!("Found entity #{}: {}", id, type_name);
30//! }
31//!
32//! // Parse individual entity
33//! let input = b"#123=IFCWALL('guid',$,$,$,$,$,$,$);";
34//! let (id, ifc_type, attrs) = parse_entity(input).unwrap();
35//! assert_eq!(ifc_type, IfcType::IfcWall);
36//! ```
37//!
38//! ## Streaming Parser
39//!
40//! For large files, use the streaming parser to process entities in batches:
41//!
42//! ```rust,ignore
43//! use ifc_lite_core::{parse_stream, StreamConfig, ParseEvent};
44//!
45//! let config = StreamConfig::default();
46//! for event in parse_stream(content, config) {
47//!     match event {
48//!         ParseEvent::Entity { id, type_name, .. } => {
49//!             println!("Entity #{}: {}", id, type_name);
50//!         }
51//!         ParseEvent::Progress { percent, .. } => {
52//!             println!("Progress: {:.1}%", percent);
53//!         }
54//!         _ => {}
55//!     }
56//! }
57//! ```
58//!
59//! ## Performance
60//!
61//! - **Tokenization**: ~1,259 MB/s throughput
62//! - **Entity scanning**: ~650 MB/s with SIMD acceleration
63//! - **Number parsing**: 10x faster than std using [lexical-core](https://docs.rs/lexical-core)
64
65pub mod columnar_index;
66pub mod compatibility;
67pub mod decoder;
68pub mod dense_index;
69pub mod error;
70pub mod express_id;
71pub mod fast_parse;
72pub mod generated;
73pub mod georef;
74pub mod limits;
75pub mod model_bounds;
76pub mod parser;
77pub mod project_units;
78pub mod schema_gen;
79pub(crate) mod schema_helpers;
80pub mod step_encoding;
81pub mod streaming;
82pub(crate) mod unit_labels;
83pub mod units;
84
85#[cfg(test)]
86#[path = "schema_registry_tests.rs"]
87mod schema_registry_tests;
88
89pub use columnar_index::{ColumnLengthMismatch, ColumnarEntityIndex};
90pub use compatibility::{is_exporter_stratum_alias, EXPORTER_STRATUM_ALIASES};
91pub use decoder::{build_entity_index, EntityDecoder, EntityIndex, GridAxisIndex};
92pub use dense_index::DenseEntityIndex;
93pub use error::{Error, Result};
94pub use fast_parse::{
95    extract_coordinate_list_from_entity, extract_coordinate_list_from_entity_f64,
96    extract_entity_refs_from_list, extract_entity_type_name,
97    extract_face_indices_from_entity, extract_first_entity_ref, parse_coordinates_direct,
98    parse_indices_direct, process_triangulated_faceset_direct, should_use_fast_path, FastMeshData,
99};
100pub use generated::{
101    attribute_names_for_schema, entity_info_for_schema, is_subtype_of_for_schema, IfcType,
102    SchemaEntityInfo, UnknownIfcType, IFC_TYPES,
103};
104pub use georef::{GeoRefExtractor, GeoRefSource, GeoReference};
105pub use limits::{RtcVerdict, MAX_MAPPED_ITEM_DEPTH, MAX_PLACEMENT_DEPTH};
106pub use model_bounds::{scan_model_bounds, scan_placement_bounds, ModelBounds};
107pub use parser::{
108    declared_schema_bounded, entity_count, find_keyword, keyword_ends_with, keyword_eq, keyword_starts_with,
109    nth_attribute_is_present, oversized_id_report, parse_entity, report_malformed_records,
110    report_oversized_ids, report_scan_diagnostics, set_report_sink, skip_step_comment,
111    EntityScanner, StepListItems, Token,
112};
113pub use project_units::{
114    measure::{measure_unit, MeasureUnit},
115    resolve_unit_by_ref, ProjectUnits, ResolvedUnit,
116};
117pub use schema_gen::{AttributeValue, DecodedEntity, GeometryCategory, IfcSchema, ProfileCategory};
118pub use schema_helpers::{
119    geometry_flags_by_name, has_geometry_by_name, is_representationless_spatial_container_by_name,
120    ifc_type_from_keyword, ifc_type_from_record, is_simple_geometry_type, type_product_ifc_type,
121};
122pub use step_encoding::decode_ifc_string;
123pub use streaming::{parse_stream, ParseEvent, StreamConfig};
124pub use units::{
125    extract_length_unit_scale, extract_plane_angle_to_radians, get_si_prefix_multiplier,
126    try_extract_length_unit_scale, try_extract_plane_angle_to_radians,
127};