cairo_proof_parser/
ast.rs1use std::{
2 fmt::Display,
3 ops::{Deref, DerefMut},
4};
5
6#[derive(Debug, Clone)]
7pub enum Expr {
8 Value(String),
9 Array(Vec<Expr>),
10}
11
12impl Display for Expr {
13 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14 match self {
15 Expr::Value(v) => write!(f, "{v}"),
16 Expr::Array(v) => {
17 write!(f, "{}", v.len())?;
18 for expr in v.iter() {
19 write!(f, " {expr}")?;
20 }
21 Ok(())
22 }
23 }
24 }
25}
26
27#[derive(Debug, Clone)]
28pub struct Exprs(pub Vec<Expr>);
29
30impl Display for Exprs {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 write!(f, "[")?;
33
34 for (i, expr) in self.iter().enumerate() {
35 if i != 0 {
36 write!(f, ", ")?;
37 }
38 write!(f, "{expr}")?;
39 }
40
41 write!(f, "]")?;
42
43 Ok(())
44 }
45}
46
47impl Deref for Exprs {
48 type Target = Vec<Expr>;
49
50 fn deref(&self) -> &Self::Target {
51 &self.0
52 }
53}
54
55impl DerefMut for Exprs {
56 fn deref_mut(&mut self) -> &mut Self::Target {
57 &mut self.0
58 }
59}