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
//! An experimental implementation of the Marlowe language for Cardano smart contracts.
//!
//! Its primary use-case is for creating smart contracts in Rust rather
//! than directly using Marlowe, and instead be able to export the contracts
//! into Marlowe programatically.
//!
//! Parser tests are done against all example
//! contracts available on the Marlowe Playground as seen on 2022-06-06.<br/>
//! _( Deserialize -> Re-serialize -> Compare )_
//!
//! ## Stability
//!
//! At the time of writing this, the language specification of Marlowe is not yet finalized
//! and so this crate may not exactly reflect the current syntax as seen in official
//! implementations such as the Marlowe playground.
//!
//! When the Marlowe v3 specs are finalized, this crate will (hopefully) be
//! updated to reflect those.
//!
//! ## Known issues:
//!
//! Currently, this parser is not known to fail at parsing anything that the
//! playground implementation can successfully parse, but we allow some
//! slightly different syntax to be used, as listed below.
//!
//! - Active parser bugs:
//! - This parser has no whitespace requirement before start parentheses: '('.
//! - This parser has no whitespace requirement between idents and arguments: 'Role"Guy"' vs 'Role "Guy"'
//!
//!
//! ## Main entry-points:
//!
//! - [`Serialization`]
//! - [`Deserialization`]
//!
//! [`Serialization`]: parsing/serialization/fn.serialize.html
//! [`Deserialization`]: parsing/deserialization/fn.deserialize.html
//!
//! This crate uses [Pest.rs](https://pest.rs)!
//! <details>
//! <summary>[grammars.rs] Click to expand/collapse</summary>
//!
//! ```pest
//! ```
//! </details>
//!
//!
//! ## Example usage
//!
//! ```rust
//! use marlowe_lang::types::marlowe::*;
//! use marlowe_lang::parsing::{
//! deserialization::deserialize,
//! serialization::serialize,
//! };
//!
//! let my_contract = Contract::When {
//! cases: vec![
//! Case {
//! action: Action::Notify {
//! notify_if: Observation::TrueObs
//! },
//! contract: Contract::Close.boxed() }
//! ],
//! timeout: Timeout::TimeParam("test".into()),
//! timeout_continuation: Contract::Close.boxed(),
//! };
//!
//! let serialized = serialize(my_contract);
//! let deserialized : Contract = deserialize(&serialized).unwrap();
//! println!("{serialized}");
//! ```
//!
//! #### Where 'println!("{serialized}")' would output this:
//! ```text
//! When [ Case (Notify (TrueObs)) Close ] (TimeParam "test") Close
//! ```
extern crate pest;
extern crate pest_derive;
/// Top level types module
/// Where the parsing happens
// Some testing yeh