katydid-0.4.0.1: A haskell implementation of Katydid

Safe HaskellSafe
LanguageHaskell2010

Data.Katydid.Relapse.Expr

Description

This module contains all the functions you need to implement a Relapse expression.

Synopsis

Documentation

data Desc Source #

Desc is the description of a function, especially built to make comparisons of user defined expressions possible.

Constructors

Desc 

Fields

Instances
Eq Desc Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

Methods

(==) :: Desc -> Desc -> Bool #

(/=) :: Desc -> Desc -> Bool #

Ord Desc Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

Methods

compare :: Desc -> Desc -> Ordering #

(<) :: Desc -> Desc -> Bool #

(<=) :: Desc -> Desc -> Bool #

(>) :: Desc -> Desc -> Bool #

(>=) :: Desc -> Desc -> Bool #

max :: Desc -> Desc -> Desc #

min :: Desc -> Desc -> Desc #

Show Desc Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

Methods

showsPrec :: Int -> Desc -> ShowS #

show :: Desc -> String #

showList :: [Desc] -> ShowS #

mkDesc :: String -> [Desc] -> Desc Source #

mkDesc makes a description from a function name and a list of the argument's descriptions.

data AnyExpr Source #

AnyExpr is used by the Relapse parser to represent an Expression that can return any type of value, where any is a predefined list of possible types represented by AnyFunc.

Constructors

AnyExpr 

Fields

Instances
Eq AnyExpr Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

Methods

(==) :: AnyExpr -> AnyExpr -> Bool #

(/=) :: AnyExpr -> AnyExpr -> Bool #

Ord AnyExpr Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

Show AnyExpr Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

data AnyFunc Source #

AnyFunc is used by the Relapse parser and represents the list all supported types of functions.

data Expr a Source #

Expr represents a user defined expression, which consists of a description for comparisons and an evaluation function.

Constructors

Expr 

Fields

Instances
Eq (Expr a) Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

Methods

(==) :: Expr a -> Expr a -> Bool #

(/=) :: Expr a -> Expr a -> Bool #

Ord (Expr a) Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

Methods

compare :: Expr a -> Expr a -> Ordering #

(<) :: Expr a -> Expr a -> Bool #

(<=) :: Expr a -> Expr a -> Bool #

(>) :: Expr a -> Expr a -> Bool #

(>=) :: Expr a -> Expr a -> Bool #

max :: Expr a -> Expr a -> Expr a #

min :: Expr a -> Expr a -> Expr a #

Show (Expr a) Source # 
Instance details

Defined in Data.Katydid.Relapse.Expr

Methods

showsPrec :: Int -> Expr a -> ShowS #

show :: Expr a -> String #

showList :: [Expr a] -> ShowS #

type Func a = Label -> Either String a Source #

Func represents the evaluation function part of a user defined expression. This function takes a label from a tree parser and returns a value or an error string.

params :: Expr a -> [Desc] Source #

params returns the descriptions of the parameters of the user defined expression.

name :: Expr a -> String Source #

name returns the name of the user defined expression.

hasVar :: Expr a -> Bool Source #

hasVar returns whether the expression or any of its children contains a variable expression.

hashWithName :: String -> [Desc] -> Int Source #

hashWithName calculates a hash of the function name and its parameters.

hashList :: Int -> [Int] -> Int Source #

hashList folds a list of hashes into one, given a seed and the list.

hashString :: String -> Int Source #

hashString calcuates a hash of a string.

evalConst :: Expr a -> Maybe a Source #

evalConst tries to evaluate a constant expression and either returns the resulting constant value or nothing.

isConst :: Desc -> Bool Source #

isConst returns whether the input description is one of the six possible constant values.

assertArgs1 :: String -> [AnyExpr] -> Either String AnyExpr Source #

assertArgs1 asserts that the list of arguments is only one argument and returns the argument or an error message containing the function name that was passed in as an argument to assertArgs1.

assertArgs2 :: String -> [AnyExpr] -> Either String (AnyExpr, AnyExpr) Source #

assertArgs2 asserts that the list of arguments is only two arguments and returns the two arguments or an error message containing the function name that was passed in as an argument to assertArgs2.

mkBoolExpr :: Expr Bool -> AnyExpr Source #

mkBoolExpr generalises a bool expression to any expression.

mkIntExpr :: Expr Int -> AnyExpr Source #

mkIntExpr generalises an int expression to any expression.

mkStringExpr :: Expr Text -> AnyExpr Source #

mkStringExpr generalises a string expression to any expression.

mkDoubleExpr :: Expr Double -> AnyExpr Source #

mkDoubleExpr generalises a double expression to any expression.

mkBytesExpr :: Expr ByteString -> AnyExpr Source #

mkBytesExpr generalises a bytes expression to any expression.

mkUintExpr :: Expr Word -> AnyExpr Source #

mkUintExpr generalises a uint expression to any expression.

assertBool :: AnyExpr -> Either String (Expr Bool) Source #

assertBool asserts that any expression is actually a bool expression.

assertInt :: AnyExpr -> Either String (Expr Int) Source #

assertInt asserts that any expression is actually an int expression.

assertString :: AnyExpr -> Either String (Expr Text) Source #

assertString asserts that any expression is actually a string expression.

assertDouble :: AnyExpr -> Either String (Expr Double) Source #

assertDouble asserts that any expression is actually a double expression.

assertBytes :: AnyExpr -> Either String (Expr ByteString) Source #

assertBytes asserts that any expression is actually a bytes expression.

assertUint :: AnyExpr -> Either String (Expr Word) Source #

assertUint asserts that any expression is actually a uint expression.

boolExpr :: Bool -> Expr Bool Source #

boolExpr creates a constant bool expression from a input value.

intExpr :: Int -> Expr Int Source #

intExpr creates a constant int expression from a input value.

stringExpr :: Text -> Expr Text Source #

stringExpr creates a constant string expression from a input value.

doubleExpr :: Double -> Expr Double Source #

doubleExpr creates a constant double expression from a input value.

bytesExpr :: ByteString -> Expr ByteString Source #

bytesExpr creates a constant bytes expression from a input value.

uintExpr :: Word -> Expr Word Source #

uintExpr creates a constant uint expression from a input value.

trimBool :: Expr Bool -> Expr Bool Source #

trimBool tries to reduce an expression to a single constant expression, if it does not contain a variable.

trimInt :: Expr Int -> Expr Int Source #

trimInt tries to reduce an expression to a single constant expression, if it does not contain a variable.

trimString :: Expr Text -> Expr Text Source #

trimString tries to reduce an expression to a single constant expression, if it does not contain a variable.

trimDouble :: Expr Double -> Expr Double Source #

trimDouble tries to reduce an expression to a single constant expression, if it does not contain a variable.

trimBytes :: Expr ByteString -> Expr ByteString Source #

trimBytes tries to reduce an expression to a single constant expression, if it does not contain a variable.

trimUint :: Expr Word -> Expr Word Source #

trimUint tries to reduce an expression to a single constant expression, if it does not contain a variable.

mkBoolsExpr :: Expr [Bool] -> AnyExpr Source #

mkBoolsExpr generalises a list of bools expression to any expression.

mkIntsExpr :: Expr [Int] -> AnyExpr Source #

mkIntsExpr generalises a list of ints expression to any expression.

mkStringsExpr :: Expr [Text] -> AnyExpr Source #

mkStringsExpr generalises a list of strings expression to any expression.

mkDoublesExpr :: Expr [Double] -> AnyExpr Source #

mkDoublesExpr generalises a list of doubles expression to any expression.

mkListOfBytesExpr :: Expr [ByteString] -> AnyExpr Source #

mkListOfBytesExpr generalises a list of bytes expression to any expression.

mkUintsExpr :: Expr [Word] -> AnyExpr Source #

mkUintsExpr generalises a list of uints expression to any expression.

assertBools :: AnyExpr -> Either String (Expr [Bool]) Source #

assertBools asserts that any expression is actually a list of bools expression.

assertInts :: AnyExpr -> Either String (Expr [Int]) Source #

assertInts asserts that any expression is actually a list of ints expression.

assertStrings :: AnyExpr -> Either String (Expr [Text]) Source #

assertStrings asserts that any expression is actually a list of strings expression.

assertDoubles :: AnyExpr -> Either String (Expr [Double]) Source #

assertDoubles asserts that any expression is actually a list of doubles expression.

assertListOfBytes :: AnyExpr -> Either String (Expr [ByteString]) Source #

assertListOfBytes asserts that any expression is actually a list of bytes expression.

assertUints :: AnyExpr -> Either String (Expr [Word]) Source #

assertUints asserts that any expression is actually a list of uints expression.

boolsExpr :: [Expr Bool] -> Expr [Bool] Source #

boolsExpr sequences a list of expressions that each return a bool, to a single expression that returns a list of bools.

intsExpr :: [Expr Int] -> Expr [Int] Source #

intsExpr sequences a list of expressions that each return an int, to a single expression that returns a list of ints.

stringsExpr :: [Expr Text] -> Expr [Text] Source #

stringsExpr sequences a list of expressions that each return a string, to a single expression that returns a list of strings.

doublesExpr :: [Expr Double] -> Expr [Double] Source #

doublesExpr sequences a list of expressions that each return a double, to a single expression that returns a list of doubles.

listOfBytesExpr :: [Expr ByteString] -> Expr [ByteString] Source #

listOfBytesExpr sequences a list of expressions that each return bytes, to a single expression that returns a list of bytes.

uintsExpr :: [Expr Word] -> Expr [Word] Source #

uintsExpr sequences a list of expressions that each return a uint, to a single expression that returns a list of uints.