Skip to main content

cbcl_parser/
lib.rs

1//! cbcl-parser: Pure S-expression parser and pipeline for CBCL.
2//!
3//! This crate implements the hand-rolled recursive-descent parser (ADR-001)
4//! and the full verified pipeline (parse -> parse_message -> validate -> verify).
5
6#![forbid(unsafe_code)]
7#![cfg_attr(not(feature = "std"), no_std)]
8
9extern crate alloc;
10
11pub mod checkpoint_dialect;
12
13#[cfg(feature = "std")]
14pub mod contract;
15#[cfg(feature = "std")]
16pub mod describe;
17pub mod dialect_parser;
18pub mod message_parser;
19pub mod parser;
20pub mod pipeline;
21pub mod protocol_parser;
22pub mod read;
23pub mod shape_exports;
24pub mod shape_parser;
25pub mod state_exports;
26pub mod state_parser;
27
28#[cfg(feature = "std")]
29pub use contract::compile_contract_str;
30#[cfg(feature = "std")]
31pub use describe::{define_text_str, describe_dialect_str, read_act_str};
32pub use dialect_parser::{parse_dialect, parse_meta_define};
33pub use message_parser::{parse_message, parse_message_lax};
34pub use parser::{parse, ParseError};
35pub use pipeline::{
36    run_pipeline, run_pipeline_full, PipelineContext, PipelineResult, ValidationError,
37};
38pub use protocol_parser::{parse_protocol, ProtocolParseError};
39pub use read::read_str;
40pub use shape_exports::verify_message_shape_str;
41pub use shape_parser::parse_shape;
42pub use state_exports::parse_and_install_dialect;
43pub use state_parser::{parse_state, parse_state_bounds};
44
45/// Parse once and return the canonical signed-envelope audience (`@` retained).
46/// No dialect installation or field declaration order is required.
47pub fn recipient_of(input: &str) -> Result<alloc::string::String, alloc::string::String> {
48    let form = parse(input).map_err(|e| alloc::format!("parse error: {e}"))?;
49    let message = parse_message(&form)?;
50    message
51        .canonical_recipient()
52        .map(alloc::string::String::from)
53        .map_err(alloc::string::String::from)
54}
55
56/// Audience accessor for hosts that already allow bare custom control verbs.
57/// This recognizes syntax only; the host must still authorize the verb.
58pub fn recipient_of_lax(input: &str) -> Result<alloc::string::String, alloc::string::String> {
59    let form = parse(input).map_err(|e| alloc::format!("parse error: {e}"))?;
60    let message = parse_message_lax(&form)?;
61    message
62        .canonical_recipient()
63        .map(alloc::string::String::from)
64        .map_err(alloc::string::String::from)
65}