dhall-1.32.0: A configuration language guaranteed to terminate

Safe Haskell | None
Language | Haskell2010

Dhall.Parser

Contents

- Utilities
- Parsers
- Types

Description

This module contains Dhall's parsing logic

Synopsis

- exprFromText :: String -> Text -> Either ParseError (Expr Src Import)
- exprAndHeaderFromText :: String -> Text -> Either ParseError (Header, Expr Src Import)
- censor :: ParseError -> ParseError
- createHeader :: Text -> Header
- expr :: Parser (Expr Src Import)
- exprA :: Parser a -> Parser (Expr Src a)
- newtype Header = Header Text
- data Src = Src {
  - srcStart :: !SourcePos
  - srcEnd :: !SourcePos
  - srcText :: Text
  }
- data SourcedException e = SourcedException Src e
- data ParseError = ParseError {
  - unwrap :: ParseErrorBundle Text Void
  - input :: Text
  }
- newtype Parser a = Parser {
  - unParser :: Parsec Void Text a
  }

# Utilities

exprFromText Source #

Arguments

:: String | User-friendly name describing the input expression, used in parsing error messages
-> Text | Input expression to parse
-> Either ParseError (Expr Src Import) |

Parse an expression from `Text` containing a Dhall program

exprAndHeaderFromText Source #

Arguments

:: String | User-friendly name describing the input expression, used in parsing error messages
-> Text | Input expression to parse
-> Either ParseError (Header, Expr Src Import) |

Like `exprFromText` but also returns the leading comments and whitespace (i.e. header) up to the last newline before the code begins

In other words, if you have a Dhall file of the form:

    -- Comment 1
    {- Comment -} 2

Then this will preserve `Comment 1`, but not `Comment 2`

This is used by `dhall-format` to preserve leading comments and whitespace

censor :: ParseError -> ParseError Source #

Replace the source code with spaces when rendering error messages

This utility is used to implement the `--censor` flag

createHeader :: Text -> Header Source #

Create a header with stripped leading spaces and trailing newlines

# Parsers

expr :: Parser (Expr Src Import) Source #

Parser for a top-level Dhall expression

exprA :: Parser a -> Parser (Expr Src a) Source #

Deprecated: Support for parsing custom imports will be dropped in a future release

Parser for a top-level Dhall expression. The expression is parameterized over any parseable type, allowing the language to be extended as needed.

# Types

newtype Header Source #

A header corresponds to the leading comment at the top of a Dhall file.

The header includes comment characters but is stripped of leading spaces and trailing newlines

Constructors

Header Text |

#### Instances

Instances details

Show Header Source # |
Instance details Defined in Dhall.Parser Methods showsPrec :: Int -> Header -> ShowS Source # show :: Header -> String Source # showList :: [Header] -> ShowS Source #

data Src Source #

Source code extract

Constructors

Src |

Fields

- srcStart :: !SourcePos
- srcEnd :: !SourcePos
- srcText :: Text

#### Instances

Instances details

Eq Src Source # |
Instance details Defined in Dhall.Src Methods (==) :: Src -> Src -> Bool Source # (/=) :: Src -> Src -> Bool Source #
Data Src Source # |

Instance details

Defined in Dhall.Src

Methods

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

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

toConstr :: Src -> Constr Source #

dataTypeOf :: Src -> DataType Source #

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

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

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

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

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

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

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

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

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

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

Ord Src Source # |
Instance details Defined in Dhall.Src Methods compare :: Src -> Src -> Ordering Source # (<) :: Src -> Src -> Bool Source # (<=) :: Src -> Src -> Bool Source # (>) :: Src -> Src -> Bool Source # (>=) :: Src -> Src -> Bool Source # max :: Src -> Src -> Src Source # min :: Src -> Src -> Src Source #
Show Src Source # |
Instance details Defined in Dhall.Src Methods showsPrec :: Int -> Src -> ShowS Source # show :: Src -> String Source # showList :: [Src] -> ShowS Source #
Generic Src Source # |
Instance details Defined in Dhall.Src Associated Types type Rep Src :: Type -> Type Source # Methods from :: Src -> Rep Src x Source # to :: Rep Src x -> Src Source #
Lift Src Source # |
Instance details Defined in Dhall.Src Methods lift :: Src -> Q Exp Source #
NFData Src Source # |
Instance details Defined in Dhall.Src Methods rnf :: Src -> () Source #
Pretty Src Source # |
Instance details Defined in Dhall.Src Methods pretty :: Src -> Doc ann Source # prettyList :: [Src] -> Doc ann Source #
type Rep Src Source # |

Instance details

Defined in Dhall.Src

type Rep Src = D1 ('MetaData "Src" "Dhall.Src" "dhall-1.32.0-8h62pP4EsmJ9qkPjREfsUQ" 'False) (C1 ('MetaCons "Src" 'PrefixI 'True) (S1 ('MetaSel ('Just "srcStart") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SourcePos) :*: (S1 ('MetaSel ('Just "srcEnd") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SourcePos) :*: S1 ('MetaSel ('Just "srcText") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))))

data SourcedException e Source #

An exception annotated with a `Src` span

Constructors

SourcedException Src e |

#### Instances

Instances details

Show e => Show (SourcedException e) Source # |
Instance details Defined in Dhall.Parser.Combinators Methods showsPrec :: Int -> SourcedException e -> ShowS Source # show :: SourcedException e -> String Source # showList :: [SourcedException e] -> ShowS Source #
Exception e => Exception (SourcedException e) Source # |
Instance details Defined in Dhall.Parser.Combinators Methods toException :: SourcedException e -> SomeException Source # fromException :: SomeException -> Maybe (SourcedException e) Source # displayException :: SourcedException e -> String Source #

data ParseError Source #

A parsing error

Constructors

ParseError |

Fields

- unwrap :: ParseErrorBundle Text Void
- input :: Text

#### Instances

Instances details

Show ParseError Source # |
Instance details Defined in Dhall.Parser Methods showsPrec :: Int -> ParseError -> ShowS Source # show :: ParseError -> String Source # showList :: [ParseError] -> ShowS Source #
Exception ParseError Source # |
Instance details Defined in Dhall.Parser Methods toException :: ParseError -> SomeException Source # fromException :: SomeException -> Maybe ParseError Source # displayException :: ParseError -> String Source #

newtype Parser a Source #

A `Parser` that is almost identical to `Text.Megaparsec.`Parsec`` except treating Haskell-style comments as whitespace

Constructors

Parser |

Fields

- unParser :: Parsec Void Text a

#### Instances

Instances details

Monad Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods (>>=) :: Parser a -> (a -> Parser b) -> Parser b Source # (>>) :: Parser a -> Parser b -> Parser b Source # return :: a -> Parser a Source #
Functor Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods fmap :: (a -> b) -> Parser a -> Parser b Source # (<$) :: a -> Parser b -> Parser a Source #
MonadFail Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods fail :: String -> Parser a Source #
Applicative Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods pure :: a -> Parser a Source # (<*>) :: Parser (a -> b) -> Parser a -> Parser b Source # liftA2 :: (a -> b -> c) -> Parser a -> Parser b -> Parser c Source # (*>) :: Parser a -> Parser b -> Parser b Source # (<*) :: Parser a -> Parser b -> Parser a Source #
Alternative Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods empty :: Parser a Source # (<|>) :: Parser a -> Parser a -> Parser a Source # some :: Parser a -> Parser [a] Source # many :: Parser a -> Parser [a] Source #
MonadPlus Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods mzero :: Parser a Source # mplus :: Parser a -> Parser a -> Parser a Source #
TokenParsing Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods someSpace :: Parser () Source # nesting :: Parser a -> Parser a Source # semi :: Parser Char Source # highlight :: Highlight -> Parser a -> Parser a Source # token :: Parser a -> Parser a Source #
CharParsing Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods satisfy :: (Char -> Bool) -> Parser Char Source # char :: Char -> Parser Char Source # notChar :: Char -> Parser Char Source # anyChar :: Parser Char Source # string :: String -> Parser String Source # text :: Text -> Parser Text Source #
Parsing Parser Source # |
Instance details Defined in Dhall.Parser.Combinators Methods try :: Parser a -> Parser a Source # (<?>) :: Parser a -> String -> Parser a Source # skipMany :: Parser a -> Parser () Source # skipSome :: Parser a -> Parser () Source # unexpected :: String -> Parser a Source # eof :: Parser () Source # notFollowedBy :: Show a => Parser a -> Parser () Source #
MonadParsec Void Text Parser Source # |

Instance details

Defined in Dhall.Parser.Combinators

Methods

parseError :: ParseError Text Void -> Parser a Source #

label :: String -> Parser a -> Parser a Source #

hidden :: Parser a -> Parser a Source #

try :: Parser a -> Parser a Source #

lookAhead :: Parser a -> Parser a Source #

notFollowedBy :: Parser a -> Parser () Source #

withRecovery :: (ParseError Text Void -> Parser a) -> Parser a -> Parser a Source #

observing :: Parser a -> Parser (Either (ParseError Text Void) a) Source #

eof :: Parser () Source #

token :: (Token Text -> Maybe a) -> Set (ErrorItem (Token Text)) -> Parser a Source #

tokens :: (Tokens Text -> Tokens Text -> Bool) -> Tokens Text -> Parser (Tokens Text) Source #

takeWhileP :: Maybe String -> (Token Text -> Bool) -> Parser (Tokens Text) Source #

takeWhile1P :: Maybe String -> (Token Text -> Bool) -> Parser (Tokens Text) Source #

takeP :: Maybe String -> Int -> Parser (Tokens Text) Source #

getParserState :: Parser (State Text Void) Source #

updateParserState :: (State Text Void -> State Text Void) -> Parser () Source #

IsString a => IsString (Parser a) Source # |
Instance details Defined in Dhall.Parser.Combinators Methods fromString :: String -> Parser a Source #
Semigroup a => Semigroup (Parser a) Source # |
Instance details Defined in Dhall.Parser.Combinators Methods (<>) :: Parser a -> Parser a -> Parser a Source # sconcat :: NonEmpty (Parser a) -> Parser a Source # stimes :: Integral b => b -> Parser a -> Parser a Source #
(Semigroup a, Monoid a) => Monoid (Parser a) Source # |
Instance details Defined in Dhall.Parser.Combinators Methods mempty :: Parser a Source # mappend :: Parser a -> Parser a -> Parser a Source # mconcat :: [Parser a] -> Parser a Source #