1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
//! AST (abstract syntax tree) for [exchange structure (ISO-10303-21)][ISO-10303-21]
//!
//! [ISO-10303-21]: https://www.iso.org/standard/63141.html
//!
//! Serde data model
//! -----------------
//!
//! [Parameter] and [Record] can be deserialize through serde data model.
//!
//! | Parameter     | serde data model |
//! |:--------------|:-----------------|
//! | Integer       | i64              |
//! | Real          | f64              |
//! | String        | string           |
//! | Enumeration   | -                |
//! | List          | seq              |
//! | NotProvided   | unit             |
//! | Omitted       | unit             |
//! | Typed, Record | map              |
//! | RValue        | enum             |
//!
//! See [the official document of serde data model](https://serde.rs/data-model.html) for detail.
//!
//! - [Parameter::Typed] e.g. `A((1.0, 2.0))` and [Record] e.g. `A(1.0, 2.0)` are mapped to "map"
//!   in [the serde data model][serde-data-model]
//! - [Parameter::RValue] is mapped to "enum" in [the serde data model][serde-data-model].
//! - FIXME Enumeration is not supported yet.
//!
//! [serde-data-model]: https://serde.rs/data-model.html
//!

mod parameter;
mod record;
mod ser;
mod single_map_deserializer;
mod value;

pub use parameter::*;
pub use record::*;
pub use ser::*;
pub use single_map_deserializer::*;
pub use value::*;

/// Entire exchange structure
#[derive(Debug, Clone, PartialEq)]
pub struct Exchange {
    /// `HEADER` section
    pub header: Vec<Record>,
    /// `ANCHOR` section
    pub anchor: Vec<Anchor>,
    /// `REFERENCE` section
    pub reference: Vec<ReferenceEntry>,
    /// `DATA` section
    pub data: Vec<DataSection>,
    /// `SIGNATURE` section
    pub signature: Vec<String>,
}

/// `DATA` section in STEP file
#[derive(Debug, Clone, PartialEq)]
pub struct DataSection {
    /// Metadata
    pub meta: Vec<Parameter>,
    /// Each lines in data section
    pub entities: Vec<EntityInstance>,
}

/// Each line of data section
#[derive(Debug, Clone, PartialEq)]
pub enum EntityInstance {
    Simple { id: u64, record: Record },
    Complex { id: u64, subsuper: Vec<Record> },
}

#[derive(Debug, Clone, PartialEq)]
pub struct ReferenceEntry {
    pub name: LValue,
    pub resource: URI,
}

#[derive(Debug, Clone, PartialEq)]
pub struct URI(pub String);

#[derive(Debug, Clone, PartialEq)]
pub struct Anchor {
    pub name: String,
    pub item: AnchorItem,
    pub tags: Vec<(String, AnchorItem)>,
}

#[derive(Debug, Clone, PartialEq)]
pub enum AnchorItem {
    Integer(i64),
    Real(f64),
    String(String),
    Enumeration(String),
    /// The special token dollar sign (`$`) is used to represent an object whose value is not provided in the exchange structure.
    NotProvided,
    /// A reference to entity or value
    RValue(RValue),
    /// List of other parameters
    List(Vec<AnchorItem>),
}