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
use crate::*;
pub(super) mod certification;
pub(super) mod document;
pub(super) mod identity;
pub(super) mod membership;
pub(super) mod revocation;
pub(super) mod transaction;
pub(super) mod wallet_script;
#[derive(Debug, Clone, Copy, Parser)]
#[grammar = "documents_grammar.pest"]
pub(crate) struct RawDocumentsParser;
pub trait FromPestPair: Sized {
fn from_pest_pair(pair: Pair<Rule>) -> Result<Self, TextParseError>;
}
pub trait ParseFromRawText: FromPestPair {
fn parse_from_raw_text(doc: &str) -> Result<Self, TextParseError>;
}
macro_rules! impl_parse_from_raw_text {
($Type:ty, $Rule:expr) => {
impl ParseFromRawText for $Type {
#[inline]
fn parse_from_raw_text(doc: &str) -> Result<Self, TextParseError> {
let mut doc_pairs = RawDocumentsParser::parse($Rule, doc)
.map_err(|e| TextParseError::PestError(e.into()))?;
Self::from_pest_pair(doc_pairs.next().unwrap_or_else(|| unreachable!()))
}
}
};
}
impl_parse_from_raw_text!(DubpDocument, Rule::document);
impl_parse_from_raw_text!(IdentityDocument, Rule::idty);
impl_parse_from_raw_text!(CertificationDocument, Rule::cert);
impl_parse_from_raw_text!(MembershipDocument, Rule::membership);
impl_parse_from_raw_text!(RevocationDocument, Rule::revoc);
impl_parse_from_raw_text!(TransactionDocument, Rule::tx);
impl_parse_from_raw_text!(TransactionDocumentV10, Rule::tx_v10);