aboutsummaryrefslogtreecommitdiff
path: root/rprt-engine/src/expression.rs
blob: 1ee898ebcf32eeaf6ef69fe7dd73667867c60df9 (plain)
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
#[derive(Debug, Clone, PartialEq)]
pub enum Composite {
    SelectionFunction {
        func: BuiltinSelectionFn,
        search_mod: Option<SearchModifier>,
        result_transform: Option<ResultTransform>,
    },

    TextFunction {
        func: BuiltinTextFn,
        swapped: bool,
    },

    Hook {
        kind: HookKind,
        left: Box<Composite>,
        right: Box<Composite>,
    },

    Train2 {
        f: Box<Composite>,
        g: Box<Composite>,
    },

    Train3 {
        f: Box<Composite>,
        g: Box<Composite>,
        h: Box<Composite>,
    },
}

#[derive(Debug, Clone, PartialEq)]
pub enum TextFn {
    Function {
        func: BuiltinTextFn,
        swapped: bool,
    },

    Hook {
        kind: HookKind,
        left: Box<TextFn>,
        right: Box<TextFn>,
    },

    Train2 {
        f: Box<TextFn>,
        g: Box<TextFn>,
    },

    Train3 {
        f: Box<TextFn>,
        g: Box<TextFn>,
        h: Box<TextFn>,
    },
}

#[derive(Debug, Clone, PartialEq)]
pub enum BuiltinSelectionFn {
    Empty,               // e
    EndOfBuffer,         // $
    Span,                // -
    CharOffset(usize),   // # (expects number arg)
    Line(usize),         // (expects number arg)
    Regex(String),       // /re/ (expects regex arg)
    AllMatches(String),  // x (expects /re/ arg)
    RelativeLine(usize), // + (expects number arg)
    BufferMatch(String), // B (expects /re/ arg)
}

#[derive(Debug, Clone, PartialEq)]
pub enum BuiltinTextFn {
    Dot,             // .
    Change,          // c
    Insert,          // i
    Append,          // a
    Delete,          // d
    Write,           // w
    Pipe,            // |
    Literal(String), // "..."
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SearchModifier {
    Reverse,           // '
    Sequential,        // ;
    ReverseSequential, // ';
    SequentialReverse, // ;'
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ResultTransform {
    Complement,            // ~
    Conditional,           // ?
    ComplementConditional, // ~?
    ConditionalComplement, // ?~
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum HookKind {
    Before, // F>G (left hook)
    After,  // F<G (right hook)
}