haskell-src-exts-simple-1.23.1.0: A simplified view on the haskell-src-exts AST

Safe Haskell | None
Language | Haskell2010

Language.Haskell.Exts.Simple.Parser

Description

This module partially reexports Language.Haskell.Exts.Parser with adaptations.

Synopsis

- parse :: (Parseable (ast SrcSpanInfo), Functor ast) => String -> ParseResult (ast ())
- parseWithMode :: (Parseable (ast SrcSpanInfo), Functor ast) => ParseMode -> String -> ParseResult (ast ())
- parseWithComments :: (Parseable (ast SrcSpanInfo), Functor ast) => ParseMode -> String -> ParseResult (ast (), [Comment])
- type ListOf = ListOf
- pattern ListOf :: [a] -> ListOf a
- type ModuleHeadAndImports = ModuleHeadAndImports ()
- pattern ModuleHeadAndImports :: [ModulePragma] -> Maybe ModuleHead -> [ImportDecl] -> ModuleHeadAndImports ()
- type PragmasAndModuleHead = PragmasAndModuleHead ()
- pattern PragmasAndModuleHead :: [ModulePragma] -> Maybe ModuleHead -> PragmasAndModuleHead ()
- type PragmasAndModuleName = PragmasAndModuleName ()
- pattern PragmasAndModuleName :: [ModulePragma] -> Maybe ModuleName -> PragmasAndModuleName
- parseModule :: String -> ParseResult Module
- parseModuleWithMode :: ParseMode -> String -> ParseResult Module
- parseModuleWithComments :: ParseMode -> String -> ParseResult (Module, [Comment])
- parseExp :: String -> ParseResult Exp
- parseExpWithMode :: ParseMode -> String -> ParseResult Exp
- parseExpWithComments :: ParseMode -> String -> ParseResult (Exp, [Comment])
- parsePat :: String -> ParseResult Pat
- parsePatWithMode :: ParseMode -> String -> ParseResult Pat
- parsePatWithComments :: ParseMode -> String -> ParseResult (Pat, [Comment])
- parseDecl :: String -> ParseResult Decl
- parseDeclWithMode :: ParseMode -> String -> ParseResult Decl
- parseDeclWithComments :: ParseMode -> String -> ParseResult (Decl, [Comment])
- parseType :: String -> ParseResult Type
- parseTypeWithMode :: ParseMode -> String -> ParseResult Type
- parseTypeWithComments :: ParseMode -> String -> ParseResult (Type, [Comment])
- parseStmt :: String -> ParseResult Stmt
- parseStmtWithMode :: ParseMode -> String -> ParseResult Stmt
- parseStmtWithComments :: ParseMode -> String -> ParseResult (Stmt, [Comment])
- parseImportDecl :: String -> ParseResult ImportDecl
- parseImportDeclWithMode :: ParseMode -> String -> ParseResult ImportDecl
- parseImportDeclWithComments :: ParseMode -> String -> ParseResult (ImportDecl, [Comment])
- getTopPragmas :: String -> ParseResult [ModulePragma]
- listOf :: [a] -> ListOf a
- data ParseMode = ParseMode {
  - parseFilename :: String
  - baseLanguage :: Language
  - extensions :: [Extension]
  - ignoreLanguagePragmas :: Bool
  - ignoreLinePragmas :: Bool
  - fixities :: Maybe [Fixity]
  - ignoreFunctionArity :: Bool
  }
- data ParseResult a
  - = ParseOk a
  - | ParseFailed SrcLoc String
- class Parseable ast
- fromParseResult :: ParseResult a -> a
- defaultParseMode :: ParseMode
- newtype NonGreedy a = NonGreedy {
  - unNonGreedy :: a
  }
- unListOf :: ListOf a -> [a]

# Documentation

parse :: (Parseable (ast SrcSpanInfo), Functor ast) => String -> ParseResult (ast ()) Source #

parseWithMode :: (Parseable (ast SrcSpanInfo), Functor ast) => ParseMode -> String -> ParseResult (ast ()) Source #

parseWithComments :: (Parseable (ast SrcSpanInfo), Functor ast) => ParseMode -> String -> ParseResult (ast (), [Comment]) Source #

type ListOf = ListOf Source #

pattern ListOf :: [a] -> ListOf a Source #

type ModuleHeadAndImports = ModuleHeadAndImports () Source #

pattern ModuleHeadAndImports :: [ModulePragma] -> Maybe ModuleHead -> [ImportDecl] -> ModuleHeadAndImports () Source #

type PragmasAndModuleHead = PragmasAndModuleHead () Source #

pattern PragmasAndModuleHead :: [ModulePragma] -> Maybe ModuleHead -> PragmasAndModuleHead () Source #

type PragmasAndModuleName = PragmasAndModuleName () Source #

pattern PragmasAndModuleName :: [ModulePragma] -> Maybe ModuleName -> PragmasAndModuleName Source #

parseModule :: String -> ParseResult Module Source #

parseModuleWithMode :: ParseMode -> String -> ParseResult Module Source #

parseModuleWithComments :: ParseMode -> String -> ParseResult (Module, [Comment]) Source #

parseExp :: String -> ParseResult Exp Source #

parseExpWithMode :: ParseMode -> String -> ParseResult Exp Source #

parseExpWithComments :: ParseMode -> String -> ParseResult (Exp, [Comment]) Source #

parsePat :: String -> ParseResult Pat Source #

parsePatWithMode :: ParseMode -> String -> ParseResult Pat Source #

parsePatWithComments :: ParseMode -> String -> ParseResult (Pat, [Comment]) Source #

parseDecl :: String -> ParseResult Decl Source #

parseDeclWithMode :: ParseMode -> String -> ParseResult Decl Source #

parseDeclWithComments :: ParseMode -> String -> ParseResult (Decl, [Comment]) Source #

parseType :: String -> ParseResult Type Source #

parseTypeWithMode :: ParseMode -> String -> ParseResult Type Source #

parseTypeWithComments :: ParseMode -> String -> ParseResult (Type, [Comment]) Source #

parseStmt :: String -> ParseResult Stmt Source #

parseStmtWithMode :: ParseMode -> String -> ParseResult Stmt Source #

parseStmtWithComments :: ParseMode -> String -> ParseResult (Stmt, [Comment]) Source #

parseImportDecl :: String -> ParseResult ImportDecl Source #

parseImportDeclWithMode :: ParseMode -> String -> ParseResult ImportDecl Source #

parseImportDeclWithComments :: ParseMode -> String -> ParseResult (ImportDecl, [Comment]) Source #

getTopPragmas :: String -> ParseResult [ModulePragma] Source #

listOf :: [a] -> ListOf a Source #

data ParseMode Source #

Static parameters governing a parse. Note that the various parse functions in Language.Haskell.Exts.Parser never look at LANGUAGE pragmas, regardless of what the `ignoreLanguagePragmas` flag is set to. Only the various `parseFile` functions in Language.Haskell.Exts will act on it, when set to `False`.

Constructors

ParseMode |

Fields

- parseFilename :: String

  original name of the file being parsed

- baseLanguage :: Language

  base language (e.g. Haskell98, Haskell2010)

- extensions :: [Extension]

  list of extensions enabled for parsing

- ignoreLanguagePragmas :: Bool

  if `True`, the parser won't care about further extensions in LANGUAGE pragmas in source files

- ignoreLinePragmas :: Bool

  if `True`, the parser won't read line position information from LINE pragmas in source files

- fixities :: Maybe [Fixity]

  list of fixities to be aware of

- ignoreFunctionArity :: Bool

  Checks whether functions have a consistent arity

data ParseResult a Source #

The result of a parse.

Constructors

ParseOk a | The parse succeeded, yielding a value.
ParseFailed SrcLoc String | The parse failed at the specified source location, with an error message.

#### Instances

Instances details

Applicative ParseResult |
Instance details Defined in Language.Haskell.Exts.ParseMonad Methods pure :: a -> ParseResult a Source # (<*>) :: ParseResult (a -> b) -> ParseResult a -> ParseResult b Source # liftA2 :: (a -> b -> c) -> ParseResult a -> ParseResult b -> ParseResult c Source # (*>) :: ParseResult a -> ParseResult b -> ParseResult b Source # (<*) :: ParseResult a -> ParseResult b -> ParseResult a Source #
Functor ParseResult |
Instance details Defined in Language.Haskell.Exts.ParseMonad Methods fmap :: (a -> b) -> ParseResult a -> ParseResult b Source # (<$) :: a -> ParseResult b -> ParseResult a Source #
Monad ParseResult |
Instance details Defined in Language.Haskell.Exts.ParseMonad Methods (>>=) :: ParseResult a -> (a -> ParseResult b) -> ParseResult b Source # (>>) :: ParseResult a -> ParseResult b -> ParseResult b Source # return :: a -> ParseResult a Source #
MonadFail ParseResult |
Instance details Defined in Language.Haskell.Exts.ParseMonad Methods fail :: String -> ParseResult a Source #
(Monoid m, Semigroup m) => Monoid (ParseResult m) |
Instance details Defined in Language.Haskell.Exts.ParseMonad Methods mempty :: ParseResult m Source # mappend :: ParseResult m -> ParseResult m -> ParseResult m Source # mconcat :: [ParseResult m] -> ParseResult m Source #
Semigroup m => Semigroup (ParseResult m) |
Instance details Defined in Language.Haskell.Exts.ParseMonad Methods (<>) :: ParseResult m -> ParseResult m -> ParseResult m Source # sconcat :: NonEmpty (ParseResult m) -> ParseResult m Source # stimes :: Integral b => b -> ParseResult m -> ParseResult m Source #
Show a => Show (ParseResult a) |
Instance details Defined in Language.Haskell.Exts.ParseMonad Methods showsPrec :: Int -> ParseResult a -> ShowS Source # show :: ParseResult a -> String Source # showList :: [ParseResult a] -> ShowS Source #
Eq a => Eq (ParseResult a) |
Instance details Defined in Language.Haskell.Exts.ParseMonad Methods (==) :: ParseResult a -> ParseResult a -> Bool Source # (/=) :: ParseResult a -> ParseResult a -> Bool Source #
Ord a => Ord (ParseResult a) |

Instance details

Defined in Language.Haskell.Exts.ParseMonad

Methods

compare :: ParseResult a -> ParseResult a -> Ordering Source #

(<) :: ParseResult a -> ParseResult a -> Bool Source #

(<=) :: ParseResult a -> ParseResult a -> Bool Source #

(>) :: ParseResult a -> ParseResult a -> Bool Source #

(>=) :: ParseResult a -> ParseResult a -> Bool Source #

max :: ParseResult a -> ParseResult a -> ParseResult a Source #

min :: ParseResult a -> ParseResult a -> ParseResult a Source #

class Parseable ast Source #

Class providing function for parsing at many different types.

Note that for convenience of implementation, the default methods have definitions equivalent to `undefined`. The minimal definition is all of the visible methods.

Minimal complete definition

parser

#### Instances

Instances details

Parseable (NonGreedy (ListOf (ModulePragma SrcSpanInfo))) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

parse :: String -> ParseResult (NonGreedy (ListOf (ModulePragma SrcSpanInfo))) Source #

parseWithMode :: ParseMode -> String -> ParseResult (NonGreedy (ListOf (ModulePragma SrcSpanInfo))) Source #

parseWithComments :: ParseMode -> String -> ParseResult (NonGreedy (ListOf (ModulePragma SrcSpanInfo)), [Comment]) Source #

parser :: Maybe [Fixity] -> P (NonGreedy (ListOf (ModulePragma SrcSpanInfo)))

Parseable (NonGreedy (ModuleHeadAndImports SrcSpanInfo)) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

parse :: String -> ParseResult (NonGreedy (ModuleHeadAndImports SrcSpanInfo)) Source #

parseWithMode :: ParseMode -> String -> ParseResult (NonGreedy (ModuleHeadAndImports SrcSpanInfo)) Source #

parseWithComments :: ParseMode -> String -> ParseResult (NonGreedy (ModuleHeadAndImports SrcSpanInfo), [Comment]) Source #

parser :: Maybe [Fixity] -> P (NonGreedy (ModuleHeadAndImports SrcSpanInfo))

Parseable (NonGreedy (PragmasAndModuleHead SrcSpanInfo)) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

parse :: String -> ParseResult (NonGreedy (PragmasAndModuleHead SrcSpanInfo)) Source #

parseWithMode :: ParseMode -> String -> ParseResult (NonGreedy (PragmasAndModuleHead SrcSpanInfo)) Source #

parseWithComments :: ParseMode -> String -> ParseResult (NonGreedy (PragmasAndModuleHead SrcSpanInfo), [Comment]) Source #

parser :: Maybe [Fixity] -> P (NonGreedy (PragmasAndModuleHead SrcSpanInfo))

Parseable (NonGreedy (PragmasAndModuleName SrcSpanInfo)) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

parse :: String -> ParseResult (NonGreedy (PragmasAndModuleName SrcSpanInfo)) Source #

parseWithMode :: ParseMode -> String -> ParseResult (NonGreedy (PragmasAndModuleName SrcSpanInfo)) Source #

parseWithComments :: ParseMode -> String -> ParseResult (NonGreedy (PragmasAndModuleName SrcSpanInfo), [Comment]) Source #

parser :: Maybe [Fixity] -> P (NonGreedy (PragmasAndModuleName SrcSpanInfo))

Parseable (Decl SrcSpanInfo) |
Instance details Defined in Language.Haskell.Exts.Parser Methods parse :: String -> ParseResult (Decl SrcSpanInfo) Source # parseWithMode :: ParseMode -> String -> ParseResult (Decl SrcSpanInfo) Source # parseWithComments :: ParseMode -> String -> ParseResult (Decl SrcSpanInfo, [Comment]) Source # parser :: Maybe [Fixity] -> P (Decl SrcSpanInfo)
Parseable (Exp SrcSpanInfo) |
Instance details Defined in Language.Haskell.Exts.Parser Methods parse :: String -> ParseResult (Exp SrcSpanInfo) Source # parseWithMode :: ParseMode -> String -> ParseResult (Exp SrcSpanInfo) Source # parseWithComments :: ParseMode -> String -> ParseResult (Exp SrcSpanInfo, [Comment]) Source # parser :: Maybe [Fixity] -> P (Exp SrcSpanInfo)
Parseable (ImportDecl SrcSpanInfo) |
Instance details Defined in Language.Haskell.Exts.Parser Methods parse :: String -> ParseResult (ImportDecl SrcSpanInfo) Source # parseWithMode :: ParseMode -> String -> ParseResult (ImportDecl SrcSpanInfo) Source # parseWithComments :: ParseMode -> String -> ParseResult (ImportDecl SrcSpanInfo, [Comment]) Source # parser :: Maybe [Fixity] -> P (ImportDecl SrcSpanInfo)
Parseable (Module SrcSpanInfo) |
Instance details Defined in Language.Haskell.Exts.Parser Methods parse :: String -> ParseResult (Module SrcSpanInfo) Source # parseWithMode :: ParseMode -> String -> ParseResult (Module SrcSpanInfo) Source # parseWithComments :: ParseMode -> String -> ParseResult (Module SrcSpanInfo, [Comment]) Source # parser :: Maybe [Fixity] -> P (Module SrcSpanInfo)
Parseable (Pat SrcSpanInfo) |
Instance details Defined in Language.Haskell.Exts.Parser Methods parse :: String -> ParseResult (Pat SrcSpanInfo) Source # parseWithMode :: ParseMode -> String -> ParseResult (Pat SrcSpanInfo) Source # parseWithComments :: ParseMode -> String -> ParseResult (Pat SrcSpanInfo, [Comment]) Source # parser :: Maybe [Fixity] -> P (Pat SrcSpanInfo)
Parseable (Stmt SrcSpanInfo) |
Instance details Defined in Language.Haskell.Exts.Parser Methods parse :: String -> ParseResult (Stmt SrcSpanInfo) Source # parseWithMode :: ParseMode -> String -> ParseResult (Stmt SrcSpanInfo) Source # parseWithComments :: ParseMode -> String -> ParseResult (Stmt SrcSpanInfo, [Comment]) Source # parser :: Maybe [Fixity] -> P (Stmt SrcSpanInfo)
Parseable (Type SrcSpanInfo) |
Instance details Defined in Language.Haskell.Exts.Parser Methods parse :: String -> ParseResult (Type SrcSpanInfo) Source # parseWithMode :: ParseMode -> String -> ParseResult (Type SrcSpanInfo) Source # parseWithComments :: ParseMode -> String -> ParseResult (Type SrcSpanInfo, [Comment]) Source # parser :: Maybe [Fixity] -> P (Type SrcSpanInfo)

fromParseResult :: ParseResult a -> a Source #

Retrieve the result of a successful parse, throwing an error if the parse is actually not successful.

defaultParseMode :: ParseMode Source #

Default parameters for a parse. The default is an unknown filename, no extensions (i.e. Haskell 98), don't ignore LANGUAGE pragmas, do ignore LINE pragmas, and be aware of fixities from the `Prelude`.

newtype NonGreedy a Source #

Instances of `Parseable` for `NonGreedy a` will only consume the input until `a` is fully parsed. This means that parse errors that come later in the input will be ignored. It's also more efficient, as it's fully lazy in the remainder of the input:

    >>> parse (unlines ("module A where" : "main =" : repeat "blah")) :: ParseResult PragmasAndModuleHead
    ParseOk (NonGreedy {unNonGreedy = PragmasAndModuleHead [] (ModuleName "A",Nothing,Nothing)})

(this example uses the simplified AST)

Constructors

NonGreedy |

Fields

- unNonGreedy :: a

#### Instances

Instances details

Functor NonGreedy |
Instance details Defined in Language.Haskell.Exts.Parser Methods fmap :: (a -> b) -> NonGreedy a -> NonGreedy b Source # (<$) :: a -> NonGreedy b -> NonGreedy a Source #
Data a => Data (NonGreedy a) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NonGreedy a -> c (NonGreedy a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NonGreedy a) Source #

toConstr :: NonGreedy a -> Constr Source #

dataTypeOf :: NonGreedy a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (NonGreedy a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NonGreedy a)) Source #

gmapT :: (forall b. Data b => b -> b) -> NonGreedy a -> NonGreedy a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NonGreedy a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NonGreedy a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> NonGreedy a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> NonGreedy a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> NonGreedy a -> m (NonGreedy a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NonGreedy a -> m (NonGreedy a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NonGreedy a -> m (NonGreedy a) Source #

Show a => Show (NonGreedy a) |
Instance details Defined in Language.Haskell.Exts.Parser Methods showsPrec :: Int -> NonGreedy a -> ShowS Source # show :: NonGreedy a -> String Source # showList :: [NonGreedy a] -> ShowS Source #
Eq a => Eq (NonGreedy a) |
Instance details Defined in Language.Haskell.Exts.Parser Methods (==) :: NonGreedy a -> NonGreedy a -> Bool Source # (/=) :: NonGreedy a -> NonGreedy a -> Bool Source #
Ord a => Ord (NonGreedy a) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

compare :: NonGreedy a -> NonGreedy a -> Ordering Source #

(<) :: NonGreedy a -> NonGreedy a -> Bool Source #

(<=) :: NonGreedy a -> NonGreedy a -> Bool Source #

(>) :: NonGreedy a -> NonGreedy a -> Bool Source #

(>=) :: NonGreedy a -> NonGreedy a -> Bool Source #

max :: NonGreedy a -> NonGreedy a -> NonGreedy a Source #

min :: NonGreedy a -> NonGreedy a -> NonGreedy a Source #

Parseable (NonGreedy (ListOf (ModulePragma SrcSpanInfo))) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

parse :: String -> ParseResult (NonGreedy (ListOf (ModulePragma SrcSpanInfo))) Source #

parseWithMode :: ParseMode -> String -> ParseResult (NonGreedy (ListOf (ModulePragma SrcSpanInfo))) Source #

parseWithComments :: ParseMode -> String -> ParseResult (NonGreedy (ListOf (ModulePragma SrcSpanInfo)), [Comment]) Source #

parser :: Maybe [Fixity] -> P (NonGreedy (ListOf (ModulePragma SrcSpanInfo)))

Parseable (NonGreedy (ModuleHeadAndImports SrcSpanInfo)) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

parse :: String -> ParseResult (NonGreedy (ModuleHeadAndImports SrcSpanInfo)) Source #

parseWithMode :: ParseMode -> String -> ParseResult (NonGreedy (ModuleHeadAndImports SrcSpanInfo)) Source #

parseWithComments :: ParseMode -> String -> ParseResult (NonGreedy (ModuleHeadAndImports SrcSpanInfo), [Comment]) Source #

parser :: Maybe [Fixity] -> P (NonGreedy (ModuleHeadAndImports SrcSpanInfo))

Parseable (NonGreedy (PragmasAndModuleHead SrcSpanInfo)) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

parse :: String -> ParseResult (NonGreedy (PragmasAndModuleHead SrcSpanInfo)) Source #

parseWithMode :: ParseMode -> String -> ParseResult (NonGreedy (PragmasAndModuleHead SrcSpanInfo)) Source #

parseWithComments :: ParseMode -> String -> ParseResult (NonGreedy (PragmasAndModuleHead SrcSpanInfo), [Comment]) Source #

parser :: Maybe [Fixity] -> P (NonGreedy (PragmasAndModuleHead SrcSpanInfo))

Parseable (NonGreedy (PragmasAndModuleName SrcSpanInfo)) |

Instance details

Defined in Language.Haskell.Exts.Parser

Methods

parse :: String -> ParseResult (NonGreedy (PragmasAndModuleName SrcSpanInfo)) Source #

parseWithMode :: ParseMode -> String -> ParseResult (NonGreedy (PragmasAndModuleName SrcSpanInfo)) Source #

parseWithComments :: ParseMode -> String -> ParseResult (NonGreedy (PragmasAndModuleName SrcSpanInfo), [Comment]) Source #

parser :: Maybe [Fixity] -> P (NonGreedy (PragmasAndModuleName SrcSpanInfo))

unListOf :: ListOf a -> [a] Source #