-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Abstract syntax descriptions for parsing and pretty-printing. -- -- Abstract syntax descriptions for parsing and pretty-printing. Write a -- single syntax description, get both a parser and a pretty-printer. -- -- Syntax descriptions are based on semi-isomorphisms from -- semi-iso library. -- -- The library is very young. There are lots of useful combinators that -- could be written. -- -- See syntax-example for an example, syntax-attoparsec -- and syntax-pretty for a parser/printer implementation. @package syntax @version 0.1.1.0 -- | Combinators that work with any sequence type. module Data.Syntax.Combinator -- | Zero or more occurences of v separated by s. sepBy :: SemiIsoAlternative f => f a -> f () -> f [a] -- | One or more occurences of v separated by s. sepBy1 :: SemiIsoAlternative f => f a -> f () -> f [a] -- | Abstract syntax descriptions based on semi-isomorphisms. module Data.Syntax -- | An abstract syntax description based on semi-isomorphisms. -- -- This class can be implemented by both parsers and printers (and maybe -- more?). -- -- The usual use is to write a polymorphic syntax description and -- instantiate it both as a parser and a printer. An example syntax -- description: -- --
--   | A simple untyped lambda calculus.
--   data AST = Var Text
--            | App AST AST
--            | Abs Text AST
--       deriving (Show)
--   
--   $(makePrisms ''AST)
--   
--   -- | A variable name.
--   name :: Syntax syn Text => syn Text
--   name = S.takeWhile1 isAlphaNum
--   
--   -- | Encloses a symbol in parentheses.
--   parens :: Syntax syn Text => syn a -> syn a
--   parens m = S.char '(' */ S.spaces_ */ m /* S.spaces_ /* S.char ')'
--   
--   -- | An atom is a variable or an expression in parentheses.
--   atom :: Syntax syn Text => syn AST
--   atom =  _Var /$/ name
--       /|/ parens expr
--   
--   --| Parses a list of applications.
--   apps :: Syntax syn Text => syn AST
--   apps = bifoldl1 (attemptAp_ _App) /$/ S.sepBy1 atom S.spaces1
--   
--   -- | An expression of our lambda calculus.
--   expr :: Syntax syn Text => syn AST
--   expr =  _Abs /$/ S.char '\\'   /* S.spaces_
--                 */ name          /* S.spaces
--                /*  S.string "->" /* S.spaces
--                /*/ expr
--       /|/ apps
--   
-- -- Methods of this class try to mimic Data.Attoparsec.Text -- interface. class (SemiIsoAlternative syn, IsSequence seq, Eq seq, Eq (Element seq)) => Syntax syn seq | syn -> seq where char c = exact c /$/ anyChar notChar c = filtered (/= c) /$/ anyChar satisfy p = filtered p /$/ anyChar satisfyWith ai p = filtered p . ai /$/ anyChar string s = exact s /$/ take (olength s) take n = packed /$/ sireplicate n anyChar takeWhile p = packed /$/ simany (satisfy p) takeWhile1 p = packed /$/ sisome (satisfy p) takeTill p = takeWhile (not . p) takeTill1 p = takeWhile1 (not . p) anyChar :: Syntax syn seq => syn (Element seq) char :: Syntax syn seq => Element seq -> syn () notChar :: Syntax syn seq => Element seq -> syn (Element seq) satisfy :: Syntax syn seq => (Element seq -> Bool) -> syn (Element seq) satisfyWith :: Syntax syn seq => ASemiIso' a (Element seq) -> (a -> Bool) -> syn a string :: Syntax syn seq => seq -> syn () take :: Syntax syn seq => Int -> syn seq takeWhile :: Syntax syn seq => (Element seq -> Bool) -> syn seq takeWhile1 :: Syntax syn seq => (Element seq -> Bool) -> syn seq takeTill :: Syntax syn seq => (Element seq -> Bool) -> syn seq takeTill1 :: Syntax syn seq => (Element seq -> Bool) -> syn seq -- | An isomorphism between a sequence and a list of its elements. packed :: IsSequence seq => Iso' seq [Element seq] -- | Common combinators that work with sequences of chars. -- -- There are A LOT of combinators missing. module Data.Syntax.Char -- | Syntax constrainted to sequences of chars. type SyntaxChar syn seq = (Syntax syn seq, Element seq ~ Char) -- | Accepts zero or more spaces. Generates a single space. spaces :: SyntaxChar syn seq => syn () -- | Accepts zero or more spaces. Generates no output. spaces_ :: SyntaxChar syn seq => syn () -- | Accepts one or more spaces. Generates a single space. spaces1 :: SyntaxChar syn seq => syn () -- | Accepts one or more spaces. Generates no output. spaces1_ :: SyntaxChar syn seq => syn () -- | Accepts a single newline. Generates a newline. endOfLine :: SyntaxChar syn seq => syn ()