Skip to content

MavenRain/ifc-lite-core-cat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ifc-lite-core

High-performance IFC/STEP parser for building data, built on comp-cat-rs.

Overview

ifc-lite-core provides the core parsing functionality for IFC (Industry Foundation Classes) files used in Building Information Modeling (BIM). All effectful operations are expressed through the comp-cat-rs effect system (Io, Stream), keeping the core parsing logic pure and composable.

Capabilities:

  • STEP Tokenization -- zero-copy parsing via nom
  • Entity Scanning -- SIMD-accelerated entity discovery via memchr, exposed as a comp_cat_rs::effect::stream::Stream
  • Lazy Decoding -- on-demand attribute parsing wrapped in comp_cat_rs::effect::io::Io
  • Streaming Parser -- event-based parsing for large files with type filtering

Quick Start

use ifc_lite_core::{parse_entity, EntityId, IfcType, Error};

fn main() -> Result<(), Error> {
    let input = "#123=IFCWALL('guid',$,$,$,'Wall-001',$,$,$);";
    let (id, ifc_type, attrs) = parse_entity(input)?;
    assert_eq!(id, EntityId::new(123));
    assert_eq!(ifc_type, IfcType::IfcWall);
    Ok(())
}

Scanning with comp-cat-rs Stream

use ifc_lite_core::{scan::scan_entities, Error};

fn main() -> Result<(), Error> {
    let content = std::fs::read_to_string("model.ifc")?;
    let entities = scan_entities(content)
        .collect()
        .run()?;
    println!("Found {} entities", entities.len());
    Ok(())
}

Decoding entities with comp-cat-rs Io

use ifc_lite_core::{decode::{decode_entity, decode_by_id}, scan::build_entity_index, Error};

fn main() -> Result<(), Error> {
    let content = std::fs::read_to_string("model.ifc")?;
    let index = build_entity_index(&content);

    // Decode a specific entity by id -- returns Io<Error, DecodedEntity>
    let wall = decode_by_id(&content, &index, 42.into())
        .run()?;
    println!("Entity: {} ({})", wall.id(), wall.ifc_type());
    Ok(())
}

Streaming parse events

use ifc_lite_core::{streaming::{parse_stream, StreamConfig, ParseEvent}, Error};

fn main() -> Result<(), Error> {
    let content = std::fs::read_to_string("model.ifc")?;
    let events = parse_stream(content, StreamConfig::default())
        .collect()
        .run()?;

    events.iter().for_each(|event| match event {
        ParseEvent::EntityScanned { entity } => {
            println!("#{}: {}", entity.id(), entity.ifc_type());
        }
        ParseEvent::Completed { entity_count } => {
            println!("Done: {entity_count} entities");
        }
        _ => {}
    });
    Ok(())
}

Architecture

Module Purpose
parse nom-based STEP tokenizer; pure &str -> Result API
scan Entity scanning; returns Stream<Error, ScannedEntity>
decode Entity decoding; returns Io<Error, DecodedEntity>
streaming High-level parse events; returns Stream<Error, ParseEvent>
schema Geometry and profile category lookups
token Zero-copy Token<'a> sum type
attribute Owned AttributeValue and DecodedEntity
ifc_type IfcType enum covering IFC4X3 entity types
entity_id EntityId newtype
error Hand-rolled Error enum

Design Principles

  • Functional: no mut, no loops, combinators everywhere
  • Type-driven: newtypes for domain primitives (EntityId, IfcType)
  • Effect-aware: side effects wrapped in comp-cat-rs Io and Stream
  • Delay run: stay inside effects via combinators; call run only at the boundary
  • Zero-copy tokenization: Token<'a> borrows from input; owned AttributeValue for storage

License

Licensed under either of

at your option.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors

Languages