Skip to content

Commit

Permalink
Removed deprecated filter item
Browse files Browse the repository at this point in the history
Add docu
  • Loading branch information
mitghi committed Mar 19, 2023
1 parent 44506f5 commit e33fcde
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use serde_json::Value;
use std::cell::RefCell;
use std::fmt;
use std::rc::Rc;

/// PathOutput is type of fully evaluated jetro expression.
type PathOutput = Rc<RefCell<Vec<Rc<Value>>>>;

/// Path represents the entry for parsing and
Expand Down Expand Up @@ -79,6 +81,8 @@ impl From<Sum> for serde_json::Number {
}
}

/// FilterOp represents comparision
/// operators inside filter function.
#[derive(Debug, PartialEq, Clone)]
pub enum FilterOp {
None,
Expand All @@ -91,6 +95,8 @@ pub enum FilterOp {
Almost,
}

/// FilterLogicalOp is logical operation
/// between several filters.
#[derive(Debug, PartialEq, Clone)]
pub enum FilterLogicalOp {
None,
Expand Down Expand Up @@ -132,6 +138,8 @@ pub enum FormatOp {
},
}

/// PickFilterInner represents arguments
/// of pick function.
#[derive(Debug, PartialEq, Clone)]
pub enum PickFilterInner {
None,
Expand All @@ -148,6 +156,8 @@ pub enum PickFilterInner {
},
}

/// FilterInnerRighthand represents the
/// right handside of filter operator.
#[derive(Debug, PartialEq, Clone)]
pub enum FilterInnerRighthand {
String(String),
Expand All @@ -156,6 +166,8 @@ pub enum FilterInnerRighthand {
Float(f64),
}

/// FilterInner represents a filter
/// statement.
#[derive(Debug, PartialEq, Clone)]
pub enum FilterInner {
Cond {
Expand Down Expand Up @@ -199,6 +211,9 @@ pub struct FilterAST {
pub right: Option<Rc<RefCell<FilterAST>>>,
}

/// Filter contains operations that transform, match
/// or search the input based on structure generated
/// the from parser.
#[derive(Debug, PartialEq, Clone)]
pub enum Filter {
Root,
Expand All @@ -213,32 +228,40 @@ pub enum Filter {
Filter(FilterInner),
MultiFilter(Rc<RefCell<FilterAST>>),
GroupedChild(Vec<String>),
All,
Len,
Function(Func),
}

/// StackItem represents an abstract step
/// in the control stack. It evaluates the
/// head of filters and either produces a
/// result ( when terminal ) or produces
/// more stack items.
#[allow(dead_code)]
struct StackItem<'a> {
value: Rc<Value>,
filters: &'a [Filter],
stack: Rc<RefCell<Vec<StackItem<'a>>>>,
}

/// Context binds components required for traversing
/// and evaluating a jetro expression.
pub(crate) struct Context<'a> {
root: Rc<Value>,
stack: Rc<RefCell<Vec<StackItem<'a>>>>,
registry: Rc<RefCell<dyn crate::func::Registry>>,
pub results: Rc<RefCell<Vec<Rc<Value>>>>,
}

/// MapBody represents the body of map function.
#[derive(Debug, PartialEq, Clone)]
pub enum MapBody {
None,
Method { name: String, subpath: Vec<Filter> },
Subpath(Vec<Filter>),
}

/// MapAST represents the abstract structure
/// of map function.
#[derive(Debug, PartialEq, Clone)]
pub struct MapAST {
pub arg: String,
Expand All @@ -254,6 +277,7 @@ impl Default for MapAST {
}
}

/// Error represents jetro errors.
#[derive(Debug)]
pub enum Error {
EmptyQuery,
Expand All @@ -262,6 +286,10 @@ pub enum Error {
FuncEval(String),
}

/// FuncArg represents an individual argument
/// produced by the parser which gets passed
/// to module reponsible for dynamic functions
/// and gets evaluated during runtime.
#[allow(dead_code)]
#[derive(Debug, PartialEq, Clone)]
pub enum FuncArg {
Expand All @@ -272,6 +300,8 @@ pub enum FuncArg {
MapStmt(MapAST),
}

/// Func represents abstract structure of
/// a jetro function.
#[derive(Debug, PartialEq, Clone)]
pub struct Func {
pub name: String,
Expand Down

0 comments on commit e33fcde

Please sign in to comment.