-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.rs
82 lines (70 loc) · 1.99 KB
/
expr.rs
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
use std::{ops::RangeInclusive, sync::Mutex};
use crate::parser::{ParseContext, ParseContextRef};
use super::{Symbol, *};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Op {
Sum, // +
Minus, // -
Product, // *
Divide, // /
Equal, // ==
NotEqual, // !=
LessThan, // <
LessEqual, // <=
GreaterThan, // >
GreaterEqual, // >=
Modulo, // %
Exponent, // ^
And, // &&
Or, // ||
Pipe, // |>
Unknown,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprRef(pub id_arena::Id<Expr>);
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum Literal {
Number(f64),
FloatParameter(Arc<FloatParameter>),
StringParameter(Arc<Mutex<String>>),
String(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Attribute(pub Symbol, pub RangeInclusive<f64>);
impl Attribute {
pub fn stringify(
&self,
ctx: &ParseContext,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
let key = ctx.interner.resolve(self.0.0).unwrap_or_default();
let start = self.1.start();
let end = self.1.end();
write!(f, "#[{key}({start}..{end})]")
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Pattern {
label: String,
}
#[derive(Debug, Clone)]
pub enum Expr {
Nop,
Error,
Literal(Literal),
Array(Vec<ExprRef>),
Var(Symbol),
Let(Symbol, ExprRef, ExprRef),
Then(ExprRef, ExprRef),
App(ExprRef, Vec<ExprRef>), //currently only single argument
BinOp(Op, ExprRef, ExprRef), //semantically identical to App
AppExt(*mut ExtFun, Vec<ExprRef>),
Lambda(Vec<Symbol>, ExprRef),
Block(ExprRef), //semantically meaningless, just for inverse evaluation
Paren(ExprRef), //semantically meaningless, just for inverse evaluation
WithAttribute(Attribute, ExprRef),
//track and region is an alias to closure
Track(ExprRef),
Region(ExprRef, ExprRef, ExprRef), //start,dur,content
Project(f64, Vec<ExprRef>),
}