{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Safe #-}
module Parser.Procedure (
) where
import Control.Applicative (empty)
import Text.Parsec
import qualified Data.Set as Set
import Base.CompileError
import Parser.Common
import Parser.Pragma
import Parser.TypeCategory ()
import Parser.TypeInstance ()
import Types.Positional
import Types.Pragma
import Types.Procedure
import Types.TypeCategory
instance ParseFromSource (ExecutableProcedure SourcePos) where
sourceParser :: ParserE m (ExecutableProcedure SourcePos)
sourceParser = String
-> ParserE m (ExecutableProcedure SourcePos)
-> ParserE m (ExecutableProcedure SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"executable procedure" (ParserE m (ExecutableProcedure SourcePos)
-> ParserE m (ExecutableProcedure SourcePos))
-> ParserE m (ExecutableProcedure SourcePos)
-> ParserE m (ExecutableProcedure SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
FunctionName
n <- ParsecT String () m FunctionName
-> ParsecT String () m FunctionName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m FunctionName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ArgValues SourcePos
as <- ParserE m (ArgValues SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ReturnValues SourcePos
rs <- ParserE m (ReturnValues SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{")
[Pragma SourcePos]
pragmas <- [ParserE m (Pragma SourcePos)] -> ParserE m [Pragma SourcePos]
forall (m :: * -> *) a.
CompileErrorM m =>
[ParserE m a] -> ParserE m [a]
parsePragmas [ParserE m (Pragma SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
ParserE m (Pragma SourcePos)
pragmaNoTrace,ParserE m (Pragma SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
ParserE m (Pragma SourcePos)
pragmaTraceCreation]
Procedure SourcePos
pp <- ParserE m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
SourcePos
c2 <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}")
ExecutableProcedure SourcePos
-> ParserE m (ExecutableProcedure SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExecutableProcedure SourcePos
-> ParserE m (ExecutableProcedure SourcePos))
-> ExecutableProcedure SourcePos
-> ParserE m (ExecutableProcedure SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> [Pragma SourcePos]
-> [SourcePos]
-> FunctionName
-> ArgValues SourcePos
-> ReturnValues SourcePos
-> Procedure SourcePos
-> ExecutableProcedure SourcePos
forall c.
[c]
-> [Pragma c]
-> [c]
-> FunctionName
-> ArgValues c
-> ReturnValues c
-> Procedure c
-> ExecutableProcedure c
ExecutableProcedure [SourcePos
c] [Pragma SourcePos]
pragmas [SourcePos
c2] FunctionName
n ArgValues SourcePos
as ReturnValues SourcePos
rs Procedure SourcePos
pp
instance ParseFromSource (TestProcedure SourcePos) where
sourceParser :: ParserE m (TestProcedure SourcePos)
sourceParser = String
-> ParserE m (TestProcedure SourcePos)
-> ParserE m (TestProcedure SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"test procedure" (ParserE m (TestProcedure SourcePos)
-> ParserE m (TestProcedure SourcePos))
-> ParserE m (TestProcedure SourcePos)
-> ParserE m (TestProcedure SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwUnittest
FunctionName
n <- ParsecT String () m FunctionName
-> ParsecT String () m FunctionName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m FunctionName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{")
Procedure SourcePos
pp <- ParserE m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}")
TestProcedure SourcePos -> ParserE m (TestProcedure SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (TestProcedure SourcePos -> ParserE m (TestProcedure SourcePos))
-> TestProcedure SourcePos -> ParserE m (TestProcedure SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> FunctionName -> Procedure SourcePos -> TestProcedure SourcePos
forall c. [c] -> FunctionName -> Procedure c -> TestProcedure c
TestProcedure [SourcePos
c] FunctionName
n Procedure SourcePos
pp
instance ParseFromSource (ArgValues SourcePos) where
sourceParser :: ParserE m (ArgValues SourcePos)
sourceParser = String
-> ParserE m (ArgValues SourcePos)
-> ParserE m (ArgValues SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"procedure arguments" (ParserE m (ArgValues SourcePos)
-> ParserE m (ArgValues SourcePos))
-> ParserE m (ArgValues SourcePos)
-> ParserE m (ArgValues SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[InputValue SourcePos]
as <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m [InputValue SourcePos]
-> ParsecT String () m [InputValue SourcePos]
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"(")
(ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
")")
(ParsecT String () m (InputValue SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [InputValue SourcePos]
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]
sepBy ParsecT String () m (InputValue SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
","))
ArgValues SourcePos -> ParserE m (ArgValues SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgValues SourcePos -> ParserE m (ArgValues SourcePos))
-> ArgValues SourcePos -> ParserE m (ArgValues SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Positional (InputValue SourcePos) -> ArgValues SourcePos
forall c. [c] -> Positional (InputValue c) -> ArgValues c
ArgValues [SourcePos
c] ([InputValue SourcePos] -> Positional (InputValue SourcePos)
forall a. [a] -> Positional a
Positional [InputValue SourcePos]
as)
instance ParseFromSource (ReturnValues SourcePos) where
sourceParser :: ParserE m (ReturnValues SourcePos)
sourceParser = String
-> ParserE m (ReturnValues SourcePos)
-> ParserE m (ReturnValues SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"procedure returns" (ParserE m (ReturnValues SourcePos)
-> ParserE m (ReturnValues SourcePos))
-> ParserE m (ReturnValues SourcePos)
-> ParserE m (ReturnValues SourcePos)
forall a b. (a -> b) -> a -> b
$ ParserE m (ReturnValues SourcePos)
namedReturns ParserE m (ReturnValues SourcePos)
-> ParserE m (ReturnValues SourcePos)
-> ParserE m (ReturnValues SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (ReturnValues SourcePos)
unnamedReturns where
namedReturns :: ParserE m (ReturnValues SourcePos)
namedReturns = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[OutputValue SourcePos]
rs <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m [OutputValue SourcePos]
-> ParsecT String () m [OutputValue SourcePos]
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"(")
(ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
")")
(ParsecT String () m (OutputValue SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [OutputValue SourcePos]
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]
sepBy ParsecT String () m (OutputValue SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
","))
ReturnValues SourcePos -> ParserE m (ReturnValues SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ReturnValues SourcePos -> ParserE m (ReturnValues SourcePos))
-> ReturnValues SourcePos -> ParserE m (ReturnValues SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Positional (OutputValue SourcePos) -> ReturnValues SourcePos
forall c. [c] -> Positional (OutputValue c) -> ReturnValues c
NamedReturns [SourcePos
c] ([OutputValue SourcePos] -> Positional (OutputValue SourcePos)
forall a. [a] -> Positional a
Positional [OutputValue SourcePos]
rs)
unnamedReturns :: ParserE m (ReturnValues SourcePos)
unnamedReturns = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
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 () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"(")
ReturnValues SourcePos -> ParserE m (ReturnValues SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ReturnValues SourcePos -> ParserE m (ReturnValues SourcePos))
-> ReturnValues SourcePos -> ParserE m (ReturnValues SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> ReturnValues SourcePos
forall c. [c] -> ReturnValues c
UnnamedReturns [SourcePos
c]
instance ParseFromSource VariableName where
sourceParser :: ParserE m VariableName
sourceParser = String -> ParserE m VariableName -> ParserE m VariableName
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"variable name" (ParserE m VariableName -> ParserE m VariableName)
-> ParserE m VariableName -> ParserE m VariableName
forall a b. (a -> b) -> a -> b
$ do
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
noKeywords
Char
b <- ParsecT String () m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
lower
String
e <- ParserE m String -> ParserE m String
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParserE m String -> ParserE m String)
-> ParserE m String -> ParserE m String
forall a b. (a -> b) -> a -> b
$ ParsecT String () m Char -> ParserE m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String () m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum
VariableName -> ParserE m VariableName
forall (m :: * -> *) a. Monad m => a -> m a
return (VariableName -> ParserE m VariableName)
-> VariableName -> ParserE m VariableName
forall a b. (a -> b) -> a -> b
$ String -> VariableName
VariableName (Char
bChar -> String -> String
forall a. a -> [a] -> [a]
:String
e)
instance ParseFromSource (InputValue SourcePos) where
sourceParser :: ParserE m (InputValue SourcePos)
sourceParser = String
-> ParserE m (InputValue SourcePos)
-> ParserE m (InputValue SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"input variable" (ParserE m (InputValue SourcePos)
-> ParserE m (InputValue SourcePos))
-> ParserE m (InputValue SourcePos)
-> ParserE m (InputValue SourcePos)
forall a b. (a -> b) -> a -> b
$ ParserE m (InputValue SourcePos)
variable ParserE m (InputValue SourcePos)
-> ParserE m (InputValue SourcePos)
-> ParserE m (InputValue SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (InputValue SourcePos)
discard where
variable :: ParserE m (InputValue SourcePos)
variable = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VariableName
v <- ParserE m VariableName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
InputValue SourcePos -> ParserE m (InputValue SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (InputValue SourcePos -> ParserE m (InputValue SourcePos))
-> InputValue SourcePos -> ParserE m (InputValue SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> VariableName -> InputValue SourcePos
forall c. [c] -> VariableName -> InputValue c
InputValue [SourcePos
c] VariableName
v
discard :: ParserE m (InputValue SourcePos)
discard = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"_")
InputValue SourcePos -> ParserE m (InputValue SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (InputValue SourcePos -> ParserE m (InputValue SourcePos))
-> InputValue SourcePos -> ParserE m (InputValue SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> InputValue SourcePos
forall c. [c] -> InputValue c
DiscardInput [SourcePos
c]
instance ParseFromSource (OutputValue SourcePos) where
sourceParser :: ParserE m (OutputValue SourcePos)
sourceParser = String
-> ParserE m (OutputValue SourcePos)
-> ParserE m (OutputValue SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"output variable" (ParserE m (OutputValue SourcePos)
-> ParserE m (OutputValue SourcePos))
-> ParserE m (OutputValue SourcePos)
-> ParserE m (OutputValue SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VariableName
v <- ParserE m VariableName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
OutputValue SourcePos -> ParserE m (OutputValue SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputValue SourcePos -> ParserE m (OutputValue SourcePos))
-> OutputValue SourcePos -> ParserE m (OutputValue SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> VariableName -> OutputValue SourcePos
forall c. [c] -> VariableName -> OutputValue c
OutputValue [SourcePos
c] VariableName
v
instance ParseFromSource (Procedure SourcePos) where
sourceParser :: ParserE m (Procedure SourcePos)
sourceParser = String
-> ParserE m (Procedure SourcePos)
-> ParserE m (Procedure SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"procedure" (ParserE m (Procedure SourcePos)
-> ParserE m (Procedure SourcePos))
-> ParserE m (Procedure SourcePos)
-> ParserE m (Procedure SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[Statement SourcePos]
rs <- ParsecT String () m (Statement SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [Statement SourcePos]
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]
sepBy ParsecT String () m (Statement SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
optionalSpace
Procedure SourcePos -> ParserE m (Procedure SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Procedure SourcePos -> ParserE m (Procedure SourcePos))
-> Procedure SourcePos -> ParserE m (Procedure SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> [Statement SourcePos] -> Procedure SourcePos
forall c. [c] -> [Statement c] -> Procedure c
Procedure [SourcePos
c] [Statement SourcePos]
rs
instance ParseFromSource (Statement SourcePos) where
sourceParser :: ParserE m (Statement SourcePos)
sourceParser = ParserE m (Statement SourcePos)
parseReturn ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (Statement SourcePos)
parseBreak ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (Statement SourcePos)
parseContinue ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (Statement SourcePos)
parseFailCall ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (Statement SourcePos)
parseVoid ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (Statement SourcePos)
parseAssign ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (Statement SourcePos)
parseIgnore where
parseAssign :: ParserE m (Statement SourcePos)
parseAssign = String
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"statement" (ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos))
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[Assignable SourcePos]
as <- ParsecT String () m (Assignable SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [Assignable SourcePos]
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]
sepBy ParsecT String () m (Assignable SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
",")
ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
assignOperator
Expression SourcePos
e <- ParserE m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
statementEnd
Statement SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParserE m (Statement SourcePos))
-> Statement SourcePos -> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Positional (Assignable SourcePos)
-> Expression SourcePos
-> Statement SourcePos
forall c.
[c] -> Positional (Assignable c) -> Expression c -> Statement c
Assignment [SourcePos
c] ([Assignable SourcePos] -> Positional (Assignable SourcePos)
forall a. [a] -> Positional a
Positional [Assignable SourcePos]
as) Expression SourcePos
e
parseBreak :: ParserE m (Statement SourcePos)
parseBreak = String
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"break" (ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos))
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwBreak
Statement SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParserE m (Statement SourcePos))
-> Statement SourcePos -> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Statement SourcePos
forall c. [c] -> Statement c
LoopBreak [SourcePos
c]
parseContinue :: ParserE m (Statement SourcePos)
parseContinue = String
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"continue" (ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos))
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwContinue
Statement SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParserE m (Statement SourcePos))
-> Statement SourcePos -> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Statement SourcePos
forall c. [c] -> Statement c
LoopContinue [SourcePos
c]
parseFailCall :: ParserE m (Statement SourcePos)
parseFailCall = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwFail
Expression SourcePos
e <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"(") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
")") ParserE m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Statement SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParserE m (Statement SourcePos))
-> Statement SourcePos -> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Expression SourcePos -> Statement SourcePos
forall c. [c] -> Expression c -> Statement c
FailCall [SourcePos
c] Expression SourcePos
e
parseIgnore :: ParserE m (Statement SourcePos)
parseIgnore = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
statementStart
Expression SourcePos
e <- ParserE m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
statementEnd
Statement SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParserE m (Statement SourcePos))
-> Statement SourcePos -> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Expression SourcePos -> Statement SourcePos
forall c. [c] -> Expression c -> Statement c
IgnoreValues [SourcePos
c] Expression SourcePos
e
parseReturn :: ParserE m (Statement SourcePos)
parseReturn = String
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"return" (ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos))
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwReturn
SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> ParserE m (Statement SourcePos)
emptyReturn SourcePos
c ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
-> ParserE m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> ParserE m (Statement SourcePos)
multiReturn SourcePos
c
multiReturn :: CompileErrorM m => SourcePos -> ParserE m (Statement SourcePos)
multiReturn :: SourcePos -> ParserE m (Statement SourcePos)
multiReturn SourcePos
c = do
[Expression SourcePos]
rs <- ParsecT String () m (Expression SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [Expression SourcePos]
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]
sepBy ParsecT String () m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
",")
ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
statementEnd
Statement SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParserE m (Statement SourcePos))
-> Statement SourcePos -> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Positional (Expression SourcePos) -> Statement SourcePos
forall c. [c] -> Positional (Expression c) -> Statement c
ExplicitReturn [SourcePos
c] ([Expression SourcePos] -> Positional (Expression SourcePos)
forall a. [a] -> Positional a
Positional [Expression SourcePos]
rs)
emptyReturn :: CompileErrorM m => SourcePos -> ParserE m (Statement SourcePos)
emptyReturn :: SourcePos -> ParserE m (Statement SourcePos)
emptyReturn SourcePos
c = do
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwIgnore
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
statementEnd
Statement SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParserE m (Statement SourcePos))
-> Statement SourcePos -> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Statement SourcePos
forall c. [c] -> Statement c
EmptyReturn [SourcePos
c]
parseVoid :: ParserE m (Statement SourcePos)
parseVoid = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VoidExpression SourcePos
e <- ParserE m (VoidExpression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Statement SourcePos -> ParserE m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParserE m (Statement SourcePos))
-> Statement SourcePos -> ParserE m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> VoidExpression SourcePos -> Statement SourcePos
forall c. [c] -> VoidExpression c -> Statement c
NoValueExpression [SourcePos
c] VoidExpression SourcePos
e
instance ParseFromSource (Assignable SourcePos) where
sourceParser :: ParserE m (Assignable SourcePos)
sourceParser = ParserE m (Assignable SourcePos)
existing ParserE m (Assignable SourcePos)
-> ParserE m (Assignable SourcePos)
-> ParserE m (Assignable SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (Assignable SourcePos)
create where
create :: ParserE m (Assignable SourcePos)
create = String
-> ParserE m (Assignable SourcePos)
-> ParserE m (Assignable SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"variable creation" (ParserE m (Assignable SourcePos)
-> ParserE m (Assignable SourcePos))
-> ParserE m (Assignable SourcePos)
-> ParserE m (Assignable SourcePos)
forall a b. (a -> b) -> a -> b
$ do
ValueType
t <- ParserE m ValueType
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParsecT String () m ()
forall b. ParsecT String () m b
strayFuncCall ParsecT String () m ()
-> ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VariableName
n <- ParserE m VariableName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Assignable SourcePos -> ParserE m (Assignable SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Assignable SourcePos -> ParserE m (Assignable SourcePos))
-> Assignable SourcePos -> ParserE m (Assignable SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> ValueType -> VariableName -> Assignable SourcePos
forall c. [c] -> ValueType -> VariableName -> Assignable c
CreateVariable [SourcePos
c] ValueType
t VariableName
n
existing :: ParserE m (Assignable SourcePos)
existing = String
-> ParserE m (Assignable SourcePos)
-> ParserE m (Assignable SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"variable name" (ParserE m (Assignable SourcePos)
-> ParserE m (Assignable SourcePos))
-> ParserE m (Assignable SourcePos)
-> ParserE m (Assignable SourcePos)
forall a b. (a -> b) -> a -> b
$ do
InputValue SourcePos
n <- ParserE m (InputValue SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParsecT String () m ()
forall b. ParsecT String () m b
strayFuncCall ParsecT String () m ()
-> ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Assignable SourcePos -> ParserE m (Assignable SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Assignable SourcePos -> ParserE m (Assignable SourcePos))
-> Assignable SourcePos -> ParserE m (Assignable SourcePos)
forall a b. (a -> b) -> a -> b
$ InputValue SourcePos -> Assignable SourcePos
forall c. InputValue c -> Assignable c
ExistingVariable InputValue SourcePos
n
strayFuncCall :: ParsecT String () m b
strayFuncCall = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
valueSymbolGet ParsecT String () m ()
-> ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () m ()
forall (m :: * -> *). CompileErrorM m => ParserE m ()
typeSymbolGet ParsecT String () m ()
-> ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () m ()
forall (m :: * -> *). CompileErrorM m => ParserE m ()
categorySymbolGet
SourcePos -> String -> ParsecT String () m b
forall (m :: * -> *) a.
CompileErrorM m =>
SourcePos -> String -> ParserE m a
parseErrorM SourcePos
c String
"function returns must be explicitly handled"
instance ParseFromSource (VoidExpression SourcePos) where
sourceParser :: ParserE m (VoidExpression SourcePos)
sourceParser = ParserE m (VoidExpression SourcePos)
conditional ParserE m (VoidExpression SourcePos)
-> ParserE m (VoidExpression SourcePos)
-> ParserE m (VoidExpression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (VoidExpression SourcePos)
loop ParserE m (VoidExpression SourcePos)
-> ParserE m (VoidExpression SourcePos)
-> ParserE m (VoidExpression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (VoidExpression SourcePos)
scoped where
conditional :: ParserE m (VoidExpression SourcePos)
conditional = do
IfElifElse SourcePos
e <- ParserE m (IfElifElse SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos))
-> VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos)
forall a b. (a -> b) -> a -> b
$ IfElifElse SourcePos -> VoidExpression SourcePos
forall c. IfElifElse c -> VoidExpression c
Conditional IfElifElse SourcePos
e
loop :: ParserE m (VoidExpression SourcePos)
loop = do
WhileLoop SourcePos
e <- ParserE m (WhileLoop SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos))
-> VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos)
forall a b. (a -> b) -> a -> b
$ WhileLoop SourcePos -> VoidExpression SourcePos
forall c. WhileLoop c -> VoidExpression c
Loop WhileLoop SourcePos
e
scoped :: ParserE m (VoidExpression SourcePos)
scoped = do
ScopedBlock SourcePos
e <- ParserE m (ScopedBlock SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos))
-> VoidExpression SourcePos -> ParserE m (VoidExpression SourcePos)
forall a b. (a -> b) -> a -> b
$ ScopedBlock SourcePos -> VoidExpression SourcePos
forall c. ScopedBlock c -> VoidExpression c
WithScope ScopedBlock SourcePos
e
instance ParseFromSource (IfElifElse SourcePos) where
sourceParser :: ParserE m (IfElifElse SourcePos)
sourceParser = String
-> ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"if-elif-else" (ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos))
-> ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwIf ParsecT String () m ()
-> ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SourcePos -> ParserE m (IfElifElse SourcePos)
parseIf SourcePos
c
where
parseIf :: SourcePos -> ParserE m (IfElifElse SourcePos)
parseIf SourcePos
c = do
Expression SourcePos
i <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Expression SourcePos)
-> ParsecT String () m (Expression SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"(") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
")") ParsecT String () m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Procedure SourcePos
p <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Procedure SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}") ParsecT String () m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
IfElifElse SourcePos
next <- ParserE m (IfElifElse SourcePos)
parseElif ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (IfElifElse SourcePos)
parseElse ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> IfElifElse SourcePos -> ParserE m (IfElifElse SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return IfElifElse SourcePos
forall c. IfElifElse c
TerminateConditional
IfElifElse SourcePos -> ParserE m (IfElifElse SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (IfElifElse SourcePos -> ParserE m (IfElifElse SourcePos))
-> IfElifElse SourcePos -> ParserE m (IfElifElse SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Expression SourcePos
-> Procedure SourcePos
-> IfElifElse SourcePos
-> IfElifElse SourcePos
forall c.
[c] -> Expression c -> Procedure c -> IfElifElse c -> IfElifElse c
IfStatement [SourcePos
c] Expression SourcePos
i Procedure SourcePos
p IfElifElse SourcePos
next
parseElif :: ParserE m (IfElifElse SourcePos)
parseElif = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwElif ParsecT String () m ()
-> ParserE m (IfElifElse SourcePos)
-> ParserE m (IfElifElse SourcePos)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SourcePos -> ParserE m (IfElifElse SourcePos)
parseIf SourcePos
c
parseElse :: ParserE m (IfElifElse SourcePos)
parseElse = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwElse
Procedure SourcePos
p <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Procedure SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}") ParsecT String () m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
IfElifElse SourcePos -> ParserE m (IfElifElse SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (IfElifElse SourcePos -> ParserE m (IfElifElse SourcePos))
-> IfElifElse SourcePos -> ParserE m (IfElifElse SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Procedure SourcePos -> IfElifElse SourcePos
forall c. [c] -> Procedure c -> IfElifElse c
ElseStatement [SourcePos
c] Procedure SourcePos
p
instance ParseFromSource (WhileLoop SourcePos) where
sourceParser :: ParserE m (WhileLoop SourcePos)
sourceParser = String
-> ParserE m (WhileLoop SourcePos)
-> ParserE m (WhileLoop SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"while" (ParserE m (WhileLoop SourcePos)
-> ParserE m (WhileLoop SourcePos))
-> ParserE m (WhileLoop SourcePos)
-> ParserE m (WhileLoop SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwWhile
Expression SourcePos
i <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Expression SourcePos)
-> ParsecT String () m (Expression SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"(") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
")") ParsecT String () m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Procedure SourcePos
p <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Procedure SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}") ParsecT String () m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Maybe (Procedure SourcePos)
u <- (Procedure SourcePos -> Maybe (Procedure SourcePos))
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Maybe (Procedure SourcePos))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Procedure SourcePos -> Maybe (Procedure SourcePos)
forall a. a -> Maybe a
Just ParsecT String () m (Procedure SourcePos)
parseUpdate ParsecT String () m (Maybe (Procedure SourcePos))
-> ParsecT String () m (Maybe (Procedure SourcePos))
-> ParsecT String () m (Maybe (Procedure SourcePos))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe (Procedure SourcePos)
-> ParsecT String () m (Maybe (Procedure SourcePos))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Procedure SourcePos)
forall a. Maybe a
Nothing
WhileLoop SourcePos -> ParserE m (WhileLoop SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (WhileLoop SourcePos -> ParserE m (WhileLoop SourcePos))
-> WhileLoop SourcePos -> ParserE m (WhileLoop SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Expression SourcePos
-> Procedure SourcePos
-> Maybe (Procedure SourcePos)
-> WhileLoop SourcePos
forall c.
[c]
-> Expression c
-> Procedure c
-> Maybe (Procedure c)
-> WhileLoop c
WhileLoop [SourcePos
c] Expression SourcePos
i Procedure SourcePos
p Maybe (Procedure SourcePos)
u
where
parseUpdate :: ParsecT String () m (Procedure SourcePos)
parseUpdate = do
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwUpdate
ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Procedure SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}") ParsecT String () m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
instance ParseFromSource (ScopedBlock SourcePos) where
sourceParser :: ParserE m (ScopedBlock SourcePos)
sourceParser = ParserE m (ScopedBlock SourcePos)
scoped ParserE m (ScopedBlock SourcePos)
-> ParserE m (ScopedBlock SourcePos)
-> ParserE m (ScopedBlock SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (ScopedBlock SourcePos)
justCleanup where
scoped :: ParserE m (ScopedBlock SourcePos)
scoped = String
-> ParserE m (ScopedBlock SourcePos)
-> ParserE m (ScopedBlock SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"scoped" (ParserE m (ScopedBlock SourcePos)
-> ParserE m (ScopedBlock SourcePos))
-> ParserE m (ScopedBlock SourcePos)
-> ParserE m (ScopedBlock SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwScoped
Procedure SourcePos
p <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Procedure SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}") ParsecT String () m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Maybe (Procedure SourcePos)
cl <- (Procedure SourcePos -> Maybe (Procedure SourcePos))
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Maybe (Procedure SourcePos))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Procedure SourcePos -> Maybe (Procedure SourcePos)
forall a. a -> Maybe a
Just ParsecT String () m (Procedure SourcePos)
parseCleanup ParsecT String () m (Maybe (Procedure SourcePos))
-> ParsecT String () m (Maybe (Procedure SourcePos))
-> ParsecT String () m (Maybe (Procedure SourcePos))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe (Procedure SourcePos)
-> ParsecT String () m (Maybe (Procedure SourcePos))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Procedure SourcePos)
forall a. Maybe a
Nothing
ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwIn
Statement SourcePos
s <- ParsecT String () m (Statement SourcePos)
unconditional ParsecT String () m (Statement SourcePos)
-> ParsecT String () m (Statement SourcePos)
-> ParsecT String () m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () m (Statement SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ScopedBlock SourcePos -> ParserE m (ScopedBlock SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScopedBlock SourcePos -> ParserE m (ScopedBlock SourcePos))
-> ScopedBlock SourcePos -> ParserE m (ScopedBlock SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Procedure SourcePos
-> Maybe (Procedure SourcePos)
-> Statement SourcePos
-> ScopedBlock SourcePos
forall c.
[c]
-> Procedure c
-> Maybe (Procedure c)
-> Statement c
-> ScopedBlock c
ScopedBlock [SourcePos
c] Procedure SourcePos
p Maybe (Procedure SourcePos)
cl Statement SourcePos
s
justCleanup :: ParserE m (ScopedBlock SourcePos)
justCleanup = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Procedure SourcePos
cl <- ParsecT String () m (Procedure SourcePos)
parseCleanup
ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwIn
Statement SourcePos
s <- ParsecT String () m (Statement SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser ParsecT String () m (Statement SourcePos)
-> ParsecT String () m (Statement SourcePos)
-> ParsecT String () m (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () m (Statement SourcePos)
unconditional
ScopedBlock SourcePos -> ParserE m (ScopedBlock SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScopedBlock SourcePos -> ParserE m (ScopedBlock SourcePos))
-> ScopedBlock SourcePos -> ParserE m (ScopedBlock SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Procedure SourcePos
-> Maybe (Procedure SourcePos)
-> Statement SourcePos
-> ScopedBlock SourcePos
forall c.
[c]
-> Procedure c
-> Maybe (Procedure c)
-> Statement c
-> ScopedBlock c
ScopedBlock [SourcePos
c] ([SourcePos] -> [Statement SourcePos] -> Procedure SourcePos
forall c. [c] -> [Statement c] -> Procedure c
Procedure [] []) (Procedure SourcePos -> Maybe (Procedure SourcePos)
forall a. a -> Maybe a
Just Procedure SourcePos
cl) Statement SourcePos
s
parseCleanup :: ParsecT String () m (Procedure SourcePos)
parseCleanup = do
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwCleanup
ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Procedure SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}") ParsecT String () m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
unconditional :: ParsecT String () m (Statement SourcePos)
unconditional = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Procedure SourcePos
p <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m (Procedure SourcePos)
-> ParsecT String () m (Procedure SourcePos)
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{") (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}") ParsecT String () m (Procedure SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Statement SourcePos -> ParsecT String () m (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos -> ParsecT String () m (Statement SourcePos))
-> Statement SourcePos -> ParsecT String () m (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> VoidExpression SourcePos -> Statement SourcePos
forall c. [c] -> VoidExpression c -> Statement c
NoValueExpression [SourcePos
c] (Procedure SourcePos -> VoidExpression SourcePos
forall c. Procedure c -> VoidExpression c
Unconditional Procedure SourcePos
p)
unaryOperator :: Monad m => ParserE m (Operator c)
unaryOperator :: ParserE m (Operator c)
unaryOperator = ParserE m String
op ParserE m String
-> (String -> ParserE m (Operator c)) -> ParserE m (Operator c)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Operator c -> ParserE m (Operator c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Operator c -> ParserE m (Operator c))
-> (String -> Operator c) -> String -> ParserE m (Operator c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Operator c
forall c. String -> Operator c
NamedOperator where
op :: ParserE m String
op = String -> ParserE m String -> ParserE m String
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"unary operator" (ParserE m String -> ParserE m String)
-> ParserE m String -> ParserE m String
forall a b. (a -> b) -> a -> b
$ (ParserE m String -> ParserE m String -> ParserE m String)
-> ParserE m String -> [ParserE m String] -> ParserE m String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ParserE m String -> ParserE m String -> ParserE m String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
(<|>) ParserE m String
forall (f :: * -> *) a. Alternative f => f a
empty ([ParserE m String] -> ParserE m String)
-> [ParserE m String] -> ParserE m String
forall a b. (a -> b) -> a -> b
$ (String -> ParserE m String) -> [String] -> [ParserE m String]
forall a b. (a -> b) -> [a] -> [b]
map (ParserE m String -> ParserE m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserE m String -> ParserE m String)
-> (String -> ParserE m String) -> String -> ParserE m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ParserE m String
forall (m :: * -> *). Monad m => String -> ParserE m String
operator) [String]
ops
ops :: [String]
ops = [String]
logicalUnary [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
arithUnary [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
bitwiseUnary
logicalUnary :: [String]
logicalUnary :: [String]
logicalUnary = [String
"!"]
arithUnary :: [String]
arithUnary :: [String]
arithUnary = [String
"-"]
bitwiseUnary :: [String]
bitwiseUnary :: [String]
bitwiseUnary = [String
"~"]
infixOperator :: Monad m => ParserE m (Operator c)
infixOperator :: ParserE m (Operator c)
infixOperator = ParserE m String
op ParserE m String
-> (String -> ParserE m (Operator c)) -> ParserE m (Operator c)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Operator c -> ParserE m (Operator c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Operator c -> ParserE m (Operator c))
-> (String -> Operator c) -> String -> ParserE m (Operator c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Operator c
forall c. String -> Operator c
NamedOperator where
op :: ParserE m String
op = String -> ParserE m String -> ParserE m String
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"binary operator" (ParserE m String -> ParserE m String)
-> ParserE m String -> ParserE m String
forall a b. (a -> b) -> a -> b
$ (ParserE m String -> ParserE m String -> ParserE m String)
-> ParserE m String -> [ParserE m String] -> ParserE m String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ParserE m String -> ParserE m String -> ParserE m String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
(<|>) ParserE m String
forall (f :: * -> *) a. Alternative f => f a
empty ([ParserE m String] -> ParserE m String)
-> [ParserE m String] -> ParserE m String
forall a b. (a -> b) -> a -> b
$ (String -> ParserE m String) -> [String] -> [ParserE m String]
forall a b. (a -> b) -> [a] -> [b]
map (ParserE m String -> ParserE m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParserE m String -> ParserE m String)
-> (String -> ParserE m String) -> String -> ParserE m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ParserE m String
forall (m :: * -> *). Monad m => String -> ParserE m String
operator) [String]
ops
ops :: [String]
ops = [String]
compareInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
logicalInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
addInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
subInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
multInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
bitwiseInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
bitshiftInfix
compareInfix :: [String]
compareInfix :: [String]
compareInfix = [String
"==",String
"!=",String
"<",String
"<=",String
">",String
">="]
logicalInfix :: [String]
logicalInfix :: [String]
logicalInfix = [String
"&&",String
"||"]
addInfix :: [String]
addInfix :: [String]
addInfix = [String
"+"]
subInfix :: [String]
subInfix :: [String]
subInfix = [String
"-"]
multInfix :: [String]
multInfix :: [String]
multInfix = [String
"*",String
"/",String
"%"]
bitwiseInfix :: [String]
bitwiseInfix :: [String]
bitwiseInfix = [String
"&",String
"|",String
"^"]
bitshiftInfix :: [String]
bitshiftInfix :: [String]
bitshiftInfix = [String
">>",String
"<<"]
infixBefore :: Operator c -> Operator c -> Bool
infixBefore :: Operator c -> Operator c -> Bool
infixBefore Operator c
o1 Operator c
o2 = (Operator c -> Int
forall p c. Num p => Operator c -> p
infixOrder Operator c
o1 :: Int) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= (Operator c -> Int
forall p c. Num p => Operator c -> p
infixOrder Operator c
o2 :: Int) where
infixOrder :: Operator c -> p
infixOrder (NamedOperator String
o)
| String
o String -> Set String -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` [String] -> Set String
forall a. Ord a => [a] -> Set a
Set.fromList ([String]
multInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
bitshiftInfix) = p
1
| String
o String -> Set String -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` [String] -> Set String
forall a. Ord a => [a] -> Set a
Set.fromList ([String]
addInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
subInfix [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
bitwiseInfix) = p
2
| String
o String -> Set String -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` [String] -> Set String
forall a. Ord a => [a] -> Set a
Set.fromList [String]
compareInfix = p
4
| String
o String -> Set String -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` [String] -> Set String
forall a. Ord a => [a] -> Set a
Set.fromList [String]
logicalInfix = p
5
infixOrder Operator c
_ = p
3
functionOperator :: CompileErrorM m => ParserE m (Operator SourcePos)
functionOperator :: ParserE m (Operator SourcePos)
functionOperator = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
infixFuncStart
FunctionSpec SourcePos
q <- ParserE m (FunctionSpec SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
infixFuncEnd
Operator SourcePos -> ParserE m (Operator SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Operator SourcePos -> ParserE m (Operator SourcePos))
-> Operator SourcePos -> ParserE m (Operator SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> FunctionSpec SourcePos -> Operator SourcePos
forall c. [c] -> FunctionSpec c -> Operator c
FunctionOperator [SourcePos
c] FunctionSpec SourcePos
q
instance ParseFromSource (Expression SourcePos) where
sourceParser :: ParserE m (Expression SourcePos)
sourceParser = do
Expression SourcePos
e <- ParserE m (Expression SourcePos)
notInfix
[Expression SourcePos]
-> [([SourcePos], Operator SourcePos)]
-> ParserE m (Expression SourcePos)
asInfix [Expression SourcePos
e] [] ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Expression SourcePos -> ParserE m (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return Expression SourcePos
e
where
notInfix :: ParserE m (Expression SourcePos)
notInfix = ParserE m (Expression SourcePos)
literal ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (Expression SourcePos)
unary ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (Expression SourcePos)
initalize ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (Expression SourcePos)
expression
asInfix :: [Expression SourcePos]
-> [([SourcePos], Operator SourcePos)]
-> ParserE m (Expression SourcePos)
asInfix [Expression SourcePos]
es [([SourcePos], Operator SourcePos)]
os = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Operator SourcePos
o <- ParserE m (Operator SourcePos)
forall (m :: * -> *) c. Monad m => ParserE m (Operator c)
infixOperator ParserE m (Operator SourcePos)
-> ParserE m (Operator SourcePos) -> ParserE m (Operator SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (Operator SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
ParserE m (Operator SourcePos)
functionOperator
Expression SourcePos
e2 <- ParserE m (Expression SourcePos)
notInfix
let es' :: [Expression SourcePos]
es' = [Expression SourcePos]
es [Expression SourcePos]
-> [Expression SourcePos] -> [Expression SourcePos]
forall a. [a] -> [a] -> [a]
++ [Expression SourcePos
e2]
let os' :: [([SourcePos], Operator SourcePos)]
os' = [([SourcePos], Operator SourcePos)]
os [([SourcePos], Operator SourcePos)]
-> [([SourcePos], Operator SourcePos)]
-> [([SourcePos], Operator SourcePos)]
forall a. [a] -> [a] -> [a]
++ [([SourcePos
c],Operator SourcePos
o)]
[Expression SourcePos]
-> [([SourcePos], Operator SourcePos)]
-> ParserE m (Expression SourcePos)
asInfix [Expression SourcePos]
es' [([SourcePos], Operator SourcePos)]
os' ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Expression SourcePos -> ParserE m (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Expression SourcePos, [SourcePos], Operator SourcePos)]
-> [Expression SourcePos]
-> [([SourcePos], Operator SourcePos)]
-> Expression SourcePos
forall c.
[(Expression c, [c], Operator c)]
-> [Expression c] -> [([c], Operator c)] -> Expression c
infixToTree [] [Expression SourcePos]
es' [([SourcePos], Operator SourcePos)]
os')
infixToTree :: [(Expression c, [c], Operator c)]
-> [Expression c] -> [([c], Operator c)] -> Expression c
infixToTree [(Expression c
e1,[c]
c1,Operator c
o1)] [Expression c
e2] [] = [c] -> Expression c -> Operator c -> Expression c -> Expression c
forall c.
[c] -> Expression c -> Operator c -> Expression c -> Expression c
InfixExpression [c]
c1 Expression c
e1 Operator c
o1 Expression c
e2
infixToTree [] (Expression c
e1:[Expression c]
es) (([c]
c1,Operator c
o1):[([c], Operator c)]
os) = [(Expression c, [c], Operator c)]
-> [Expression c] -> [([c], Operator c)] -> Expression c
infixToTree [(Expression c
e1,[c]
c1,Operator c
o1)] [Expression c]
es [([c], Operator c)]
os
infixToTree ((Expression c
e1,[c]
c1,Operator c
o1):[(Expression c, [c], Operator c)]
ss) [Expression c
e2] [] = let e2' :: Expression c
e2' = [c] -> Expression c -> Operator c -> Expression c -> Expression c
forall c.
[c] -> Expression c -> Operator c -> Expression c -> Expression c
InfixExpression [c]
c1 Expression c
e1 Operator c
o1 Expression c
e2 in
[(Expression c, [c], Operator c)]
-> [Expression c] -> [([c], Operator c)] -> Expression c
infixToTree [(Expression c, [c], Operator c)]
ss [Expression c
e2'] []
infixToTree ((Expression c
e1,[c]
c1,Operator c
o1):[(Expression c, [c], Operator c)]
ss) (Expression c
e2:[Expression c]
es) (([c]
c2,Operator c
o2):[([c], Operator c)]
os)
| Operator c
o1 Operator c -> Operator c -> Bool
forall c. Operator c -> Operator c -> Bool
`infixBefore` Operator c
o2 = let e1' :: Expression c
e1' = [c] -> Expression c -> Operator c -> Expression c -> Expression c
forall c.
[c] -> Expression c -> Operator c -> Expression c -> Expression c
InfixExpression [c]
c1 Expression c
e1 Operator c
o1 Expression c
e2 in
[(Expression c, [c], Operator c)]
-> [Expression c] -> [([c], Operator c)] -> Expression c
infixToTree [(Expression c, [c], Operator c)]
ss (Expression c
e1'Expression c -> [Expression c] -> [Expression c]
forall a. a -> [a] -> [a]
:[Expression c]
es) (([c]
c2,Operator c
o2)([c], Operator c) -> [([c], Operator c)] -> [([c], Operator c)]
forall a. a -> [a] -> [a]
:[([c], Operator c)]
os)
| Bool
otherwise = [(Expression c, [c], Operator c)]
-> [Expression c] -> [([c], Operator c)] -> Expression c
infixToTree ((Expression c
e2,[c]
c2,Operator c
o2)(Expression c, [c], Operator c)
-> [(Expression c, [c], Operator c)]
-> [(Expression c, [c], Operator c)]
forall a. a -> [a] -> [a]
:(Expression c
e1,[c]
c1,Operator c
o1)(Expression c, [c], Operator c)
-> [(Expression c, [c], Operator c)]
-> [(Expression c, [c], Operator c)]
forall a. a -> [a] -> [a]
:[(Expression c, [c], Operator c)]
ss) [Expression c]
es [([c], Operator c)]
os
infixToTree [(Expression c, [c], Operator c)]
_ [Expression c]
_ [([c], Operator c)]
_ = Expression c
forall a. HasCallStack => a
undefined
literal :: ParserE m (Expression SourcePos)
literal = do
ValueLiteral SourcePos
l <- ParserE m (ValueLiteral SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Expression SourcePos -> ParserE m (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression SourcePos -> ParserE m (Expression SourcePos))
-> Expression SourcePos -> ParserE m (Expression SourcePos)
forall a b. (a -> b) -> a -> b
$ ValueLiteral SourcePos -> Expression SourcePos
forall c. ValueLiteral c -> Expression c
Literal ValueLiteral SourcePos
l
unary :: ParserE m (Expression SourcePos)
unary = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Operator SourcePos
o <- ParserE m (Operator SourcePos)
forall (m :: * -> *) c. Monad m => ParserE m (Operator c)
unaryOperator ParserE m (Operator SourcePos)
-> ParserE m (Operator SourcePos) -> ParserE m (Operator SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (Operator SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
ParserE m (Operator SourcePos)
functionOperator
Expression SourcePos
e <- ParserE m (Expression SourcePos)
notInfix
Expression SourcePos -> ParserE m (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression SourcePos -> ParserE m (Expression SourcePos))
-> Expression SourcePos -> ParserE m (Expression SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> Operator SourcePos
-> Expression SourcePos
-> Expression SourcePos
forall c. [c] -> Operator c -> Expression c -> Expression c
UnaryExpression [SourcePos
c] Operator SourcePos
o Expression SourcePos
e
expression :: ParserE m (Expression SourcePos)
expression = String
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"expression" (ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos))
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ExpressionStart SourcePos
s <- ParserE m (ExpressionStart SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
[ValueOperation SourcePos]
vs <- ParsecT String () m (ValueOperation SourcePos)
-> ParsecT String () m [ValueOperation SourcePos]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String () m (ValueOperation SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
Expression SourcePos -> ParserE m (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression SourcePos -> ParserE m (Expression SourcePos))
-> Expression SourcePos -> ParserE m (Expression SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> ExpressionStart SourcePos
-> [ValueOperation SourcePos]
-> Expression SourcePos
forall c.
[c] -> ExpressionStart c -> [ValueOperation c] -> Expression c
Expression [SourcePos
c] ExpressionStart SourcePos
s [ValueOperation SourcePos]
vs
initalize :: ParserE m (Expression SourcePos)
initalize = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
TypeInstance
t <- ParsecT String () m TypeInstance
-> ParsecT String () m TypeInstance
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () m TypeInstance
-> ParsecT String () m TypeInstance)
-> ParsecT String () m TypeInstance
-> ParsecT String () m TypeInstance
forall a b. (a -> b) -> a -> b
$ do
TypeInstance
t2 <- ParsecT String () m TypeInstance
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParserE m () -> ParserE m ()
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"@value initializer" (ParserE m () -> ParserE m ()) -> ParserE m () -> ParserE m ()
forall a b. (a -> b) -> a -> b
$ String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"{")
TypeInstance -> ParsecT String () m TypeInstance
forall (m :: * -> *) a. Monad m => a -> m a
return TypeInstance
t2
SourcePos -> TypeInstance -> ParserE m (Expression SourcePos)
forall (m :: * -> *) c.
(CompileErrorM m, ParseFromSource (Expression c)) =>
c -> TypeInstance -> ParsecT String () m (Expression c)
withParams SourcePos
c TypeInstance
t ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
-> ParserE m (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> TypeInstance -> ParserE m (Expression SourcePos)
forall (m :: * -> *) c.
(ParseFromSource (Expression c), CompileErrorM m) =>
c -> TypeInstance -> ParsecT String () m (Expression c)
withoutParams SourcePos
c TypeInstance
t
withParams :: c -> TypeInstance -> ParsecT String () m (Expression c)
withParams c
c TypeInstance
t = do
ParsecT String () m () -> ParsecT String () m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwTypes
[GeneralInstance]
ps <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m [GeneralInstance]
-> ParsecT String () m [GeneralInstance]
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"<")
(ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
">")
(ParsecT String () m GeneralInstance
-> ParsecT String () m () -> ParsecT String () m [GeneralInstance]
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]
sepBy ParsecT String () m GeneralInstance
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
","))
[Expression c]
as <- (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
",") ParsecT String () m ()
-> ParsecT String () m [Expression c]
-> ParsecT String () m [Expression c]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () m (Expression c)
-> ParsecT String () m () -> ParsecT String () m [Expression c]
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]
sepBy ParsecT String () m (Expression c)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
",")) ParsecT String () m [Expression c]
-> ParsecT String () m [Expression c]
-> ParsecT String () m [Expression c]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [Expression c] -> ParsecT String () m [Expression c]
forall (m :: * -> *) a. Monad m => a -> m a
return []
ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}")
Expression c -> ParsecT String () m (Expression c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression c -> ParsecT String () m (Expression c))
-> Expression c -> ParsecT String () m (Expression c)
forall a b. (a -> b) -> a -> b
$ [c]
-> TypeInstance
-> Positional GeneralInstance
-> Positional (Expression c)
-> Expression c
forall c.
[c]
-> TypeInstance
-> Positional GeneralInstance
-> Positional (Expression c)
-> Expression c
InitializeValue [c
c] TypeInstance
t ([GeneralInstance] -> Positional GeneralInstance
forall a. [a] -> Positional a
Positional [GeneralInstance]
ps) ([Expression c] -> Positional (Expression c)
forall a. [a] -> Positional a
Positional [Expression c]
as)
withoutParams :: c -> TypeInstance -> ParsecT String () m (Expression c)
withoutParams c
c TypeInstance
t = do
[Expression c]
as <- ParsecT String () m (Expression c)
-> ParsecT String () m () -> ParsecT String () m [Expression c]
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]
sepBy ParsecT String () m (Expression c)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
",")
ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"}")
Expression c -> ParsecT String () m (Expression c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression c -> ParsecT String () m (Expression c))
-> Expression c -> ParsecT String () m (Expression c)
forall a b. (a -> b) -> a -> b
$ [c]
-> TypeInstance
-> Positional GeneralInstance
-> Positional (Expression c)
-> Expression c
forall c.
[c]
-> TypeInstance
-> Positional GeneralInstance
-> Positional (Expression c)
-> Expression c
InitializeValue [c
c] TypeInstance
t ([GeneralInstance] -> Positional GeneralInstance
forall a. [a] -> Positional a
Positional []) ([Expression c] -> Positional (Expression c)
forall a. [a] -> Positional a
Positional [Expression c]
as)
instance ParseFromSource (FunctionQualifier SourcePos) where
sourceParser :: ParserE m (FunctionQualifier SourcePos)
sourceParser = ParserE m (FunctionQualifier SourcePos)
valueFunc ParserE m (FunctionQualifier SourcePos)
-> ParserE m (FunctionQualifier SourcePos)
-> ParserE m (FunctionQualifier SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (FunctionQualifier SourcePos)
categoryFunc ParserE m (FunctionQualifier SourcePos)
-> ParserE m (FunctionQualifier SourcePos)
-> ParserE m (FunctionQualifier SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (FunctionQualifier SourcePos)
typeFunc where
valueFunc :: ParserE m (FunctionQualifier SourcePos)
valueFunc = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Expression SourcePos
q <- ParsecT String () m (Expression SourcePos)
-> ParsecT String () m (Expression SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
valueSymbolGet
FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos))
-> FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Expression SourcePos -> FunctionQualifier SourcePos
forall c. [c] -> Expression c -> FunctionQualifier c
ValueFunction [SourcePos
c] Expression SourcePos
q
categoryFunc :: ParserE m (FunctionQualifier SourcePos)
categoryFunc = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
CategoryName
q <- ParsecT String () m CategoryName
-> ParsecT String () m CategoryName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () m CategoryName
-> ParsecT String () m CategoryName)
-> ParsecT String () m CategoryName
-> ParsecT String () m CategoryName
forall a b. (a -> b) -> a -> b
$ do
CategoryName
q2 <- ParsecT String () m CategoryName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m ()
forall (m :: * -> *). CompileErrorM m => ParserE m ()
categorySymbolGet
CategoryName -> ParsecT String () m CategoryName
forall (m :: * -> *) a. Monad m => a -> m a
return CategoryName
q2
FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos))
-> FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> CategoryName -> FunctionQualifier SourcePos
forall c. [c] -> CategoryName -> FunctionQualifier c
CategoryFunction [SourcePos
c] CategoryName
q
typeFunc :: ParserE m (FunctionQualifier SourcePos)
typeFunc = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
TypeInstanceOrParam
q <- ParsecT String () m TypeInstanceOrParam
-> ParsecT String () m TypeInstanceOrParam
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m TypeInstanceOrParam
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m ()
forall (m :: * -> *). CompileErrorM m => ParserE m ()
typeSymbolGet
FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos))
-> FunctionQualifier SourcePos
-> ParserE m (FunctionQualifier SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> TypeInstanceOrParam -> FunctionQualifier SourcePos
forall c. [c] -> TypeInstanceOrParam -> FunctionQualifier c
TypeFunction [SourcePos
c] TypeInstanceOrParam
q
instance ParseFromSource (FunctionSpec SourcePos) where
sourceParser :: ParserE m (FunctionSpec SourcePos)
sourceParser = ParserE m (FunctionSpec SourcePos)
-> ParserE m (FunctionSpec SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParserE m (FunctionSpec SourcePos)
qualified ParserE m (FunctionSpec SourcePos)
-> ParserE m (FunctionSpec SourcePos)
-> ParserE m (FunctionSpec SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (FunctionSpec SourcePos)
unqualified where
qualified :: ParserE m (FunctionSpec SourcePos)
qualified = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
FunctionQualifier SourcePos
q <- ParserE m (FunctionQualifier SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
FunctionName
n <- ParserE m FunctionName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
[InstanceOrInferred SourcePos]
ps <- ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos])
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall a b. (a -> b) -> a -> b
$ ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"<")
(ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
">")
(ParsecT String () m (InstanceOrInferred SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [InstanceOrInferred SourcePos]
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]
sepBy ParsecT String () m (InstanceOrInferred SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
",")) ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall (m :: * -> *) a. Monad m => a -> m a
return []
FunctionSpec SourcePos -> ParserE m (FunctionSpec SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionSpec SourcePos -> ParserE m (FunctionSpec SourcePos))
-> FunctionSpec SourcePos -> ParserE m (FunctionSpec SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> FunctionQualifier SourcePos
-> FunctionName
-> Positional (InstanceOrInferred SourcePos)
-> FunctionSpec SourcePos
forall c.
[c]
-> FunctionQualifier c
-> FunctionName
-> Positional (InstanceOrInferred c)
-> FunctionSpec c
FunctionSpec [SourcePos
c] FunctionQualifier SourcePos
q FunctionName
n ([InstanceOrInferred SourcePos]
-> Positional (InstanceOrInferred SourcePos)
forall a. [a] -> Positional a
Positional [InstanceOrInferred SourcePos]
ps)
unqualified :: ParserE m (FunctionSpec SourcePos)
unqualified = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
FunctionName
n <- ParserE m FunctionName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
[InstanceOrInferred SourcePos]
ps <- ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos])
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall a b. (a -> b) -> a -> b
$ ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"<")
(ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
">")
(ParsecT String () m (InstanceOrInferred SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [InstanceOrInferred SourcePos]
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]
sepBy ParsecT String () m (InstanceOrInferred SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
",")) ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall (m :: * -> *) a. Monad m => a -> m a
return []
FunctionSpec SourcePos -> ParserE m (FunctionSpec SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionSpec SourcePos -> ParserE m (FunctionSpec SourcePos))
-> FunctionSpec SourcePos -> ParserE m (FunctionSpec SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> FunctionQualifier SourcePos
-> FunctionName
-> Positional (InstanceOrInferred SourcePos)
-> FunctionSpec SourcePos
forall c.
[c]
-> FunctionQualifier c
-> FunctionName
-> Positional (InstanceOrInferred c)
-> FunctionSpec c
FunctionSpec [SourcePos
c] FunctionQualifier SourcePos
forall c. FunctionQualifier c
UnqualifiedFunction FunctionName
n ([InstanceOrInferred SourcePos]
-> Positional (InstanceOrInferred SourcePos)
forall a. [a] -> Positional a
Positional [InstanceOrInferred SourcePos]
ps)
instance ParseFromSource (InstanceOrInferred SourcePos) where
sourceParser :: ParserE m (InstanceOrInferred SourcePos)
sourceParser = ParserE m (InstanceOrInferred SourcePos)
assigned ParserE m (InstanceOrInferred SourcePos)
-> ParserE m (InstanceOrInferred SourcePos)
-> ParserE m (InstanceOrInferred SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (InstanceOrInferred SourcePos)
inferred where
assigned :: ParserE m (InstanceOrInferred SourcePos)
assigned = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
GeneralInstance
t <- ParserE m GeneralInstance
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
InstanceOrInferred SourcePos
-> ParserE m (InstanceOrInferred SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (InstanceOrInferred SourcePos
-> ParserE m (InstanceOrInferred SourcePos))
-> InstanceOrInferred SourcePos
-> ParserE m (InstanceOrInferred SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> GeneralInstance -> InstanceOrInferred SourcePos
forall c. [c] -> GeneralInstance -> InstanceOrInferred c
AssignedInstance [SourcePos
c] GeneralInstance
t
inferred :: ParserE m (InstanceOrInferred SourcePos)
inferred = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m ()
sepAfter_ ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
inferredParam
InstanceOrInferred SourcePos
-> ParserE m (InstanceOrInferred SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (InstanceOrInferred SourcePos
-> ParserE m (InstanceOrInferred SourcePos))
-> InstanceOrInferred SourcePos
-> ParserE m (InstanceOrInferred SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> InstanceOrInferred SourcePos
forall c. [c] -> InstanceOrInferred c
InferredInstance [SourcePos
c]
parseFunctionCall :: CompileErrorM m => SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
parseFunctionCall :: SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n = do
[InstanceOrInferred SourcePos]
ps <- ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos])
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall a b. (a -> b) -> a -> b
$ ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"<")
(ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
">")
(ParsecT String () m (InstanceOrInferred SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [InstanceOrInferred SourcePos]
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]
sepBy ParsecT String () m (InstanceOrInferred SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
",")) ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [InstanceOrInferred SourcePos]
-> ParsecT String () m [InstanceOrInferred SourcePos]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[Expression SourcePos]
es <- ParsecT String () m ()
-> ParsecT String () m ()
-> ParsecT String () m [Expression SourcePos]
-> ParsecT String () m [Expression SourcePos]
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 () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"(")
(ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
")")
(ParsecT String () m (Expression SourcePos)
-> ParsecT String () m ()
-> ParsecT String () m [Expression SourcePos]
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]
sepBy ParsecT String () m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser (ParsecT String () m () -> ParsecT String () m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (ParsecT String () m () -> ParsecT String () m ())
-> ParsecT String () m () -> ParsecT String () m ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String () m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
","))
FunctionCall SourcePos -> ParserE m (FunctionCall SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionCall SourcePos -> ParserE m (FunctionCall SourcePos))
-> FunctionCall SourcePos -> ParserE m (FunctionCall SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> FunctionName
-> Positional (InstanceOrInferred SourcePos)
-> Positional (Expression SourcePos)
-> FunctionCall SourcePos
forall c.
[c]
-> FunctionName
-> Positional (InstanceOrInferred c)
-> Positional (Expression c)
-> FunctionCall c
FunctionCall [SourcePos
c] FunctionName
n ([InstanceOrInferred SourcePos]
-> Positional (InstanceOrInferred SourcePos)
forall a. [a] -> Positional a
Positional [InstanceOrInferred SourcePos]
ps) ([Expression SourcePos] -> Positional (Expression SourcePos)
forall a. [a] -> Positional a
Positional [Expression SourcePos]
es)
builtinFunction :: Monad m => ParserE m FunctionName
builtinFunction :: ParserE m FunctionName
builtinFunction = (ParserE m FunctionName
-> ParserE m FunctionName -> ParserE m FunctionName)
-> ParserE m FunctionName
-> [ParserE m FunctionName]
-> ParserE m FunctionName
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ParserE m FunctionName
-> ParserE m FunctionName -> ParserE m FunctionName
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
(<|>) ParserE m FunctionName
forall (f :: * -> *) a. Alternative f => f a
empty ([ParserE m FunctionName] -> ParserE m FunctionName)
-> [ParserE m FunctionName] -> ParserE m FunctionName
forall a b. (a -> b) -> a -> b
$ (ParserE m FunctionName -> ParserE m FunctionName)
-> [ParserE m FunctionName] -> [ParserE m FunctionName]
forall a b. (a -> b) -> [a] -> [b]
map ParserE m FunctionName -> ParserE m FunctionName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try [
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwPresent ParserE m () -> ParserE m FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinPresent,
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwReduce ParserE m () -> ParserE m FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinReduce,
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwRequire ParserE m () -> ParserE m FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinRequire,
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwStrong ParserE m () -> ParserE m FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinStrong,
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwTypename ParserE m () -> ParserE m FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParserE m FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinTypename
]
instance ParseFromSource (ExpressionStart SourcePos) where
sourceParser :: ParserE m (ExpressionStart SourcePos)
sourceParser = String
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"expression start" (ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos))
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$
ParserE m (ExpressionStart SourcePos)
parens ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ExpressionStart SourcePos)
variableOrUnqualified ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ExpressionStart SourcePos)
builtinCall ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ExpressionStart SourcePos)
builtinValue ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ExpressionStart SourcePos)
sourceContext ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ExpressionStart SourcePos)
exprLookup ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ExpressionStart SourcePos)
categoryCall ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ExpressionStart SourcePos)
typeCall where
parens :: ParserE m (ExpressionStart SourcePos)
parens = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"(")
ExpressionStart SourcePos
e <- ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> ParserE m (ExpressionStart SourcePos)
assign SourcePos
c) ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> ParserE m (ExpressionStart SourcePos)
expr SourcePos
c
ParserE m () -> ParserE m ()
forall (m :: * -> *) a. Monad m => ParserE m a -> ParserE m a
sepAfter (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
")")
ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return ExpressionStart SourcePos
e
assign :: CompileErrorM m => SourcePos -> ParserE m (ExpressionStart SourcePos)
assign :: SourcePos -> ParserE m (ExpressionStart SourcePos)
assign SourcePos
c = do
VariableName
n <- ParserE m VariableName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
assignOperator
Expression SourcePos
e <- ParserE m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> VariableName
-> Expression SourcePos
-> ExpressionStart SourcePos
forall c. [c] -> VariableName -> Expression c -> ExpressionStart c
InlineAssignment [SourcePos
c] VariableName
n Expression SourcePos
e
expr :: CompileErrorM m => SourcePos -> ParserE m (ExpressionStart SourcePos)
expr :: SourcePos -> ParserE m (ExpressionStart SourcePos)
expr SourcePos
c = do
Expression SourcePos
e <- ParserE m (Expression SourcePos)
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Expression SourcePos -> ExpressionStart SourcePos
forall c. [c] -> Expression c -> ExpressionStart c
ParensExpression [SourcePos
c] Expression SourcePos
e
builtinCall :: ParserE m (ExpressionStart SourcePos)
builtinCall = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
FunctionName
n <- ParserE m FunctionName
forall (m :: * -> *). Monad m => ParserE m FunctionName
builtinFunction
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> FunctionCall SourcePos -> ExpressionStart SourcePos
forall c. [c] -> FunctionCall c -> ExpressionStart c
BuiltinCall [SourcePos
c] FunctionCall SourcePos
f
builtinValue :: ParserE m (ExpressionStart SourcePos)
builtinValue = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
String
n <- ParserE m String
forall (m :: * -> *). Monad m => ParserE m String
builtinValues
ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ OutputValue SourcePos -> ExpressionStart SourcePos
forall c. OutputValue c -> ExpressionStart c
NamedVariable ([SourcePos] -> VariableName -> OutputValue SourcePos
forall c. [c] -> VariableName -> OutputValue c
OutputValue [SourcePos
c] (String -> VariableName
VariableName String
n))
sourceContext :: ParserE m (ExpressionStart SourcePos)
sourceContext = do
Pragma SourcePos
pragma <- ParserE m (Pragma SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
ParserE m (Pragma SourcePos)
pragmaSourceContext
case Pragma SourcePos
pragma of
(PragmaSourceContext SourcePos
c) -> ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Expression SourcePos -> ExpressionStart SourcePos
forall c. [c] -> Expression c -> ExpressionStart c
ParensExpression [SourcePos
c] (Expression SourcePos -> ExpressionStart SourcePos)
-> Expression SourcePos -> ExpressionStart SourcePos
forall a b. (a -> b) -> a -> b
$ ValueLiteral SourcePos -> Expression SourcePos
forall c. ValueLiteral c -> Expression c
Literal ([SourcePos] -> String -> ValueLiteral SourcePos
forall c. [c] -> String -> ValueLiteral c
StringLiteral [SourcePos
c] (SourcePos -> String
forall a. Show a => a -> String
show SourcePos
c))
Pragma SourcePos
_ -> ParserE m (ExpressionStart SourcePos)
forall a. HasCallStack => a
undefined
exprLookup :: ParserE m (ExpressionStart SourcePos)
exprLookup = do
Pragma SourcePos
pragma <- ParserE m (Pragma SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
ParserE m (Pragma SourcePos)
pragmaExprLookup
case Pragma SourcePos
pragma of
(PragmaExprLookup [SourcePos]
c MacroName
name) -> ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> MacroName -> ExpressionStart SourcePos
forall c. [c] -> MacroName -> ExpressionStart c
NamedMacro [SourcePos]
c MacroName
name
Pragma SourcePos
_ -> ParserE m (ExpressionStart SourcePos)
forall a. HasCallStack => a
undefined
variableOrUnqualified :: ParserE m (ExpressionStart SourcePos)
variableOrUnqualified = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VariableName
n <- forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
forall (m :: * -> *). CompileErrorM m => ParserE m VariableName
sourceParser :: CompileErrorM m => ParserE m VariableName
SourcePos -> VariableName -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos
-> VariableName -> ParsecT String () m (ExpressionStart SourcePos)
asUnqualifiedCall SourcePos
c VariableName
n ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
-> ParserE m (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> VariableName -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) c.
Monad m =>
c -> VariableName -> m (ExpressionStart c)
asVariable SourcePos
c VariableName
n
asVariable :: c -> VariableName -> m (ExpressionStart c)
asVariable c
c VariableName
n = do
ExpressionStart c -> m (ExpressionStart c)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart c -> m (ExpressionStart c))
-> ExpressionStart c -> m (ExpressionStart c)
forall a b. (a -> b) -> a -> b
$ OutputValue c -> ExpressionStart c
forall c. OutputValue c -> ExpressionStart c
NamedVariable ([c] -> VariableName -> OutputValue c
forall c. [c] -> VariableName -> OutputValue c
OutputValue [c
c] VariableName
n)
asUnqualifiedCall :: SourcePos
-> VariableName -> ParsecT String () m (ExpressionStart SourcePos)
asUnqualifiedCall SourcePos
c VariableName
n = do
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
parseFunctionCall SourcePos
c (String -> FunctionName
FunctionName (VariableName -> String
vnName VariableName
n))
ExpressionStart SourcePos
-> ParsecT String () m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParsecT String () m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParsecT String () m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> FunctionCall SourcePos -> ExpressionStart SourcePos
forall c. [c] -> FunctionCall c -> ExpressionStart c
UnqualifiedCall [SourcePos
c] FunctionCall SourcePos
f
categoryCall :: ParserE m (ExpressionStart SourcePos)
categoryCall = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
CategoryName
t <- ParsecT String () m CategoryName
-> ParsecT String () m CategoryName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () m CategoryName
-> ParsecT String () m CategoryName)
-> ParsecT String () m CategoryName
-> ParsecT String () m CategoryName
forall a b. (a -> b) -> a -> b
$ do
CategoryName
t2 <- ParsecT String () m CategoryName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m ()
forall (m :: * -> *). CompileErrorM m => ParserE m ()
categorySymbolGet
CategoryName -> ParsecT String () m CategoryName
forall (m :: * -> *) a. Monad m => a -> m a
return CategoryName
t2
FunctionName
n <- ParserE m FunctionName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> CategoryName
-> FunctionCall SourcePos
-> ExpressionStart SourcePos
forall c.
[c] -> CategoryName -> FunctionCall c -> ExpressionStart c
CategoryCall [SourcePos
c] CategoryName
t FunctionCall SourcePos
f
typeCall :: ParserE m (ExpressionStart SourcePos)
typeCall = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
TypeInstanceOrParam
t <- ParsecT String () m TypeInstanceOrParam
-> ParsecT String () m TypeInstanceOrParam
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () m TypeInstanceOrParam
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m ()
forall (m :: * -> *). CompileErrorM m => ParserE m ()
typeSymbolGet
FunctionName
n <- ParserE m FunctionName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ExpressionStart SourcePos -> ParserE m (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos))
-> ExpressionStart SourcePos
-> ParserE m (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> TypeInstanceOrParam
-> FunctionCall SourcePos
-> ExpressionStart SourcePos
forall c.
[c] -> TypeInstanceOrParam -> FunctionCall c -> ExpressionStart c
TypeCall [SourcePos
c] TypeInstanceOrParam
t FunctionCall SourcePos
f
instance ParseFromSource (ValueLiteral SourcePos) where
sourceParser :: ParserE m (ValueLiteral SourcePos)
sourceParser = String
-> ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"literal" (ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos))
-> ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
forall a b. (a -> b) -> a -> b
$
ParserE m (ValueLiteral SourcePos)
stringLiteral ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ValueLiteral SourcePos)
charLiteral ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ValueLiteral SourcePos)
escapedInteger ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ValueLiteral SourcePos)
integerOrDecimal ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ValueLiteral SourcePos)
boolLiteral ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParserE m (ValueLiteral SourcePos)
emptyLiteral where
stringLiteral :: ParserE m (ValueLiteral SourcePos)
stringLiteral = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
String
ss <- ParserE m String
forall (m :: * -> *). Monad m => ParserE m String
quotedString
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
optionalSpace
ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> String -> ValueLiteral SourcePos
forall c. [c] -> String -> ValueLiteral c
StringLiteral [SourcePos
c] String
ss
charLiteral :: ParserE m (ValueLiteral SourcePos)
charLiteral = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"'"
Char
ch <- ParserE m Char
forall (m :: * -> *). Monad m => ParserE m Char
stringChar ParserE m Char -> ParserE m Char -> ParserE m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParserE m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'"'
String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"'"
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
optionalSpace
ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Char -> ValueLiteral SourcePos
forall c. [c] -> Char -> ValueLiteral c
CharLiteral [SourcePos
c] Char
ch
escapedInteger :: ParserE m (ValueLiteral SourcePos)
escapedInteger = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
escapeStart
Char
b <- String -> ParserE m Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"bBoOdDxX"
Integer
d <- case Char
b of
Char
'b' -> ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseBin
Char
'B' -> ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseBin
Char
'o' -> ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseOct
Char
'O' -> ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseOct
Char
'd' -> ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseDec
Char
'D' -> ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseDec
Char
'x' -> ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseHex
Char
'X' -> ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseHex
Char
_ -> ParsecT String () m Integer
forall a. HasCallStack => a
undefined
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
optionalSpace
ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Bool -> Integer -> ValueLiteral SourcePos
forall c. [c] -> Bool -> Integer -> ValueLiteral c
IntegerLiteral [SourcePos
c] Bool
True Integer
d
integerOrDecimal :: ParserE m (ValueLiteral SourcePos)
integerOrDecimal = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Integer
d <- ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseDec
SourcePos -> Integer -> ParserE m (ValueLiteral SourcePos)
forall c. c -> Integer -> ParsecT String () m (ValueLiteral c)
decimal SourcePos
c Integer
d ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
-> ParserE m (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> Integer -> ParserE m (ValueLiteral SourcePos)
forall (m :: * -> *) c.
Monad m =>
c -> Integer -> ParsecT String () m (ValueLiteral c)
integer SourcePos
c Integer
d
decimal :: c -> Integer -> ParsecT String () m (ValueLiteral c)
decimal c
c Integer
d = do
Char -> ParserE m ()
forall (m :: * -> *). Monad m => Char -> ParserE m ()
char_ Char
'.'
(Integer
n,Integer
d2) <- ParserE m (Integer, Integer)
forall (m :: * -> *). Monad m => ParserE m (Integer, Integer)
parseSubOne
Integer
e <- ParsecT String () m Integer
decExponent ParsecT String () m Integer
-> ParsecT String () m Integer -> ParsecT String () m Integer
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Integer -> ParsecT String () m Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
0
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
optionalSpace
ValueLiteral c -> ParsecT String () m (ValueLiteral c)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral c -> ParsecT String () m (ValueLiteral c))
-> ValueLiteral c -> ParsecT String () m (ValueLiteral c)
forall a b. (a -> b) -> a -> b
$ [c] -> Integer -> Integer -> ValueLiteral c
forall c. [c] -> Integer -> Integer -> ValueLiteral c
DecimalLiteral [c
c] (Integer
dInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
10Integer -> Integer -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
d2) (Integer
e Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
n)
decExponent :: ParsecT String () m Integer
decExponent = do
String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"e" ParserE m () -> ParserE m () -> ParserE m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"E"
Integer
s <- (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"+" ParserE m ()
-> ParsecT String () m Integer -> ParsecT String () m Integer
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Integer -> ParsecT String () m Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
1) ParsecT String () m Integer
-> ParsecT String () m Integer -> ParsecT String () m Integer
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (String -> ParserE m ()
forall (m :: * -> *). Monad m => String -> ParserE m ()
string_ String
"-" ParserE m ()
-> ParsecT String () m Integer -> ParsecT String () m Integer
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Integer -> ParsecT String () m Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (-Integer
1)) ParsecT String () m Integer
-> ParsecT String () m Integer -> ParsecT String () m Integer
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Integer -> ParsecT String () m Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
1
Integer
e <- ParsecT String () m Integer
forall (m :: * -> *). Monad m => ParserE m Integer
parseDec
Integer -> ParsecT String () m Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer
sInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
e)
integer :: c -> Integer -> ParsecT String () m (ValueLiteral c)
integer c
c Integer
d = do
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
optionalSpace
ValueLiteral c -> ParsecT String () m (ValueLiteral c)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral c -> ParsecT String () m (ValueLiteral c))
-> ValueLiteral c -> ParsecT String () m (ValueLiteral c)
forall a b. (a -> b) -> a -> b
$ [c] -> Bool -> Integer -> ValueLiteral c
forall c. [c] -> Bool -> Integer -> ValueLiteral c
IntegerLiteral [c
c] Bool
False Integer
d
boolLiteral :: ParserE m (ValueLiteral SourcePos)
boolLiteral = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Bool
b <- ParsecT String () m Bool -> ParsecT String () m Bool
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () m Bool -> ParsecT String () m Bool)
-> ParsecT String () m Bool -> ParsecT String () m Bool
forall a b. (a -> b) -> a -> b
$ (ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwTrue ParserE m ()
-> ParsecT String () m Bool -> ParsecT String () m Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT String () m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True) ParsecT String () m Bool
-> ParsecT String () m Bool -> ParsecT String () m Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwFalse ParserE m ()
-> ParsecT String () m Bool -> ParsecT String () m Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT String () m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False)
ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Bool -> ValueLiteral SourcePos
forall c. [c] -> Bool -> ValueLiteral c
BoolLiteral [SourcePos
c] Bool
b
emptyLiteral :: ParserE m (ValueLiteral SourcePos)
emptyLiteral = do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m () -> ParserE m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
kwEmpty
ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> ParserE m (ValueLiteral SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> ValueLiteral SourcePos
forall c. [c] -> ValueLiteral c
EmptyLiteral [SourcePos
c]
instance ParseFromSource (ValueOperation SourcePos) where
sourceParser :: ParserE m (ValueOperation SourcePos)
sourceParser = ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParserE m (ValueOperation SourcePos)
valueCall ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParserE m (ValueOperation SourcePos)
conversion where
valueCall :: ParserE m (ValueOperation SourcePos)
valueCall = String
-> ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"function call" (ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos))
-> ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
valueSymbolGet
FunctionName
n <- ParserE m FunctionName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ValueOperation SourcePos -> ParserE m (ValueOperation SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueOperation SourcePos -> ParserE m (ValueOperation SourcePos))
-> ValueOperation SourcePos -> ParserE m (ValueOperation SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> FunctionCall SourcePos -> ValueOperation SourcePos
forall c. [c] -> FunctionCall c -> ValueOperation c
ValueCall [SourcePos
c] FunctionCall SourcePos
f
conversion :: ParserE m (ValueOperation SourcePos)
conversion = String
-> ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos)
forall (m :: * -> *) a.
Monad m =>
String -> ParserE m a -> ParserE m a
labeled String
"type conversion" (ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos))
-> ParserE m (ValueOperation SourcePos)
-> ParserE m (ValueOperation SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ParserE m ()
forall (m :: * -> *). Monad m => ParserE m ()
valueSymbolGet
TypeInstance
t <- ParserE m TypeInstance
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
ParserE m ()
forall (m :: * -> *). CompileErrorM m => ParserE m ()
typeSymbolGet
FunctionName
n <- ParserE m FunctionName
forall a (m :: * -> *).
(ParseFromSource a, CompileErrorM m) =>
ParserE m a
sourceParser
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
forall (m :: * -> *).
CompileErrorM m =>
SourcePos -> FunctionName -> ParserE m (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ValueOperation SourcePos -> ParserE m (ValueOperation SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueOperation SourcePos -> ParserE m (ValueOperation SourcePos))
-> ValueOperation SourcePos -> ParserE m (ValueOperation SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos]
-> TypeInstance
-> FunctionCall SourcePos
-> ValueOperation SourcePos
forall c. [c] -> TypeInstance -> FunctionCall c -> ValueOperation c
ConvertedCall [SourcePos
c] TypeInstance
t FunctionCall SourcePos
f