1use std::ops::Range;
4
5#[derive(Debug, PartialEq)]
6pub enum Expr {
7 Bool(Box<ExprBool>),
8 Identifier(Box<ExprIdentifier>),
9 Call(Box<ExprCall>),
10 String(Box<ExprString>),
11}
12
13impl Expr {
14 pub fn identifier(identifier: &str) -> Self {
15 Self::Identifier(Box::new(ExprIdentifier::new(identifier)))
16 }
17
18 pub fn string(string: &str) -> Self {
19 Self::String(ExprString::new(string).into())
20 }
21
22 pub fn call(callee: (Expr, Range<usize>), args: Vec<(Expr, Range<usize>)>) -> Self {
23 Self::Call(Box::new(ExprCall { callee, args }))
24 }
25
26 pub fn bool(value: bool) -> Self {
27 Self::Bool(Box::new(ExprBool::new(value)))
28 }
29}
30
31#[derive(Debug, PartialEq)]
32pub struct ExprIdentifier(pub String);
33
34impl ExprIdentifier {
35 pub fn new(identifier: &str) -> Self {
36 Self(identifier.to_string())
37 }
38}
39
40#[derive(Debug, PartialEq)]
41pub struct ExprString(pub String);
42
43impl ExprString {
44 pub fn new(string: &str) -> Self {
45 Self(string.to_string())
46 }
47}
48
49#[derive(Debug, PartialEq)]
50pub struct ExprCall {
51 pub callee: (Expr, Range<usize>),
52 pub args: Vec<(Expr, Range<usize>)>,
53}
54
55#[derive(Debug, PartialEq)]
56pub struct ExprBool(pub bool);
57
58impl ExprBool {
59 pub fn new(value: bool) -> Self {
60 Self(value)
61 }
62}