aboutsummaryrefslogtreecommitdiff
path: root/rprt-engine/src/expression.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rprt-engine/src/expression.rs')
-rw-r--r--rprt-engine/src/expression.rs116
1 files changed, 116 insertions, 0 deletions
diff --git a/rprt-engine/src/expression.rs b/rprt-engine/src/expression.rs
new file mode 100644
index 0000000..68849cb
--- /dev/null
+++ b/rprt-engine/src/expression.rs
@@ -0,0 +1,116 @@
+#[derive(Debug, Clone, PartialEq)]
+pub enum SelectionValuedExpr {
+ // Nullary selection function application
+ NullaryApplicationS(SelectionFn),
+ NullaryApplicationT(TextFn),
+
+ // Monadic selection function application: α F
+ MonadicApplicationS {
+ arg: Box<SelectionValuedExpr>,
+ func: SelectionFn,
+ },
+ // Monadic selection function application: F τ
+ MonadicApplicationT {
+ arg: Box<TextValuedExpr>,
+ func: TextFn,
+ },
+
+ // Dyadic selection function application: α F β
+ DyadicApplicationS {
+ left: Box<SelectionValuedExpr>,
+ right: Box<SelectionValuedExpr>,
+ func: SelectionFn,
+ },
+ // Dyadic text function application: α F τ
+ DyadicApplicationT {
+ left: Box<SelectionValuedExpr>,
+ right: Box<SelectionValuedExpr>,
+ func: SelectionFn,
+ },
+}
+
+#[derive(Debug, Clone, PartialEq)]
+pub enum TextValuedExpr {
+ // Selection coerced to text (implicit coercion)
+ FromSelection(Box<SelectionValuedExpr>),
+}
+
+#[derive(Debug, Clone, PartialEq)]
+pub enum SelectionFn {
+ Function {
+ func: BuiltinSelectionFn,
+ search_mod: Option<SearchModifier>,
+ result_transform: Option<ResultTransform>,
+ },
+
+ Hook {
+ kind: HookKind,
+ left: Box<SelectionFn>,
+ right: Box<SelectionFn>,
+ },
+
+ Train(Vec<SelectionFn>),
+}
+
+#[derive(Debug, Clone, PartialEq)]
+pub enum TextFn {
+ Function {
+ func: BuiltinTextFn,
+ swapped: bool,
+ },
+
+ Hook {
+ kind: HookKind,
+ left: Box<TextFn>,
+ right: Box<TextFn>,
+ },
+
+ Train(Vec<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)
+}