Skip to main content

step_p21/parser/exchange/
mod.rs

1//! Parser for exchange structure
2
3mod anchor;
4mod data;
5mod header;
6mod parameter;
7mod reference;
8
9pub use anchor::*;
10pub use data::*;
11pub use header::*;
12pub use parameter::*;
13pub use reference::*;
14
15use crate::{
16    ast::*,
17    parser::{combinator::*, token::*},
18};
19use nom::Parser;
20
21/// exchange_file = `ISO-10303-21;`
22///                 [header_section]
23///              \[ [anchor_section] \]
24///              \[ [reference_section] \]
25///               { [data_section] }
26///                 `END-ISO-10303-21;`
27///               { signature_section } .
28pub fn exchange_file(input: &str) -> ParseResult<'_, Exchange> {
29    tuple_((
30        tag_("ISO-10303-21;"),
31        header_section,
32        opt_(anchor_section),
33        opt_(reference_section),
34        many0_(data_section),
35        tag_("END-ISO-10303-21;"),
36        many0_(signature_section),
37    ))
38    .map(
39        |(_start, header, anchor, reference, data, _end, signature)| Exchange {
40            header,
41            anchor: anchor.unwrap_or_default(),
42            reference: reference.unwrap_or_default(),
43            data,
44            signature,
45        },
46    )
47    .parse(input)
48}
49
50/// signature_section  = `SIGNATURE` signature_content `ENDSEC;`.
51pub fn signature_section(input: &str) -> ParseResult<'_, String> {
52    tuple_((tag_("SIGNATURE"), signature_content, tag_("ENDSEC;")))
53        .map(|(_start, sig, _end)| sig)
54        .parse(input)
55}