-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A haskell implementation of Katydid
--   
--   A haskell implementation of Katydid
--   
--   This includes:
--   
--   <ul>
--   <li>Relapse, a validation Language</li>
--   <li>Parsers for JSON, XML and an abstraction for trees</li>
--   </ul>
--   
--   You should only need the following modules:
--   
--   <ul>
--   <li>The Relapse module is used for validation.</li>
--   <li>The Json and XML modules are used to create Json and XML trees
--   that can be validated.</li>
--   </ul>
--   
--   If you want to implement your own parser then you can look at the
--   Parsers module
@package katydid
@version 0.1.1.0


-- | This module describes the abstract tree that can be validated by
--   Relapse.
--   
--   The JSON and XML parsers both are both versions of this type class.
module Parsers
class Tree a
getLabel :: Tree a => a -> Label
getChildren :: Tree a => a -> [a]
data Label
String :: String -> Label
Number :: Rational -> Label
Bool :: Bool -> Label
instance GHC.Classes.Ord Parsers.Label
instance GHC.Classes.Eq Parsers.Label
instance GHC.Show.Show Parsers.Label


-- | This module contains the Json Parser.
module Json

-- | decodeJSON returns a JsonTree, given an input string.
decodeJSON :: String -> Either String [JsonTree]

-- | JsonTree is a tree that can be validated by Relapse.
type JsonTree = Tree Label
instance Parsers.Tree Json.JsonTree


-- | This module contains all the Relapse expressions.
--   
--   It also contains an eval function and a simplfication function for
--   these expressions.
module Expr
data Expr a
[Const] :: a -> Expr a
[BoolVariable] :: Expr Bool
[OrFunc] :: Expr Bool -> Expr Bool -> Expr Bool
[AndFunc] :: Expr Bool -> Expr Bool -> Expr Bool
[NotFunc] :: Expr Bool -> Expr Bool
[BoolEqualFunc] :: Expr Bool -> Expr Bool -> Expr Bool
[DoubleEqualFunc] :: Expr Double -> Expr Double -> Expr Bool
[IntEqualFunc] :: Expr Int -> Expr Int -> Expr Bool
[UintEqualFunc] :: Expr Uint -> Expr Uint -> Expr Bool
[StringEqualFunc] :: Expr String -> Expr String -> Expr Bool
[BytesEqualFunc] :: Expr Bytes -> Expr Bytes -> Expr Bool
[IntListContainsFunc] :: Expr Int -> [Expr Int] -> Expr Bool
[StringListContainsFunc] :: Expr String -> [Expr String] -> Expr Bool
[UintListContainsFunc] :: Expr Uint -> [Expr Uint] -> Expr Bool
[StringContainsFunc] :: Expr String -> Expr String -> Expr Bool
[BoolListElemFunc] :: [Expr Bool] -> Expr Int -> Expr Bool
[BytesGreaterOrEqualFunc] :: Expr Bytes -> Expr Bytes -> Expr Bool
[DoubleGreaterOrEqualFunc] :: Expr Double -> Expr Double -> Expr Bool
[IntGreaterOrEqualFunc] :: Expr Int -> Expr Int -> Expr Bool
[UintGreaterOrEqualFunc] :: Expr Uint -> Expr Uint -> Expr Bool
[BytesGreaterThanFunc] :: Expr Bytes -> Expr Bytes -> Expr Bool
[DoubleGreaterThanFunc] :: Expr Double -> Expr Double -> Expr Bool
[IntGreaterThanFunc] :: Expr Int -> Expr Int -> Expr Bool
[UintGreaterThanFunc] :: Expr Uint -> Expr Uint -> Expr Bool
[StringHasPrefixFunc] :: Expr String -> Expr String -> Expr Bool
[StringHasSuffixFunc] :: Expr String -> Expr String -> Expr Bool
[BytesLessOrEqualFunc] :: Expr Bytes -> Expr Bytes -> Expr Bool
[DoubleLessOrEqualFunc] :: Expr Double -> Expr Double -> Expr Bool
[IntLessOrEqualFunc] :: Expr Int -> Expr Int -> Expr Bool
[UintLessOrEqualFunc] :: Expr Uint -> Expr Uint -> Expr Bool
[BytesLessThanFunc] :: Expr Bytes -> Expr Bytes -> Expr Bool
[DoubleLessThanFunc] :: Expr Double -> Expr Double -> Expr Bool
[IntLessThanFunc] :: Expr Int -> Expr Int -> Expr Bool
[UintLessThanFunc] :: Expr Uint -> Expr Uint -> Expr Bool
[BytesNotEqualFunc] :: Expr Bytes -> Expr Bytes -> Expr Bool
[BoolNotEqualFunc] :: Expr Bool -> Expr Bool -> Expr Bool
[DoubleNotEqualFunc] :: Expr Double -> Expr Double -> Expr Bool
[IntNotEqualFunc] :: Expr Int -> Expr Int -> Expr Bool
[StringNotEqualFunc] :: Expr String -> Expr String -> Expr Bool
[UintNotEqualFunc] :: Expr Uint -> Expr Uint -> Expr Bool
[BytesTypeFunc] :: Expr Bytes -> Expr Bool
[BoolTypeFunc] :: Expr Bool -> Expr Bool
[DoubleTypeFunc] :: Expr Double -> Expr Bool
[IntTypeFunc] :: Expr Int -> Expr Bool
[UintTypeFunc] :: Expr Uint -> Expr Bool
[StringTypeFunc] :: Expr String -> Expr Bool
[RegexFunc] :: Expr String -> Expr String -> Expr Bool
[DoubleVariable] :: Expr Double
[DoubleListElemFunc] :: [Expr Double] -> Expr Int -> Expr Double
[IntVariable] :: Expr Int
[IntListElemFunc] :: [Expr Int] -> Expr Int -> Expr Int
[BytesListLengthFunc] :: [Expr Bytes] -> Expr Int
[BoolListLengthFunc] :: [Expr Bool] -> Expr Int
[BytesLengthFunc] :: Expr Bytes -> Expr Int
[DoubleListLengthFunc] :: [Expr Double] -> Expr Int
[IntListLengthFunc] :: [Expr Int] -> Expr Int
[StringListLengthFunc] :: [Expr String] -> Expr Int
[UintListLengthFunc] :: [Expr Uint] -> Expr Int
[StringLengthFunc] :: Expr String -> Expr Int
[UintVariable] :: Expr Uint
[UintListElemFunc] :: [Expr Uint] -> Expr Int -> Expr Uint
[StringVariable] :: Expr String
[StringListElemFunc] :: [Expr String] -> Expr Int -> Expr String
[StringToLowerFunc] :: Expr String -> Expr String
[StringToUpperFunc] :: Expr String -> Expr String
[BytesVariable] :: Expr Bytes
[BytesListElemFunc] :: [Expr Bytes] -> Expr Int -> Expr Bytes
type Bytes = String
type Uint = Int

-- | simplifyBoolExpr returns an equivalent, but simpler version of the
--   input boolean expression.
simplifyBoolExpr :: Expr Bool -> Expr Bool

-- | eval evaluates a boolean expression, given an input label.
eval :: Expr Bool -> Label -> Except ValueErr Bool
data ValueErr
instance GHC.Show.Show Expr.ValueErr
instance GHC.Classes.Ord Expr.ValueErr
instance GHC.Classes.Eq Expr.ValueErr
instance GHC.Classes.Eq a => GHC.Classes.Eq (Expr.Expr a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Expr.Expr a)
instance GHC.Show.Show a => GHC.Show.Show (Expr.Expr a)


-- | This module describes the patterns supported by Relapse.
--   
--   It also contains some simple functions for the map of references that
--   a Relapse grammar consists of.
--   
--   Finally it also contains some very simple pattern functions.
module Patterns

-- | Pattern recursively describes a Relapse Pattern.
data Pattern
Empty :: Pattern
ZAny :: Pattern
Node :: (Expr Bool) -> Pattern -> Pattern
Or :: Pattern -> Pattern -> Pattern
And :: Pattern -> Pattern -> Pattern
Not :: Pattern -> Pattern
Concat :: Pattern -> Pattern -> Pattern
Interleave :: Pattern -> Pattern -> Pattern
ZeroOrMore :: Pattern -> Pattern
Optional :: Pattern -> Pattern
Contains :: Pattern -> Pattern
Reference :: String -> Pattern

-- | Refs is a map from reference name to pattern and describes a relapse
--   grammar.
data Refs

-- | emptyRef returns an empty reference map.
emptyRef :: Refs

-- | union returns the union of two reference maps.
union :: Refs -> Refs -> Refs

-- | newRef returns a new reference map given a single pattern and its
--   reference name.
newRef :: String -> Pattern -> Refs

-- | reverseLookupRef returns the reference name for a given pattern.
reverseLookupRef :: Pattern -> Refs -> Maybe String

-- | lookupRef looks up a pattern in the reference map, given a reference
--   name.
lookupRef :: Refs -> String -> Pattern

-- | hasRecursion returns whether an relapse grammar has any recursion,
--   starting from the "main" reference.
hasRecursion :: Refs -> Bool

-- | The nullable function returns whether a pattern is nullable. This
--   means that the pattern matches the empty string.
nullable :: Refs -> Pattern -> Bool

-- | unescapable is used for short circuiting. A part of the tree can be
--   skipped if all patterns are unescapable.
unescapable :: Pattern -> Bool
instance GHC.Classes.Eq Patterns.Refs
instance GHC.Show.Show Patterns.Refs
instance GHC.Show.Show Patterns.Pattern
instance GHC.Classes.Ord Patterns.Pattern
instance GHC.Classes.Eq Patterns.Pattern


-- | This is an internal relapse module.
--   
--   It contains relapse grammar parsing helper functions and
--   
--   it also contains a parser for the JSON serialized relapse AST.
module ParsePatterns
data ParsedExpr
BoolExpr :: (Expr Bool) -> ParsedExpr
DoubleExpr :: (Expr Double) -> ParsedExpr
IntExpr :: (Expr Int) -> ParsedExpr
UintExpr :: (Expr Uint) -> ParsedExpr
StringExpr :: (Expr String) -> ParsedExpr
BytesExpr :: (Expr Bytes) -> ParsedExpr
BoolListExpr :: [Expr Bool] -> ParsedExpr
DoubleListExpr :: [Expr Double] -> ParsedExpr
IntListExpr :: [Expr Int] -> ParsedExpr
UintListExpr :: [Expr Uint] -> ParsedExpr
StringListExpr :: [Expr String] -> ParsedExpr
BytesListExpr :: [Expr Bytes] -> ParsedExpr

-- | newBuiltIn parsers a builtin function to a relapse expression.
newBuiltIn :: String -> ParsedExpr -> Either String ParsedExpr

-- | newFunction parsers a relapse function to a relapse expression.
newFunction :: String -> [ParsedExpr] -> Either String ParsedExpr

-- | fromJson parses the relapse AST that has been serialized to JSON.
fromJson :: String -> Either String Refs
instance GHC.Show.Show ParsePatterns.ParsedExpr


-- | This module parses the Relapse Grammar using the Parsec Library.
module Parser

-- | parseGrammar parses the Relapse Grammar.
parseGrammar :: String -> Either ParseError Refs
grammar :: CharParser () Refs
pattern :: CharParser () Pattern
nameExpr :: CharParser () (Expr Bool)
expr :: CharParser () (Expr Bool)
idLit :: CharParser () String
bytesCastLit :: CharParser () String
stringLit :: CharParser () String
doubleCastLit :: CharParser () Double
uintCastLit :: CharParser () Int
intLit :: CharParser () Int
ws :: CharParser () ()


-- | This module simplifies Relapse patterns.
module Simplify

-- | simplify simplifies an input pattern to an equivalent simpler pattern.
simplify :: Refs -> Pattern -> Pattern


-- | This module contains the XML Parser.
module Xml

-- | decodeXML returns a XmlTree, given an input string.
decodeXML :: String -> [XmlTree]
instance Parsers.Tree Text.XML.HXT.DOM.TypeDefs.XmlTree


-- | This is an internal relapse module.
--   
--   It zips patterns to reduce the state space.
module Zip
data Zipper
zippy :: [Pattern] -> ([Pattern], Zipper)
unzipby :: Zipper -> [Bool] -> [Bool]
instance GHC.Classes.Ord Zip.Zipper
instance GHC.Classes.Eq Zip.Zipper
instance GHC.Classes.Ord Zip.ZipEntry
instance GHC.Classes.Eq Zip.ZipEntry


-- | This is an internal relapse module.
--   
--   It contains multiple implementations of if expressions.
module IfExprs
data IfExprs
data IfExpr
newIfExpr :: Expr Bool -> Pattern -> Pattern -> IfExpr
evalIfExprs :: IfExprs -> Label -> Except ValueErr [Pattern]
compileIfExprs :: Refs -> [IfExpr] -> IfExprs
data ZippedIfExprs
zipIfExprs :: IfExprs -> ZippedIfExprs
evalZippedIfExprs :: ZippedIfExprs -> Label -> Except ValueErr ([Pattern], Zipper)


-- | This module is a simple implementation of the internal derivative
--   algorithm.
--   
--   It is intended to be used for explanation purposes.
--   
--   This means that it gives up speed for readability.
--   
--   Thus it has no type of memoization.
module Derive

-- | derive is the classic derivative implementation for trees.
derive :: Tree t => Refs -> [t] -> Except String Pattern

-- | calls returns a compiled if expression tree. Each if expression
--   returns a child pattern, given the input value. In other words calls
--   signature is actually:
--   
--   <pre>
--   Refs -&gt; [Pattern] -&gt; Value -&gt; [Pattern]
--   </pre>
--   
--   , where the resulting list of patterns are the child patterns, that
--   need to be derived given the trees child values.
calls :: Refs -> [Pattern] -> IfExprs

-- | returns takes a list of patterns and list of bools. The list of bools
--   represent the nullability of the derived child patterns. Each bool
--   will then replace each Node pattern with either an Empty or EmptySet.
--   The lists do not to be the same length, because each Pattern can
--   contain an arbitrary number of Node Patterns.
returns :: Refs -> ([Pattern], [Bool]) -> [Pattern]

-- | zipderive is a slighty optimized version of derivs. It zips its
--   intermediate pattern lists to reduce the state space.
zipderive :: Tree t => Refs -> [t] -> Except String Pattern


-- | This module contains a VPA (Visual Pushdown Automaton) implementation
--   of the internal derivative algorithm.
--   
--   It is intended to be used for explanation purposes.
--   
--   It shows how out algorithm is effective equivalent to a visual
--   pushdown automaton.
module VpaDerive
derive :: Tree t => Refs -> [t] -> Except String Pattern


-- | This module is an efficient implementation of the derivative algorithm
--   for trees.
--   
--   It is intended to be used for production purposes.
--   
--   This means that it gives up some readability for speed.
--   
--   This module provides memoization of the nullable, calls and returns
--   functions.
module MemDerive

-- | derive is the classic derivative implementation for trees.
derive :: Tree t => Refs -> [t] -> Except String Pattern

-- | Mem is the object used to store memoized results of the nullable,
--   calls and returns functions.
data Mem

-- | newMem creates a object used for memoization by the validate function.
--   Each grammar should create its own memoize object.
newMem :: Mem

-- | nullable returns whether a pattern is nullable and memoizes the
--   results.
nullable :: Refs -> Pattern -> State Mem Bool

-- | validate is the uses the derivative implementation for trees and
--   return whether tree is valid, given the input grammar and start
--   pattern.
validate :: Tree t => Refs -> Pattern -> [t] -> (State Mem) Bool


-- | This module provides an implementation of the relapse validation
--   language.
--   
--   Relapse is intended to be used for validation of trees or filtering of
--   lists of trees.
--   
--   Katydid currently provides two types of trees out of the box: Json and
--   XML, but relapse supports any type of tree as long the type is of the
--   Tree typeclass provided by the Parsers module.
--   
--   The validate and filter functions expects a Tree to be a list of
--   trees, since not all serialization formats have a single root. For
--   example, valid json like "[1, 2]" does not have a single root. Relapse
--   can also validate these types of trees. If your tree has a single
--   root, simply provide a singleton list as input.
module Relapse

-- | parseGrammar parses the relapse grammar and returns either a parsed
--   grammar (Refs, for the list of references) or an error string.
parseGrammar :: String -> Except String Refs

-- | validate returns whether a tree is valid, given the grammar (Refs).
validate :: Tree t => Refs -> [t] -> Bool

-- | filter returns a filtered list of trees, given the grammar (Refs).
filter :: Tree t => Refs -> [[t]] -> [[t]]
