diff options
| author | tslil <tslil@posteo.de> | 2025-10-18 15:15:02 +0100 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2025-10-18 17:00:19 +0100 |
| commit | 9a845a610aaf42aaba301d7b0ce1c88096d36915 (patch) | |
| tree | 13cfdea2a93c2d95e4f9ebcbfae6306fa5da7eea /rprt-engine/src/expression.rs | |
| parent | 7cb0b2d8f1dad40e7b90ced7b19bb32aaf0eaff3 (diff) | |
Beginning lexing & parsing work, probably looking at hand rolled recursive descent parser
Diffstat (limited to 'rprt-engine/src/expression.rs')
| -rw-r--r-- | rprt-engine/src/expression.rs | 116 |
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) +} |
