-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Manipulating Egison patterns: abstract syntax, parser, and pretty-printer -- -- egison-pattern-src provides a standalone syntax definition -- for patterns in the Egison programming language. This package -- enables you to embed Egison's patterns in your parser (pretty-printer) -- by supplying expression and name parsers (printers) externally. @package egison-pattern-src @version 0.2.1.1 -- | This module defines an AST (Abstract Syntax Tree) for Egison pattern -- expression. module Language.Egison.Syntax.Pattern.Expr -- | Egison pattern expressions. n is a type for name references -- in patterns, such as them in pattern constructors. v is a -- type for name bindings in patterns, such as them in pattern variables. -- e is a type for expressions in patterns, such as them in -- value patterns. data Expr n v e -- | Wildcard pattern. Match with everything. Wildcard :: Expr n v e -- | Pattern variable. The matched term is bound to the name. Variable :: v -> Expr n v e -- | Value pattern. Match with equal terms. Value :: e -> Expr n v e -- | Predicate pattern. Match with terms that satisfy the given predicate. Predicate :: e -> Expr n v e -- | And pattern. Match when both patterns matches. And :: Expr n v e -> Expr n v e -> Expr n v e -- | Or pattern. Match when one of given patterns matches. Or :: Expr n v e -> Expr n v e -> Expr n v e -- | Not pattern. Match when the given pattern does not match. Not :: Expr n v e -> Expr n v e -- | Tuple pattern. Match with tuples whose elements match with respective -- patterns. Tuple :: [Expr n v e] -> Expr n v e -- | Collection pattern. Match with collections whose elements match with -- respective patterns. Collection :: [Expr n v e] -> Expr n v e -- | User-defined infix pattern. Infix :: n -> Expr n v e -> Expr n v e -> Expr n v e -- | User-defined normal pattern. Pattern :: n -> [Expr n v e] -> Expr n v e instance GHC.Generics.Generic (Language.Egison.Syntax.Pattern.Expr.Expr n v e) instance (Data.Data.Data n, Data.Data.Data v, Data.Data.Data e) => Data.Data.Data (Language.Egison.Syntax.Pattern.Expr.Expr n v e) instance (GHC.Show.Show v, GHC.Show.Show e, GHC.Show.Show n) => GHC.Show.Show (Language.Egison.Syntax.Pattern.Expr.Expr n v e) instance (GHC.Classes.Ord v, GHC.Classes.Ord e, GHC.Classes.Ord n) => GHC.Classes.Ord (Language.Egison.Syntax.Pattern.Expr.Expr n v e) instance (GHC.Classes.Eq v, GHC.Classes.Eq e, GHC.Classes.Eq n) => GHC.Classes.Eq (Language.Egison.Syntax.Pattern.Expr.Expr n v e) -- | This module defines a base functor of Expr that is useful to -- abstract recursive computations on Expr. module Language.Egison.Syntax.Pattern.Base -- | Base functor of Expr. data ExprF (n_aiZ9 :: Type) (v_aiZa :: Type) (e_aiZb :: Type) r_anzL WildcardF :: ExprF r_anzL VariableF :: v_aiZa -> ExprF r_anzL ValueF :: e_aiZb -> ExprF r_anzL PredicateF :: e_aiZb -> ExprF r_anzL AndF :: r_anzL -> r_anzL -> ExprF r_anzL OrF :: r_anzL -> r_anzL -> ExprF r_anzL NotF :: r_anzL -> ExprF r_anzL TupleF :: [r_anzL] -> ExprF r_anzL CollectionF :: [r_anzL] -> ExprF r_anzL InfixF :: n_aiZ9 -> r_anzL -> r_anzL -> ExprF r_anzL PatternF :: n_aiZ9 -> [r_anzL] -> ExprF r_anzL instance Data.Traversable.Traversable (Language.Egison.Syntax.Pattern.Base.ExprF n v e) instance Data.Foldable.Foldable (Language.Egison.Syntax.Pattern.Base.ExprF n v e) instance GHC.Base.Functor (Language.Egison.Syntax.Pattern.Base.ExprF n v e) instance Data.Functor.Foldable.Recursive (Language.Egison.Syntax.Pattern.Expr.Expr n v e) instance Data.Functor.Foldable.Corecursive (Language.Egison.Syntax.Pattern.Expr.Expr n v e) -- | Useful combinators to manipulate Egison pattern ASTs. module Language.Egison.Syntax.Pattern.Combinator -- | Unwrap annotations from AST. unAnnotate :: Cofree (ExprF n v e) a -> Expr n v e -- | fold an v expr. -- -- Note that this is just a type specialization of cata. foldExpr :: (ExprF n v e a -> a) -> Expr n v e -> a -- | Map over n in Expr n v e. mapName :: (n -> n') -> Expr n v e -> Expr n' v e -- | Map over v in Expr n v e. mapVarName :: (v -> v') -> Expr n v e -> Expr n v' e -- | Map over e in Expr n v e. mapValueExpr :: (e -> e') -> Expr n v e -> Expr n v e' -- | List bound pattern variables in a pattern. variables :: Alternative f => Expr n v e -> f v -- | This package provides a standalone syntax definition for patterns in -- the Egison programming language. module Language.Egison.Syntax.Pattern -- | A fixity of infix operators. module Language.Egison.Syntax.Pattern.Fixity -- | Fixity of infix operators. data Fixity n Fixity :: Associativity -> Precedence -> n -> Fixity n [$sel:associativity:Fixity] :: Fixity n -> Associativity [$sel:precedence:Fixity] :: Fixity n -> Precedence [$sel:symbol:Fixity] :: Fixity n -> n -- | Associativity of infix operators. data Associativity AssocLeft :: Associativity AssocRight :: Associativity AssocNone :: Associativity -- | A precedence of infix operators. newtype Precedence Precedence :: Int -> Precedence -- | A pretty printer for Egison patterns. module Language.Egison.Pretty.Pattern -- | Pretty print Expr. prettyExpr :: (MonadError (Error n) m, Ord n) => PrintMode n v e -> Expr n v e -> m Text -- | A pretty printer error. newtype Error n UnknownInfixOperator :: n -> Error n -- | Associativity of infix operators. data Associativity AssocLeft :: Associativity AssocRight :: Associativity AssocNone :: Associativity -- | A precedence of infix operators. newtype Precedence Precedence :: Int -> Precedence -- | Fixity of infix operators. data Fixity n Fixity :: Associativity -> Precedence -> n -> Fixity n [$sel:associativity:Fixity] :: Fixity n -> Associativity [$sel:precedence:Fixity] :: Fixity n -> Precedence [$sel:symbol:Fixity] :: Fixity n -> n -- | Printer configuration. data PrintMode n v e PrintMode :: [PrintFixity n] -> ExtPrinter v -> ExtPrinter n -> ExtPrinter e -> Maybe PageMode -> PrintMode n v e [$sel:fixities:PrintMode] :: PrintMode n v e -> [PrintFixity n] [$sel:varNamePrinter:PrintMode] :: PrintMode n v e -> ExtPrinter v [$sel:namePrinter:PrintMode] :: PrintMode n v e -> ExtPrinter n [$sel:valueExprPrinter:PrintMode] :: PrintMode n v e -> ExtPrinter e [$sel:pageMode:PrintMode] :: PrintMode n v e -> Maybe PageMode -- | Rendering style configuration. data PageMode PageMode :: Int -> Double -> PageMode [$sel:lineLength:PageMode] :: PageMode -> Int [$sel:ribbonsPerLine:PageMode] :: PageMode -> Double -- | Fixity of infix operators. data PrintFixity n PrintFixity :: Fixity n -> Text -> PrintFixity n [$sel:fixity:PrintFixity] :: PrintFixity n -> Fixity n [$sel:printed:PrintFixity] :: PrintFixity n -> Text -- | ExtPrinter a is a type for externally provided printer -- of a. type ExtPrinter a = a -> Text -- | A parser for Egison patterns. module Language.Egison.Parser.Pattern -- | Parse Expr. parseExpr :: (Source s, MonadError (Errors s) m) => ParseMode n v e s -> s -> m (Expr n v e) -- | Parse Expr with locations annotated. parseExprL :: forall m s n v e. (Source s, MonadError (Errors s) m) => ParseMode n v e s -> s -> m (ExprL n v e) -- | Location, a range of positions in source code. data Location Location :: Position -> Position -> Location [$sel:begin:Location] :: Location -> Position [$sel:end:Location] :: Location -> Position -- | Position in source code. data Position Position :: Int -> Int -> Position [$sel:line:Position] :: Position -> Int [$sel:column:Position] :: Position -> Int -- | Provide a set of tokens needed to parse pattern expressions. class IsToken c isSpace :: IsToken c => c -> Bool newline :: IsToken c => c parenLeft :: IsToken c => c parenRight :: IsToken c => c underscore :: IsToken c => c hash :: IsToken c => c question :: IsToken c => c exclamation :: IsToken c => c and :: IsToken c => c vertical :: IsToken c => c dollar :: IsToken c => c bracketLeft :: IsToken c => c bracketRight :: IsToken c => c comma :: IsToken c => c -- | Constraint for the source of parser. TODO: Hide these methods in -- haddock (see haskell/haddock#330) class (Stream s, IsToken (Token s)) => Source s -- | Type of tokens in the source. type Tokens s = Tokens s -- | Type of token in the source. type Token s = Token s -- | Type synonym for an error list. type Errors s = NonEmpty (Error s) -- | Parse error. data Error s UnexpectedToken :: Position -> [ErrorItem s] -> Maybe (ErrorItem s) -> Error s [$sel:position:UnexpectedToken] :: Error s -> Position [$sel:expected:UnexpectedToken] :: Error s -> [ErrorItem s] [$sel:found:UnexpectedToken] :: Error s -> Maybe (ErrorItem s) ExternalError :: Position -> Tokens s -> String -> Error s [$sel:position:UnexpectedToken] :: Error s -> Position [$sel:input:UnexpectedToken] :: Error s -> Tokens s [$sel:message:UnexpectedToken] :: Error s -> String UnexpectedEndOfFile :: Tokens s -> Error s [$sel:rest:UnexpectedToken] :: Error s -> Tokens s -- | Token representation in Error. data ErrorItem s Tokens :: Tokens s -> ErrorItem s Label :: String -> ErrorItem s EndOfInput :: ErrorItem s -- | Type class providing functions for parsing. class Source s => Parsable a s mode -- | Parse a source stream. parse :: (Parsable a s mode, MonadError (Errors s) m) => mode -> s -> m a -- | Parse a source stream with location annotations. parseWithLocation :: (Parsable a s mode, MonadError (Errors s) m) => mode -> s -> m (Cofree (Base a) Location) -- | Parse a source stream non-greedily. That is, this parser will only -- consume the input until a is fully parsed, and return the rest of the -- input. parseNonGreedy :: (Parsable a s mode, MonadError (Errors s) m) => mode -> s -> m (a, s) -- | Parse a source stream non-greedily with location annotations. parseNonGreedyWithLocation :: (Parsable a s mode, MonadError (Errors s) m) => mode -> s -> m (Cofree (Base a) Location, s) -- | Parse a source stream non-greedily. That is, this parser will only -- consume the input until a is fully parsed, and return the rest of the -- input. parseNonGreedy :: (Parsable a s mode, Recursive a, Corecursive a, MonadError (Errors s) m) => mode -> s -> m (a, s) -- | Parse a source stream. parse :: (Parsable a s mode, Recursive a, Corecursive a, MonadError (Errors s) m) => mode -> s -> m a -- | Associativity of infix operators. data Associativity AssocLeft :: Associativity AssocRight :: Associativity AssocNone :: Associativity -- | A precedence of infix operators. newtype Precedence Precedence :: Int -> Precedence -- | Fixity of infix operators. data Fixity n Fixity :: Associativity -> Precedence -> n -> Fixity n [$sel:associativity:Fixity] :: Fixity n -> Associativity [$sel:precedence:Fixity] :: Fixity n -> Precedence [$sel:symbol:Fixity] :: Fixity n -> n -- | Parser configuration. data ParseMode n v e s ParseMode :: FilePath -> [ParseFixity n s] -> Maybe (Tokens s, Tokens s) -> Maybe (Tokens s) -> ExtParser s v -> ExtParser s n -> ExtParser s e -> ParseMode n v e s [$sel:filename:ParseMode] :: ParseMode n v e s -> FilePath [$sel:fixities:ParseMode] :: ParseMode n v e s -> [ParseFixity n s] [$sel:blockComment:ParseMode] :: ParseMode n v e s -> Maybe (Tokens s, Tokens s) [$sel:lineComment:ParseMode] :: ParseMode n v e s -> Maybe (Tokens s) [$sel:varNameParser:ParseMode] :: ParseMode n v e s -> ExtParser s v [$sel:nameParser:ParseMode] :: ParseMode n v e s -> ExtParser s n [$sel:valueExprParser:ParseMode] :: ParseMode n v e s -> ExtParser s e -- | Fixity of infix operators. data ParseFixity n s ParseFixity :: Fixity n -> ExtParser s () -> ParseFixity n s [$sel:fixity:ParseFixity] :: ParseFixity n s -> Fixity n [$sel:parser:ParseFixity] :: ParseFixity n s -> ExtParser s () -- | ExtParser s a is a type for externally provided parser -- of a. type ExtParser s a = Tokens s -> Either String a -- | Expr with locations annotated. type ExprL n v e = Cofree (ExprF n v e) Location instance Language.Egison.Parser.Pattern.Prim.Source.Source s => Language.Egison.Parser.Pattern.Parsable.Parsable (Language.Egison.Syntax.Pattern.Expr.Expr n v e) s (Language.Egison.Parser.Pattern.Prim.ParseMode.ParseMode n v e s)