docgen_bases/ast.rs
1//! Expression AST for the Bases language. A `Call` whose `callee` is a `Member`
2//! is a *method* call (`list.contains(x)`); a `Call` on a bare `Ident` is a
3//! *global function* call (`link("x")`). The evaluator makes that distinction.
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum Expr {
7 Null,
8 Bool(bool),
9 Number(f64),
10 Str(String),
11 Regex(String, String),
12 /// A bare identifier: a namespace (`file`/`note`/`formula`/`this`), a global
13 /// function name (when directly called), or a note property.
14 Ident(String),
15 /// `object.member` — property/method access.
16 Member(Box<Expr>, String),
17 /// `object[index]` — dynamic index/property access.
18 Index(Box<Expr>, Box<Expr>),
19 /// `callee(args...)` — function or method call.
20 Call(Box<Expr>, Vec<Expr>),
21 Unary(UnaryOp, Box<Expr>),
22 Binary(BinaryOp, Box<Expr>, Box<Expr>),
23}
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum UnaryOp {
27 Not,
28 Neg,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum BinaryOp {
33 Add,
34 Sub,
35 Mul,
36 Div,
37 Mod,
38 Eq,
39 NotEq,
40 Lt,
41 Gt,
42 LtEq,
43 GtEq,
44 And,
45 Or,
46}