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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use crate::{Constant, PropertyKind};
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
pub type Bool = bool;
pub type Int = u32;
pub type Double = f64;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CharSet {
pub ints: Vec<Int>,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum ListOp {
Times,
Divide,
Or,
And,
Plus,
Minus,
}
parse_enum! {
ListOp,
(Times, "times"),
(Divide, "divide"),
(Or, "or"),
(And, "and"),
(Plus, "plus"),
(Minus, "minus"),
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum UnaryOp {
Not,
}
parse_enum! {
UnaryOp,
(Not, "not"),
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum BinaryOp {
Eq,
NotEq,
Less,
LessEq,
More,
MoreEq,
Contains,
NotContains,
}
parse_enum! {
BinaryOp,
(Eq, "eq"),
(NotEq, "noteq"),
(Less, "less"),
(LessEq, "lesseq"),
(More, "more"),
(MoreEq, "moreeq"),
(Contains, "contains"),
(NotContains, "notcontains"),
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum TernaryOp {
If,
}
parse_enum! {
TernaryOp,
(If, "if"),
}
#[derive(Clone, Debug, PartialEq)]
pub enum Expression<'a> {
Simple(Value<'a>),
Unary(Box<Self>, UnaryOp),
Binary(Box<Self>, Box<Self>, BinaryOp),
Ternary(Box<Self>, Box<Self>, Box<Self>, TernaryOp),
List(Vec<Self>, ListOp),
}
impl<'a> From<Value<'a>> for Expression<'a> {
fn from(v: Value<'a>) -> Self {
Expression::Simple(v)
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Value<'a> {
Int(Int),
Double(Double),
String(&'a str),
Const(Constant),
Bool(Bool),
Matrix([Double; 4]),
Range(Int, Int),
CharSet(CharSet),
Property(PropertyKind),
Prefer(Vec<&'a str>),
Accept(Vec<&'a str>),
Default(Vec<&'a str>),
}