kodept_core/structure/rlt/
expression.rs1use crate::code_point::CodePoint;
2use crate::structure::Located;
3use crate::structure::rlt::{IfExpr, Literal, Parameter, Term};
4use crate::structure::rlt::block_level::BlockLevelNode;
5use crate::structure::rlt::new_types::*;
6
7#[derive(Debug, Clone, PartialEq)]
8pub struct Application {
9 pub expr: Operation,
10 pub params: Option<Enclosed<Box<[Operation]>>>,
11}
12
13#[derive(Debug, Clone, PartialEq)]
14pub enum Operation {
15 Block(ExpressionBlock),
16 Access {
17 left: Box<Operation>,
18 dot: Symbol,
19 right: Box<Operation>,
20 },
21 TopUnary {
22 operator: UnaryOperationSymbol,
23 expr: Box<Operation>,
24 },
25 Binary {
26 left: Box<Operation>,
27 operation: BinaryOperationSymbol,
28 right: Box<Operation>,
29 },
30 Application(Box<Application>),
31 Expression(Expression),
32}
33
34#[derive(Debug, Clone, PartialEq)]
35pub enum Expression {
36 Lambda {
37 keyword: Keyword,
38 binds: Box<[Parameter]>,
39 flow: Symbol,
40 expr: Box<Operation>,
41 },
42 Term(Term),
43 Literal(Literal),
44 If(Box<IfExpr>),
45}
46
47#[derive(Debug, Clone, PartialEq)]
48pub struct ExpressionBlock {
49 pub lbrace: Symbol,
50 pub expression: Box<[BlockLevelNode]>,
51 pub rbrace: Symbol,
52}
53
54impl Located for Application {
55 fn location(&self) -> CodePoint {
56 self.params
57 .as_ref()
58 .map_or(self.expr.location(), |it| it.left.location())
59 }
60}
61
62impl Located for Operation {
63 fn location(&self) -> CodePoint {
64 match self {
65 Operation::Block(x) => x.location(),
66 Operation::Access { dot, .. } => dot.location(),
67 Operation::TopUnary { operator, .. } => operator.location(),
68 Operation::Binary { operation, .. } => operation.location(),
69 Operation::Application(x) => x.location(),
70 Operation::Expression(x) => x.location(),
71 }
72 }
73}
74
75impl Located for Expression {
76 fn location(&self) -> CodePoint {
77 match self {
78 Expression::Lambda { flow, .. } => flow.location(),
79 Expression::Term(x) => x.location(),
80 Expression::Literal(x) => x.location(),
81 Expression::If(x) => x.location(),
82 }
83 }
84}
85
86impl Located for ExpressionBlock {
87 fn location(&self) -> CodePoint {
88 self.lbrace.location()
89 }
90}