1#![allow(ambiguous_glob_reexports)]
24
25mod composite;
26pub use self::composite::*;
27
28pub mod common;
29pub use self::common::*;
30
31pub mod constructor;
32pub use self::constructor::*;
33
34mod expressions;
35pub use self::expressions::*;
36
37mod functions;
38pub use self::functions::*;
39
40mod interface;
41pub use self::interface::*;
42
43mod indent_display;
44use indent_display::*;
45
46pub mod const_eval;
47
48mod library;
49pub use self::library::*;
50
51mod mapping;
52pub use self::mapping::*;
53
54mod module;
55pub use self::module::*;
56
57mod passes;
58pub use self::passes::*;
59
60mod program;
61pub use self::program::*;
62
63mod statement;
64pub use self::statement::*;
65
66mod storage;
67pub use self::storage::*;
68
69mod types;
70pub use self::types::*;
71
72mod stub;
73pub use self::stub::*;
74
75pub use common::node::*;
76
77#[allow(clippy::large_enum_variant)]
83#[derive(Clone, Debug, Eq, PartialEq)]
84pub enum Ast {
85 Program(Program),
86 Library(Library),
87}
88
89impl std::fmt::Display for Ast {
90 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91 match self {
92 Ast::Program(program) => write!(f, "{}", program),
93 Ast::Library(library) => write!(f, "{}", library),
94 }
95 }
96}
97
98impl Default for Ast {
101 fn default() -> Self {
102 Ast::Program(Program::default())
103 }
104}
105
106impl Ast {
107 pub fn map(self, program_fn: impl FnOnce(Program) -> Program, library_fn: impl FnOnce(Library) -> Library) -> Self {
108 match self {
109 Ast::Program(p) => Ast::Program(program_fn(p)),
110 Ast::Library(l) => Ast::Library(library_fn(l)),
111 }
112 }
113
114 pub fn try_map<E>(
115 self,
116 program_fn: impl FnOnce(Program) -> Result<Program, E>,
117 library_fn: impl FnOnce(Library) -> Result<Library, E>,
118 ) -> Result<Self, E> {
119 match self {
120 Ast::Program(p) => Ok(Ast::Program(program_fn(p)?)),
121 Ast::Library(l) => Ok(Ast::Library(library_fn(l)?)),
122 }
123 }
124
125 pub fn visit(&self, program_fn: impl FnOnce(&Program), library_fn: impl FnOnce(&Library)) {
126 match self {
127 Ast::Program(p) => program_fn(p),
128 Ast::Library(l) => library_fn(l),
129 }
130 }
131}