-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Derivative Parsing -- -- A parser based on derivatives of parser combinators (Might and -- Darais). Our paper on Arxiv details the theory of parsing with -- derivatives: http://arxiv.org/abs/1010.5023. This -- implementation uses my latest work on the theory that brings the -- O(n*|G|^2) complexity bound to O(n) for parsing most -- not-painfully-ambiguous grammars. (|G| would be the size of the -- initial grammar, n would be size of the input. These bounds are based -- off of observation and intuition; they are not proven yet.) This -- implementation will not terminate if the resulting parse frest is -- infinite. We know how to extend the implementation to work for -- infinite parse trees with little effort. If this is something you -- would like to see, shoot me an email. @package derp @version 0.1.3 module Text.Derp -- | Represents both a formal context-free language and the reduction of a -- member of that language to a value of type a. data Parser a -- | The input type for parsing. For example the parser: -- --
--   (ter "x") 
--   
-- -- will parse: -- --
--   (Token "x" "foo") 
--   
-- -- into: -- --
--   (eps "foo")
--   
data Token Token :: String -> String -> Token tokenClass :: Token -> String tokenValue :: Token -> String -- | Alternation. (<|>) :: ResultType a => Parser a -> Parser a -> Parser a -- | Concatenation. (<~>) :: (ResultType a, ResultType b) => Parser a -> Parser b -> Parser (a, b) -- | Reduction. (==>) :: (ResultType a, ResultType b) => Parser a -> (a -> b) -> Parser b -- | Set generalized version of ==>. (==>|) :: (ResultType a, ResultType b) => Parser a -> (Set a -> Set b) -> Parser b -- | Null-parse extraction. nul :: ResultType a => Parser a -> Parser a -- | One-hole-context focus. pzip :: (ResultType a, ResultType b) => Parser a -> Context a b -> Parser b -- | Terminal. ter :: String -> Parser String -- | Epsilon/empty-string. eps :: ResultType a => a -> Parser a -- | Set generalized version of eps. epsM :: ResultType a => Set a -> Parser a -- | The empty language. emp :: ResultType a => Parser a -- | The main derivative function. derive :: Parser a -> Token -> Parser a -- | The optimization step of the algorithm. compact :: Parser a -> Parser a -- | Extract the parse-null set of a parser. parseNull :: ResultType a => Parser a -> Set a -- | The number of compact steps that usually keeps a parser constant in -- size while parsing. defaultCompactSteps :: Int -- | A specified number of compactions. compactNum :: Int -> Parser a -> Parser a -- | Derivation followed by specified number of compactions. deriveStepNum :: Int -> Parser a -> Token -> Parser a -- | Parse using a specified number of intermediate compactions. runParseNum :: ResultType a => Int -> Parser a -> [Token] -> Set a -- | Derivation followed by the default number of compactions. deriveStep :: Parser a -> Token -> Parser a -- | Parse using the default number of intermediate compactions. This is -- the main parsing function. Examples: -- --
--   let e =     ter "num"
--           <|> e <~> ter "+" <~> e ==> (\(x1,(o,x2)) -> "(" ++ x1 ++ o ++ x2 ++ ")")
--   in runParse e [Token "num" "1", Token "+" "+", Token "num" 3", Token "+" "+", Token "num" "5"]
--   
-- -- evaluates to: -- --
--   Set.fromList ["((1+3)+5)", "(1+(3+5))"]
--   
-- --
--   let e =     ter "num" ==> read 
--           <|> e <~> ter "+" <~> e ==> (\(x1,(_,x2)) -> x1 + x2)
--   in runParse e [Token "num" "1", Token "+" "+", Token "num" 3", Token "+" "+", Token "num" "5"]
--   
-- -- evaluates to: -- --
--   Set.fromList [9]
--   
runParse :: ResultType a => Parser a -> [Token] -> Set a xsR :: () -> Parser String xsL :: () -> Parser String xsIn :: [Token] parens :: () -> Parser String parensIn :: [Token] amb :: () -> Parser String ambIn :: [Token] sexp :: () -> Parser String sexpIn :: [Token] instance Eq a => Eq (FPValue a) instance Ord a => Ord (FPValue a) instance Show a => Show (FPValue a) instance Eq ParserRecType instance Ord ParserRecType instance Show ParserRecType instance Eq Token instance Ord Token instance Show Token instance Show (Parser a) instance Ord a => ResultType a