{-# LANGUAGE FlexibleContexts #-}
{-| Parsing Giml

Here's an example Giml program that we are going to parse:

@
type List a =
    | Nil {}
    | Cons { head : a, tail : List a }
end

def length(xs) := do
    case xs of
        | Nil {} -> 0
        | Cons { head = _, tail = rest } -> do
            def res := add(1, length(rest))
            res
        end
    end
end

def main() := do
    ffi("console.log", length(Cons { head = 1, tail = Cons { head = 2, tail = Nil {} } }))
end
@

-}

{-# LANGUAGE ScopedTypeVariables #-}
{-# language OverloadedStrings #-}

module Language.Giml.Syntax.Parser
  ( module Language.Giml.Syntax.Parser
  , P.SourcePos(..), P.unPos
  )
  where

import Utils
import Data.Void (Void)
import Control.Monad.Except
import qualified Data.Text as T
import qualified Data.Map as M
import Text.Megaparsec ((<?>))
import qualified Text.Megaparsec as P
import qualified Text.Megaparsec.Char as P
import qualified Text.Megaparsec.Char.Lexer as L

import Language.Giml.Syntax.Ast
import Language.Giml.Logging

-- * Types

type Parser = P.Parsec Void Text

type ParseErr = P.ParseErrorBundle Text Void

type Ann = P.SourcePos

-- * Utils

getAnn :: Parser Ann
getAnn :: Parser Ann
getAnn = Parser Ann
forall s e (m :: * -> *).
(TraversableStream s, MonadParsec e s m) =>
m Ann
P.getSourcePos

-- * Run

-- | Run a parse and prettyprint errors
runParser :: CompilePhase Text env b m => Parser a -> FilePath -> Text -> m a
runParser :: Parser a -> FilePath -> Text -> m a
runParser Parser a
p FilePath
file Text
src =
  case (ParseErrorBundle Text Void -> Text)
-> Either (ParseErrorBundle Text Void) a -> Either Text a
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ParseErrorBundle Text Void -> Text
ppErrors (Either (ParseErrorBundle Text Void) a -> Either Text a)
-> Either (ParseErrorBundle Text Void) a -> Either Text a
forall a b. (a -> b) -> a -> b
$ Parser a
-> FilePath -> Text -> Either (ParseErrorBundle Text Void) a
forall a.
Parser a
-> FilePath -> Text -> Either (ParseErrorBundle Text Void) a
runParser' Parser a
p FilePath
file Text
src of
    Left Text
err -> Text -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError Text
err
    Right a
res -> a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
res

-- | Run a parse and preserve errors structure
runParser' :: Parser a -> FilePath -> Text -> Either ParseErr a
runParser' :: Parser a
-> FilePath -> Text -> Either (ParseErrorBundle Text Void) a
runParser' Parser a
p FilePath
file Text
src =
  Parser a
-> FilePath -> Text -> Either (ParseErrorBundle Text Void) a
forall e s a.
Parsec e s a -> FilePath -> s -> Either (ParseErrorBundle s e) a
P.runParser
    (Parser () -> Parser ()
forall a. Parser a -> Parser a
lexeme (() -> Parser ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines Parser () -> Parser a -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser a -> Parser a
forall a. Parser a -> Parser a
lexeme Parser a
p Parser a -> Parser () -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines Parser a -> Parser () -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
P.eof)
    FilePath
file
    Text
src

runReplParser :: FilePath -> Text -> Either ParseErr (ReplResult Text)
runReplParser :: FilePath
-> Text -> Either (ParseErrorBundle Text Void) (ReplResult Text)
runReplParser FilePath
file Text
src = do
  ReplResult ()
result <- Parser (ReplResult ())
-> FilePath
-> Text
-> Either (ParseErrorBundle Text Void) (ReplResult ())
forall a.
Parser a
-> FilePath -> Text -> Either (ParseErrorBundle Text Void) a
runParser' Parser (ReplResult ())
parseREPL FilePath
file Text
src
  ReplResult Text
-> Either (ParseErrorBundle Text Void) (ReplResult Text)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplResult Text
 -> Either (ParseErrorBundle Text Void) (ReplResult Text))
-> ReplResult Text
-> Either (ParseErrorBundle Text Void) (ReplResult Text)
forall a b. (a -> b) -> a -> b
$ case ReplResult ()
result of
    ReplExpr Expr Ann
e -> Expr Ann -> ReplResult Text
forall a. Expr Ann -> ReplResult a
ReplExpr Expr Ann
e
    ReplDefinition Definition Ann
def -> Definition Ann -> ReplResult Text
forall a. Definition Ann -> ReplResult a
ReplDefinition Definition Ann
def
    EarlyEOF{} -> Text -> ReplResult Text
forall a. a -> ReplResult a
EarlyEOF Text
src

-- * REPL parser

data ReplResult a
  = ReplExpr (Expr Ann)
  | ReplDefinition (Definition Ann)
  | EarlyEOF a
  deriving Int -> ReplResult a -> ShowS
[ReplResult a] -> ShowS
ReplResult a -> FilePath
(Int -> ReplResult a -> ShowS)
-> (ReplResult a -> FilePath)
-> ([ReplResult a] -> ShowS)
-> Show (ReplResult a)
forall a. Show a => Int -> ReplResult a -> ShowS
forall a. Show a => [ReplResult a] -> ShowS
forall a. Show a => ReplResult a -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ReplResult a] -> ShowS
$cshowList :: forall a. Show a => [ReplResult a] -> ShowS
show :: ReplResult a -> FilePath
$cshow :: forall a. Show a => ReplResult a -> FilePath
showsPrec :: Int -> ReplResult a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> ReplResult a -> ShowS
Show

parseREPL :: Parser (ReplResult ())
parseREPL :: Parser (ReplResult ())
parseREPL = do
  let
    replinput :: ParsecT Void Text Identity (ReplResult a)
replinput =
      [ParsecT Void Text Identity (ReplResult a)]
-> ParsecT Void Text Identity (ReplResult a)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
        [ Definition Ann -> ReplResult a
forall a. Definition Ann -> ReplResult a
ReplDefinition (Definition Ann -> ReplResult a)
-> (Datatype Ann -> Definition Ann) -> Datatype Ann -> ReplResult a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Datatype Ann -> Definition Ann
forall a. Datatype a -> Definition a
TypeDef (Datatype Ann -> ReplResult a)
-> ParsecT Void Text Identity (Datatype Ann)
-> ParsecT Void Text Identity (ReplResult a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Datatype Ann)
parseTypeDef
        , Definition Ann -> ReplResult a
forall a. Definition Ann -> ReplResult a
ReplDefinition (Definition Ann -> ReplResult a)
-> (TermDef Ann -> Definition Ann) -> TermDef Ann -> ReplResult a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TermDef Ann -> Definition Ann
forall a. TermDef a -> Definition a
TermDef (TermDef Ann -> ReplResult a)
-> ParsecT Void Text Identity (TermDef Ann)
-> ParsecT Void Text Identity (ReplResult a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (TermDef Ann)
replParseTermDef
        , Expr Ann -> ReplResult a
forall a. Expr Ann -> ReplResult a
ReplExpr (Expr Ann -> ReplResult a)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (ReplResult a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Expr Ann)
parseExpr
        ]
  ((ParseError Text Void -> Parser (ReplResult ()))
 -> Parser (ReplResult ()) -> Parser (ReplResult ()))
-> Parser (ReplResult ())
-> (ParseError Text Void -> Parser (ReplResult ()))
-> Parser (ReplResult ())
forall a b c. (a -> b -> c) -> b -> a -> c
flip (ParseError Text Void -> Parser (ReplResult ()))
-> Parser (ReplResult ()) -> Parser (ReplResult ())
forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
P.withRecovery Parser (ReplResult ())
forall a. ParsecT Void Text Identity (ReplResult a)
replinput ((ParseError Text Void -> Parser (ReplResult ()))
 -> Parser (ReplResult ()))
-> (ParseError Text Void -> Parser (ReplResult ()))
-> Parser (ReplResult ())
forall a b. (a -> b) -> a -> b
$ \case
    P.TrivialError Int
_ (Just ErrorItem (Token Text)
P.EndOfInput) Set (ErrorItem (Token Text))
_ ->
      ReplResult () -> Parser (ReplResult ())
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplResult () -> Parser (ReplResult ()))
-> ReplResult () -> Parser (ReplResult ())
forall a b. (a -> b) -> a -> b
$ () -> ReplResult ()
forall a. a -> ReplResult a
EarlyEOF ()
    P.TrivialError Int
_ Maybe (ErrorItem (Token Text))
tok1 Set (ErrorItem (Token Text))
toks ->
      Maybe (ErrorItem (Token Text))
-> Set (ErrorItem (Token Text)) -> Parser (ReplResult ())
forall e s (m :: * -> *) a.
MonadParsec e s m =>
Maybe (ErrorItem (Token s)) -> Set (ErrorItem (Token s)) -> m a
P.failure Maybe (ErrorItem (Token Text))
tok1 Set (ErrorItem (Token Text))
toks
    P.FancyError Int
_ Set (ErrorFancy Void)
ex -> Set (ErrorFancy Void) -> Parser (ReplResult ())
forall e s (m :: * -> *) a.
MonadParsec e s m =>
Set (ErrorFancy e) -> m a
P.fancyFailure Set (ErrorFancy Void)
ex

replParseTermDef :: Parser (TermDef Ann)
replParseTermDef :: ParsecT Void Text Identity (TermDef Ann)
replParseTermDef = do
  (Ann
ann, Text
name, [Maybe Text]
args) <- ParsecT Void Text Identity (Ann, Text, [Maybe Text])
-> ParsecT Void Text Identity (Ann, Text, [Maybe Text])
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
P.try (ParsecT Void Text Identity (Ann, Text, [Maybe Text])
 -> ParsecT Void Text Identity (Ann, Text, [Maybe Text]))
-> ParsecT Void Text Identity (Ann, Text, [Maybe Text])
-> ParsecT Void Text Identity (Ann, Text, [Maybe Text])
forall a b. (a -> b) -> a -> b
$ do
    Ann
ann <- Parser Ann
getAnn
    Text
name <- Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Parser Text -> Parser Text
forall a. Parser a -> Parser a
withKeywordFail Parser Text
var)
    [Maybe Text]
args <- ParsecT Void Text Identity (Maybe Text)
-> ParsecT Void Text Identity [Maybe Text]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many ParsecT Void Text Identity (Maybe Text)
funArg
    Parser ()
equals
    (Ann, Text, [Maybe Text])
-> ParsecT Void Text Identity (Ann, Text, [Maybe Text])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ann
ann, Text
name, [Maybe Text]
args)
  case [Maybe Text]
args of
    [] -> Ann -> Text -> Expr Ann -> TermDef Ann
forall a. a -> Text -> Expr a -> TermDef a
Variable Ann
ann Text
name (Expr Ann -> TermDef Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (TermDef Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Expr Ann)
parseExpr
    [Maybe Text]
_ -> Ann -> Text -> [Maybe Text] -> Expr Ann -> TermDef Ann
forall a. a -> Text -> [Maybe Text] -> Expr a -> TermDef a
Function Ann
ann Text
name [Maybe Text]
args (Expr Ann -> TermDef Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (TermDef Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Expr Ann)
parseExpr



-- * Lexing

-- | How to read whitespace after reading a node
sc :: Parser ()
sc :: Parser ()
sc = Parser () -> Parser () -> Parser () -> Parser ()
forall e s (m :: * -> *).
MonadParsec e s m =>
m () -> m () -> m () -> m ()
L.space
  Parser ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
P.hspace1 -- We don't want to read newlines because they matter semantically
  (Tokens Text -> Parser ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Tokens s -> m ()
L.skipLineComment Tokens Text
"--")
  (Tokens Text -> Tokens Text -> Parser ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Tokens s -> Tokens s -> m ()
L.skipBlockCommentNested Tokens Text
"{-" Tokens Text
"-}")

lexeme :: Parser a -> Parser a
lexeme :: Parser a -> Parser a
lexeme = Parser () -> Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m () -> m a -> m a
L.lexeme Parser ()
sc

-- * newlines

newline :: Parser ()
newline :: Parser ()
newline =
  Parser () -> Parser ()
forall a. Parser a -> Parser a
lexeme (ParsecT Void Text Identity Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT Void Text Identity Char
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
P.newline Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
P.<|> Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Parser Text
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Tokens s)
P.crlf) Parser () -> FilePath -> Parser ()
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a newline"

newlines :: Parser ()
newlines :: Parser ()
newlines =
  ParsecT Void Text Identity [()] -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Void Text Identity [()] -> Parser ())
-> ParsecT Void Text Identity [()] -> Parser ()
forall a b. (a -> b) -> a -> b
$ Parser () -> ParsecT Void Text Identity [()]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many Parser ()
newline

newlines1 :: Parser ()
newlines1 :: Parser ()
newlines1 =
  ParsecT Void Text Identity [()] -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Void Text Identity [()] -> Parser ())
-> ParsecT Void Text Identity [()] -> Parser ()
forall a b. (a -> b) -> a -> b
$ Parser () -> ParsecT Void Text Identity [()]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.some Parser ()
newline

-- * symbols

symbol :: Text -> Parser ()
symbol :: Text -> Parser ()
symbol = Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Text -> Parser ())
-> (Text -> Parser Text) -> Text -> Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser ()
-> Tokens Text -> ParsecT Void Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
m () -> Tokens s -> m (Tokens s)
L.symbol Parser ()
sc

equals :: Parser ()
equals :: Parser ()
equals = Text -> Parser ()
symbol Text
"=" Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines

arrow :: Parser ()
arrow :: Parser ()
arrow = Text -> Parser ()
symbol Text
"->" Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines

backarrow :: Parser ()
backarrow :: Parser ()
backarrow = Text -> Parser ()
symbol Text
"<-" Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines

lambda :: Parser ()
lambda :: Parser ()
lambda = Text -> Parser ()
symbol Text
"\\"

underscore :: Parser ()
underscore :: Parser ()
underscore = Text -> Parser ()
symbol Text
"_"

comma :: Parser ()
comma :: Parser ()
comma = Text -> Parser ()
symbol Text
","

bar :: Parser ()
bar :: Parser ()
bar = Text -> Parser ()
symbol Text
"|"

harddot :: Parser ()
harddot :: Parser ()
harddot = ParsecT Void Text Identity Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Void Text Identity Char -> Parser ())
-> ParsecT Void Text Identity Char -> Parser ()
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'.'

colon :: Parser ()
colon :: Parser ()
colon = Text -> Parser ()
symbol Text
":"

between :: Char -> Char -> Parser a -> Parser a
between :: Char -> Char -> Parser a -> Parser a
between Char
open Char
close Parser a
p = do
  Parser () -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ ParsecT Void Text Identity Char -> ParsecT Void Text Identity Char
forall a. Parser a -> Parser a
lexeme (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
open) ParsecT Void Text Identity Char -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines
  a
result <- Parser a
p
  ParsecT Void Text Identity Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
close)
  a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
result

parens :: Parser a -> Parser a
parens :: Parser a -> Parser a
parens = Char -> Char -> Parser a -> Parser a
forall a. Char -> Char -> Parser a -> Parser a
between Char
'(' Char
')' (Parser a -> Parser a)
-> (Parser a -> Parser a) -> Parser a -> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser a -> Parser a
forall a. Parser a -> Parser a
lexeme

brackets :: Parser a -> Parser a
brackets :: Parser a -> Parser a
brackets = Char -> Char -> Parser a -> Parser a
forall a. Char -> Char -> Parser a -> Parser a
between Char
'[' Char
']' (Parser a -> Parser a)
-> (Parser a -> Parser a) -> Parser a -> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser a -> Parser a
forall a. Parser a -> Parser a
lexeme

braces :: Parser a -> Parser a
braces :: Parser a -> Parser a
braces = Char -> Char -> Parser a -> Parser a
forall a. Char -> Char -> Parser a -> Parser a
between Char
'{' Char
'}' (Parser a -> Parser a)
-> (Parser a -> Parser a) -> Parser a -> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser a -> Parser a
forall a. Parser a -> Parser a
lexeme

-- * atoms

stringLiteral :: Parser Text
stringLiteral :: Parser Text
stringLiteral =
  (FilePath -> Text)
-> ParsecT Void Text Identity FilePath -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FilePath -> Text
T.pack (ParsecT Void Text Identity FilePath -> Parser Text)
-> ParsecT Void Text Identity FilePath -> Parser Text
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'\"' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity FilePath
-> ParsecT Void Text Identity FilePath
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity FilePath
forall (m :: * -> *) a end. MonadPlus m => m a -> m end -> m [a]
P.manyTill ParsecT Void Text Identity Char
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m Char
L.charLiteral (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'\"')

number :: Parser Lit
number :: Parser Lit
number = Parser Lit -> Parser Lit
forall a. Parser a -> Parser a
lexeme (Parser Lit -> Parser Lit) -> Parser Lit -> Parser Lit
forall a b. (a -> b) -> a -> b
$ do
  Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
P.notFollowedBy Parser ()
arrow
  Maybe Char
sign <- ParsecT Void Text Identity Char
-> ParsecT Void Text Identity (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (ParsecT Void Text Identity Char
 -> ParsecT Void Text Identity (Maybe Char))
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity (Maybe Char)
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'-'
  (Int
num1 :: Int) <- [ParsecT Void Text Identity Int] -> ParsecT Void Text Identity Int
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'0' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Int -> ParsecT Void Text Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
      [ParsecT Void Text Identity Int] -> ParsecT Void Text Identity Int
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
        [ Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'x' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Int -> ParsecT Void Text Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity Int
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.hexadecimal
        , Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'b' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Int -> ParsecT Void Text Identity Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity Int
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.binary
        , Int -> ParsecT Void Text Identity Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
0
        ]
    , ParsecT Void Text Identity Int
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal
    ]
  Maybe FilePath
num2 <- ParsecT Void Text Identity FilePath
-> ParsecT Void Text Identity (Maybe FilePath)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (ParsecT Void Text Identity FilePath
 -> ParsecT Void Text Identity (Maybe FilePath))
-> ParsecT Void Text Identity FilePath
-> ParsecT Void Text Identity (Maybe FilePath)
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'.' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity FilePath
-> ParsecT Void Text Identity FilePath
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity FilePath
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.some ParsecT Void Text Identity Char
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
P.digitChar
  case Maybe FilePath
num2 of
    Maybe FilePath
Nothing ->
      Lit -> Parser Lit
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Lit -> Parser Lit) -> Lit -> Parser Lit
forall a b. (a -> b) -> a -> b
$ Int -> Lit
LInt (FilePath -> Int
forall a. Read a => FilePath -> a
read (FilePath -> Int) -> FilePath -> Int
forall a b. (a -> b) -> a -> b
$ FilePath -> (Char -> FilePath) -> Maybe Char -> FilePath
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Char -> FilePath
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Char
sign FilePath -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> FilePath
forall a. Show a => a -> FilePath
show Int
num1)
    Just FilePath
n ->
      Lit -> Parser Lit
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Lit -> Parser Lit) -> Lit -> Parser Lit
forall a b. (a -> b) -> a -> b
$ Float -> Lit
LFloat (FilePath -> Float
forall a. Read a => FilePath -> a
read (FilePath -> Float) -> FilePath -> Float
forall a b. (a -> b) -> a -> b
$ FilePath -> (Char -> FilePath) -> Maybe Char -> FilePath
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Char -> FilePath
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Char
sign FilePath -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> FilePath
forall a. Show a => a -> FilePath
show Int
num1 FilePath -> ShowS
forall a. Semigroup a => a -> a -> a
<> FilePath
"." FilePath -> ShowS
forall a. Semigroup a => a -> a -> a
<> FilePath
n)

reservedWords :: [Text]
reservedWords :: [Text]
reservedWords =
  [ Text
"do"
  , Text
"end"
  , Text
"let"
  , Text
"in"
  , Text
"case"
  , Text
"of"
  , Text
"ffi"
  , Text
"if"
  , Text
"then"
  , Text
"else"
  ]


rword :: Text -> Parser Text
rword :: Text -> Parser Text
rword Text
rw =
  (Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Parser Text -> Parser Text)
-> (Parser Text -> Parser Text) -> Parser Text -> Parser Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser Text -> Parser Text
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
P.try) (Tokens Text -> ParsecT Void Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
P.string Text
Tokens Text
rw Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Void Text Identity Char -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
P.notFollowedBy ParsecT Void Text Identity Char
nameRest) Parser Text -> FilePath -> Parser Text
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> Text -> FilePath
T.unpack Text
rw

reservedWord :: Parser (Int, Text)
reservedWord :: Parser (Int, Text)
reservedWord =
  (,)
    (Int -> Text -> (Int, Text))
-> ParsecT Void Text Identity Int
-> ParsecT Void Text Identity (Text -> (Int, Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity Int
forall e s (m :: * -> *). MonadParsec e s m => m Int
P.getOffset
    ParsecT Void Text Identity (Text -> (Int, Text))
-> Parser Text -> Parser (Int, Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Parser Text] -> Parser Text
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice ((Text -> Parser Text) -> [Text] -> [Parser Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Parser Text
rword [Text]
reservedWords)

var :: Parser Text
var :: Parser Text
var = Parser Text
lowername Parser Text -> FilePath -> Parser Text
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a variable"

label :: Parser Text
label :: Parser Text
label = (Parser Text -> Parser Text
forall a. Parser a -> Parser a
withKeywordFail Parser Text
lowername) Parser Text -> FilePath -> Parser Text
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a label"

typevar :: Parser Text
typevar :: Parser Text
typevar = Parser Text
lowername Parser Text -> FilePath -> Parser Text
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a type variable"

typename :: Parser Text
typename :: Parser Text
typename = Parser Text
uppername Parser Text -> FilePath -> Parser Text
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a type name"

lowername :: Parser Text
lowername :: Parser Text
lowername = ParsecT Void Text Identity Char -> Parser Text
name' ParsecT Void Text Identity Char
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
P.lowerChar

uppername :: Parser Text
uppername :: Parser Text
uppername = ParsecT Void Text Identity Char -> Parser Text
name' ParsecT Void Text Identity Char
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
P.upperChar

name' :: Parser Char -> Parser Text
name' :: ParsecT Void Text Identity Char -> Parser Text
name' ParsecT Void Text Identity Char
begin = do
  Parser (Int, Text) -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
P.notFollowedBy Parser (Int, Text)
reservedWord
  Char
c <- ParsecT Void Text Identity Char
begin
  FilePath
rest <- ParsecT Void Text Identity Char
-> ParsecT Void Text Identity FilePath
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many ParsecT Void Text Identity Char
nameRest
  Text -> Parser Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Parser Text) -> Text -> Parser Text
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
T.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ Char
c Char -> ShowS
forall a. a -> [a] -> [a]
: FilePath
rest

withKeywordFail :: Parser a -> Parser a
withKeywordFail :: Parser a -> Parser a
withKeywordFail Parser a
p = Parser ()
keywordFail Parser () -> Parser a -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser a
p Parser a -> FilePath -> Parser a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a variable"

keywordFail :: Parser ()
keywordFail :: Parser ()
keywordFail = 
  Parser (Int, Text)
-> ParsecT Void Text Identity (Maybe (Int, Text))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional Parser (Int, Text)
reservedWord ParsecT Void Text Identity (Maybe (Int, Text))
-> (Maybe (Int, Text) -> Parser ()) -> Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    Maybe (Int, Text)
Nothing -> () -> Parser ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
    Just (Int
offset, Text
keyword) -> do
      Int -> Parser ()
forall e s (m :: * -> *). MonadParsec e s m => Int -> m ()
P.setOffset Int
offset
      FilePath -> Parser ()
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser ()) -> FilePath -> Parser ()
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
toString Text
keyword FilePath -> ShowS
forall a. Semigroup a => a -> a -> a
<> FilePath
" is a reserved keyword and cannot be used as an identifier name."

nameRest :: Parser Char
nameRest :: ParsecT Void Text Identity Char
nameRest =
  [ParsecT Void Text Identity Char]
-> ParsecT Void Text Identity Char
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ ParsecT Void Text Identity Char
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
P.alphaNumChar
    , Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'_'
    ]


-- * Parser

parseFile :: Parser (ParsedFile Ann)
parseFile :: Parser (ParsedFile Ann)
parseFile = do
  -- File . fmap pure <$> P.many (lexeme parseDef <* (newlines1 P.<|> P.eof))
  [Definition Ann] -> ParsedFile Ann
forall a. [Definition a] -> ParsedFile a
ParsedFile ([Definition Ann] -> ParsedFile Ann)
-> ParsecT Void Text Identity [Definition Ann]
-> Parser (ParsedFile Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Definition Ann)
-> ParsecT Void Text Identity [Definition Ann]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many (ParsecT Void Text Identity (Definition Ann)
-> ParsecT Void Text Identity (Definition Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Definition Ann)
parseDef ParsecT Void Text Identity (Definition Ann)
-> Parser () -> ParsecT Void Text Identity (Definition Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (Parser ()
newlines1 Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
P.<|> Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
P.eof))

parseDef :: Parser (Definition Ann)
parseDef :: ParsecT Void Text Identity (Definition Ann)
parseDef = do
  [ParsecT Void Text Identity (Definition Ann)]
-> ParsecT Void Text Identity (Definition Ann)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ Datatype Ann -> Definition Ann
forall a. Datatype a -> Definition a
TypeDef (Datatype Ann -> Definition Ann)
-> ParsecT Void Text Identity (Datatype Ann)
-> ParsecT Void Text Identity (Definition Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Datatype Ann)
parseTypeDef
    , TermDef Ann -> Definition Ann
forall a. TermDef a -> Definition a
TermDef (TermDef Ann -> Definition Ann)
-> ParsecT Void Text Identity (TermDef Ann)
-> ParsecT Void Text Identity (Definition Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (TermDef Ann)
parseTermDef
    ]

-- * Types


parseTypeDef :: Parser (Datatype Ann)
parseTypeDef :: ParsecT Void Text Identity (Datatype Ann)
parseTypeDef = do
  Ann
ann <- Parser Ann
getAnn
  Text
name <- Parser Text -> Parser Text
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
P.try (Parser Text -> Parser Text) -> Parser Text -> Parser Text
forall a b. (a -> b) -> a -> b
$ do
    Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Text -> Parser ()) -> Parser Text -> Parser ()
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
rword Text
"type"
    Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme Parser Text
typename Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines
  [Text]
args <- Parser Text -> ParsecT Void Text Identity [Text]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many
    (Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Parser Text -> Parser Text
forall a. Parser a -> Parser a
withKeywordFail Parser Text
typevar) Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
  Parser ()
equals Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines
  [Variant (Maybe Type)]
typ <- ParsecT Void Text Identity (Variant (Maybe Type))
-> ParsecT Void Text Identity [Variant (Maybe Type)]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many
    (Parser ()
bar Parser ()
-> ParsecT Void Text Identity (Variant (Maybe Type))
-> ParsecT Void Text Identity (Variant (Maybe Type))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity (Variant (Maybe Type))
-> ParsecT Void Text Identity (Variant (Maybe Type))
forall a. Parser a -> Parser a
lexeme (Parser (Maybe Type)
-> ParsecT Void Text Identity (Variant (Maybe Type))
forall a. Parser a -> Parser (Variant a)
parseVariant (Parser (Maybe Type)
 -> ParsecT Void Text Identity (Variant (Maybe Type)))
-> Parser (Maybe Type)
-> ParsecT Void Text Identity (Variant (Maybe Type))
forall a b. (a -> b) -> a -> b
$ ParsecT Void Text Identity Type -> Parser (Maybe Type)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional ParsecT Void Text Identity Type
parseType) ParsecT Void Text Identity (Variant (Maybe Type))
-> Parser () -> ParsecT Void Text Identity (Variant (Maybe Type))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
  Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Text -> Parser ()) -> Parser Text -> Parser ()
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
rword Text
"end"
  Datatype Ann -> ParsecT Void Text Identity (Datatype Ann)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Datatype Ann -> ParsecT Void Text Identity (Datatype Ann))
-> Datatype Ann -> ParsecT Void Text Identity (Datatype Ann)
forall a b. (a -> b) -> a -> b
$ Ann -> Text -> [Text] -> [Variant (Maybe Type)] -> Datatype Ann
forall a.
a -> Text -> [Text] -> [Variant (Maybe Type)] -> Datatype a
Datatype Ann
ann Text
name [Text]
args [Variant (Maybe Type)]
typ

parseType :: Parser Type
parseType :: ParsecT Void Text Identity Type
parseType = do
  [Type]
t <- ParsecT Void Text Identity Type
-> Parser () -> ParsecT Void Text Identity [Type]
forall (m :: * -> *) a end. MonadPlus m => m a -> m end -> m [a]
P.sepBy1 (ParsecT Void Text Identity Type -> ParsecT Void Text Identity Type
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity Type
parseType' ParsecT Void Text Identity Type
-> Parser () -> ParsecT Void Text Identity Type
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines) Parser ()
arrow
  let ([Type]
targs, Type
tret) = ([Type] -> [Type]
forall a. [a] -> [a]
init [Type]
t, [Type] -> Type
forall a. [a] -> a
last [Type]
t)
  Type -> ParsecT Void Text Identity Type
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Type -> ParsecT Void Text Identity Type)
-> Type -> ParsecT Void Text Identity Type
forall a b. (a -> b) -> a -> b
$ [Type] -> Type -> Type
typeFun [Type]
targs Type
tret

parseType' :: Parser Type
parseType' :: ParsecT Void Text Identity Type
parseType' = do
  Type
t <- (ParsecT Void Text Identity Type -> ParsecT Void Text Identity Type
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity Type
parseType'' ParsecT Void Text Identity Type
-> Parser () -> ParsecT Void Text Identity Type
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
  [Type]
args <- ParsecT Void Text Identity Type
-> ParsecT Void Text Identity [Type]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many (ParsecT Void Text Identity Type -> ParsecT Void Text Identity Type
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity Type
parseType'' ParsecT Void Text Identity Type
-> Parser () -> ParsecT Void Text Identity Type
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
  Type -> ParsecT Void Text Identity Type
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Type -> ParsecT Void Text Identity Type)
-> Type -> ParsecT Void Text Identity Type
forall a b. (a -> b) -> a -> b
$ (Type -> Type -> Type) -> Type -> [Type] -> Type
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Type -> Type -> Type
TypeApp Type
t [Type]
args

parseType'' :: Parser Type
parseType'' :: ParsecT Void Text Identity Type
parseType'' =
  [ParsecT Void Text Identity Type]
-> ParsecT Void Text Identity Type
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ ParsecT Void Text Identity Type -> ParsecT Void Text Identity Type
forall a. Parser a -> Parser a
parens ParsecT Void Text Identity Type
parseType
    , Text -> Type
TypeVar (Text -> Type) -> Parser Text -> ParsecT Void Text Identity Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
typevar
    , Text -> Type
TypeCon (Text -> Type) -> Parser Text -> ParsecT Void Text Identity Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
typename
    , [(Text, Type)] -> Type
TypeRec ([(Text, Type)] -> Type)
-> ((Map Text Type, Maybe Any) -> [(Text, Type)])
-> (Map Text Type, Maybe Any)
-> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Text Type -> [(Text, Type)]
forall k a. Map k a -> [(k, a)]
M.toList (Map Text Type -> [(Text, Type)])
-> ((Map Text Type, Maybe Any) -> Map Text Type)
-> (Map Text Type, Maybe Any)
-> [(Text, Type)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map Text Type, Maybe Any) -> Map Text Type
forall a b. (a, b) -> a
fst
      ((Map Text Type, Maybe Any) -> Type)
-> ParsecT Void Text Identity (Map Text Type, Maybe Any)
-> ParsecT Void Text Identity Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ()
-> ParsecT Void Text Identity Type
-> Maybe (Parser Any)
-> ParsecT Void Text Identity (Map Text Type, Maybe Any)
forall a b.
Parser ()
-> Parser a -> Maybe (Parser b) -> Parser (Record a, Maybe b)
parseRecord Parser ()
colon ParsecT Void Text Identity Type
parseType Maybe (Parser Any)
forall a. Maybe a
Nothing
      ParsecT Void Text Identity Type
-> FilePath -> ParsecT Void Text Identity Type
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"type record"
    ] -- @TODO: Add polymorphic variants

-- * Terms

parseTermDef :: Parser (TermDef Ann)
parseTermDef :: ParsecT Void Text Identity (TermDef Ann)
parseTermDef = do
  Ann
ann <- Parser Ann
getAnn
  Text
name <- Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Parser Text -> Parser Text
forall a. Parser a -> Parser a
withKeywordFail Parser Text
var)
  [Maybe Text]
args <- ParsecT Void Text Identity (Maybe Text)
-> ParsecT Void Text Identity [Maybe Text]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many ParsecT Void Text Identity (Maybe Text)
funArg
  Parser ()
equals
  case [Maybe Text]
args of
    [] -> Ann -> Text -> Expr Ann -> TermDef Ann
forall a. a -> Text -> Expr a -> TermDef a
Variable Ann
ann Text
name (Expr Ann -> TermDef Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (TermDef Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Expr Ann)
parseExpr
    [Maybe Text]
_ -> Ann -> Text -> [Maybe Text] -> Expr Ann -> TermDef Ann
forall a. a -> Text -> [Maybe Text] -> Expr a -> TermDef a
Function Ann
ann Text
name [Maybe Text]
args (Expr Ann -> TermDef Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (TermDef Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Expr Ann)
parseExpr

funArg :: Parser (Maybe Text)
funArg :: ParsecT Void Text Identity (Maybe Text)
funArg =
  [ParsecT Void Text Identity (Maybe Text)]
-> ParsecT Void Text Identity (Maybe Text)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ Maybe Text
forall a. Maybe a
Nothing Maybe Text -> Parser () -> ParsecT Void Text Identity (Maybe Text)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser ()
underscore
    , Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text)
-> Parser Text -> ParsecT Void Text Identity (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Parser Text -> Parser Text
forall a. Parser a -> Parser a
withKeywordFail Parser Text
var)
    ]

parseBlock :: Parser (Block Ann)
parseBlock :: Parser (Block Ann)
parseBlock = do
  Text -> Parser Text
rword Text
"do" Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines
  Block Ann
stmts <- ParsecT Void Text Identity (Statement Ann) -> Parser (Block Ann)
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.some (ParsecT Void Text Identity (Statement Ann)
-> ParsecT Void Text Identity (Statement Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Statement Ann)
parseStmt ParsecT Void Text Identity (Statement Ann)
-> Parser () -> ParsecT Void Text Identity (Statement Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (Parser ()
newlines1 Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
P.<|> Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
P.eof))
  Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Text -> Parser ()) -> Parser Text -> Parser ()
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
rword Text
"end"
  Block Ann -> Parser (Block Ann)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Block Ann
stmts

parseStmt :: Parser (Statement Ann)
parseStmt :: ParsecT Void Text Identity (Statement Ann)
parseStmt = do
  Ann
ann <- Parser Ann
getAnn
  [ParsecT Void Text Identity (Statement Ann)]
-> ParsecT Void Text Identity (Statement Ann)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ Ann -> Text -> Expr Ann -> Statement Ann
forall a. a -> Text -> Expr a -> Statement a
SBind Ann
ann
      (Text -> Expr Ann -> Statement Ann)
-> Parser Text
-> ParsecT Void Text Identity (Expr Ann -> Statement Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text -> Parser Text
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
P.try (Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme Parser Text
var Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
backarrow Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
      ParsecT Void Text Identity (Expr Ann -> Statement Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Statement Ann)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Void Text Identity (Expr Ann)
parseExpr
    , Text -> Parser Text
rword Text
"let" Parser Text
-> ParsecT Void Text Identity (Statement Ann)
-> ParsecT Void Text Identity (Statement Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Ann -> TermDef Ann -> Statement Ann
forall a. a -> TermDef a -> Statement a
SDef Ann
ann (TermDef Ann -> Statement Ann)
-> ParsecT Void Text Identity (TermDef Ann)
-> ParsecT Void Text Identity (Statement Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (TermDef Ann)
parseTermDef ParsecT Void Text Identity (Statement Ann)
-> FilePath -> ParsecT Void Text Identity (Statement Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a definition")
    , Ann -> Expr Ann -> Statement Ann
forall a. a -> Expr a -> Statement a
SExpr Ann
ann (Expr Ann -> Statement Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Statement Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Expr Ann)
parseExpr ParsecT Void Text Identity (Statement Ann)
-> FilePath -> ParsecT Void Text Identity (Statement Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"an expression"
    ]

-- * Expr

parseExpr :: Parser (Expr Ann)
parseExpr :: ParsecT Void Text Identity (Expr Ann)
parseExpr = (ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"an expression") (ParsecT Void Text Identity (Expr Ann)
 -> ParsecT Void Text Identity (Expr Ann))
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ do
  Ann
ann <- Parser Ann
getAnn
  Expr Ann
e <- ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Expr Ann)
parseExpr'
  [Expr Ann]
args <- ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity [Expr Ann]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many (ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Expr Ann)
parseExpr')

  Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Expr Ann -> ParsecT Void Text Identity (Expr Ann))
-> Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ case [Expr Ann]
args of
    [] -> Expr Ann
e
    [Expr Ann]
_ -> Ann -> Expr Ann -> Expr Ann
forall a. a -> Expr a -> Expr a
EAnnotated Ann
ann (Expr Ann -> Expr Ann) -> Expr Ann -> Expr Ann
forall a b. (a -> b) -> a -> b
$ Expr Ann -> [Expr Ann] -> Expr Ann
forall a. Expr a -> [Expr a] -> Expr a
EFunCall Expr Ann
e [Expr Ann]
args


parseExpr' :: Parser (Expr Ann)
parseExpr' :: ParsecT Void Text Identity (Expr Ann)
parseExpr' = do
  Ann
ann <- Parser Ann
getAnn
  Expr Ann
e <- Ann -> Expr Ann -> Expr Ann
forall a. a -> Expr a -> Expr a
EAnnotated Ann
ann (Expr Ann -> Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Expr Ann)
parseExpr''

  Maybe [Text]
mlabels <- (ParsecT Void Text Identity (Maybe [Text])
-> FilePath -> ParsecT Void Text Identity (Maybe [Text])
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"record accessor") (ParsecT Void Text Identity (Maybe [Text])
 -> ParsecT Void Text Identity (Maybe [Text]))
-> ParsecT Void Text Identity (Maybe [Text])
-> ParsecT Void Text Identity (Maybe [Text])
forall a b. (a -> b) -> a -> b
$
    ParsecT Void Text Identity [Text]
-> ParsecT Void Text Identity (Maybe [Text])
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (ParsecT Void Text Identity [Text]
 -> ParsecT Void Text Identity (Maybe [Text]))
-> ParsecT Void Text Identity [Text]
-> ParsecT Void Text Identity (Maybe [Text])
forall a b. (a -> b) -> a -> b
$ do
      Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
P.notFollowedBy Parser ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
P.space1
      Parser ()
harddot
      Parser Text -> Parser () -> ParsecT Void Text Identity [Text]
forall (m :: * -> *) a end. MonadPlus m => m a -> m end -> m [a]
P.sepBy Parser Text
label Parser ()
harddot

  Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Expr Ann -> ParsecT Void Text Identity (Expr Ann))
-> Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ Expr Ann -> ([Text] -> Expr Ann) -> Maybe [Text] -> Expr Ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
    Expr Ann
e
    (Ann -> Expr Ann -> Expr Ann
forall a. a -> Expr a -> Expr a
EAnnotated Ann
ann (Expr Ann -> Expr Ann)
-> ([Text] -> Expr Ann) -> [Text] -> Expr Ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Expr Ann -> Text -> Expr Ann) -> Expr Ann -> [Text] -> Expr Ann
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Expr Ann -> Text -> Expr Ann
forall a. Expr a -> Text -> Expr a
ERecordAccess Expr Ann
e)
    Maybe [Text]
mlabels

parseExpr'' :: Parser (Expr Ann)
parseExpr'' :: ParsecT Void Text Identity (Expr Ann)
parseExpr'' =
  (ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"an expression") (ParsecT Void Text Identity (Expr Ann)
 -> ParsecT Void Text Identity (Expr Ann))
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ [ParsecT Void Text Identity (Expr Ann)]
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
parens ParsecT Void Text Identity (Expr Ann)
parseExpr ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"parenthesis"
    , Block Ann -> Expr Ann
forall a. Block a -> Expr a
EBlock (Block Ann -> Expr Ann)
-> Parser (Block Ann) -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Block Ann)
parseBlock ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a do block"
    , ParsecT Void Text Identity (Expr Ann)
parseFfi ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"an ffi call"
    , ParsecT Void Text Identity (Expr Ann)
parseCaseOf ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a case expression"
    , ParsecT Void Text Identity (Expr Ann)
parseLambda ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a lambda"
    , (ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a record") (ParsecT Void Text Identity (Expr Ann)
 -> ParsecT Void Text Identity (Expr Ann))
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ do
      (Record (Expr Ann)
record, Maybe (Expr Ann)
mext) <- Parser ()
-> ParsecT Void Text Identity (Expr Ann)
-> Maybe (ParsecT Void Text Identity (Expr Ann))
-> Parser (Record (Expr Ann), Maybe (Expr Ann))
forall a b.
Parser ()
-> Parser a -> Maybe (Parser b) -> Parser (Record a, Maybe b)
parseRecord Parser ()
equals ParsecT Void Text Identity (Expr Ann)
parseExpr (ParsecT Void Text Identity (Expr Ann)
-> Maybe (ParsecT Void Text Identity (Expr Ann))
forall a. a -> Maybe a
Just ParsecT Void Text Identity (Expr Ann)
parseExpr)
      Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Expr Ann -> ParsecT Void Text Identity (Expr Ann))
-> Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ Expr Ann -> (Expr Ann -> Expr Ann) -> Maybe (Expr Ann) -> Expr Ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
        (Record (Expr Ann) -> Expr Ann
forall a. Record (Expr a) -> Expr a
ERecord Record (Expr Ann)
record)
        (Record (Expr Ann) -> Expr Ann -> Expr Ann
forall a. Record (Expr a) -> Expr a -> Expr a
ERecordExtension Record (Expr Ann)
record)
        Maybe (Expr Ann)
mext
    , TermDef Ann -> Expr Ann -> Expr Ann
forall a. TermDef a -> Expr a -> Expr a
ELet
      (TermDef Ann -> Expr Ann -> Expr Ann)
-> ParsecT Void Text Identity (TermDef Ann)
-> ParsecT Void Text Identity (Expr Ann -> Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
rword Text
"let" Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines Parser ()
-> ParsecT Void Text Identity (TermDef Ann)
-> ParsecT Void Text Identity (TermDef Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity (TermDef Ann)
parseTermDef ParsecT Void Text Identity (TermDef Ann)
-> Parser () -> ParsecT Void Text Identity (TermDef Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines ParsecT Void Text Identity (TermDef Ann)
-> FilePath -> ParsecT Void Text Identity (TermDef Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a definition")
      ParsecT Void Text Identity (Expr Ann -> Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> Parser Text
rword Text
"in"  Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines Parser ()
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity (Expr Ann)
parseExpr)
    , Expr Ann -> Expr Ann -> Expr Ann -> Expr Ann
forall a. Expr a -> Expr a -> Expr a -> Expr a
EIf
      (Expr Ann -> Expr Ann -> Expr Ann -> Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann -> Expr Ann -> Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
rword Text
"if" Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines Parser ()
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Expr Ann)
parseExpr ParsecT Void Text Identity (Expr Ann)
-> Parser () -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
      ParsecT Void Text Identity (Expr Ann -> Expr Ann -> Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann -> Expr Ann)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> Parser Text
rword Text
"then" Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines Parser ()
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Expr Ann)
parseExpr ParsecT Void Text Identity (Expr Ann)
-> Parser () -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
      ParsecT Void Text Identity (Expr Ann -> Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> Parser Text
rword Text
"else" Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines Parser ()
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity (Expr Ann)
parseExpr)
      ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"an if expression"
    , Text -> Expr Ann
forall a. Text -> Expr a
EVariant
      (Text -> Expr Ann)
-> Parser Text -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
typename
      ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a variant"
    , Text -> Expr Ann
forall a. Text -> Expr a
EOpenVariant
      (Text -> Expr Ann)
-> Parser Text -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'#' ParsecT Void Text Identity Char -> Parser Text -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text
typename)
      ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a variant"
    , Lit -> Expr Ann
forall a. Lit -> Expr a
ELit (Lit -> Expr Ann)
-> Parser Lit -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Lit
parseLit ParsecT Void Text Identity (Expr Ann)
-> FilePath -> ParsecT Void Text Identity (Expr Ann)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a literal"
    , Text -> Expr Ann
forall a. Text -> Expr a
EVar (Text -> Expr Ann)
-> Parser Text -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
var
    ]

parseCaseOf :: Parser (Expr Ann)
parseCaseOf :: ParsecT Void Text Identity (Expr Ann)
parseCaseOf = do
  Text -> Parser Text
rword Text
"case" Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines
  Expr Ann
e <- ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Expr Ann)
parseExpr
  Text -> Parser Text
rword Text
"of" Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines
  [(Pattern, Expr Ann)]
pats <- Parser [(Pattern, Expr Ann)]
parsePatterns
  Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Text -> Parser ()) -> Parser Text -> Parser ()
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
rword Text
"end"
  Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Expr Ann -> ParsecT Void Text Identity (Expr Ann))
-> Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ Expr Ann -> [(Pattern, Expr Ann)] -> Expr Ann
forall a. Expr a -> [(Pattern, Expr a)] -> Expr a
ECase Expr Ann
e [(Pattern, Expr Ann)]
pats

parsePatterns :: Parser [(Pattern, Expr Ann)]
parsePatterns :: Parser [(Pattern, Expr Ann)]
parsePatterns = ParsecT Void Text Identity (Pattern, Expr Ann)
-> Parser [(Pattern, Expr Ann)]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many (ParsecT Void Text Identity (Pattern, Expr Ann)
 -> Parser [(Pattern, Expr Ann)])
-> ParsecT Void Text Identity (Pattern, Expr Ann)
-> Parser [(Pattern, Expr Ann)]
forall a b. (a -> b) -> a -> b
$
  (,)
    (Pattern -> Expr Ann -> (Pattern, Expr Ann))
-> ParsecT Void Text Identity Pattern
-> ParsecT Void Text Identity (Expr Ann -> (Pattern, Expr Ann))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ()
bar Parser ()
-> ParsecT Void Text Identity Pattern
-> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity Pattern
-> ParsecT Void Text Identity Pattern
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity Pattern
parsePattern ParsecT Void Text Identity Pattern
-> Parser () -> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
    ParsecT Void Text Identity (Expr Ann -> (Pattern, Expr Ann))
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Pattern, Expr Ann)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ()
arrow Parser ()
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Expr Ann)
parseExpr ParsecT Void Text Identity (Expr Ann)
-> Parser () -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)

parsePattern :: Parser Pattern
parsePattern :: ParsecT Void Text Identity Pattern
parsePattern =
  (ParsecT Void Text Identity Pattern
-> FilePath -> ParsecT Void Text Identity Pattern
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a pattern") (ParsecT Void Text Identity Pattern
 -> ParsecT Void Text Identity Pattern)
-> ParsecT Void Text Identity Pattern
-> ParsecT Void Text Identity Pattern
forall a b. (a -> b) -> a -> b
$ [ParsecT Void Text Identity Pattern]
-> ParsecT Void Text Identity Pattern
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ ParsecT Void Text Identity Pattern
-> ParsecT Void Text Identity Pattern
forall a. Parser a -> Parser a
parens ParsecT Void Text Identity Pattern
parsePattern
    , Pattern
PWildcard Pattern -> Parser () -> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser ()
underscore
    , Text -> Pattern
PVar (Text -> Pattern)
-> Parser Text -> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser Text -> Parser Text
forall a. Parser a -> Parser a
withKeywordFail Parser Text
var)
    , Lit -> Pattern
PLit (Lit -> Pattern)
-> Parser Lit -> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Lit
parseLit
    , Record Pattern -> Pattern
PRecord (Record Pattern -> Pattern)
-> ((Record Pattern, Maybe Any) -> Record Pattern)
-> (Record Pattern, Maybe Any)
-> Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Record Pattern, Maybe Any) -> Record Pattern
forall a b. (a, b) -> a
fst
      ((Record Pattern, Maybe Any) -> Pattern)
-> ParsecT Void Text Identity (Record Pattern, Maybe Any)
-> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ()
-> ParsecT Void Text Identity Pattern
-> Maybe (Parser Any)
-> ParsecT Void Text Identity (Record Pattern, Maybe Any)
forall a b.
Parser ()
-> Parser a -> Maybe (Parser b) -> Parser (Record a, Maybe b)
parseRecord Parser ()
equals ParsecT Void Text Identity Pattern
parsePattern Maybe (Parser Any)
forall a. Maybe a
Nothing
      ParsecT Void Text Identity Pattern
-> FilePath -> ParsecT Void Text Identity Pattern
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a record pattern"
    , Variant (Maybe Pattern) -> Pattern
PVariant
      (Variant (Maybe Pattern) -> Pattern)
-> ParsecT Void Text Identity (Variant (Maybe Pattern))
-> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Maybe Pattern)
-> ParsecT Void Text Identity (Variant (Maybe Pattern))
forall a. Parser a -> Parser (Variant a)
parseVariant (ParsecT Void Text Identity Pattern -> Parser (Maybe Pattern)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (ParsecT Void Text Identity Pattern -> Parser (Maybe Pattern))
-> ParsecT Void Text Identity Pattern -> Parser (Maybe Pattern)
forall a b. (a -> b) -> a -> b
$ ParsecT Void Text Identity Pattern
-> ParsecT Void Text Identity Pattern
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity Pattern
parsePattern ParsecT Void Text Identity Pattern
-> Parser () -> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
      ParsecT Void Text Identity Pattern
-> FilePath -> ParsecT Void Text Identity Pattern
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a variant pattern"
    , Variant Pattern -> Pattern
POpenVariant
      (Variant Pattern -> Pattern)
-> ParsecT Void Text Identity (Variant Pattern)
-> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity Pattern
-> ParsecT Void Text Identity (Variant Pattern)
forall a. Parser a -> Parser (Variant a)
parseOpenVariant (ParsecT Void Text Identity Pattern
-> ParsecT Void Text Identity Pattern
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity Pattern
parsePattern ParsecT Void Text Identity Pattern
-> Parser () -> ParsecT Void Text Identity Pattern
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
      ParsecT Void Text Identity Pattern
-> FilePath -> ParsecT Void Text Identity Pattern
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"a variant pattern"
    ]

parseFfi :: Parser (Expr Ann)
parseFfi :: ParsecT Void Text Identity (Expr Ann)
parseFfi = do
  Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Text -> Parser ()) -> Parser Text -> Parser ()
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
rword Text
"ffi"
  ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
parens (ParsecT Void Text Identity (Expr Ann)
 -> ParsecT Void Text Identity (Expr Ann))
-> ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ do
    Text
fun <- Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme Parser Text
stringLiteral Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines
    Maybe Type
typ <- ParsecT Void Text Identity Type -> Parser (Maybe Type)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (Parser ()
colon Parser ()
-> ParsecT Void Text Identity Type
-> ParsecT Void Text Identity Type
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity Type -> ParsecT Void Text Identity Type
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity Type
parseType ParsecT Void Text Identity Type
-> Parser () -> ParsecT Void Text Identity Type
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
    Parser ()
comma Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines
    Text -> Maybe Type -> [Expr Ann] -> Expr Ann
forall a. Text -> Maybe Type -> [Expr a] -> Expr a
EFfi Text
fun Maybe Type
typ
      ([Expr Ann] -> Expr Ann)
-> ParsecT Void Text Identity [Expr Ann]
-> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity (Expr Ann)
-> Parser () -> ParsecT Void Text Identity [Expr Ann]
forall (m :: * -> *) a end. MonadPlus m => m a -> m end -> m [a]
P.sepBy (ParsecT Void Text Identity (Expr Ann)
-> ParsecT Void Text Identity (Expr Ann)
forall a. Parser a -> Parser a
lexeme ParsecT Void Text Identity (Expr Ann)
parseExpr ParsecT Void Text Identity (Expr Ann)
-> Parser () -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines) (Parser ()
comma Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines)

parseLambda :: Parser (Expr Ann)
parseLambda :: ParsecT Void Text Identity (Expr Ann)
parseLambda = do
  Parser ()
lambda
  [Maybe Text]
args <- ParsecT Void Text Identity (Maybe Text)
-> ParsecT Void Text Identity [Maybe Text]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.some ParsecT Void Text Identity (Maybe Text)
funArg
  Parser ()
arrow Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines
  Expr Ann
body <- ParsecT Void Text Identity (Expr Ann)
parseExpr
  Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Expr Ann -> ParsecT Void Text Identity (Expr Ann))
-> Expr Ann -> ParsecT Void Text Identity (Expr Ann)
forall a b. (a -> b) -> a -> b
$ [Maybe Text] -> Expr Ann -> Expr Ann
forall a. [Maybe Text] -> Expr a -> Expr a
EFun [Maybe Text]
args Expr Ann
body

-- * General

parseLit :: Parser Lit
parseLit :: Parser Lit
parseLit =
  [Parser Lit] -> Parser Lit
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
P.choice
    [ Parser Lit
number
    , Text -> Lit
LString (Text -> Lit) -> Parser Text -> Parser Lit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
stringLiteral
    ]

parseVariant :: Parser a -> Parser (Variant a)
parseVariant :: Parser a -> Parser (Variant a)
parseVariant Parser a
p =
  Text -> a -> Variant a
forall a. Text -> a -> Variant a
Variant
    (Text -> a -> Variant a)
-> Parser Text -> ParsecT Void Text Identity (a -> Variant a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme Parser Text
uppername Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines Parser Text -> FilePath -> Parser Text
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"data constructor")
    ParsecT Void Text Identity (a -> Variant a)
-> Parser a -> Parser (Variant a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser a
p

parseOpenVariant :: Parser a -> Parser (Variant a)
parseOpenVariant :: Parser a -> Parser (Variant a)
parseOpenVariant Parser a
p =
  Text -> a -> Variant a
forall a. Text -> a -> Variant a
Variant
    (Text -> a -> Variant a)
-> Parser Text -> ParsecT Void Text Identity (a -> Variant a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
P.char Char
Token Text
'#' ParsecT Void Text Identity Char -> Parser Text -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text
uppername) Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines Parser Text -> FilePath -> Parser Text
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"open variant")
    ParsecT Void Text Identity (a -> Variant a)
-> Parser a -> Parser (Variant a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser a
p

parseRecord :: Parser () -> Parser a -> Maybe (Parser b) -> Parser (Record a, Maybe b)
parseRecord :: Parser ()
-> Parser a -> Maybe (Parser b) -> Parser (Record a, Maybe b)
parseRecord Parser ()
pSym Parser a
pa Maybe (Parser b)
mpb = Parser (Record a, Maybe b) -> Parser (Record a, Maybe b)
forall a. Parser a -> Parser a
braces (Parser (Record a, Maybe b) -> Parser (Record a, Maybe b))
-> Parser (Record a, Maybe b) -> Parser (Record a, Maybe b)
forall a b. (a -> b) -> a -> b
$ do
  -- we are going to allow records with duplicate
  -- labels. Semantically, this means that
  -- the first label matches and the rest
  -- are discarded.
  Record a
record <- ([(Text, a)] -> Record a)
-> ParsecT Void Text Identity [(Text, a)]
-> ParsecT Void Text Identity (Record a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    ((a -> a -> a) -> [(Text, a)] -> Record a
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
M.fromListWith ((a -> a -> a) -> [(Text, a)] -> Record a)
-> (a -> a -> a) -> [(Text, a)] -> Record a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> a -> a -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> a -> a
forall a b. a -> b -> a
const) (ParsecT Void Text Identity [(Text, a)]
 -> ParsecT Void Text Identity (Record a))
-> ParsecT Void Text Identity [(Text, a)]
-> ParsecT Void Text Identity (Record a)
forall a b. (a -> b) -> a -> b
$ ParsecT Void Text Identity [(Text, a)]
-> ParsecT Void Text Identity [(Text, a)]
forall a. Parser a -> Parser a
lexeme (ParsecT Void Text Identity [(Text, a)]
 -> ParsecT Void Text Identity [(Text, a)])
-> ParsecT Void Text Identity [(Text, a)]
-> ParsecT Void Text Identity [(Text, a)]
forall a b. (a -> b) -> a -> b
$
      ParsecT Void Text Identity (Text, a)
-> Parser () -> ParsecT Void Text Identity [(Text, a)]
forall (m :: * -> *) a end. MonadPlus m => m a -> m end -> m [a]
P.sepBy
        ( do
          Text
l <- Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme Parser Text
label
          Parser ()
pSym Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
newlines
          (,) Text
l (a -> (Text, a))
-> Parser a -> ParsecT Void Text Identity (Text, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser a -> Parser a
forall a. Parser a -> Parser a
lexeme Parser a
pa Parser a -> Parser () -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines)
        )
        Parser ()
comma

  Maybe b
ext <-
    case Maybe (Parser b)
mpb of
      Just Parser b
pb ->
        Parser b -> ParsecT Void Text Identity (Maybe b)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (Parser b -> ParsecT Void Text Identity (Maybe b))
-> Parser b -> ParsecT Void Text Identity (Maybe b)
forall a b. (a -> b) -> a -> b
$ Parser ()
bar Parser () -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser b -> Parser b
forall a. Parser a -> Parser a
lexeme Parser b
pb Parser b -> Parser () -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
newlines
      Maybe (Parser b)
Nothing ->
        Maybe b -> ParsecT Void Text Identity (Maybe b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe b
forall a. Maybe a
Nothing

  (Record a, Maybe b) -> Parser (Record a, Maybe b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Record a
record, Maybe b
ext)
    
dummyAnn :: FilePath -> P.SourcePos
dummyAnn :: FilePath -> Ann
dummyAnn FilePath
fname = FilePath -> Pos -> Pos -> Ann
P.SourcePos FilePath
fname (Int -> Pos
P.mkPos Int
1) (Int -> Pos
P.mkPos Int
1)

ppErrors :: P.ParseErrorBundle Text Void -> Text
ppErrors :: ParseErrorBundle Text Void -> Text
ppErrors = FilePath -> Text
T.pack (FilePath -> Text)
-> (ParseErrorBundle Text Void -> FilePath)
-> ParseErrorBundle Text Void
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseErrorBundle Text Void -> FilePath
forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> FilePath
P.errorBundlePretty