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
pub mod annotation;
pub use self::annotation::*;
pub mod circuits;
pub use self::circuits::*;
pub mod common;
pub use self::common::*;
pub mod console;
pub use self::console::*;
pub mod errors;
pub use self::errors::*;
pub mod expression;
pub use self::expression::*;
pub mod functions;
pub use self::functions::*;
pub mod groups;
pub use self::groups::*;
pub mod imports;
pub use self::imports::*;
pub mod input;
pub use self::input::*;
pub mod program;
pub use self::program::*;
pub mod statements;
pub use self::statements::*;
pub mod types;
pub use self::types::*;
use leo_ast::LeoAst;
#[derive(Debug, Eq, PartialEq)]
pub struct LeoTypedAst {
typed_ast: Program,
}
impl LeoTypedAst {
pub fn new<'ast>(program_name: &str, ast: &LeoAst<'ast>) -> Self {
Self {
typed_ast: Program::from(program_name, ast.as_repr()),
}
}
pub fn into_repr(self) -> Program {
self.typed_ast
}
pub fn to_json_string(&self) -> Result<String, serde_json::Error> {
Ok(serde_json::to_string_pretty(&self.typed_ast)?)
}
pub fn from_json_string(json: &str) -> Result<Self, serde_json::Error> {
let typed_ast: Program = serde_json::from_str(json)?;
Ok(Self { typed_ast })
}
}