kodept_core/structure/rlt/
code_flow.rs

1use crate::code_point::CodePoint;
2use crate::structure::Located;
3use crate::structure::rlt::{Body, Operation};
4use crate::structure::rlt::new_types::Keyword;
5
6#[derive(Clone, Debug, PartialEq)]
7pub struct IfExpr {
8    pub keyword: Keyword,
9    pub condition: Operation,
10    pub body: Body,
11    pub elif: Box<[ElifExpr]>,
12    pub el: Option<ElseExpr>,
13}
14
15#[derive(Clone, Debug, PartialEq)]
16pub struct ElifExpr {
17    pub keyword: Keyword,
18    pub condition: Operation,
19    pub body: Body,
20}
21
22#[derive(Clone, Debug, PartialEq)]
23pub struct ElseExpr {
24    pub keyword: Keyword,
25    pub body: Body,
26}
27
28#[derive(Clone, Debug, PartialEq)]
29pub enum CodeFlow {
30    If(IfExpr),
31}
32
33impl Located for IfExpr {
34    fn location(&self) -> CodePoint {
35        self.keyword.location()
36    }
37}
38
39impl Located for ElifExpr {
40    fn location(&self) -> CodePoint {
41        self.keyword.location()
42    }
43}
44
45impl Located for ElseExpr {
46    fn location(&self) -> CodePoint {
47        self.keyword.location()
48    }
49}
50
51impl Located for CodeFlow {
52    fn location(&self) -> CodePoint {
53        match self {
54            CodeFlow::If(x) => x.location(),
55        }
56    }
57}