{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-all  #-} -- Since we will soon deprecate this parser

{- |
Module      : Language.Egison.Parser.SExpr
Licence     : MIT

This module implements the parser for the old S-expression syntax.
-}

module Language.Egison.Parser.SExpr
       (
       -- * Parse a string
         parseTopExprs
       , parseTopExpr
       , parseExprs
       , parseExpr
       ) where

import           Control.Applicative    (pure, (*>), (<$>), (<*), (<*>))
import           Control.Monad.Except   (throwError)
import           Control.Monad.Identity (Identity)

import           Data.Char              (isLower, isUpper, toUpper)
import           Data.Either
import           Data.Functor           (($>))
import           Data.Ratio
import qualified Data.Set               as Set
import qualified Data.Text              as T

import           Text.Parsec
import           Text.Parsec.String
import qualified Text.Parsec.Token      as P

import           Language.Egison.AST

parseTopExprs :: String -> Either String [TopExpr]
parseTopExprs :: String -> Either String [TopExpr]
parseTopExprs = Parser [TopExpr] -> String -> Either String [TopExpr]
forall a. Parser a -> String -> Either String a
doParse (Parser [TopExpr] -> String -> Either String [TopExpr])
-> Parser [TopExpr] -> String -> Either String [TopExpr]
forall a b. (a -> b) -> a -> b
$ do
  [TopExpr]
ret <- Parser ()
whiteSpace Parser () -> Parser [TopExpr] -> Parser [TopExpr]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity TopExpr -> Parser () -> Parser [TopExpr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
endBy ParsecT String () Identity TopExpr
topExpr Parser ()
whiteSpace
  Parser ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  [TopExpr] -> Parser [TopExpr]
forall (m :: * -> *) a. Monad m => a -> m a
return [TopExpr]
ret

parseTopExpr :: String -> Either String TopExpr
parseTopExpr :: String -> Either String TopExpr
parseTopExpr = ParsecT String () Identity TopExpr
-> String -> Either String TopExpr
forall a. Parser a -> String -> Either String a
doParse (ParsecT String () Identity TopExpr
 -> String -> Either String TopExpr)
-> ParsecT String () Identity TopExpr
-> String
-> Either String TopExpr
forall a b. (a -> b) -> a -> b
$ do
  TopExpr
ret <- Parser ()
whiteSpace Parser ()
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity TopExpr
topExpr
  Parser ()
whiteSpace Parser () -> Parser () -> Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  TopExpr -> ParsecT String () Identity TopExpr
forall (m :: * -> *) a. Monad m => a -> m a
return TopExpr
ret

parseExprs :: String -> Either String [Expr]
parseExprs :: String -> Either String [Expr]
parseExprs = Parser [Expr] -> String -> Either String [Expr]
forall a. Parser a -> String -> Either String a
doParse (Parser [Expr] -> String -> Either String [Expr])
-> Parser [Expr] -> String -> Either String [Expr]
forall a b. (a -> b) -> a -> b
$ do
  [Expr]
ret <- Parser ()
whiteSpace Parser () -> Parser [Expr] -> Parser [Expr]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr -> Parser () -> Parser [Expr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
endBy ParsecT String () Identity Expr
expr Parser ()
whiteSpace
  Parser ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  [Expr] -> Parser [Expr]
forall (m :: * -> *) a. Monad m => a -> m a
return [Expr]
ret

parseExpr :: String -> Either String Expr
parseExpr :: String -> Either String Expr
parseExpr = ParsecT String () Identity Expr -> String -> Either String Expr
forall a. Parser a -> String -> Either String a
doParse (ParsecT String () Identity Expr -> String -> Either String Expr)
-> ParsecT String () Identity Expr -> String -> Either String Expr
forall a b. (a -> b) -> a -> b
$ do
  Expr
ret <- Parser ()
whiteSpace Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr
  Parser ()
whiteSpace Parser () -> Parser () -> Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  Expr -> ParsecT String () Identity Expr
forall (m :: * -> *) a. Monad m => a -> m a
return Expr
ret

--
-- Parser
--

doParse :: Parser a -> String -> Either String a
doParse :: Parser a -> String -> Either String a
doParse Parser a
p String
input = (ParseError -> Either String a)
-> (a -> Either String a) -> Either ParseError a -> Either String a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Either String a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String -> Either String a)
-> (ParseError -> String) -> ParseError -> Either String a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError -> String
forall a. Show a => a -> String
show) a -> Either String a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either ParseError a -> Either String a)
-> Either ParseError a -> Either String a
forall a b. (a -> b) -> a -> b
$ Parser a -> String -> String -> Either ParseError a
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
parse Parser a
p String
"egison" String
input

doParse' :: Parser a -> String -> a
doParse' :: Parser a -> String -> a
doParse' Parser a
p String
input = case Parser a -> String -> Either String a
forall a. Parser a -> String -> Either String a
doParse Parser a
p String
input of
                     Right a
x -> a
x

--
-- Expressions
--
topExpr :: Parser TopExpr
topExpr :: ParsecT String () Identity TopExpr
topExpr = ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> TopExpr
Test (Expr -> TopExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity TopExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr)
      ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity TopExpr
defineExpr
      ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall a. Parser a -> Parser a
parens (ParsecT String () Identity TopExpr
testExpr
                   ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity TopExpr
executeExpr
                   ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity TopExpr
loadFileExpr
                   ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity TopExpr
loadExpr))
      ParsecT String () Identity TopExpr
-> String -> ParsecT String () Identity TopExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"top-level expression"

defineExpr :: Parser TopExpr
defineExpr :: ParsecT String () Identity TopExpr
defineExpr = ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall a. Parser a -> Parser a
parens (Parser ()
keywordDefine Parser ()
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> VarWithIndices -> Expr -> TopExpr
Define (VarWithIndices -> Expr -> TopExpr)
-> ParsecT String () Identity VarWithIndices
-> ParsecT String () Identity (Expr -> TopExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity VarWithIndices
-> ParsecT String () Identity VarWithIndices
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity VarWithIndices
identVarWithIndices) ParsecT String () Identity (Expr -> TopExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity TopExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr)

testExpr :: Parser TopExpr
testExpr :: ParsecT String () Identity TopExpr
testExpr = Parser ()
keywordTest Parser ()
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> TopExpr
Test (Expr -> TopExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity TopExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr

executeExpr :: Parser TopExpr
executeExpr :: ParsecT String () Identity TopExpr
executeExpr = Parser ()
keywordExecute Parser ()
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> TopExpr
Execute (Expr -> TopExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity TopExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr

loadFileExpr :: Parser TopExpr
loadFileExpr :: ParsecT String () Identity TopExpr
loadFileExpr = Parser ()
keywordLoadFile Parser ()
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> TopExpr
LoadFile (String -> TopExpr)
-> ParsecT String () Identity String
-> ParsecT String () Identity TopExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
stringLiteral

loadExpr :: Parser TopExpr
loadExpr :: ParsecT String () Identity TopExpr
loadExpr = Parser ()
keywordLoad Parser ()
-> ParsecT String () Identity TopExpr
-> ParsecT String () Identity TopExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> TopExpr
Load (String -> TopExpr)
-> ParsecT String () Identity String
-> ParsecT String () Identity TopExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
stringLiteral

expr :: Parser Expr
expr :: ParsecT String () Identity Expr
expr = GenTokenParser String () Identity
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer (do Expr
expr0 <- ParsecT String () Identity Expr
expr' ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
quoteExpr
                          Expr
expr1 <- Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Expr
expr0 (ParsecT String () Identity Expr
 -> ParsecT String () Identity Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"..." ParsecT String () Identity String
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Expr -> [IndexExpr Expr] -> Expr
IndexedExpr Bool
False Expr
expr0 ([IndexExpr Expr] -> Expr)
-> ParsecT String () Identity [IndexExpr Expr]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [IndexExpr Expr]
parseindex)
                                                  ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> Expr -> [IndexExpr Expr] -> Expr
IndexedExpr Bool
True Expr
expr0 ([IndexExpr Expr] -> Expr)
-> ParsecT String () Identity [IndexExpr Expr]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [IndexExpr Expr]
parseindex
                          Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Expr
expr1 (ParsecT String () Identity Expr
 -> ParsecT String () Identity Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ (\Expr
x -> String -> [Expr] -> Expr
makeApply String
"**" [Expr
expr1, Expr
x]) (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'^' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr'))
                            where parseindex :: Parser [IndexExpr Expr]
                                  parseindex :: ParsecT String () Identity [IndexExpr Expr]
parseindex = ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity [IndexExpr Expr]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> Expr -> IndexExpr Expr
forall a. a -> a -> IndexExpr a
MultiSubscript   (Expr -> Expr -> IndexExpr Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> IndexExpr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'_' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr') ParsecT String () Identity (Expr -> IndexExpr Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (IndexExpr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"..._" ParsecT String () Identity String
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr'))
                                                  ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> Expr -> IndexExpr Expr
forall a. a -> a -> IndexExpr a
MultiSuperscript (Expr -> Expr -> IndexExpr Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> IndexExpr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'~' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr') ParsecT String () Identity (Expr -> IndexExpr Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (IndexExpr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"...~" ParsecT String () Identity String
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr'))
                                                  ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> IndexExpr Expr
forall a. a -> IndexExpr a
Subscript    (Expr -> IndexExpr Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (IndexExpr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'_' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr'))
                                                  ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> IndexExpr Expr
forall a. a -> IndexExpr a
Superscript  (Expr -> IndexExpr Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (IndexExpr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'~' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr'))
                                                  ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> IndexExpr Expr
forall a. a -> IndexExpr a
SupSubscript (Expr -> IndexExpr Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (IndexExpr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"~_" ParsecT String () Identity String
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr'))
                                                  ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (IndexExpr Expr)
-> ParsecT String () Identity (IndexExpr Expr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> IndexExpr Expr
forall a. a -> IndexExpr a
Userscript   (Expr -> IndexExpr Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (IndexExpr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'|' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr')))


quoteExpr :: Parser Expr
quoteExpr :: ParsecT String () Identity Expr
quoteExpr = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\'' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr
QuoteExpr (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr'

expr' :: Parser Expr
expr' :: ParsecT String () Identity Expr
expr' = ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Expr
anonParamFuncExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ConstantExpr -> Expr
ConstantExpr (ConstantExpr -> Expr)
-> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity ConstantExpr
constantExpr)
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Expr
anonParamExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Expr
freshVarExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Expr
varExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
inductiveDataExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Expr
vectorExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Expr
tupleExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Expr
hashExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
collectionExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
quoteSymbolExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
wedgeExpr
            ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall a. Parser a -> Parser a
parens (ParsecT String () Identity Expr
ifExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
lambdaExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
memoizedLambdaExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
cambdaExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
patternFunctionExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
letRecExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
letExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
letStarExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
withSymbolsExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
doExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
matchAllExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
matchAllDFSExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
matchExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
matchDFSExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
matchAllLambdaExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
matchLambdaExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
matcherExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
seqExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
applyExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
cApplyExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
algebraicDataMatcherExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
generateTensorExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
tensorExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
tensorContractExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
tensorMapExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
tensorMap2Expr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
transposeExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
subrefsExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
suprefsExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
userrefsExpr
                        ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Expr
functionWithArgExpr
                        )
            ParsecT String () Identity Expr
-> String -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"expression"

varExpr :: Parser Expr
varExpr :: ParsecT String () Identity Expr
varExpr = String -> Expr
VarExpr (String -> Expr)
-> ParsecT String () Identity String
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident

freshVarExpr :: Parser Expr
freshVarExpr :: ParsecT String () Identity Expr
freshVarExpr = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'#' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> ParsecT String () Identity Expr
forall (m :: * -> *) a. Monad m => a -> m a
return Expr
FreshVarExpr

inductiveDataExpr :: Parser Expr
inductiveDataExpr :: ParsecT String () Identity Expr
inductiveDataExpr = ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall a. Parser a -> Parser a
angles (ParsecT String () Identity Expr
 -> ParsecT String () Identity Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ do
  String
name <- ParsecT String () Identity String
upperName
  [Expr]
args <- ParsecT String () Identity Expr -> Parser () -> Parser [Expr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Expr
expr Parser ()
whiteSpace
  Expr -> ParsecT String () Identity Expr
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> ParsecT String () Identity Expr)
-> Expr -> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ String -> [Expr] -> Expr
makeApply String
name [Expr]
args

tupleExpr :: Parser Expr
tupleExpr :: ParsecT String () Identity Expr
tupleExpr = ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity Expr
 -> ParsecT String () Identity Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
TupleExpr ([Expr] -> Expr)
-> Parser [Expr] -> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr -> Parser () -> Parser [Expr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Expr
expr Parser ()
whiteSpace

data InnerExpr
  = ElementExpr Expr
  | SubCollectionExpr Expr

collectionExpr :: Parser Expr
collectionExpr :: ParsecT String () Identity Expr
collectionExpr = do
  [InnerExpr]
inners <- Parser [InnerExpr] -> Parser [InnerExpr]
forall a. Parser a -> Parser a
braces (Parser [InnerExpr] -> Parser [InnerExpr])
-> Parser [InnerExpr] -> Parser [InnerExpr]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity InnerExpr
-> Parser () -> Parser [InnerExpr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity InnerExpr
innerExpr Parser ()
whiteSpace
  Expr -> ParsecT String () Identity Expr
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> ParsecT String () Identity Expr)
-> Expr -> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ [Expr] -> [InnerExpr] -> Expr
f [] [InnerExpr]
inners
 where
  innerExpr :: Parser InnerExpr
  innerExpr :: ParsecT String () Identity InnerExpr
innerExpr = (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'@' ParsecT String () Identity Char
-> ParsecT String () Identity InnerExpr
-> ParsecT String () Identity InnerExpr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> InnerExpr
SubCollectionExpr (Expr -> InnerExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity InnerExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr)
               ParsecT String () Identity InnerExpr
-> ParsecT String () Identity InnerExpr
-> ParsecT String () Identity InnerExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Expr -> InnerExpr
ElementExpr (Expr -> InnerExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity InnerExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr

  isElementExpr :: InnerExpr -> Bool
  isElementExpr :: InnerExpr -> Bool
isElementExpr ElementExpr{} = Bool
True
  isElementExpr InnerExpr
_             = Bool
False

  f :: [Expr] -> [InnerExpr] -> Expr
  f :: [Expr] -> [InnerExpr] -> Expr
f [Expr]
xs []                          = [Expr] -> Expr
CollectionExpr [Expr]
xs
  f [Expr]
xs [ElementExpr Expr
y]             = [Expr] -> Expr
CollectionExpr ([Expr]
xs [Expr] -> [Expr] -> [Expr]
forall a. [a] -> [a] -> [a]
++ [Expr
y])
  f []  [SubCollectionExpr Expr
y]      = Expr
y
  f [Expr
x] [SubCollectionExpr Expr
y]      = Expr -> Expr -> Expr
ConsExpr Expr
x Expr
y
  f [Expr]
xs  [SubCollectionExpr Expr
y]      = Expr -> Expr -> Expr
JoinExpr ([Expr] -> Expr
CollectionExpr [Expr]
xs) Expr
y
  f [Expr]
xs (ElementExpr Expr
y : [InnerExpr]
ys)        = [Expr] -> [InnerExpr] -> Expr
f ([Expr]
xs [Expr] -> [Expr] -> [Expr]
forall a. [a] -> [a] -> [a]
++ [Expr
y]) [InnerExpr]
ys
  f []  (SubCollectionExpr Expr
y : [InnerExpr]
ys) = Expr -> Expr -> Expr
JoinExpr Expr
y ([Expr] -> [InnerExpr] -> Expr
f [] [InnerExpr]
ys)
  f [Expr
x] (SubCollectionExpr Expr
y : [InnerExpr]
ys) = Expr -> Expr -> Expr
ConsExpr Expr
x (Expr -> Expr -> Expr
JoinExpr Expr
y ([Expr] -> [InnerExpr] -> Expr
f [] [InnerExpr]
ys))
  f [Expr]
xs  (SubCollectionExpr Expr
y : [InnerExpr]
ys) = Expr -> Expr -> Expr
JoinExpr ([Expr] -> Expr
CollectionExpr [Expr]
xs) (Expr -> Expr -> Expr
JoinExpr Expr
y ([Expr] -> [InnerExpr] -> Expr
f [] [InnerExpr]
ys))


vectorExpr :: Parser Expr
vectorExpr :: ParsecT String () Identity Expr
vectorExpr = ParsecT String () Identity String
-> ParsecT String () Identity String
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between ParsecT String () Identity String
lp ParsecT String () Identity String
forall u. ParsecT String u Identity String
rp (ParsecT String () Identity Expr
 -> ParsecT String () Identity Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
VectorExpr ([Expr] -> Expr)
-> Parser [Expr] -> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr -> Parser () -> Parser [Expr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Expr
expr Parser ()
whiteSpace
  where
    lp :: ParsecT String () Identity String
lp = GenTokenParser String () Identity
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"[|")
    rp :: ParsecT String u Identity String
rp = String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"|]"

hashExpr :: Parser Expr
hashExpr :: ParsecT String () Identity Expr
hashExpr = ParsecT String () Identity String
-> ParsecT String () Identity String
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between ParsecT String () Identity String
lp ParsecT String () Identity String
forall u. ParsecT String u Identity String
rp (ParsecT String () Identity Expr
 -> ParsecT String () Identity Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ [(Expr, Expr)] -> Expr
HashExpr ([(Expr, Expr)] -> Expr)
-> ParsecT String () Identity [(Expr, Expr)]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity (Expr, Expr)
-> Parser () -> ParsecT String () Identity [(Expr, Expr)]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity (Expr, Expr)
pairExpr Parser ()
whiteSpace
  where
    lp :: ParsecT String () Identity String
lp = GenTokenParser String () Identity
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"{|")
    rp :: ParsecT String u Identity String
rp = String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"|}"
    pairExpr :: Parser (Expr, Expr)
    pairExpr :: ParsecT String () Identity (Expr, Expr)
pairExpr = ParsecT String () Identity (Expr, Expr)
-> ParsecT String () Identity (Expr, Expr)
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity (Expr, Expr)
 -> ParsecT String () Identity (Expr, Expr))
-> ParsecT String () Identity (Expr, Expr)
-> ParsecT String () Identity (Expr, Expr)
forall a b. (a -> b) -> a -> b
$ (,) (Expr -> Expr -> (Expr, Expr))
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> (Expr, Expr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> (Expr, Expr))
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr, Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

wedgeExpr :: Parser Expr
wedgeExpr :: ParsecT String () Identity Expr
wedgeExpr = do
  Expr
e <- Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'!' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr
  case Expr
e of
    ApplyExpr Expr
e1 [Expr]
e2 -> Expr -> ParsecT String () Identity Expr
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> ParsecT String () Identity Expr)
-> Expr -> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ Expr -> [Expr] -> Expr
WedgeApplyExpr Expr
e1 [Expr]
e2

functionWithArgExpr :: Parser Expr
functionWithArgExpr :: ParsecT String () Identity Expr
functionWithArgExpr = Parser ()
keywordFunction Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [String] -> Expr
FunctionExpr ([String] -> Expr)
-> ParsecT String () Identity [String]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity [String]
-> ParsecT String () Identity [String]
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between ParsecT String () Identity Char
lp ParsecT String () Identity Char
forall u. ParsecT String u Identity Char
rp (ParsecT String () Identity String
-> Parser () -> ParsecT String () Identity [String]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity String
ident Parser ()
whiteSpace)
  where
    lp :: ParsecT String () Identity Char
lp = GenTokenParser String () Identity
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'[')
    rp :: ParsecT String u Identity Char
rp = Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'

quoteSymbolExpr :: Parser Expr
quoteSymbolExpr :: ParsecT String () Identity Expr
quoteSymbolExpr = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'`' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr
QuoteSymbolExpr (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr

matchAllExpr :: Parser Expr
matchAllExpr :: ParsecT String () Identity Expr
matchAllExpr = Parser ()
keywordMatchAll Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PMMode -> Expr -> Expr -> [MatchClause] -> Expr
MatchAllExpr PMMode
BFSMode (Expr -> Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> [MatchClause] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity ([MatchClause] -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT String () Identity ([MatchClause] -> Expr)
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (((MatchClause -> [MatchClause] -> [MatchClause]
forall a. a -> [a] -> [a]
:[]) (MatchClause -> [MatchClause])
-> ParsecT String () Identity MatchClause
-> ParsecT String () Identity [MatchClause]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity MatchClause
matchClause) ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity [MatchClause]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity [MatchClause]
matchClauses)

matchAllDFSExpr :: Parser Expr
matchAllDFSExpr :: ParsecT String () Identity Expr
matchAllDFSExpr = Parser ()
keywordMatchAllDFS Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PMMode -> Expr -> Expr -> [MatchClause] -> Expr
MatchAllExpr PMMode
DFSMode (Expr -> Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> [MatchClause] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity ([MatchClause] -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT String () Identity ([MatchClause] -> Expr)
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (((MatchClause -> [MatchClause] -> [MatchClause]
forall a. a -> [a] -> [a]
:[]) (MatchClause -> [MatchClause])
-> ParsecT String () Identity MatchClause
-> ParsecT String () Identity [MatchClause]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity MatchClause
matchClause) ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity [MatchClause]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity [MatchClause]
matchClauses)

matchExpr :: Parser Expr
matchExpr :: ParsecT String () Identity Expr
matchExpr = Parser ()
keywordMatch Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PMMode -> Expr -> Expr -> [MatchClause] -> Expr
MatchExpr PMMode
BFSMode (Expr -> Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> [MatchClause] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity ([MatchClause] -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT String () Identity ([MatchClause] -> Expr)
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity [MatchClause]
matchClauses

matchDFSExpr :: Parser Expr
matchDFSExpr :: ParsecT String () Identity Expr
matchDFSExpr = Parser ()
keywordMatchDFS Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PMMode -> Expr -> Expr -> [MatchClause] -> Expr
MatchExpr PMMode
DFSMode (Expr -> Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> [MatchClause] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity ([MatchClause] -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT String () Identity ([MatchClause] -> Expr)
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity [MatchClause]
matchClauses

matchAllLambdaExpr :: Parser Expr
matchAllLambdaExpr :: ParsecT String () Identity Expr
matchAllLambdaExpr = Parser ()
keywordMatchAllLambda Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> [MatchClause] -> Expr
MatchAllLambdaExpr (Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity ([MatchClause] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity ([MatchClause] -> Expr)
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (((MatchClause -> [MatchClause] -> [MatchClause]
forall a. a -> [a] -> [a]
:[]) (MatchClause -> [MatchClause])
-> ParsecT String () Identity MatchClause
-> ParsecT String () Identity [MatchClause]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity MatchClause
matchClause) ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity [MatchClause]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity [MatchClause]
matchClauses)

matchLambdaExpr :: Parser Expr
matchLambdaExpr :: ParsecT String () Identity Expr
matchLambdaExpr = Parser ()
keywordMatchLambda Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> [MatchClause] -> Expr
MatchLambdaExpr (Expr -> [MatchClause] -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity ([MatchClause] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity ([MatchClause] -> Expr)
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity [MatchClause]
matchClauses

matchClauses :: Parser [MatchClause]
matchClauses :: ParsecT String () Identity [MatchClause]
matchClauses = ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity [MatchClause]
forall a. Parser a -> Parser a
braces (ParsecT String () Identity [MatchClause]
 -> ParsecT String () Identity [MatchClause])
-> ParsecT String () Identity [MatchClause]
-> ParsecT String () Identity [MatchClause]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity MatchClause
-> Parser () -> ParsecT String () Identity [MatchClause]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity MatchClause
matchClause Parser ()
whiteSpace

matchClause :: Parser MatchClause
matchClause :: ParsecT String () Identity MatchClause
matchClause = ParsecT String () Identity MatchClause
-> ParsecT String () Identity MatchClause
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity MatchClause
 -> ParsecT String () Identity MatchClause)
-> ParsecT String () Identity MatchClause
-> ParsecT String () Identity MatchClause
forall a b. (a -> b) -> a -> b
$ (,) (Pattern -> Expr -> MatchClause)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity (Expr -> MatchClause)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Pattern
pattern ParsecT String () Identity (Expr -> MatchClause)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity MatchClause
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

matcherExpr :: Parser Expr
matcherExpr :: ParsecT String () Identity Expr
matcherExpr = Parser ()
keywordMatcher Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [PatternDef] -> Expr
MatcherExpr ([PatternDef] -> Expr)
-> ParsecT String () Identity [PatternDef]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [PatternDef]
ppMatchClauses

ppMatchClauses :: Parser [PatternDef]
ppMatchClauses :: ParsecT String () Identity [PatternDef]
ppMatchClauses = ParsecT String () Identity [PatternDef]
-> ParsecT String () Identity [PatternDef]
forall a. Parser a -> Parser a
braces (ParsecT String () Identity [PatternDef]
 -> ParsecT String () Identity [PatternDef])
-> ParsecT String () Identity [PatternDef]
-> ParsecT String () Identity [PatternDef]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity PatternDef
-> Parser () -> ParsecT String () Identity [PatternDef]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity PatternDef
ppMatchClause Parser ()
whiteSpace

ppMatchClause :: Parser PatternDef
ppMatchClause :: ParsecT String () Identity PatternDef
ppMatchClause = ParsecT String () Identity PatternDef
-> ParsecT String () Identity PatternDef
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity PatternDef
 -> ParsecT String () Identity PatternDef)
-> ParsecT String () Identity PatternDef
-> ParsecT String () Identity PatternDef
forall a b. (a -> b) -> a -> b
$ (,,) (PrimitivePatPattern
 -> Expr -> [(PrimitiveDataPattern, Expr)] -> PatternDef)
-> ParsecT String () Identity PrimitivePatPattern
-> ParsecT
     String
     ()
     Identity
     (Expr -> [(PrimitiveDataPattern, Expr)] -> PatternDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity PrimitivePatPattern
ppPattern ParsecT
  String
  ()
  Identity
  (Expr -> [(PrimitiveDataPattern, Expr)] -> PatternDef)
-> ParsecT String () Identity Expr
-> ParsecT
     String () Identity ([(PrimitiveDataPattern, Expr)] -> PatternDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT
  String () Identity ([(PrimitiveDataPattern, Expr)] -> PatternDef)
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
-> ParsecT String () Identity PatternDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
pdMatchClauses

pdMatchClauses :: Parser [(PrimitiveDataPattern, Expr)]
pdMatchClauses :: ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
pdMatchClauses = ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
forall a. Parser a -> Parser a
braces (ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
 -> ParsecT String () Identity [(PrimitiveDataPattern, Expr)])
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity (PrimitiveDataPattern, Expr)
-> Parser ()
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity (PrimitiveDataPattern, Expr)
pdMatchClause Parser ()
whiteSpace

pdMatchClause :: Parser (PrimitiveDataPattern, Expr)
pdMatchClause :: ParsecT String () Identity (PrimitiveDataPattern, Expr)
pdMatchClause = ParsecT String () Identity (PrimitiveDataPattern, Expr)
-> ParsecT String () Identity (PrimitiveDataPattern, Expr)
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity (PrimitiveDataPattern, Expr)
 -> ParsecT String () Identity (PrimitiveDataPattern, Expr))
-> ParsecT String () Identity (PrimitiveDataPattern, Expr)
-> ParsecT String () Identity (PrimitiveDataPattern, Expr)
forall a b. (a -> b) -> a -> b
$ (,) (PrimitiveDataPattern -> Expr -> (PrimitiveDataPattern, Expr))
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT
     String () Identity (Expr -> (PrimitiveDataPattern, Expr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity PrimitiveDataPattern
pdPattern ParsecT String () Identity (Expr -> (PrimitiveDataPattern, Expr))
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (PrimitiveDataPattern, Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

ppPattern :: Parser PrimitivePatPattern
ppPattern :: ParsecT String () Identity PrimitivePatPattern
ppPattern = GenTokenParser String () Identity
-> ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer (ParsecT String () Identity PrimitivePatPattern
ppWildCard
                        ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity PrimitivePatPattern
ppPatVar
                        ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity PrimitivePatPattern
ppValuePat
                        ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity PrimitivePatPattern
ppInductivePat
                        ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity PrimitivePatPattern
ppTuplePat
                        ParsecT String () Identity PrimitivePatPattern
-> String -> ParsecT String () Identity PrimitivePatPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"primitive-pattren-pattern")

ppWildCard :: Parser PrimitivePatPattern
ppWildCard :: ParsecT String () Identity PrimitivePatPattern
ppWildCard = String -> Parser ()
reservedOp String
"_" Parser ()
-> PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> PrimitivePatPattern
PPWildCard

ppPatVar :: Parser PrimitivePatPattern
ppPatVar :: ParsecT String () Identity PrimitivePatPattern
ppPatVar = String -> Parser ()
reservedOp String
"$" Parser ()
-> PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> PrimitivePatPattern
PPPatVar

ppValuePat :: Parser PrimitivePatPattern
ppValuePat :: ParsecT String () Identity PrimitivePatPattern
ppValuePat = String -> Parser ()
reservedOp String
",$" Parser ()
-> ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> PrimitivePatPattern
PPValuePat (String -> PrimitivePatPattern)
-> ParsecT String () Identity String
-> ParsecT String () Identity PrimitivePatPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident

ppInductivePat :: Parser PrimitivePatPattern
ppInductivePat :: ParsecT String () Identity PrimitivePatPattern
ppInductivePat = ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall a. Parser a -> Parser a
angles (String -> [PrimitivePatPattern] -> PrimitivePatPattern
PPInductivePat (String -> [PrimitivePatPattern] -> PrimitivePatPattern)
-> ParsecT String () Identity String
-> ParsecT
     String () Identity ([PrimitivePatPattern] -> PrimitivePatPattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
lowerName ParsecT
  String () Identity ([PrimitivePatPattern] -> PrimitivePatPattern)
-> ParsecT String () Identity [PrimitivePatPattern]
-> ParsecT String () Identity PrimitivePatPattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity PrimitivePatPattern
-> Parser () -> ParsecT String () Identity [PrimitivePatPattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity PrimitivePatPattern
ppPattern Parser ()
whiteSpace)

ppTuplePat :: Parser PrimitivePatPattern
ppTuplePat :: ParsecT String () Identity PrimitivePatPattern
ppTuplePat = ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity PrimitivePatPattern
 -> ParsecT String () Identity PrimitivePatPattern)
-> ParsecT String () Identity PrimitivePatPattern
-> ParsecT String () Identity PrimitivePatPattern
forall a b. (a -> b) -> a -> b
$ [PrimitivePatPattern] -> PrimitivePatPattern
PPTuplePat ([PrimitivePatPattern] -> PrimitivePatPattern)
-> ParsecT String () Identity [PrimitivePatPattern]
-> ParsecT String () Identity PrimitivePatPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity PrimitivePatPattern
-> Parser () -> ParsecT String () Identity [PrimitivePatPattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity PrimitivePatPattern
ppPattern Parser ()
whiteSpace

pdPattern :: Parser PrimitiveDataPattern
pdPattern :: ParsecT String () Identity PrimitiveDataPattern
pdPattern = GenTokenParser String () Identity
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer ParsecT String () Identity PrimitiveDataPattern
pdPattern'

pdPattern' :: Parser PrimitiveDataPattern
pdPattern' :: ParsecT String () Identity PrimitiveDataPattern
pdPattern' = String -> Parser ()
reservedOp String
"_" Parser ()
-> PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> PrimitiveDataPattern
forall var. PDPatternBase var
PDWildCard
                    ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> PrimitiveDataPattern
forall var. var -> PDPatternBase var
PDPatVar (String -> PrimitiveDataPattern)
-> ParsecT String () Identity String
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident)
                    ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall a. Parser a -> Parser a
braces ((PrimitiveDataPattern
-> PrimitiveDataPattern -> PrimitiveDataPattern
forall var.
PDPatternBase var -> PDPatternBase var -> PDPatternBase var
PDConsPat (PrimitiveDataPattern
 -> PrimitiveDataPattern -> PrimitiveDataPattern)
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT
     String () Identity (PrimitiveDataPattern -> PrimitiveDataPattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity PrimitiveDataPattern
pdPattern ParsecT
  String () Identity (PrimitiveDataPattern -> PrimitiveDataPattern)
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'@' ParsecT String () Identity Char
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT String () Identity PrimitiveDataPattern
pdPattern))
                            ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (PrimitiveDataPattern
-> PrimitiveDataPattern -> PrimitiveDataPattern
forall var.
PDPatternBase var -> PDPatternBase var -> PDPatternBase var
PDSnocPat (PrimitiveDataPattern
 -> PrimitiveDataPattern -> PrimitiveDataPattern)
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT
     String () Identity (PrimitiveDataPattern -> PrimitiveDataPattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'@' ParsecT String () Identity Char
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT String () Identity PrimitiveDataPattern
pdPattern) ParsecT
  String () Identity (PrimitiveDataPattern -> PrimitiveDataPattern)
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity PrimitiveDataPattern
pdPattern)
                            ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a. Applicative f => a -> f a
pure PrimitiveDataPattern
forall var. PDPatternBase var
PDEmptyPat)
                    ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall a. Parser a -> Parser a
angles (String -> [PrimitiveDataPattern] -> PrimitiveDataPattern
forall var. String -> [PDPatternBase var] -> PDPatternBase var
PDInductivePat (String -> [PrimitiveDataPattern] -> PrimitiveDataPattern)
-> ParsecT String () Identity String
-> ParsecT
     String () Identity ([PrimitiveDataPattern] -> PrimitiveDataPattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
upperName ParsecT
  String () Identity ([PrimitiveDataPattern] -> PrimitiveDataPattern)
-> ParsecT String () Identity [PrimitiveDataPattern]
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity PrimitiveDataPattern
-> Parser () -> ParsecT String () Identity [PrimitiveDataPattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity PrimitiveDataPattern
pdPattern Parser ()
whiteSpace)
                    ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall a. Parser a -> Parser a
brackets ([PrimitiveDataPattern] -> PrimitiveDataPattern
forall var. [PDPatternBase var] -> PDPatternBase var
PDTuplePat ([PrimitiveDataPattern] -> PrimitiveDataPattern)
-> ParsecT String () Identity [PrimitiveDataPattern]
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity PrimitiveDataPattern
-> Parser () -> ParsecT String () Identity [PrimitiveDataPattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity PrimitiveDataPattern
pdPattern Parser ()
whiteSpace)
                    ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ConstantExpr -> PrimitiveDataPattern
forall var. ConstantExpr -> PDPatternBase var
PDConstantPat (ConstantExpr -> PrimitiveDataPattern)
-> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity ConstantExpr
constantExpr
                    ParsecT String () Identity PrimitiveDataPattern
-> String -> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"primitive-data-pattern"

ifExpr :: Parser Expr
ifExpr :: ParsecT String () Identity Expr
ifExpr = Parser ()
keywordIf Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr -> Expr -> Expr
IfExpr (Expr -> Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

lambdaExpr :: Parser Expr
lambdaExpr :: ParsecT String () Identity Expr
lambdaExpr = Parser ()
keywordLambda Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Arg ArgPattern] -> Expr -> Expr
LambdaExpr ([Arg ArgPattern] -> Expr -> Expr)
-> ParsecT String () Identity [Arg ArgPattern]
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [Arg ArgPattern]
argNames ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

memoizedLambdaExpr :: Parser Expr
memoizedLambdaExpr :: ParsecT String () Identity Expr
memoizedLambdaExpr = Parser ()
keywordMemoizedLambda Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [String] -> Expr -> Expr
MemoizedLambdaExpr ([String] -> Expr -> Expr)
-> ParsecT String () Identity [String]
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [String]
varNames ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

memoizeFrame :: Parser [(Expr, Expr, Expr)]
memoizeFrame :: Parser [(Expr, Expr, Expr)]
memoizeFrame = Parser [(Expr, Expr, Expr)] -> Parser [(Expr, Expr, Expr)]
forall a. Parser a -> Parser a
braces (Parser [(Expr, Expr, Expr)] -> Parser [(Expr, Expr, Expr)])
-> Parser [(Expr, Expr, Expr)] -> Parser [(Expr, Expr, Expr)]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity (Expr, Expr, Expr)
-> Parser () -> Parser [(Expr, Expr, Expr)]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity (Expr, Expr, Expr)
memoizeBinding Parser ()
whiteSpace

memoizeBinding :: Parser (Expr, Expr, Expr)
memoizeBinding :: ParsecT String () Identity (Expr, Expr, Expr)
memoizeBinding = ParsecT String () Identity (Expr, Expr, Expr)
-> ParsecT String () Identity (Expr, Expr, Expr)
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity (Expr, Expr, Expr)
 -> ParsecT String () Identity (Expr, Expr, Expr))
-> ParsecT String () Identity (Expr, Expr, Expr)
-> ParsecT String () Identity (Expr, Expr, Expr)
forall a b. (a -> b) -> a -> b
$ (,,) (Expr -> Expr -> Expr -> (Expr, Expr, Expr))
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr -> (Expr, Expr, Expr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr -> (Expr, Expr, Expr))
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> (Expr, Expr, Expr))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> (Expr, Expr, Expr))
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr, Expr, Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

cambdaExpr :: Parser Expr
cambdaExpr :: ParsecT String () Identity Expr
cambdaExpr = Parser ()
keywordCambda Parser ()
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Expr -> Expr
CambdaExpr (String -> Expr -> Expr)
-> ParsecT String () Identity String
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

patternFunctionExpr :: Parser Expr
patternFunctionExpr :: ParsecT String () Identity Expr
patternFunctionExpr = Parser ()
keywordPatternFunction Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [String] -> Pattern -> Expr
PatternFunctionExpr ([String] -> Pattern -> Expr)
-> ParsecT String () Identity [String]
-> ParsecT String () Identity (Pattern -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [String]
varNames ParsecT String () Identity (Pattern -> Expr)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Pattern
pattern

letRecExpr :: Parser Expr
letRecExpr :: ParsecT String () Identity Expr
letRecExpr =  Parser ()
keywordLetRec Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [BindingExpr] -> Expr -> Expr
LetRecExpr ([BindingExpr] -> Expr -> Expr)
-> ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [BindingExpr]
bindings ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

letExpr :: Parser Expr
letExpr :: ParsecT String () Identity Expr
letExpr = Parser ()
keywordLet Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [BindingExpr] -> Expr -> Expr
LetRecExpr ([BindingExpr] -> Expr -> Expr)
-> ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [BindingExpr]
bindings ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

letStarExpr :: Parser Expr
letStarExpr :: ParsecT String () Identity Expr
letStarExpr = Parser ()
keywordLetStar Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [BindingExpr] -> Expr -> Expr
LetRecExpr ([BindingExpr] -> Expr -> Expr)
-> ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [BindingExpr]
bindings ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

withSymbolsExpr :: Parser Expr
withSymbolsExpr :: ParsecT String () Identity Expr
withSymbolsExpr = Parser ()
keywordWithSymbols Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [String] -> Expr -> Expr
WithSymbolsExpr ([String] -> Expr -> Expr)
-> ParsecT String () Identity [String]
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [String]
-> ParsecT String () Identity [String]
forall a. Parser a -> Parser a
braces (ParsecT String () Identity String
-> Parser () -> ParsecT String () Identity [String]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity String
ident Parser ()
whiteSpace) ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

doExpr :: Parser Expr
doExpr :: ParsecT String () Identity Expr
doExpr = Parser ()
keywordDo Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [BindingExpr] -> Expr -> Expr
DoExpr ([BindingExpr] -> Expr -> Expr)
-> ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [BindingExpr]
statements ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (String -> [Expr] -> Expr
makeApply String
"return" []) ParsecT String () Identity Expr
expr

statements :: Parser [BindingExpr]
statements :: ParsecT String () Identity [BindingExpr]
statements = ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity [BindingExpr]
forall a. Parser a -> Parser a
braces (ParsecT String () Identity [BindingExpr]
 -> ParsecT String () Identity [BindingExpr])
-> ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity [BindingExpr]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity BindingExpr
-> Parser () -> ParsecT String () Identity [BindingExpr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity BindingExpr
statement Parser ()
whiteSpace

statement :: Parser BindingExpr
statement :: ParsecT String () Identity BindingExpr
statement = ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity BindingExpr
binding
        ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
forall a. Parser a -> Parser a
brackets (PrimitiveDataPattern -> Expr -> BindingExpr
Bind ([PrimitiveDataPattern] -> PrimitiveDataPattern
forall var. [PDPatternBase var] -> PDPatternBase var
PDTuplePat []) (Expr -> BindingExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity BindingExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr))
        ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (PrimitiveDataPattern -> Expr -> BindingExpr
Bind ([PrimitiveDataPattern] -> PrimitiveDataPattern
forall var. [PDPatternBase var] -> PDPatternBase var
PDTuplePat []) (Expr -> BindingExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity BindingExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr)

bindings' :: Parser [(PrimitiveDataPattern, Expr)]
bindings' :: ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
bindings' = ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
forall a. Parser a -> Parser a
braces (ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
 -> ParsecT String () Identity [(PrimitiveDataPattern, Expr)])
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity (PrimitiveDataPattern, Expr)
-> Parser ()
-> ParsecT String () Identity [(PrimitiveDataPattern, Expr)]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity (PrimitiveDataPattern, Expr)
binding' Parser ()
whiteSpace

binding' :: Parser (PrimitiveDataPattern, Expr)
binding' :: ParsecT String () Identity (PrimitiveDataPattern, Expr)
binding' = ParsecT String () Identity (PrimitiveDataPattern, Expr)
-> ParsecT String () Identity (PrimitiveDataPattern, Expr)
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity (PrimitiveDataPattern, Expr)
 -> ParsecT String () Identity (PrimitiveDataPattern, Expr))
-> ParsecT String () Identity (PrimitiveDataPattern, Expr)
-> ParsecT String () Identity (PrimitiveDataPattern, Expr)
forall a b. (a -> b) -> a -> b
$ (,) (PrimitiveDataPattern -> Expr -> (PrimitiveDataPattern, Expr))
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT
     String () Identity (Expr -> (PrimitiveDataPattern, Expr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity PrimitiveDataPattern
varNames' ParsecT String () Identity (Expr -> (PrimitiveDataPattern, Expr))
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (PrimitiveDataPattern, Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

bindings :: Parser [BindingExpr]
bindings :: ParsecT String () Identity [BindingExpr]
bindings = ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity [BindingExpr]
forall a. Parser a -> Parser a
braces (ParsecT String () Identity [BindingExpr]
 -> ParsecT String () Identity [BindingExpr])
-> ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity [BindingExpr]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity BindingExpr
-> Parser () -> ParsecT String () Identity [BindingExpr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity BindingExpr
binding Parser ()
whiteSpace

binding :: Parser BindingExpr
binding :: ParsecT String () Identity BindingExpr
binding = ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity BindingExpr
 -> ParsecT String () Identity BindingExpr)
-> ParsecT String () Identity BindingExpr
-> ParsecT String () Identity BindingExpr
forall a b. (a -> b) -> a -> b
$ PrimitiveDataPattern -> Expr -> BindingExpr
Bind (PrimitiveDataPattern -> Expr -> BindingExpr)
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity (Expr -> BindingExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity PrimitiveDataPattern
varNames' ParsecT String () Identity (Expr -> BindingExpr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity BindingExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

varNames :: Parser [String]
varNames :: ParsecT String () Identity [String]
varNames = String -> [String]
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> [String])
-> ParsecT String () Identity String
-> ParsecT String () Identity [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity String
ident)
            ParsecT String () Identity [String]
-> ParsecT String () Identity [String]
-> ParsecT String () Identity [String]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity [String]
-> ParsecT String () Identity [String]
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity String
-> Parser () -> ParsecT String () Identity [String]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity String
ident) Parser ()
whiteSpace)

varNames' :: Parser PrimitiveDataPattern
varNames' :: ParsecT String () Identity PrimitiveDataPattern
varNames' = String -> PrimitiveDataPattern
forall var. var -> PDPatternBase var
PDPatVar (String -> PrimitiveDataPattern)
-> ParsecT String () Identity String
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity String
ident)
        ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
-> ParsecT String () Identity PrimitiveDataPattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [PrimitiveDataPattern] -> PrimitiveDataPattern
forall var. [PDPatternBase var] -> PDPatternBase var
PDTuplePat ([PrimitiveDataPattern] -> PrimitiveDataPattern)
-> ParsecT String () Identity [PrimitiveDataPattern]
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [PrimitiveDataPattern]
-> ParsecT String () Identity [PrimitiveDataPattern]
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity PrimitiveDataPattern
-> Parser () -> ParsecT String () Identity [PrimitiveDataPattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy (String -> PrimitiveDataPattern
forall var. var -> PDPatternBase var
PDPatVar (String -> PrimitiveDataPattern)
-> ParsecT String () Identity String
-> ParsecT String () Identity PrimitiveDataPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity String
ident)) Parser ()
whiteSpace)

argNames :: Parser [Arg ArgPattern]
argNames :: ParsecT String () Identity [Arg ArgPattern]
argNames = Arg ArgPattern -> [Arg ArgPattern]
forall (m :: * -> *) a. Monad m => a -> m a
return (Arg ArgPattern -> [Arg ArgPattern])
-> ParsecT String () Identity (Arg ArgPattern)
-> ParsecT String () Identity [Arg ArgPattern]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity (Arg ArgPattern)
argName
            ParsecT String () Identity [Arg ArgPattern]
-> ParsecT String () Identity [Arg ArgPattern]
-> ParsecT String () Identity [Arg ArgPattern]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity [Arg ArgPattern]
-> ParsecT String () Identity [Arg ArgPattern]
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity (Arg ArgPattern)
-> Parser () -> ParsecT String () Identity [Arg ArgPattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity (Arg ArgPattern)
argName Parser ()
whiteSpace)

argName :: Parser (Arg ArgPattern)
argName :: ParsecT String () Identity (Arg ArgPattern)
argName = ParsecT String () Identity (Arg ArgPattern)
-> ParsecT String () Identity (Arg ArgPattern)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ArgPattern -> Arg ArgPattern
forall a. a -> Arg a
ScalarArg (ArgPattern -> Arg ArgPattern)
-> ParsecT String () Identity ArgPattern
-> ParsecT String () Identity (Arg ArgPattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity ArgPattern
-> ParsecT String () Identity ArgPattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity ArgPattern
argPattern))
      ParsecT String () Identity (Arg ArgPattern)
-> ParsecT String () Identity (Arg ArgPattern)
-> ParsecT String () Identity (Arg ArgPattern)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (Arg ArgPattern)
-> ParsecT String () Identity (Arg ArgPattern)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ArgPattern -> Arg ArgPattern
forall a. a -> Arg a
InvertedScalarArg (ArgPattern -> Arg ArgPattern)
-> ParsecT String () Identity ArgPattern
-> ParsecT String () Identity (Arg ArgPattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"*$" ParsecT String () Identity String
-> ParsecT String () Identity ArgPattern
-> ParsecT String () Identity ArgPattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity ArgPattern
argPattern))
      ParsecT String () Identity (Arg ArgPattern)
-> ParsecT String () Identity (Arg ArgPattern)
-> ParsecT String () Identity (Arg ArgPattern)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (Arg ArgPattern)
-> ParsecT String () Identity (Arg ArgPattern)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ArgPattern -> Arg ArgPattern
forall a. a -> Arg a
TensorArg (ArgPattern -> Arg ArgPattern)
-> ParsecT String () Identity ArgPattern
-> ParsecT String () Identity (Arg ArgPattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'%' ParsecT String () Identity Char
-> ParsecT String () Identity ArgPattern
-> ParsecT String () Identity ArgPattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity ArgPattern
argPattern))

argPattern :: Parser ArgPattern
argPattern :: ParsecT String () Identity ArgPattern
argPattern = VarWithIndices -> ArgPattern
APPatVar (VarWithIndices -> ArgPattern)
-> ParsecT String () Identity VarWithIndices
-> ParsecT String () Identity ArgPattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity VarWithIndices
identVarWithIndices

seqExpr :: Parser Expr
seqExpr :: ParsecT String () Identity Expr
seqExpr = Parser ()
keywordSeq Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr -> Expr
SeqExpr (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

cApplyExpr :: Parser Expr
cApplyExpr :: ParsecT String () Identity Expr
cApplyExpr = Parser ()
keywordCApply Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr -> Expr
CApplyExpr (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

applyExpr :: Parser Expr
applyExpr :: ParsecT String () Identity Expr
applyExpr = do
  Expr
func <- ParsecT String () Identity Expr
expr
  [Either String Expr]
args <- ParsecT String () Identity (Either String Expr)
-> Parser () -> ParsecT String () Identity [Either String Expr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity (Either String Expr)
arg Parser ()
whiteSpace
  let vars :: [String]
vars = [Either String Expr] -> [String]
forall a b. [Either a b] -> [a]
lefts [Either String Expr]
args
  case [String]
vars of
    [] -> Expr -> ParsecT String () Identity Expr
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> ParsecT String () Identity Expr)
-> Expr -> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ Expr -> [Expr] -> Expr
ApplyExpr Expr
func ([Either String Expr] -> [Expr]
forall a b. [Either a b] -> [b]
rights [Either String Expr]
args)
    [String]
_ | (String -> Bool) -> [String] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
vars ->
        let n :: Integer
n = Int -> Integer
forall a. Integral a => a -> Integer
toInteger ([String] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [String]
vars)
            args' :: [Expr]
args' = [Either String Expr] -> Integer -> [Expr]
forall a. [Either a Expr] -> Integer -> [Expr]
f [Either String Expr]
args Integer
1
         in Expr -> ParsecT String () Identity Expr
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> ParsecT String () Identity Expr)
-> Expr -> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ Integer -> Expr -> Expr
AnonParamFuncExpr Integer
n (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ Expr -> [Expr] -> Expr
ApplyExpr Expr
func [Expr]
args'
      | Bool -> Bool
not ((String -> Bool) -> [String] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
vars) ->
        let ns :: Set Int
ns = [Int] -> Set Int
forall a. Ord a => [a] -> Set a
Set.fromList ([Int] -> Set Int) -> [Int] -> Set Int
forall a b. (a -> b) -> a -> b
$ (String -> Int) -> [String] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map String -> Int
forall a. Read a => String -> a
read [String]
vars
            n :: Int
n = Set Int -> Int
forall a. Set a -> Int
Set.size Set Int
ns
        in if Set Int -> Int
forall a. Set a -> a
Set.findMin Set Int
ns Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 Bool -> Bool -> Bool
&& Set Int -> Int
forall a. Set a -> a
Set.findMax Set Int
ns Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n
             then
               let args' :: [Expr]
args' = (Either String Expr -> Expr) -> [Either String Expr] -> [Expr]
forall a b. (a -> b) -> [a] -> [b]
map Either String Expr -> Expr
g [Either String Expr]
args
                in Expr -> ParsecT String () Identity Expr
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> ParsecT String () Identity Expr)
-> Expr -> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ Integer -> Expr -> Expr
AnonParamFuncExpr (Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
n) (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ Expr -> [Expr] -> Expr
ApplyExpr Expr
func [Expr]
args'
             else String -> ParsecT String () Identity Expr
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid anonymous parameter function"
      | Bool
otherwise -> String -> ParsecT String () Identity Expr
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid anonymous parameter function"
 where
  arg :: ParsecT String () Identity (Either String Expr)
arg = ParsecT String () Identity (Either String Expr)
-> ParsecT String () Identity (Either String Expr)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> Either String Expr
forall a b. b -> Either a b
Right (Expr -> Either String Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Either String Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr)
         ParsecT String () Identity (Either String Expr)
-> ParsecT String () Identity (Either String Expr)
-> ParsecT String () Identity (Either String Expr)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity (Either String Expr)
-> ParsecT String () Identity (Either String Expr)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (String -> Either String Expr
forall a b. a -> Either a b
Left (String -> Either String Expr)
-> ParsecT String () Identity String
-> ParsecT String () Identity (Either String Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option String
"" ParsecT String () Identity String
forall u. ParsecT String u Identity String
index)
  index :: ParsecT String u Identity String
index = (:) (Char -> String -> String)
-> ParsecT String u Identity Char
-> ParsecT String u Identity (String -> String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> Bool) -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
c -> Char
'1' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'9') ParsecT String u Identity (String -> String)
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String u Identity Char -> ParsecT String u Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit
  f :: [Either a Expr] -> Integer -> [Expr]
f [] Integer
_                  = []
  f (Left a
_ : [Either a Expr]
args) Integer
n     = Integer -> Expr
AnonParamExpr Integer
n Expr -> [Expr] -> [Expr]
forall a. a -> [a] -> [a]
: [Either a Expr] -> Integer -> [Expr]
f [Either a Expr]
args (Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
1)
  f (Right Expr
expr : [Either a Expr]
args) Integer
n = Expr
expr Expr -> [Expr] -> [Expr]
forall a. a -> [a] -> [a]
: [Either a Expr] -> Integer -> [Expr]
f [Either a Expr]
args Integer
n
  g :: Either String Expr -> Expr
g (Left String
arg)   = Integer -> Expr
AnonParamExpr (String -> Integer
forall a. Read a => String -> a
read String
arg)
  g (Right Expr
expr) = Expr
expr

anonParamFuncExpr :: Parser Expr
anonParamFuncExpr :: ParsecT String () Identity Expr
anonParamFuncExpr = (Integer -> Expr -> Expr
AnonParamFuncExpr (Integer -> Expr -> Expr)
-> (String -> Integer) -> String -> Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Integer
forall a. Read a => String -> a
read (String -> Expr -> Expr)
-> ParsecT String () Identity String
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
forall u. ParsecT String u Identity String
index) ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'#' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr)
 where
  index :: ParsecT String u Identity String
index = (:) (Char -> String -> String)
-> ParsecT String u Identity Char
-> ParsecT String u Identity (String -> String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> Bool) -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
c -> Char
'1' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'9') ParsecT String u Identity (String -> String)
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String u Identity Char -> ParsecT String u Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit

anonParamExpr :: Parser Expr
anonParamExpr :: ParsecT String () Identity Expr
anonParamExpr = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'%' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Integer -> Expr
AnonParamExpr (Integer -> Expr)
-> ParsecT String () Identity Integer
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Integer
integerLiteral

algebraicDataMatcherExpr :: Parser Expr
algebraicDataMatcherExpr :: ParsecT String () Identity Expr
algebraicDataMatcherExpr = Parser ()
keywordAlgebraicDataMatcher
                                Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall a. Parser a -> Parser a
braces ([(String, [Expr])] -> Expr
AlgebraicDataMatcherExpr ([(String, [Expr])] -> Expr)
-> ParsecT String () Identity [(String, [Expr])]
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity (String, [Expr])
-> Parser () -> ParsecT String () Identity [(String, [Expr])]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy1 ParsecT String () Identity (String, [Expr])
inductivePat' Parser ()
whiteSpace)
  where
    inductivePat' :: Parser (String, [Expr])
    inductivePat' :: ParsecT String () Identity (String, [Expr])
inductivePat' = ParsecT String () Identity (String, [Expr])
-> ParsecT String () Identity (String, [Expr])
forall a. Parser a -> Parser a
angles (ParsecT String () Identity (String, [Expr])
 -> ParsecT String () Identity (String, [Expr]))
-> ParsecT String () Identity (String, [Expr])
-> ParsecT String () Identity (String, [Expr])
forall a b. (a -> b) -> a -> b
$ (,) (String -> [Expr] -> (String, [Expr]))
-> ParsecT String () Identity String
-> ParsecT String () Identity ([Expr] -> (String, [Expr]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
lowerName ParsecT String () Identity ([Expr] -> (String, [Expr]))
-> Parser [Expr] -> ParsecT String () Identity (String, [Expr])
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr -> Parser () -> Parser [Expr]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Expr
expr Parser ()
whiteSpace

generateTensorExpr :: Parser Expr
generateTensorExpr :: ParsecT String () Identity Expr
generateTensorExpr = Parser ()
keywordGenerateTensor Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr -> Expr
GenerateTensorExpr (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

tensorExpr :: Parser Expr
tensorExpr :: ParsecT String () Identity Expr
tensorExpr = Parser ()
keywordTensor Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr -> Expr
TensorExpr (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

tensorContractExpr :: Parser Expr
tensorContractExpr :: ParsecT String () Identity Expr
tensorContractExpr = Parser ()
keywordTensorContract Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr
TensorContractExpr (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr

tensorMapExpr :: Parser Expr
tensorMapExpr :: ParsecT String () Identity Expr
tensorMapExpr = Parser ()
keywordTensorMap Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr -> Expr
TensorMapExpr (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

tensorMap2Expr :: Parser Expr
tensorMap2Expr :: ParsecT String () Identity Expr
tensorMap2Expr = Parser ()
keywordTensorMap2 Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr -> Expr -> Expr
TensorMap2Expr (Expr -> Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

transposeExpr :: Parser Expr
transposeExpr :: ParsecT String () Identity Expr
transposeExpr = Parser ()
keywordTranspose Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Expr -> Expr
TransposeExpr (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr

subrefsExpr :: Parser Expr
subrefsExpr :: ParsecT String () Identity Expr
subrefsExpr = (Parser ()
keywordSubrefs Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Expr -> Expr -> Expr
SubrefsExpr Bool
False (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr)
               ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Parser ()
keywordSubrefsNew Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Expr -> Expr -> Expr
SubrefsExpr Bool
True (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr)

suprefsExpr :: Parser Expr
suprefsExpr :: ParsecT String () Identity Expr
suprefsExpr = (Parser ()
keywordSuprefs Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Expr -> Expr -> Expr
SuprefsExpr Bool
False (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr)
               ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Parser ()
keywordSuprefsNew Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Expr -> Expr -> Expr
SuprefsExpr Bool
True (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr)

userrefsExpr :: Parser Expr
userrefsExpr :: ParsecT String () Identity Expr
userrefsExpr = (Parser ()
keywordUserrefs Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Expr -> Expr -> Expr
UserrefsExpr Bool
False (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr)
                ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Parser ()
keywordUserrefsNew Parser ()
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Expr -> Expr -> Expr
UserrefsExpr Bool
True (Expr -> Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr)

-- Patterns

pattern :: Parser Pattern
pattern :: ParsecT String () Identity Pattern
pattern = GenTokenParser String () Identity
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer (do Pattern
pattern <- ParsecT String () Identity Pattern
pattern'
                             Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Pattern
pattern (ParsecT String () Identity Pattern
 -> ParsecT String () Identity Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ Pattern -> [Expr] -> Pattern
IndexedPat Pattern
pattern ([Expr] -> Pattern)
-> Parser [Expr] -> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr -> Parser [Expr]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String () Identity Expr -> ParsecT String () Identity Expr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity Expr
 -> ParsecT String () Identity Expr)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'_' ParsecT String () Identity Char
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Expr
expr'))

pattern' :: Parser Pattern
pattern' :: ParsecT String () Identity Pattern
pattern' = ParsecT String () Identity Pattern
wildCard
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
contPat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
patVar
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
varPat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
valuePat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
predPat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
notPat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
tuplePat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
inductivePat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
laterPatVar
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Pattern
seqNilPat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Pattern
seqConsPat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Pattern
seqPat
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a. Parser a -> Parser a
parens (ParsecT String () Identity Pattern
andPat
                    ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
notPat'
                    ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
orPat
                    ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
loopPat
                    ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
letPat
                    ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Pattern
dApplyPat
                    ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity Pattern
pApplyPat
                    )

pattern'' :: Parser Pattern
pattern'' :: ParsecT String () Identity Pattern
pattern'' = ParsecT String () Identity Pattern
wildCard
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
patVar
            ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Pattern
valuePat

wildCard :: Parser Pattern
wildCard :: ParsecT String () Identity Pattern
wildCard = String -> Parser ()
reservedOp String
"_" Parser ()
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pattern -> ParsecT String () Identity Pattern
forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern
WildCard

patVar :: Parser Pattern
patVar :: ParsecT String () Identity Pattern
patVar = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Pattern
PatVar (String -> Pattern)
-> ParsecT String () Identity String
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident

varPat :: Parser Pattern
varPat :: ParsecT String () Identity Pattern
varPat = String -> Pattern
VarPat (String -> Pattern)
-> ParsecT String () Identity String
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident

valuePat :: Parser Pattern
valuePat :: ParsecT String () Identity Pattern
valuePat = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
',' ParsecT String () Identity Char
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Pattern
ValuePat (Expr -> Pattern)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr

predPat :: Parser Pattern
predPat :: ParsecT String () Identity Pattern
predPat = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'?' ParsecT String () Identity Char
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Pattern
PredPat (Expr -> Pattern)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr

letPat :: Parser Pattern
letPat :: ParsecT String () Identity Pattern
letPat = Parser ()
keywordLet Parser ()
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [BindingExpr] -> Pattern -> Pattern
LetPat ([BindingExpr] -> Pattern -> Pattern)
-> ParsecT String () Identity [BindingExpr]
-> ParsecT String () Identity (Pattern -> Pattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity [BindingExpr]
bindings ParsecT String () Identity (Pattern -> Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Pattern
pattern

notPat :: Parser Pattern
notPat :: ParsecT String () Identity Pattern
notPat = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'!' ParsecT String () Identity Char
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pattern -> Pattern
NotPat (Pattern -> Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Pattern
pattern

notPat' :: Parser Pattern
notPat' :: ParsecT String () Identity Pattern
notPat' = Parser ()
keywordNot Parser ()
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pattern -> Pattern
NotPat (Pattern -> Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Pattern
pattern

tuplePat :: Parser Pattern
tuplePat :: ParsecT String () Identity Pattern
tuplePat = ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity Pattern
 -> ParsecT String () Identity Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ [Pattern] -> Pattern
TuplePat ([Pattern] -> Pattern)
-> ParsecT String () Identity [Pattern]
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Pattern
-> Parser () -> ParsecT String () Identity [Pattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Pattern
pattern Parser ()
whiteSpace

inductivePat :: Parser Pattern
inductivePat :: ParsecT String () Identity Pattern
inductivePat = ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a. Parser a -> Parser a
angles (ParsecT String () Identity Pattern
 -> ParsecT String () Identity Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ String -> [Pattern] -> Pattern
InductivePat (String -> [Pattern] -> Pattern)
-> ParsecT String () Identity String
-> ParsecT String () Identity ([Pattern] -> Pattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
lowerName ParsecT String () Identity ([Pattern] -> Pattern)
-> ParsecT String () Identity [Pattern]
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Pattern
-> Parser () -> ParsecT String () Identity [Pattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Pattern
pattern Parser ()
whiteSpace

contPat :: Parser Pattern
contPat :: ParsecT String () Identity Pattern
contPat = Parser ()
keywordCont Parser ()
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pattern -> ParsecT String () Identity Pattern
forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern
ContPat

andPat :: Parser Pattern
andPat :: ParsecT String () Identity Pattern
andPat = do
  [Pattern]
pats <- (String -> Parser ()
reservedOp String
"&" Parser () -> Parser () -> Parser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser ()
keywordAnd) Parser ()
-> ParsecT String () Identity [Pattern]
-> ParsecT String () Identity [Pattern]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Pattern
-> Parser () -> ParsecT String () Identity [Pattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Pattern
pattern Parser ()
whiteSpace
  case [Pattern]
pats of
    [] -> Pattern -> ParsecT String () Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return Pattern
WildCard
    [Pattern]
_  -> Pattern -> ParsecT String () Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> ParsecT String () Identity Pattern)
-> Pattern -> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ (Pattern -> Pattern -> Pattern) -> [Pattern] -> Pattern
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 Pattern -> Pattern -> Pattern
AndPat [Pattern]
pats

orPat :: Parser Pattern
orPat :: ParsecT String () Identity Pattern
orPat = do
  [Pattern]
pats <- (String -> Parser ()
reservedOp String
"|" Parser () -> Parser () -> Parser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser ()
keywordOr) Parser ()
-> ParsecT String () Identity [Pattern]
-> ParsecT String () Identity [Pattern]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Pattern
-> Parser () -> ParsecT String () Identity [Pattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Pattern
pattern Parser ()
whiteSpace
  case [Pattern]
pats of
    [] -> Pattern -> ParsecT String () Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> Pattern
NotPat Pattern
WildCard)
    [Pattern]
_  -> Pattern -> ParsecT String () Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> ParsecT String () Identity Pattern)
-> Pattern -> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ (Pattern -> Pattern -> Pattern) -> [Pattern] -> Pattern
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 Pattern -> Pattern -> Pattern
OrPat [Pattern]
pats

pApplyPat :: Parser Pattern
pApplyPat :: ParsecT String () Identity Pattern
pApplyPat = Expr -> [Pattern] -> Pattern
PApplyPat (Expr -> [Pattern] -> Pattern)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity ([Pattern] -> Pattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity ([Pattern] -> Pattern)
-> ParsecT String () Identity [Pattern]
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Pattern
-> Parser () -> ParsecT String () Identity [Pattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Pattern
pattern Parser ()
whiteSpace

dApplyPat :: Parser Pattern
dApplyPat :: ParsecT String () Identity Pattern
dApplyPat = Pattern -> [Pattern] -> Pattern
DApplyPat (Pattern -> [Pattern] -> Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity ([Pattern] -> Pattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Pattern
pattern'' ParsecT String () Identity ([Pattern] -> Pattern)
-> ParsecT String () Identity [Pattern]
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Pattern
-> Parser () -> ParsecT String () Identity [Pattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Pattern
pattern Parser ()
whiteSpace

loopPat :: Parser Pattern
loopPat :: ParsecT String () Identity Pattern
loopPat = Parser ()
keywordLoop Parser ()
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'$' ParsecT String () Identity Char
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> LoopRange -> Pattern -> Pattern -> Pattern
LoopPat (String -> LoopRange -> Pattern -> Pattern -> Pattern)
-> ParsecT String () Identity String
-> ParsecT
     String () Identity (LoopRange -> Pattern -> Pattern -> Pattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident ParsecT
  String () Identity (LoopRange -> Pattern -> Pattern -> Pattern)
-> ParsecT String () Identity LoopRange
-> ParsecT String () Identity (Pattern -> Pattern -> Pattern)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity LoopRange
loopRange ParsecT String () Identity (Pattern -> Pattern -> Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity (Pattern -> Pattern)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Pattern
pattern ParsecT String () Identity (Pattern -> Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Pattern -> Pattern
NotPat Pattern
WildCard) ParsecT String () Identity Pattern
pattern

loopRange :: Parser LoopRange
loopRange :: ParsecT String () Identity LoopRange
loopRange = ParsecT String () Identity LoopRange
-> ParsecT String () Identity LoopRange
forall a. Parser a -> Parser a
brackets (ParsecT String () Identity LoopRange
-> ParsecT String () Identity LoopRange
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Expr -> Expr -> Pattern -> LoopRange
LoopRange (Expr -> Expr -> Pattern -> LoopRange)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Expr -> Pattern -> LoopRange)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Expr
expr ParsecT String () Identity (Expr -> Pattern -> LoopRange)
-> ParsecT String () Identity Expr
-> ParsecT String () Identity (Pattern -> LoopRange)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT String () Identity Expr
expr ParsecT String () Identity (Pattern -> LoopRange)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity LoopRange
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Pattern
WildCard ParsecT String () Identity Pattern
pattern)
                      ParsecT String () Identity LoopRange
-> ParsecT String () Identity LoopRange
-> ParsecT String () Identity LoopRange
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (do Expr
s <- ParsecT String () Identity Expr
expr
                              Pattern
ep <- Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Pattern
WildCard ParsecT String () Identity Pattern
pattern
                              LoopRange -> ParsecT String () Identity LoopRange
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> Expr -> Pattern -> LoopRange
LoopRange Expr
s (String -> [Expr] -> Expr
makeApply String
"from" [String -> [Expr] -> Expr
makeApply String
"-'" [Expr
s, ConstantExpr -> Expr
ConstantExpr (Integer -> ConstantExpr
IntegerExpr Integer
1)]]) Pattern
ep)))

seqNilPat :: Parser Pattern
seqNilPat :: ParsecT String () Identity Pattern
seqNilPat = ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a. Parser a -> Parser a
braces (ParsecT String () Identity Pattern
 -> ParsecT String () Identity Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ Pattern -> ParsecT String () Identity Pattern
forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern
SeqNilPat

seqConsPat :: Parser Pattern
seqConsPat :: ParsecT String () Identity Pattern
seqConsPat = ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a. Parser a -> Parser a
braces (ParsecT String () Identity Pattern
 -> ParsecT String () Identity Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ Pattern -> Pattern -> Pattern
SeqConsPat (Pattern -> Pattern -> Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity (Pattern -> Pattern)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Pattern
pattern ParsecT String () Identity (Pattern -> Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'@' ParsecT String () Identity Char
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Pattern
pattern)

seqPat :: Parser Pattern
seqPat :: ParsecT String () Identity Pattern
seqPat = ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a. Parser a -> Parser a
braces (ParsecT String () Identity Pattern
 -> ParsecT String () Identity Pattern)
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ do
  [Pattern]
pats <- ParsecT String () Identity Pattern
-> Parser () -> ParsecT String () Identity [Pattern]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy ParsecT String () Identity Pattern
pattern Parser ()
whiteSpace
  Pattern
tailPat <- Pattern
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Pattern
SeqNilPat (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'@' ParsecT String () Identity Char
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Pattern
pattern)
  Pattern -> ParsecT String () Identity Pattern
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern -> ParsecT String () Identity Pattern)
-> Pattern -> ParsecT String () Identity Pattern
forall a b. (a -> b) -> a -> b
$ (Pattern -> Pattern -> Pattern) -> Pattern -> [Pattern] -> Pattern
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Pattern -> Pattern -> Pattern
SeqConsPat Pattern
tailPat [Pattern]
pats

laterPatVar :: Parser Pattern
laterPatVar :: ParsecT String () Identity Pattern
laterPatVar = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'#' ParsecT String () Identity Char
-> ParsecT String () Identity Pattern
-> ParsecT String () Identity Pattern
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pattern -> ParsecT String () Identity Pattern
forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern
LaterPatVar

-- Constants

constantExpr :: Parser ConstantExpr
constantExpr :: ParsecT String () Identity ConstantExpr
constantExpr = Text -> ConstantExpr
StringExpr (Text -> ConstantExpr)
-> (String -> Text) -> String -> ConstantExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> ConstantExpr)
-> ParsecT String () Identity String
-> ParsecT String () Identity ConstantExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
stringLiteral
                 ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ConstantExpr
BoolExpr (Bool -> ConstantExpr)
-> ParsecT String () Identity Bool
-> ParsecT String () Identity ConstantExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Bool
boolLiteral
                 ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ConstantExpr
CharExpr (Char -> ConstantExpr)
-> ParsecT String () Identity Char
-> ParsecT String () Identity ConstantExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Char
oneChar)
                 ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Double -> ConstantExpr
FloatExpr (Double -> ConstantExpr)
-> ParsecT String () Identity Double
-> ParsecT String () Identity ConstantExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Double
positiveFloatLiteral)
                 ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Integer -> ConstantExpr
IntegerExpr (Integer -> ConstantExpr)
-> ParsecT String () Identity Integer
-> ParsecT String () Identity ConstantExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Integer
integerLiteral)
                 ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Parser ()
keywordSomething Parser ()
-> ConstantExpr -> ParsecT String () Identity ConstantExpr
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ConstantExpr
SomethingExpr)
                 ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
-> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Parser ()
keywordUndefined Parser ()
-> ConstantExpr -> ParsecT String () Identity ConstantExpr
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ConstantExpr
UndefinedExpr)
                 ParsecT String () Identity ConstantExpr
-> String -> ParsecT String () Identity ConstantExpr
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"constant"

positiveFloatLiteral :: Parser Double
positiveFloatLiteral :: ParsecT String () Identity Double
positiveFloatLiteral = do
  Integer
n <- ParsecT String () Identity Integer
integerLiteral
  Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'.'
  String
mStr <- ParsecT String () Identity Char
-> ParsecT String () Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit
  let m :: Integer
m = String -> Integer
forall a. Read a => String -> a
read String
mStr
  let l :: Ratio Integer
l = Integer
m Integer -> Integer -> Ratio Integer
forall a. Integral a => a -> a -> Ratio a
% (Integer
10 Integer -> Integer -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
mStr))
  if Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0 then Double -> ParsecT String () Identity Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Ratio Integer -> Double
forall a. Fractional a => Ratio Integer -> a
fromRational (Integer -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
- Ratio Integer
l) :: Double)
           else Double -> ParsecT String () Identity Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Ratio Integer -> Double
forall a. Fractional a => Ratio Integer -> a
fromRational (Integer -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
+ Ratio Integer
l) :: Double)

--
-- Tokens
--

egisonDef :: P.GenLanguageDef String () Identity
egisonDef :: GenLanguageDef String () Identity
egisonDef =
  LanguageDef :: forall s u (m :: * -> *).
String
-> String
-> String
-> Bool
-> ParsecT s u m Char
-> ParsecT s u m Char
-> ParsecT s u m Char
-> ParsecT s u m Char
-> [String]
-> [String]
-> Bool
-> GenLanguageDef s u m
P.LanguageDef { commentStart :: String
P.commentStart       = String
"#|"
                , commentEnd :: String
P.commentEnd         = String
"|#"
                , commentLine :: String
P.commentLine        = String
";"
                , identStart :: ParsecT String () Identity Char
P.identStart         = ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Char
forall u. ParsecT String u Identity Char
symbol1 ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Char
forall u. ParsecT String u Identity Char
symbol0
                , identLetter :: ParsecT String () Identity Char
P.identLetter        = ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Char
forall u. ParsecT String u Identity Char
symbol2
                , opStart :: ParsecT String () Identity Char
P.opStart            = ParsecT String () Identity Char
forall u. ParsecT String u Identity Char
symbol1
                , opLetter :: ParsecT String () Identity Char
P.opLetter           = ParsecT String () Identity Char
forall u. ParsecT String u Identity Char
symbol1
                , reservedNames :: [String]
P.reservedNames      = [String]
reservedKeywords
                , reservedOpNames :: [String]
P.reservedOpNames    = [String]
reservedOperators
                , nestedComments :: Bool
P.nestedComments     = Bool
True
                , caseSensitive :: Bool
P.caseSensitive      = Bool
True }

symbol0 :: ParsecT String u Identity Char
symbol0 = Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'^'
-- Don't allow three consecutive dots to be a part of identifier
symbol1 :: ParsecT String u Identity Char
symbol1 = String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"+-*/=∂∇" ParsecT String u Identity Char
-> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'.' ParsecT String u Identity Char
-> ParsecT String u Identity () -> ParsecT String u Identity Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT String u Identity String -> ParsecT String u Identity ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
".."))
symbol2 :: ParsecT String u Identity Char
symbol2 = ParsecT String u Identity Char
forall u. ParsecT String u Identity Char
symbol1 ParsecT String u Identity Char
-> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"'!?₀₁₂₃₄₅₆₇₈₉"

lexer :: P.GenTokenParser String () Identity
lexer :: GenTokenParser String () Identity
lexer = GenLanguageDef String () Identity
-> GenTokenParser String () Identity
forall s (m :: * -> *) u.
Stream s m Char =>
GenLanguageDef s u m -> GenTokenParser s u m
P.makeTokenParser GenLanguageDef String () Identity
egisonDef

reservedKeywords :: [String]
reservedKeywords :: [String]
reservedKeywords =
  [ String
"define"
  , String
"set!"
  , String
"test"
  , String
"execute"
  , String
"load-file"
  , String
"load"
  , String
"if"
  , String
"seq"
  , String
"capply"
  , String
"lambda"
  , String
"memoized-lambda"
  , String
"memoize"
  , String
"cambda"
  , String
"pattern-function"
  , String
"letrec"
  , String
"let"
  , String
"let*"
  , String
"with-symbols"
--  , "not"
--  , "and"
--  , "or"
  , String
"loop"
  , String
"match-all"
  , String
"match"
  , String
"match-all-dfs"
  , String
"match-dfs"
  , String
"match-all-lambda"
  , String
"match-lambda"
  , String
"matcher"
  , String
"do"
  , String
"algebraic-data-matcher"
  , String
"generate-tensor"
  , String
"tensor"
  , String
"contract"
  , String
"tensor-map"
  , String
"tensor-map2"
  , String
"transpose"
  , String
"subrefs"
  , String
"subrefs!"
  , String
"suprefs"
  , String
"suprefs!"
  , String
"user-refs"
  , String
"user-refs!"
  , String
"function"
  , String
"something"
  , String
"undefined"]

reservedOperators :: [String]
reservedOperators :: [String]
reservedOperators =
  [ String
"$"
  , String
",$"
  , String
"_"
  , String
"^"
  , String
"&"
  , String
"|*"
--  , "'"
--  , "~"
--  , "!"
--  , ","
--  , "@"
  , String
"..."]

reserved :: String -> Parser ()
reserved :: String -> Parser ()
reserved = GenTokenParser String () Identity -> String -> Parser ()
forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
P.reserved GenTokenParser String () Identity
lexer

reservedOp :: String -> Parser ()
reservedOp :: String -> Parser ()
reservedOp = GenTokenParser String () Identity -> String -> Parser ()
forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
P.reservedOp GenTokenParser String () Identity
lexer

keywordDefine :: Parser ()
keywordDefine               = String -> Parser ()
reserved String
"define"
keywordSet :: Parser ()
keywordSet                  = String -> Parser ()
reserved String
"set!"
keywordTest :: Parser ()
keywordTest                 = String -> Parser ()
reserved String
"test"
keywordExecute :: Parser ()
keywordExecute              = String -> Parser ()
reserved String
"execute"
keywordLoadFile :: Parser ()
keywordLoadFile             = String -> Parser ()
reserved String
"load-file"
keywordLoad :: Parser ()
keywordLoad                 = String -> Parser ()
reserved String
"load"
keywordIf :: Parser ()
keywordIf                   = String -> Parser ()
reserved String
"if"
keywordNot :: Parser ()
keywordNot                  = String -> Parser ()
reserved String
"not"
keywordAnd :: Parser ()
keywordAnd                  = String -> Parser ()
reserved String
"and"
keywordOr :: Parser ()
keywordOr                   = String -> Parser ()
reserved String
"or"
keywordSeq :: Parser ()
keywordSeq                  = String -> Parser ()
reserved String
"seq"
keywordCApply :: Parser ()
keywordCApply               = String -> Parser ()
reserved String
"capply"
keywordLambda :: Parser ()
keywordLambda               = String -> Parser ()
reserved String
"lambda"
keywordMemoizedLambda :: Parser ()
keywordMemoizedLambda       = String -> Parser ()
reserved String
"memoized-lambda"
keywordMemoize :: Parser ()
keywordMemoize              = String -> Parser ()
reserved String
"memoize"
keywordCambda :: Parser ()
keywordCambda               = String -> Parser ()
reserved String
"cambda"
keywordPatternFunction :: Parser ()
keywordPatternFunction      = String -> Parser ()
reserved String
"pattern-function"
keywordLetRec :: Parser ()
keywordLetRec               = String -> Parser ()
reserved String
"letrec"
keywordLet :: Parser ()
keywordLet                  = String -> Parser ()
reserved String
"let"
keywordLetStar :: Parser ()
keywordLetStar              = String -> Parser ()
reserved String
"let*"
keywordWithSymbols :: Parser ()
keywordWithSymbols          = String -> Parser ()
reserved String
"with-symbols"
keywordLoop :: Parser ()
keywordLoop                 = String -> Parser ()
reserved String
"loop"
keywordCont :: Parser ()
keywordCont                 = String -> Parser ()
reserved String
"..."
keywordMatchAll :: Parser ()
keywordMatchAll             = String -> Parser ()
reserved String
"match-all"
keywordMatchAllDFS :: Parser ()
keywordMatchAllDFS          = String -> Parser ()
reserved String
"match-all-dfs"
keywordMatchAllLambda :: Parser ()
keywordMatchAllLambda       = String -> Parser ()
reserved String
"match-all-lambda"
keywordMatch :: Parser ()
keywordMatch                = String -> Parser ()
reserved String
"match"
keywordMatchDFS :: Parser ()
keywordMatchDFS             = String -> Parser ()
reserved String
"match-dfs"
keywordMatchLambda :: Parser ()
keywordMatchLambda          = String -> Parser ()
reserved String
"match-lambda"
keywordMatcher :: Parser ()
keywordMatcher              = String -> Parser ()
reserved String
"matcher"
keywordDo :: Parser ()
keywordDo                   = String -> Parser ()
reserved String
"do"
keywordIo :: Parser ()
keywordIo                   = String -> Parser ()
reserved String
"io"
keywordSomething :: Parser ()
keywordSomething            = String -> Parser ()
reserved String
"something"
keywordUndefined :: Parser ()
keywordUndefined            = String -> Parser ()
reserved String
"undefined"
keywordAlgebraicDataMatcher :: Parser ()
keywordAlgebraicDataMatcher = String -> Parser ()
reserved String
"algebraic-data-matcher"
keywordGenerateTensor :: Parser ()
keywordGenerateTensor       = String -> Parser ()
reserved String
"generate-tensor"
keywordTensor :: Parser ()
keywordTensor               = String -> Parser ()
reserved String
"tensor"
keywordTensorContract :: Parser ()
keywordTensorContract       = String -> Parser ()
reserved String
"contract"
keywordTensorMap :: Parser ()
keywordTensorMap            = String -> Parser ()
reserved String
"tensor-map"
keywordTensorMap2 :: Parser ()
keywordTensorMap2           = String -> Parser ()
reserved String
"tensor-map2"
keywordTranspose :: Parser ()
keywordTranspose            = String -> Parser ()
reserved String
"transpose"
keywordSubrefs :: Parser ()
keywordSubrefs              = String -> Parser ()
reserved String
"subrefs"
keywordSubrefsNew :: Parser ()
keywordSubrefsNew           = String -> Parser ()
reserved String
"subrefs!"
keywordSuprefs :: Parser ()
keywordSuprefs              = String -> Parser ()
reserved String
"suprefs"
keywordSuprefsNew :: Parser ()
keywordSuprefsNew           = String -> Parser ()
reserved String
"suprefs!"
keywordUserrefs :: Parser ()
keywordUserrefs             = String -> Parser ()
reserved String
"user-refs"
keywordUserrefsNew :: Parser ()
keywordUserrefsNew          = String -> Parser ()
reserved String
"user-refs!"
keywordFunction :: Parser ()
keywordFunction             = String -> Parser ()
reserved String
"function"

sign :: Num a => Parser (a -> a)
sign :: Parser (a -> a)
sign = (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-' ParsecT String () Identity Char
-> Parser (a -> a) -> Parser (a -> a)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (a -> a) -> Parser (a -> a)
forall (m :: * -> *) a. Monad m => a -> m a
return a -> a
forall a. Num a => a -> a
negate)
   Parser (a -> a) -> Parser (a -> a) -> Parser (a -> a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'+' ParsecT String () Identity Char
-> Parser (a -> a) -> Parser (a -> a)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (a -> a) -> Parser (a -> a)
forall (m :: * -> *) a. Monad m => a -> m a
return a -> a
forall a. a -> a
id)
   Parser (a -> a) -> Parser (a -> a) -> Parser (a -> a)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (a -> a) -> Parser (a -> a)
forall (m :: * -> *) a. Monad m => a -> m a
return a -> a
forall a. a -> a
id

integerLiteral :: Parser Integer
integerLiteral :: ParsecT String () Identity Integer
integerLiteral = Parser (Integer -> Integer)
forall a. Num a => Parser (a -> a)
sign Parser (Integer -> Integer)
-> ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GenTokenParser String () Identity
-> ParsecT String () Identity Integer
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
P.natural GenTokenParser String () Identity
lexer

stringLiteral :: Parser String
stringLiteral :: ParsecT String () Identity String
stringLiteral = GenTokenParser String () Identity
-> ParsecT String () Identity String
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
P.stringLiteral GenTokenParser String () Identity
lexer

charLiteral :: Parser Char
charLiteral :: ParsecT String () Identity Char
charLiteral = GenTokenParser String () Identity
-> ParsecT String () Identity Char
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Char
P.charLiteral GenTokenParser String () Identity
lexer

oneChar :: Parser Char
oneChar :: ParsecT String () Identity Char
oneChar = do
  String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"c#"
  String
x <- (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\\' ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar ParsecT String () Identity Char
-> (Char -> ParsecT String () Identity String)
-> ParsecT String () Identity String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\Char
x -> String -> ParsecT String () Identity String
forall (m :: * -> *) a. Monad m => a -> m a
return [Char
'\\', Char
x])) ParsecT String () Identity String
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar ParsecT String () Identity Char
-> (Char -> ParsecT String () Identity String)
-> ParsecT String () Identity String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\Char
x -> String -> ParsecT String () Identity String
forall (m :: * -> *) a. Monad m => a -> m a
return [Char
x]))
  Char -> ParsecT String () Identity Char
forall (m :: * -> *) a. Monad m => a -> m a
return (Char -> ParsecT String () Identity Char)
-> Char -> ParsecT String () Identity Char
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity Char -> String -> Char
forall a. Parser a -> String -> a
doParse' ParsecT String () Identity Char
charLiteral (String -> Char) -> String -> Char
forall a b. (a -> b) -> a -> b
$ String
"'" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'"

boolLiteral :: Parser Bool
boolLiteral :: ParsecT String () Identity Bool
boolLiteral = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'#' ParsecT String () Identity Char
-> ParsecT String () Identity Bool
-> ParsecT String () Identity Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
't' ParsecT String () Identity Char
-> Bool -> ParsecT String () Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True ParsecT String () Identity Bool
-> ParsecT String () Identity Bool
-> ParsecT String () Identity Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'f' ParsecT String () Identity Char
-> Bool -> ParsecT String () Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False)

whiteSpace :: Parser ()
whiteSpace :: Parser ()
whiteSpace = GenTokenParser String () Identity -> Parser ()
forall s u (m :: * -> *). GenTokenParser s u m -> ParsecT s u m ()
P.whiteSpace GenTokenParser String () Identity
lexer

parens :: Parser a -> Parser a
parens :: Parser a -> Parser a
parens = GenTokenParser String () Identity -> forall a. Parser a -> Parser a
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.parens GenTokenParser String () Identity
lexer

brackets :: Parser a -> Parser a
brackets :: Parser a -> Parser a
brackets = GenTokenParser String () Identity -> forall a. Parser a -> Parser a
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.brackets GenTokenParser String () Identity
lexer

braces :: Parser a -> Parser a
braces :: Parser a -> Parser a
braces = GenTokenParser String () Identity -> forall a. Parser a -> Parser a
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.braces GenTokenParser String () Identity
lexer

angles :: Parser a -> Parser a
angles :: Parser a -> Parser a
angles = GenTokenParser String () Identity -> forall a. Parser a -> Parser a
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.angles GenTokenParser String () Identity
lexer

ident :: Parser String
ident :: ParsecT String () Identity String
ident = String -> String
toCamelCase (String -> String)
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenTokenParser String () Identity
-> ParsecT String () Identity String
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
P.identifier GenTokenParser String () Identity
lexer

identVarWithIndices :: Parser VarWithIndices
identVarWithIndices :: ParsecT String () Identity VarWithIndices
identVarWithIndices = GenTokenParser String () Identity
-> ParsecT String () Identity VarWithIndices
-> ParsecT String () Identity VarWithIndices
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer (do
  String
name <- ParsecT String () Identity String
ident
  [VarIndex]
is <- ParsecT String () Identity VarIndex
-> ParsecT String () Identity [VarIndex]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String () Identity VarIndex
indexForVar
  VarWithIndices -> ParsecT String () Identity VarWithIndices
forall (m :: * -> *) a. Monad m => a -> m a
return (VarWithIndices -> ParsecT String () Identity VarWithIndices)
-> VarWithIndices -> ParsecT String () Identity VarWithIndices
forall a b. (a -> b) -> a -> b
$ String -> [VarIndex] -> VarWithIndices
VarWithIndices String
name [VarIndex]
is)

indexForVar :: Parser VarIndex
indexForVar :: ParsecT String () Identity VarIndex
indexForVar = ParsecT String () Identity VarIndex
-> ParsecT String () Identity VarIndex
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'~' ParsecT String () Identity Char
-> ParsecT String () Identity VarIndex
-> ParsecT String () Identity VarIndex
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> VarIndex
VSuperscript (String -> VarIndex)
-> ParsecT String () Identity String
-> ParsecT String () Identity VarIndex
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident)
        ParsecT String () Identity VarIndex
-> ParsecT String () Identity VarIndex
-> ParsecT String () Identity VarIndex
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity VarIndex
-> ParsecT String () Identity VarIndex
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'_' ParsecT String () Identity Char
-> ParsecT String () Identity VarIndex
-> ParsecT String () Identity VarIndex
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> VarIndex
VSubscript (String -> VarIndex)
-> ParsecT String () Identity String
-> ParsecT String () Identity VarIndex
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
ident)

indexType :: Parser (IndexExpr ())
indexType :: Parser (IndexExpr ())
indexType = Parser (IndexExpr ()) -> Parser (IndexExpr ())
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'~' ParsecT String () Identity Char
-> Parser (IndexExpr ()) -> Parser (IndexExpr ())
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IndexExpr () -> Parser (IndexExpr ())
forall (m :: * -> *) a. Monad m => a -> m a
return (() -> IndexExpr ()
forall a. a -> IndexExpr a
Superscript ()))
        Parser (IndexExpr ())
-> Parser (IndexExpr ()) -> Parser (IndexExpr ())
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (IndexExpr ()) -> Parser (IndexExpr ())
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'_' ParsecT String () Identity Char
-> Parser (IndexExpr ()) -> Parser (IndexExpr ())
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IndexExpr () -> Parser (IndexExpr ())
forall (m :: * -> *) a. Monad m => a -> m a
return (() -> IndexExpr ()
forall a. a -> IndexExpr a
Subscript ()))

upperName :: Parser String
upperName :: ParsecT String () Identity String
upperName = GenTokenParser String () Identity
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer ParsecT String () Identity String
upperName'

upperName' :: Parser String
upperName' :: ParsecT String () Identity String
upperName' = (:) (Char -> String -> String)
-> ParsecT String () Identity Char
-> ParsecT String () Identity (String -> String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Char
upper ParsecT String () Identity (String -> String)
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option String
"" ParsecT String () Identity String
ident
 where
  upper :: Parser Char
  upper :: ParsecT String () Identity Char
upper = (Char -> Bool) -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isUpper

lowerName :: Parser String
lowerName :: ParsecT String () Identity String
lowerName = GenTokenParser String () Identity
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
P.lexeme GenTokenParser String () Identity
lexer ParsecT String () Identity String
lowerName'

lowerName' :: Parser String
lowerName' :: ParsecT String () Identity String
lowerName' = (:) (Char -> String -> String)
-> ParsecT String () Identity Char
-> ParsecT String () Identity (String -> String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity Char
lower ParsecT String () Identity (String -> String)
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option String
"" ParsecT String () Identity String
ident
 where
  lower :: Parser Char
  lower :: ParsecT String () Identity Char
lower = (Char -> Bool) -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isLower

renamedFunctions :: [(String, String)]
renamedFunctions :: [(String, String)]
renamedFunctions =
  [ (String
"empty?",      String
"isEmpty")
  , (String
"S.empty?",    String
"S.isEmpty")
  , (String
"bool?",       String
"isBool")
  , (String
"integer?",    String
"isInteger")
  , (String
"rational?",   String
"isRational")
  , (String
"scalar?",     String
"isScalar")
  , (String
"float?",      String
"isFloat")
  , (String
"char?",       String
"isChar")
  , (String
"string?",     String
"isString")
  , (String
"collection?", String
"isCollection")
  , (String
"hash?",       String
"isHash")
  , (String
"tensor?",     String
"isTensor")
  , (String
"even?",       String
"isEven")
  , (String
"odd?",        String
"isOdd")
  , (String
"prime?",      String
"isPrime")
  , (String
"eof?",        String
"isEof")
  , (String
"eof-port?",   String
"isEofPort")
  , (String
"alphabet?",   String
"isAlphabet")
  , (String
"C.between?",  String
"C.isBetween")
  , (String
"alphabets?",  String
"isAlphabetString")
  , (String
"include?",    String
"include")
  , (String
"include/m?",  String
"includeAs")
  , (String
"member?",     String
"member")
  , (String
"member/m?",   String
"memberAs")
  , (String
"divisor?",    String
"divisor")
  , (String
"tree-member?",String
"treeMember")
  , (String
"eq/m?",       String
"eqAs")
  , (String
"eq?",         String
"equal")
  , (String
"lt?",         String
"lt")
  , (String
"lte?",        String
"lte")
  , (String
"gt?",         String
"gt")
  , (String
"gte?",        String
"gte")
  , (String
"car",         String
"head")
  , (String
"cdr",         String
"tail")
  , (String
"rac",         String
"last")
  , (String
"rdc",         String
"init")
  ]

splitOn :: Eq a => a -> [a] -> [[a]]
splitOn :: a -> [a] -> [[a]]
splitOn a
sep [a]
list =
  case (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
sep) [a]
list of
    ([], [])    -> []
    ([], a
_ : [a]
t) -> a -> [a] -> [[a]]
forall a. Eq a => a -> [a] -> [[a]]
splitOn a
sep [a]
t
    ([a]
h, [])     -> [[a]
h]
    ([a]
h, a
_ : [a]
t)  -> [a]
h [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: a -> [a] -> [[a]]
forall a. Eq a => a -> [a] -> [[a]]
splitOn a
sep [a]
t

-- Translate identifiers for Non-S syntax
toCamelCase :: String -> String
toCamelCase :: String -> String
toCamelCase String
"-" = String
"-"
toCamelCase String
"-'" = String
"-'"
toCamelCase String
"f.-'" = String
"f.-'"
toCamelCase String
"b.." = String
"b."
toCamelCase String
"b..'" = String
"b.'"
toCamelCase ((String -> [(String, String)] -> Maybe String)
-> [(String, String)] -> String -> Maybe String
forall a b c. (a -> b -> c) -> b -> a -> c
flip String -> [(String, String)] -> Maybe String
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup [(String, String)]
renamedFunctions -> Just String
name') =
  String
name'
toCamelCase (String -> String
forall a. [a] -> [a]
reverse -> Char
'm':Char
'/':String
xs) =
  String -> String
toCamelCase (String -> String
forall a. [a] -> [a]
reverse String
xs String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"-as")
toCamelCase String
x =
  let String
heads:[String]
tails = Char -> String -> [String]
forall a. Eq a => a -> [a] -> [[a]]
splitOn Char
'-' String
x
   in [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ String
heads String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
capitalize [String]
tails
  where
    capitalize :: String -> String
capitalize []     = String
"-"
    capitalize (Char
x:String
xs) = Char -> Char
toUpper Char
x Char -> String -> String
forall a. a -> [a] -> [a]
: String
xs