{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Safe #-}
module Parser.Procedure (
) where
import Text.Parsec
import Text.Parsec.String
import qualified Data.Set as Set
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 :: Parser (ExecutableProcedure SourcePos)
sourceParser = String
-> Parser (ExecutableProcedure SourcePos)
-> Parser (ExecutableProcedure SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"executable procedure" (Parser (ExecutableProcedure SourcePos)
-> Parser (ExecutableProcedure SourcePos))
-> Parser (ExecutableProcedure SourcePos)
-> Parser (ExecutableProcedure SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
FunctionName
n <- ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity FunctionName
forall a. ParseFromSource a => Parser a
sourceParser
ArgValues SourcePos
as <- Parser (ArgValues SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
ReturnValues SourcePos
rs <- Parser (ReturnValues SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser ()
string_ String
"{")
[Pragma SourcePos]
pragmas <- [Parser (Pragma SourcePos)] -> Parser [Pragma SourcePos]
forall a. [Parser a] -> Parser [a]
parsePragmas [Parser (Pragma SourcePos)
pragmaNoTrace,Parser (Pragma SourcePos)
pragmaTraceCreation]
Procedure SourcePos
pp <- Parser (Procedure SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
SourcePos
c2 <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser ()
string_ String
"}")
ExecutableProcedure SourcePos
-> Parser (ExecutableProcedure SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExecutableProcedure SourcePos
-> Parser (ExecutableProcedure SourcePos))
-> ExecutableProcedure SourcePos
-> Parser (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 (ArgValues SourcePos) where
sourceParser :: Parser (ArgValues SourcePos)
sourceParser = String
-> Parser (ArgValues SourcePos) -> Parser (ArgValues SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"procedure arguments" (Parser (ArgValues SourcePos) -> Parser (ArgValues SourcePos))
-> Parser (ArgValues SourcePos) -> Parser (ArgValues SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[InputValue SourcePos]
as <- Parser ()
-> Parser ()
-> ParsecT String () Identity [InputValue SourcePos]
-> ParsecT String () Identity [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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"(")
(Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
")")
(ParsecT String () Identity (InputValue SourcePos)
-> Parser () -> ParsecT String () Identity [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 () Identity (InputValue SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
","))
ArgValues SourcePos -> Parser (ArgValues SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgValues SourcePos -> Parser (ArgValues SourcePos))
-> ArgValues SourcePos -> Parser (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 :: Parser (ReturnValues SourcePos)
sourceParser = String
-> Parser (ReturnValues SourcePos)
-> Parser (ReturnValues SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"procedure returns" (Parser (ReturnValues SourcePos)
-> Parser (ReturnValues SourcePos))
-> Parser (ReturnValues SourcePos)
-> Parser (ReturnValues SourcePos)
forall a b. (a -> b) -> a -> b
$ Parser (ReturnValues SourcePos)
namedReturns Parser (ReturnValues SourcePos)
-> Parser (ReturnValues SourcePos)
-> Parser (ReturnValues SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (ReturnValues SourcePos)
unnamedReturns where
namedReturns :: Parser (ReturnValues SourcePos)
namedReturns = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[OutputValue SourcePos]
rs <- Parser ()
-> Parser ()
-> ParsecT String () Identity [OutputValue SourcePos]
-> ParsecT String () Identity [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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"(")
(Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
")")
(ParsecT String () Identity (OutputValue SourcePos)
-> Parser () -> ParsecT String () Identity [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 () Identity (OutputValue SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
","))
ReturnValues SourcePos -> Parser (ReturnValues SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ReturnValues SourcePos -> Parser (ReturnValues SourcePos))
-> ReturnValues SourcePos -> Parser (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 :: Parser (ReturnValues SourcePos)
unnamedReturns = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (String -> Parser ()
string_ String
"(")
ReturnValues SourcePos -> Parser (ReturnValues SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ReturnValues SourcePos -> Parser (ReturnValues SourcePos))
-> ReturnValues SourcePos -> Parser (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 :: Parser VariableName
sourceParser = String -> Parser VariableName -> Parser VariableName
forall a. String -> Parser a -> Parser a
labeled String
"variable name" (Parser VariableName -> Parser VariableName)
-> Parser VariableName -> Parser VariableName
forall a b. (a -> b) -> a -> b
$ do
Parser ()
noKeywords
Char
b <- ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
lower
String
e <- Parser String -> Parser String
forall a. Parser a -> Parser a
sepAfter (Parser String -> Parser String) -> Parser String -> Parser String
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity Char -> Parser String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum
VariableName -> Parser VariableName
forall (m :: * -> *) a. Monad m => a -> m a
return (VariableName -> Parser VariableName)
-> VariableName -> Parser 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 :: ParsecT String () Identity (InputValue SourcePos)
sourceParser = String
-> ParsecT String () Identity (InputValue SourcePos)
-> ParsecT String () Identity (InputValue SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"input variable" (ParsecT String () Identity (InputValue SourcePos)
-> ParsecT String () Identity (InputValue SourcePos))
-> ParsecT String () Identity (InputValue SourcePos)
-> ParsecT String () Identity (InputValue SourcePos)
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity (InputValue SourcePos)
variable ParsecT String () Identity (InputValue SourcePos)
-> ParsecT String () Identity (InputValue SourcePos)
-> ParsecT String () Identity (InputValue SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (InputValue SourcePos)
discard where
variable :: ParsecT String () Identity (InputValue SourcePos)
variable = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VariableName
v <- Parser VariableName
forall a. ParseFromSource a => Parser a
sourceParser
InputValue SourcePos
-> ParsecT String () Identity (InputValue SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (InputValue SourcePos
-> ParsecT String () Identity (InputValue SourcePos))
-> InputValue SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (InputValue SourcePos)
discard = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser ()
string_ String
"_")
InputValue SourcePos
-> ParsecT String () Identity (InputValue SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (InputValue SourcePos
-> ParsecT String () Identity (InputValue SourcePos))
-> InputValue SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (OutputValue SourcePos)
sourceParser = String
-> ParsecT String () Identity (OutputValue SourcePos)
-> ParsecT String () Identity (OutputValue SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"output variable" (ParsecT String () Identity (OutputValue SourcePos)
-> ParsecT String () Identity (OutputValue SourcePos))
-> ParsecT String () Identity (OutputValue SourcePos)
-> ParsecT String () Identity (OutputValue SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VariableName
v <- Parser VariableName
forall a. ParseFromSource a => Parser a
sourceParser
OutputValue SourcePos
-> ParsecT String () Identity (OutputValue SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputValue SourcePos
-> ParsecT String () Identity (OutputValue SourcePos))
-> OutputValue SourcePos
-> ParsecT String () Identity (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 :: Parser (Procedure SourcePos)
sourceParser = String
-> Parser (Procedure SourcePos) -> Parser (Procedure SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"procedure" (Parser (Procedure SourcePos) -> Parser (Procedure SourcePos))
-> Parser (Procedure SourcePos) -> Parser (Procedure SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[Statement SourcePos]
rs <- ParsecT String () Identity (Statement SourcePos)
-> Parser () -> ParsecT String () Identity [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 () Identity (Statement SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser Parser ()
optionalSpace
Procedure SourcePos -> Parser (Procedure SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Procedure SourcePos -> Parser (Procedure SourcePos))
-> Procedure SourcePos -> Parser (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 :: ParsecT String () Identity (Statement SourcePos)
sourceParser = ParsecT String () Identity (Statement SourcePos)
parseReturn ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT String () Identity (Statement SourcePos)
parseBreak ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT String () Identity (Statement SourcePos)
parseContinue ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT String () Identity (Statement SourcePos)
parseFailCall ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT String () Identity (Statement SourcePos)
parseVoid ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT String () Identity (Statement SourcePos)
parseAssign ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
ParsecT String () Identity (Statement SourcePos)
parseIgnore where
parseAssign :: ParsecT String () Identity (Statement SourcePos)
parseAssign = String
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"statement" (ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos))
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[Assignable SourcePos]
as <- ParsecT String () Identity (Assignable SourcePos)
-> Parser () -> ParsecT String () Identity [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 () Identity (Assignable SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
",")
Parser ()
assignOperator
Expression SourcePos
e <- Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
statementEnd
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (Statement SourcePos)
parseBreak = String
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"break" (ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos))
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwBreak
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Statement SourcePos
forall c. [c] -> Statement c
LoopBreak [SourcePos
c]
parseContinue :: ParsecT String () Identity (Statement SourcePos)
parseContinue = String
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"continue" (ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos))
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwContinue
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Statement SourcePos
forall c. [c] -> Statement c
LoopContinue [SourcePos
c]
parseFailCall :: ParsecT String () Identity (Statement SourcePos)
parseFailCall = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwFail
Expression SourcePos
e <- Parser ()
-> Parser ()
-> Parser (Expression SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"(") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
")") Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (Statement SourcePos)
parseIgnore = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser ()
statementStart
Expression SourcePos
e <- Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
statementEnd
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (Statement SourcePos)
parseReturn = String
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"return" (ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos))
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwReturn
SourcePos -> ParsecT String () Identity (Statement SourcePos)
emptyReturn SourcePos
c ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> ParsecT String () Identity (Statement SourcePos)
multiReturn SourcePos
c
multiReturn :: SourcePos -> Parser (Statement SourcePos)
multiReturn :: SourcePos -> ParsecT String () Identity (Statement SourcePos)
multiReturn SourcePos
c = do
[Expression SourcePos]
rs <- Parser (Expression SourcePos)
-> Parser () -> ParsecT String () Identity [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 Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
",")
Parser ()
statementEnd
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (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 :: SourcePos -> Parser (Statement SourcePos)
emptyReturn :: SourcePos -> ParsecT String () Identity (Statement SourcePos)
emptyReturn SourcePos
c = do
Parser ()
kwIgnore
Parser ()
statementEnd
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> Statement SourcePos
forall c. [c] -> Statement c
EmptyReturn [SourcePos
c]
parseVoid :: ParsecT String () Identity (Statement SourcePos)
parseVoid = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VoidExpression SourcePos
e <- Parser (VoidExpression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (Assignable SourcePos)
sourceParser = ParsecT String () Identity (Assignable SourcePos)
existing ParsecT String () Identity (Assignable SourcePos)
-> ParsecT String () Identity (Assignable SourcePos)
-> ParsecT String () Identity (Assignable SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (Assignable SourcePos)
create where
create :: ParsecT String () Identity (Assignable SourcePos)
create = String
-> ParsecT String () Identity (Assignable SourcePos)
-> ParsecT String () Identity (Assignable SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"variable creation" (ParsecT String () Identity (Assignable SourcePos)
-> ParsecT String () Identity (Assignable SourcePos))
-> ParsecT String () Identity (Assignable SourcePos)
-> ParsecT String () Identity (Assignable SourcePos)
forall a b. (a -> b) -> a -> b
$ do
ValueType
t <- Parser ValueType
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
forall b. ParsecT String () Identity b
strayFuncCall Parser () -> Parser () -> Parser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () -> Parser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VariableName
n <- Parser VariableName
forall a. ParseFromSource a => Parser a
sourceParser
Assignable SourcePos
-> ParsecT String () Identity (Assignable SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Assignable SourcePos
-> ParsecT String () Identity (Assignable SourcePos))
-> Assignable SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (Assignable SourcePos)
existing = String
-> ParsecT String () Identity (Assignable SourcePos)
-> ParsecT String () Identity (Assignable SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"variable name" (ParsecT String () Identity (Assignable SourcePos)
-> ParsecT String () Identity (Assignable SourcePos))
-> ParsecT String () Identity (Assignable SourcePos)
-> ParsecT String () Identity (Assignable SourcePos)
forall a b. (a -> b) -> a -> b
$ do
InputValue SourcePos
n <- ParsecT String () Identity (InputValue SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
forall b. ParsecT String () Identity b
strayFuncCall Parser () -> Parser () -> Parser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () -> Parser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Assignable SourcePos
-> ParsecT String () Identity (Assignable SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Assignable SourcePos
-> ParsecT String () Identity (Assignable SourcePos))
-> Assignable SourcePos
-> ParsecT String () Identity (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 () Identity b
strayFuncCall = do
Parser ()
valueSymbolGet Parser () -> Parser () -> Parser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser ()
typeSymbolGet Parser () -> Parser () -> Parser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser ()
categorySymbolGet
String -> ParsecT String () Identity b
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"function returns must be explicitly handled"
instance ParseFromSource (VoidExpression SourcePos) where
sourceParser :: Parser (VoidExpression SourcePos)
sourceParser = Parser (VoidExpression SourcePos)
conditional Parser (VoidExpression SourcePos)
-> Parser (VoidExpression SourcePos)
-> Parser (VoidExpression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (VoidExpression SourcePos)
loop Parser (VoidExpression SourcePos)
-> Parser (VoidExpression SourcePos)
-> Parser (VoidExpression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (VoidExpression SourcePos)
scoped where
conditional :: Parser (VoidExpression SourcePos)
conditional = do
IfElifElse SourcePos
e <- Parser (IfElifElse SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
VoidExpression SourcePos -> Parser (VoidExpression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (VoidExpression SourcePos -> Parser (VoidExpression SourcePos))
-> VoidExpression SourcePos -> Parser (VoidExpression SourcePos)
forall a b. (a -> b) -> a -> b
$ IfElifElse SourcePos -> VoidExpression SourcePos
forall c. IfElifElse c -> VoidExpression c
Conditional IfElifElse SourcePos
e
loop :: Parser (VoidExpression SourcePos)
loop = do
WhileLoop SourcePos
e <- Parser (WhileLoop SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
VoidExpression SourcePos -> Parser (VoidExpression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (VoidExpression SourcePos -> Parser (VoidExpression SourcePos))
-> VoidExpression SourcePos -> Parser (VoidExpression SourcePos)
forall a b. (a -> b) -> a -> b
$ WhileLoop SourcePos -> VoidExpression SourcePos
forall c. WhileLoop c -> VoidExpression c
Loop WhileLoop SourcePos
e
scoped :: Parser (VoidExpression SourcePos)
scoped = do
ScopedBlock SourcePos
e <- Parser (ScopedBlock SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
VoidExpression SourcePos -> Parser (VoidExpression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (VoidExpression SourcePos -> Parser (VoidExpression SourcePos))
-> VoidExpression SourcePos -> Parser (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 :: Parser (IfElifElse SourcePos)
sourceParser = String
-> Parser (IfElifElse SourcePos) -> Parser (IfElifElse SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"if-elif-else" (Parser (IfElifElse SourcePos) -> Parser (IfElifElse SourcePos))
-> Parser (IfElifElse SourcePos) -> Parser (IfElifElse SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwIf Parser ()
-> Parser (IfElifElse SourcePos) -> Parser (IfElifElse SourcePos)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SourcePos -> Parser (IfElifElse SourcePos)
parseIf SourcePos
c
where
parseIf :: SourcePos -> Parser (IfElifElse SourcePos)
parseIf SourcePos
c = do
Expression SourcePos
i <- Parser ()
-> Parser ()
-> Parser (Expression SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"(") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
")") Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Procedure SourcePos
p <- Parser ()
-> Parser ()
-> Parser (Procedure SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"{") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"}") Parser (Procedure SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
IfElifElse SourcePos
next <- Parser (IfElifElse SourcePos)
parseElif Parser (IfElifElse SourcePos)
-> Parser (IfElifElse SourcePos) -> Parser (IfElifElse SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (IfElifElse SourcePos)
parseElse Parser (IfElifElse SourcePos)
-> Parser (IfElifElse SourcePos) -> Parser (IfElifElse SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> IfElifElse SourcePos -> Parser (IfElifElse SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return IfElifElse SourcePos
forall c. IfElifElse c
TerminateConditional
IfElifElse SourcePos -> Parser (IfElifElse SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (IfElifElse SourcePos -> Parser (IfElifElse SourcePos))
-> IfElifElse SourcePos -> Parser (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 :: Parser (IfElifElse SourcePos)
parseElif = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwElif Parser ()
-> Parser (IfElifElse SourcePos) -> Parser (IfElifElse SourcePos)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SourcePos -> Parser (IfElifElse SourcePos)
parseIf SourcePos
c
parseElse :: Parser (IfElifElse SourcePos)
parseElse = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwElse
Procedure SourcePos
p <- Parser ()
-> Parser ()
-> Parser (Procedure SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"{") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"}") Parser (Procedure SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
IfElifElse SourcePos -> Parser (IfElifElse SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (IfElifElse SourcePos -> Parser (IfElifElse SourcePos))
-> IfElifElse SourcePos -> Parser (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 :: Parser (WhileLoop SourcePos)
sourceParser = String
-> Parser (WhileLoop SourcePos) -> Parser (WhileLoop SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"while" (Parser (WhileLoop SourcePos) -> Parser (WhileLoop SourcePos))
-> Parser (WhileLoop SourcePos) -> Parser (WhileLoop SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwWhile
Expression SourcePos
i <- Parser ()
-> Parser ()
-> Parser (Expression SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"(") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
")") Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Procedure SourcePos
p <- Parser ()
-> Parser ()
-> Parser (Procedure SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"{") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"}") Parser (Procedure SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Maybe (Procedure SourcePos)
u <- (Procedure SourcePos -> Maybe (Procedure SourcePos))
-> Parser (Procedure SourcePos)
-> ParsecT String () Identity (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 Parser (Procedure SourcePos)
parseUpdate ParsecT String () Identity (Maybe (Procedure SourcePos))
-> ParsecT String () Identity (Maybe (Procedure SourcePos))
-> ParsecT String () Identity (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 () Identity (Maybe (Procedure SourcePos))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Procedure SourcePos)
forall a. Maybe a
Nothing
WhileLoop SourcePos -> Parser (WhileLoop SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (WhileLoop SourcePos -> Parser (WhileLoop SourcePos))
-> WhileLoop SourcePos -> Parser (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 :: Parser (Procedure SourcePos)
parseUpdate = do
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwUpdate
Parser ()
-> Parser ()
-> Parser (Procedure SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"{") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"}") Parser (Procedure SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
instance ParseFromSource (ScopedBlock SourcePos) where
sourceParser :: Parser (ScopedBlock SourcePos)
sourceParser = Parser (ScopedBlock SourcePos)
scoped Parser (ScopedBlock SourcePos)
-> Parser (ScopedBlock SourcePos) -> Parser (ScopedBlock SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (ScopedBlock SourcePos)
justCleanup where
scoped :: Parser (ScopedBlock SourcePos)
scoped = String
-> Parser (ScopedBlock SourcePos) -> Parser (ScopedBlock SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"scoped" (Parser (ScopedBlock SourcePos) -> Parser (ScopedBlock SourcePos))
-> Parser (ScopedBlock SourcePos) -> Parser (ScopedBlock SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwScoped
Procedure SourcePos
p <- Parser ()
-> Parser ()
-> Parser (Procedure SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"{") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"}") Parser (Procedure SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Maybe (Procedure SourcePos)
cl <- (Procedure SourcePos -> Maybe (Procedure SourcePos))
-> Parser (Procedure SourcePos)
-> ParsecT String () Identity (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 Parser (Procedure SourcePos)
parseCleanup ParsecT String () Identity (Maybe (Procedure SourcePos))
-> ParsecT String () Identity (Maybe (Procedure SourcePos))
-> ParsecT String () Identity (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 () Identity (Maybe (Procedure SourcePos))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Procedure SourcePos)
forall a. Maybe a
Nothing
Parser ()
kwIn
Statement SourcePos
s <- ParsecT String () Identity (Statement SourcePos)
unconditional ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (Statement SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
ScopedBlock SourcePos -> Parser (ScopedBlock SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScopedBlock SourcePos -> Parser (ScopedBlock SourcePos))
-> ScopedBlock SourcePos -> Parser (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 :: Parser (ScopedBlock SourcePos)
justCleanup = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Procedure SourcePos
cl <- Parser (Procedure SourcePos)
parseCleanup
Parser ()
kwIn
Statement SourcePos
s <- ParsecT String () Identity (Statement SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
-> ParsecT String () Identity (Statement SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (Statement SourcePos)
unconditional
ScopedBlock SourcePos -> Parser (ScopedBlock SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScopedBlock SourcePos -> Parser (ScopedBlock SourcePos))
-> ScopedBlock SourcePos -> Parser (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 :: Parser (Procedure SourcePos)
parseCleanup = do
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwCleanup
Parser ()
-> Parser ()
-> Parser (Procedure SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"{") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"}") Parser (Procedure SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
unconditional :: ParsecT String () Identity (Statement SourcePos)
unconditional = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Procedure SourcePos
p <- Parser ()
-> Parser ()
-> Parser (Procedure SourcePos)
-> Parser (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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"{") (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"}") Parser (Procedure SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Statement SourcePos
-> ParsecT String () Identity (Statement SourcePos))
-> Statement SourcePos
-> ParsecT String () Identity (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 :: Parser (Operator c)
unaryOperator :: Parser (Operator c)
unaryOperator = Parser String
op Parser String
-> (String -> Parser (Operator c)) -> Parser (Operator c)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Operator c -> Parser (Operator c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Operator c -> Parser (Operator c))
-> (String -> Operator c) -> String -> Parser (Operator c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Operator c
forall c. String -> Operator c
NamedOperator where
op :: Parser String
op = String -> Parser String -> Parser String
forall a. String -> Parser a -> Parser a
labeled String
"unary operator" (Parser String -> Parser String) -> Parser String -> Parser String
forall a b. (a -> b) -> a -> b
$ (Parser String -> Parser String -> Parser String)
-> Parser String -> [Parser String] -> Parser String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Parser String -> Parser String -> Parser String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
(<|>) (String -> Parser String
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"empty") ([Parser String] -> Parser String)
-> [Parser String] -> Parser String
forall a b. (a -> b) -> a -> b
$ (String -> Parser String) -> [String] -> [Parser String]
forall a b. (a -> b) -> [a] -> [b]
map (Parser String -> Parser String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Parser String -> Parser String)
-> (String -> Parser String) -> String -> Parser String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Parser 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 :: Parser (Operator c)
infixOperator :: Parser (Operator c)
infixOperator = Parser String
op Parser String
-> (String -> Parser (Operator c)) -> Parser (Operator c)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Operator c -> Parser (Operator c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Operator c -> Parser (Operator c))
-> (String -> Operator c) -> String -> Parser (Operator c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Operator c
forall c. String -> Operator c
NamedOperator where
op :: Parser String
op = String -> Parser String -> Parser String
forall a. String -> Parser a -> Parser a
labeled String
"binary operator" (Parser String -> Parser String) -> Parser String -> Parser String
forall a b. (a -> b) -> a -> b
$ (Parser String -> Parser String -> Parser String)
-> Parser String -> [Parser String] -> Parser String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Parser String -> Parser String -> Parser String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
(<|>) (String -> Parser String
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"empty") ([Parser String] -> Parser String)
-> [Parser String] -> Parser String
forall a b. (a -> b) -> a -> b
$ (String -> Parser String) -> [String] -> [Parser String]
forall a b. (a -> b) -> [a] -> [b]
map (Parser String -> Parser String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Parser String -> Parser String)
-> (String -> Parser String) -> String -> Parser String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Parser 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 :: Parser (Operator SourcePos)
functionOperator :: Parser (Operator SourcePos)
functionOperator = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser ()
infixFuncStart
FunctionSpec SourcePos
q <- Parser (FunctionSpec SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
infixFuncEnd
Operator SourcePos -> Parser (Operator SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Operator SourcePos -> Parser (Operator SourcePos))
-> Operator SourcePos -> Parser (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 :: Parser (Expression SourcePos)
sourceParser = do
Expression SourcePos
e <- Parser (Expression SourcePos)
notInfix
[Expression SourcePos]
-> [([SourcePos], Operator SourcePos)]
-> Parser (Expression SourcePos)
asInfix [Expression SourcePos
e] [] Parser (Expression SourcePos)
-> Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Expression SourcePos -> Parser (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return Expression SourcePos
e
where
notInfix :: Parser (Expression SourcePos)
notInfix = Parser (Expression SourcePos)
literal Parser (Expression SourcePos)
-> Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (Expression SourcePos)
unary Parser (Expression SourcePos)
-> Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (Expression SourcePos)
initalize Parser (Expression SourcePos)
-> Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (Expression SourcePos)
expression
asInfix :: [Expression SourcePos]
-> [([SourcePos], Operator SourcePos)]
-> Parser (Expression SourcePos)
asInfix [Expression SourcePos]
es [([SourcePos], Operator SourcePos)]
os = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Operator SourcePos
o <- Parser (Operator SourcePos)
forall c. Parser (Operator c)
infixOperator Parser (Operator SourcePos)
-> Parser (Operator SourcePos) -> Parser (Operator SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (Operator SourcePos)
functionOperator
Expression SourcePos
e2 <- Parser (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)]
-> Parser (Expression SourcePos)
asInfix [Expression SourcePos]
es' [([SourcePos], Operator SourcePos)]
os' Parser (Expression SourcePos)
-> Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Expression SourcePos -> Parser (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 :: Parser (Expression SourcePos)
literal = do
ValueLiteral SourcePos
l <- Parser (ValueLiteral SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Expression SourcePos -> Parser (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression SourcePos -> Parser (Expression SourcePos))
-> Expression SourcePos -> Parser (Expression SourcePos)
forall a b. (a -> b) -> a -> b
$ ValueLiteral SourcePos -> Expression SourcePos
forall c. ValueLiteral c -> Expression c
Literal ValueLiteral SourcePos
l
unary :: Parser (Expression SourcePos)
unary = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Operator SourcePos
o <- Parser (Operator SourcePos)
forall c. Parser (Operator c)
unaryOperator Parser (Operator SourcePos)
-> Parser (Operator SourcePos) -> Parser (Operator SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (Operator SourcePos)
functionOperator
Expression SourcePos
e <- Parser (Expression SourcePos)
notInfix
Expression SourcePos -> Parser (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression SourcePos -> Parser (Expression SourcePos))
-> Expression SourcePos -> Parser (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 :: Parser (Expression SourcePos)
expression = String
-> Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"expression" (Parser (Expression SourcePos) -> Parser (Expression SourcePos))
-> Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
ExpressionStart SourcePos
s <- Parser (ExpressionStart SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
[ValueOperation SourcePos]
vs <- ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity [ValueOperation SourcePos]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String () Identity (ValueOperation SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Expression SourcePos -> Parser (Expression SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression SourcePos -> Parser (Expression SourcePos))
-> Expression SourcePos -> Parser (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 :: Parser (Expression SourcePos)
initalize = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
TypeInstance
t <- ParsecT String () Identity TypeInstance
-> ParsecT String () Identity TypeInstance
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity TypeInstance
-> ParsecT String () Identity TypeInstance)
-> ParsecT String () Identity TypeInstance
-> ParsecT String () Identity TypeInstance
forall a b. (a -> b) -> a -> b
$ do
TypeInstance
t2 <- ParsecT String () Identity TypeInstance
forall a. ParseFromSource a => Parser a
sourceParser
Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser () -> Parser ()
forall a. String -> Parser a -> Parser a
labeled String
"@value initializer" (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"{")
TypeInstance -> ParsecT String () Identity TypeInstance
forall (m :: * -> *) a. Monad m => a -> m a
return TypeInstance
t2
SourcePos -> TypeInstance -> Parser (Expression SourcePos)
forall c.
ParseFromSource (Expression c) =>
c -> TypeInstance -> ParsecT String () Identity (Expression c)
withParams SourcePos
c TypeInstance
t Parser (Expression SourcePos)
-> Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> TypeInstance -> Parser (Expression SourcePos)
forall c.
ParseFromSource (Expression c) =>
c -> TypeInstance -> ParsecT String () Identity (Expression c)
withoutParams SourcePos
c TypeInstance
t
withParams :: c -> TypeInstance -> ParsecT String () Identity (Expression c)
withParams c
c TypeInstance
t = do
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwTypes
[GeneralInstance]
ps <- Parser ()
-> Parser ()
-> ParsecT String () Identity [GeneralInstance]
-> ParsecT String () Identity [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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"<")
(Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
">")
(ParsecT String () Identity GeneralInstance
-> Parser () -> ParsecT String () Identity [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 () Identity GeneralInstance
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
","))
[Expression c]
as <- (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser ()
string_ String
",") Parser ()
-> ParsecT String () Identity [Expression c]
-> ParsecT String () Identity [Expression c]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity (Expression c)
-> Parser () -> ParsecT String () Identity [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 () Identity (Expression c)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
",")) ParsecT String () Identity [Expression c]
-> ParsecT String () Identity [Expression c]
-> ParsecT String () Identity [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 () Identity [Expression c]
forall (m :: * -> *) a. Monad m => a -> m a
return []
Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser ()
string_ String
"}")
Expression c -> ParsecT String () Identity (Expression c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression c -> ParsecT String () Identity (Expression c))
-> Expression c -> ParsecT String () Identity (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 () Identity (Expression c)
withoutParams c
c TypeInstance
t = do
[Expression c]
as <- ParsecT String () Identity (Expression c)
-> Parser () -> ParsecT String () Identity [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 () Identity (Expression c)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
",")
Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser ()
string_ String
"}")
Expression c -> ParsecT String () Identity (Expression c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Expression c -> ParsecT String () Identity (Expression c))
-> Expression c -> ParsecT String () Identity (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 :: Parser (FunctionQualifier SourcePos)
sourceParser = Parser (FunctionQualifier SourcePos)
valueFunc Parser (FunctionQualifier SourcePos)
-> Parser (FunctionQualifier SourcePos)
-> Parser (FunctionQualifier SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (FunctionQualifier SourcePos)
categoryFunc Parser (FunctionQualifier SourcePos)
-> Parser (FunctionQualifier SourcePos)
-> Parser (FunctionQualifier SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (FunctionQualifier SourcePos)
typeFunc where
valueFunc :: Parser (FunctionQualifier SourcePos)
valueFunc = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Expression SourcePos
q <- Parser (Expression SourcePos) -> Parser (Expression SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
valueSymbolGet
FunctionQualifier SourcePos -> Parser (FunctionQualifier SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionQualifier SourcePos
-> Parser (FunctionQualifier SourcePos))
-> FunctionQualifier SourcePos
-> Parser (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 :: Parser (FunctionQualifier SourcePos)
categoryFunc = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
CategoryName
q <- ParsecT String () Identity CategoryName
-> ParsecT String () Identity CategoryName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity CategoryName
-> ParsecT String () Identity CategoryName)
-> ParsecT String () Identity CategoryName
-> ParsecT String () Identity CategoryName
forall a b. (a -> b) -> a -> b
$ do
CategoryName
q2 <- ParsecT String () Identity CategoryName
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
categorySymbolGet
CategoryName -> ParsecT String () Identity CategoryName
forall (m :: * -> *) a. Monad m => a -> m a
return CategoryName
q2
FunctionQualifier SourcePos -> Parser (FunctionQualifier SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionQualifier SourcePos
-> Parser (FunctionQualifier SourcePos))
-> FunctionQualifier SourcePos
-> Parser (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 :: Parser (FunctionQualifier SourcePos)
typeFunc = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
TypeInstanceOrParam
q <- ParsecT String () Identity TypeInstanceOrParam
-> ParsecT String () Identity TypeInstanceOrParam
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity TypeInstanceOrParam
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
typeSymbolGet
FunctionQualifier SourcePos -> Parser (FunctionQualifier SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionQualifier SourcePos
-> Parser (FunctionQualifier SourcePos))
-> FunctionQualifier SourcePos
-> Parser (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 :: Parser (FunctionSpec SourcePos)
sourceParser = Parser (FunctionSpec SourcePos) -> Parser (FunctionSpec SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser (FunctionSpec SourcePos)
qualified Parser (FunctionSpec SourcePos)
-> Parser (FunctionSpec SourcePos)
-> Parser (FunctionSpec SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser (FunctionSpec SourcePos)
unqualified where
qualified :: Parser (FunctionSpec SourcePos)
qualified = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
FunctionQualifier SourcePos
q <- Parser (FunctionQualifier SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
FunctionName
n <- ParsecT String () Identity FunctionName
forall a. ParseFromSource a => Parser a
sourceParser
[InstanceOrInferred SourcePos]
ps <- ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos])
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
forall a b. (a -> b) -> a -> b
$ Parser ()
-> Parser ()
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"<")
(Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
">")
(ParsecT String () Identity (InstanceOrInferred SourcePos)
-> Parser ()
-> ParsecT String () Identity [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 () Identity (InstanceOrInferred SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
",")) ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [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 () Identity [InstanceOrInferred SourcePos]
forall (m :: * -> *) a. Monad m => a -> m a
return []
FunctionSpec SourcePos -> Parser (FunctionSpec SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionSpec SourcePos -> Parser (FunctionSpec SourcePos))
-> FunctionSpec SourcePos -> Parser (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 :: Parser (FunctionSpec SourcePos)
unqualified = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
FunctionName
n <- ParsecT String () Identity FunctionName
forall a. ParseFromSource a => Parser a
sourceParser
[InstanceOrInferred SourcePos]
ps <- ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos])
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
forall a b. (a -> b) -> a -> b
$ Parser ()
-> Parser ()
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"<")
(Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
">")
(ParsecT String () Identity (InstanceOrInferred SourcePos)
-> Parser ()
-> ParsecT String () Identity [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 () Identity (InstanceOrInferred SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
",")) ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [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 () Identity [InstanceOrInferred SourcePos]
forall (m :: * -> *) a. Monad m => a -> m a
return []
FunctionSpec SourcePos -> Parser (FunctionSpec SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionSpec SourcePos -> Parser (FunctionSpec SourcePos))
-> FunctionSpec SourcePos -> Parser (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 :: ParsecT String () Identity (InstanceOrInferred SourcePos)
sourceParser = ParsecT String () Identity (InstanceOrInferred SourcePos)
assigned ParsecT String () Identity (InstanceOrInferred SourcePos)
-> ParsecT String () Identity (InstanceOrInferred SourcePos)
-> ParsecT String () Identity (InstanceOrInferred SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (InstanceOrInferred SourcePos)
inferred where
assigned :: ParsecT String () Identity (InstanceOrInferred SourcePos)
assigned = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
GeneralInstance
t <- ParsecT String () Identity GeneralInstance
forall a. ParseFromSource a => Parser a
sourceParser
InstanceOrInferred SourcePos
-> ParsecT String () Identity (InstanceOrInferred SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (InstanceOrInferred SourcePos
-> ParsecT String () Identity (InstanceOrInferred SourcePos))
-> InstanceOrInferred SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (InstanceOrInferred SourcePos)
inferred = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall a. Parser a -> Parser ()
sepAfter_ Parser ()
inferredParam
InstanceOrInferred SourcePos
-> ParsecT String () Identity (InstanceOrInferred SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (InstanceOrInferred SourcePos
-> ParsecT String () Identity (InstanceOrInferred SourcePos))
-> InstanceOrInferred SourcePos
-> ParsecT String () Identity (InstanceOrInferred SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> InstanceOrInferred SourcePos
forall c. [c] -> InstanceOrInferred c
InferredInstance [SourcePos
c]
parseFunctionCall :: SourcePos -> FunctionName -> Parser (FunctionCall SourcePos)
parseFunctionCall :: SourcePos -> FunctionName -> Parser (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n = do
[InstanceOrInferred SourcePos]
ps <- ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos])
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
forall a b. (a -> b) -> a -> b
$ Parser ()
-> Parser ()
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"<")
(Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
">")
(ParsecT String () Identity (InstanceOrInferred SourcePos)
-> Parser ()
-> ParsecT String () Identity [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 () Identity (InstanceOrInferred SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
",")) ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [InstanceOrInferred SourcePos]
-> ParsecT String () Identity [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 () Identity [InstanceOrInferred SourcePos]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[Expression SourcePos]
es <- Parser ()
-> Parser ()
-> ParsecT String () Identity [Expression SourcePos]
-> ParsecT String () Identity [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 (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
"(")
(Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
")")
(Parser (Expression SourcePos)
-> Parser () -> ParsecT String () Identity [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 Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser (Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
string_ String
","))
FunctionCall SourcePos -> Parser (FunctionCall SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (FunctionCall SourcePos -> Parser (FunctionCall SourcePos))
-> FunctionCall SourcePos -> Parser (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 :: Parser FunctionName
builtinFunction :: ParsecT String () Identity FunctionName
builtinFunction = (ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName)
-> ParsecT String () Identity FunctionName
-> [ParsecT String () Identity FunctionName]
-> ParsecT String () Identity FunctionName
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
(<|>) (String -> ParsecT String () Identity FunctionName
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"empty") ([ParsecT String () Identity FunctionName]
-> ParsecT String () Identity FunctionName)
-> [ParsecT String () Identity FunctionName]
-> ParsecT String () Identity FunctionName
forall a b. (a -> b) -> a -> b
$ (ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName)
-> [ParsecT String () Identity FunctionName]
-> [ParsecT String () Identity FunctionName]
forall a b. (a -> b) -> [a] -> [b]
map ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try [
Parser ()
kwPresent Parser ()
-> ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParsecT String () Identity FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinPresent,
Parser ()
kwReduce Parser ()
-> ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParsecT String () Identity FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinReduce,
Parser ()
kwRequire Parser ()
-> ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParsecT String () Identity FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinRequire,
Parser ()
kwStrong Parser ()
-> ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParsecT String () Identity FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinStrong,
Parser ()
kwTypename Parser ()
-> ParsecT String () Identity FunctionName
-> ParsecT String () Identity FunctionName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunctionName -> ParsecT String () Identity FunctionName
forall (m :: * -> *) a. Monad m => a -> m a
return FunctionName
BuiltinTypename
]
instance ParseFromSource (ExpressionStart SourcePos) where
sourceParser :: Parser (ExpressionStart SourcePos)
sourceParser = String
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"expression start" (Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos))
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$
Parser (ExpressionStart SourcePos)
parens Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ExpressionStart SourcePos)
variableOrUnqualified Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ExpressionStart SourcePos)
builtinCall Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ExpressionStart SourcePos)
builtinValue Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ExpressionStart SourcePos)
sourceContext Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ExpressionStart SourcePos)
exprLookup Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ExpressionStart SourcePos)
categoryCall Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ExpressionStart SourcePos)
typeCall where
parens :: Parser (ExpressionStart SourcePos)
parens = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser ()
string_ String
"(")
ExpressionStart SourcePos
e <- Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (SourcePos -> Parser (ExpressionStart SourcePos)
assign SourcePos
c) Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> Parser (ExpressionStart SourcePos)
expr SourcePos
c
Parser () -> Parser ()
forall a. Parser a -> Parser a
sepAfter (String -> Parser ()
string_ String
")")
ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return ExpressionStart SourcePos
e
assign :: SourcePos -> Parser (ExpressionStart SourcePos)
assign :: SourcePos -> Parser (ExpressionStart SourcePos)
assign SourcePos
c = do
VariableName
n <- Parser VariableName
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
assignOperator
Expression SourcePos
e <- Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (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 :: SourcePos -> Parser (ExpressionStart SourcePos)
expr :: SourcePos -> Parser (ExpressionStart SourcePos)
expr SourcePos
c = do
Expression SourcePos
e <- Parser (Expression SourcePos)
forall a. ParseFromSource a => Parser a
sourceParser
ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (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 :: Parser (ExpressionStart SourcePos)
builtinCall = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
FunctionName
n <- ParsecT String () Identity FunctionName
builtinFunction
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> Parser (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (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 :: Parser (ExpressionStart SourcePos)
builtinValue = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
String
n <- Parser String
builtinValues
ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (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 :: Parser (ExpressionStart SourcePos)
sourceContext = do
Pragma SourcePos
pragma <- Parser (Pragma SourcePos)
pragmaSourceContext
case Pragma SourcePos
pragma of
(PragmaSourceContext SourcePos
c) -> ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (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
_ -> Parser (ExpressionStart SourcePos)
forall a. HasCallStack => a
undefined
exprLookup :: Parser (ExpressionStart SourcePos)
exprLookup = do
Pragma SourcePos
pragma <- Parser (Pragma SourcePos)
pragmaExprLookup
case Pragma SourcePos
pragma of
(PragmaExprLookup [SourcePos]
c String
name) -> ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall a b. (a -> b) -> a -> b
$ [SourcePos] -> String -> ExpressionStart SourcePos
forall c. [c] -> String -> ExpressionStart c
NamedMacro [SourcePos]
c String
name
Pragma SourcePos
_ -> Parser (ExpressionStart SourcePos)
forall a. HasCallStack => a
undefined
variableOrUnqualified :: Parser (ExpressionStart SourcePos)
variableOrUnqualified = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
VariableName
n <- Parser VariableName
forall a. ParseFromSource a => Parser a
sourceParser :: Parser VariableName
SourcePos -> VariableName -> Parser (ExpressionStart SourcePos)
asUnqualifiedCall SourcePos
c VariableName
n Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
-> Parser (ExpressionStart SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> VariableName -> Parser (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 -> Parser (ExpressionStart SourcePos)
asUnqualifiedCall SourcePos
c VariableName
n = do
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> Parser (FunctionCall SourcePos)
parseFunctionCall SourcePos
c (String -> FunctionName
FunctionName (VariableName -> String
vnName VariableName
n))
ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (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 :: Parser (ExpressionStart SourcePos)
categoryCall = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
CategoryName
t <- ParsecT String () Identity CategoryName
-> ParsecT String () Identity CategoryName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity CategoryName
-> ParsecT String () Identity CategoryName)
-> ParsecT String () Identity CategoryName
-> ParsecT String () Identity CategoryName
forall a b. (a -> b) -> a -> b
$ do
CategoryName
t2 <- ParsecT String () Identity CategoryName
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
categorySymbolGet
CategoryName -> ParsecT String () Identity CategoryName
forall (m :: * -> *) a. Monad m => a -> m a
return CategoryName
t2
FunctionName
n <- ParsecT String () Identity FunctionName
forall a. ParseFromSource a => Parser a
sourceParser
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> Parser (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (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 :: Parser (ExpressionStart SourcePos)
typeCall = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
TypeInstanceOrParam
t <- ParsecT String () Identity TypeInstanceOrParam
-> ParsecT String () Identity TypeInstanceOrParam
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity TypeInstanceOrParam
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
typeSymbolGet
FunctionName
n <- ParsecT String () Identity FunctionName
forall a. ParseFromSource a => Parser a
sourceParser
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> Parser (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ExpressionStart SourcePos -> Parser (ExpressionStart SourcePos))
-> ExpressionStart SourcePos -> Parser (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 :: Parser (ValueLiteral SourcePos)
sourceParser = String
-> Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"literal" (Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos))
-> Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
forall a b. (a -> b) -> a -> b
$
Parser (ValueLiteral SourcePos)
stringLiteral Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ValueLiteral SourcePos)
charLiteral Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ValueLiteral SourcePos)
escapedInteger Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ValueLiteral SourcePos)
integerOrDecimal Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ValueLiteral SourcePos)
boolLiteral Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
Parser (ValueLiteral SourcePos)
emptyLiteral where
stringLiteral :: Parser (ValueLiteral SourcePos)
stringLiteral = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
String -> Parser ()
string_ String
"\""
String
ss <- ParsecT String () Identity Char -> Parser () -> Parser String
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill ParsecT String () Identity Char
stringChar (String -> Parser ()
string_ String
"\"")
Parser ()
optionalSpace
ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> Parser (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 :: Parser (ValueLiteral SourcePos)
charLiteral = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
String -> Parser ()
string_ String
"'"
Char
ch <- ParsecT String () Identity Char
stringChar ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'"'
String -> Parser ()
string_ String
"'"
Parser ()
optionalSpace
ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> Parser (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 :: Parser (ValueLiteral SourcePos)
escapedInteger = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser ()
escapeStart
Char
b <- String -> ParsecT String () Identity 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 () Identity Integer
parseBin
Char
'B' -> ParsecT String () Identity Integer
parseBin
Char
'o' -> ParsecT String () Identity Integer
parseOct
Char
'O' -> ParsecT String () Identity Integer
parseOct
Char
'd' -> ParsecT String () Identity Integer
parseDec
Char
'D' -> ParsecT String () Identity Integer
parseDec
Char
'x' -> ParsecT String () Identity Integer
parseHex
Char
'X' -> ParsecT String () Identity Integer
parseHex
Char
_ -> ParsecT String () Identity Integer
forall a. HasCallStack => a
undefined
Parser ()
optionalSpace
ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> Parser (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 :: Parser (ValueLiteral SourcePos)
integerOrDecimal = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Integer
d <- ParsecT String () Identity Integer
parseDec
SourcePos -> Integer -> Parser (ValueLiteral SourcePos)
forall c.
c -> Integer -> ParsecT String () Identity (ValueLiteral c)
decimal SourcePos
c Integer
d Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
-> Parser (ValueLiteral SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> SourcePos -> Integer -> Parser (ValueLiteral SourcePos)
forall c.
c -> Integer -> ParsecT String () Identity (ValueLiteral c)
integer SourcePos
c Integer
d
decimal :: c -> Integer -> ParsecT String () Identity (ValueLiteral c)
decimal c
c Integer
d = do
Char -> Parser ()
char_ Char
'.'
(Integer
n,Integer
d2) <- Parser (Integer, Integer)
parseSubOne
Integer
e <- ParsecT String () Identity Integer
decExponent ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Integer -> ParsecT String () Identity Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
0
Parser ()
optionalSpace
ValueLiteral c -> ParsecT String () Identity (ValueLiteral c)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral c -> ParsecT String () Identity (ValueLiteral c))
-> ValueLiteral c -> ParsecT String () Identity (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 () Identity Integer
decExponent = do
String -> Parser ()
string_ String
"e" Parser () -> Parser () -> Parser ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> Parser ()
string_ String
"E"
Integer
s <- (String -> Parser ()
string_ String
"+" Parser ()
-> ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Integer -> ParsecT String () Identity Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
1) ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (String -> Parser ()
string_ String
"-" Parser ()
-> ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Integer -> ParsecT String () Identity Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (-Integer
1)) ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
-> ParsecT String () Identity Integer
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Integer -> ParsecT String () Identity Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
1
Integer
e <- ParsecT String () Identity Integer
parseDec
Integer -> ParsecT String () Identity 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 () Identity (ValueLiteral c)
integer c
c Integer
d = do
Parser ()
optionalSpace
ValueLiteral c -> ParsecT String () Identity (ValueLiteral c)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral c -> ParsecT String () Identity (ValueLiteral c))
-> ValueLiteral c -> ParsecT String () Identity (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 :: Parser (ValueLiteral SourcePos)
boolLiteral = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Bool
b <- ParsecT String () Identity Bool -> ParsecT String () Identity Bool
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity Bool
-> ParsecT String () Identity Bool)
-> ParsecT String () Identity Bool
-> ParsecT String () Identity Bool
forall a b. (a -> b) -> a -> b
$ (Parser ()
kwTrue Parser ()
-> ParsecT String () Identity Bool
-> ParsecT String () Identity Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT String () Identity Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True) ParsecT String () Identity Bool
-> ParsecT String () Identity Bool
-> ParsecT String () Identity Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Parser ()
kwFalse Parser ()
-> ParsecT String () Identity Bool
-> ParsecT String () Identity Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT String () Identity Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False)
ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> Parser (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 :: Parser (ValueLiteral SourcePos)
emptyLiteral = do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser () -> Parser ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try Parser ()
kwEmpty
ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueLiteral SourcePos -> Parser (ValueLiteral SourcePos))
-> ValueLiteral SourcePos -> Parser (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 :: ParsecT String () Identity (ValueOperation SourcePos)
sourceParser = ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity (ValueOperation SourcePos)
valueCall ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT String () Identity (ValueOperation SourcePos)
conversion where
valueCall :: ParsecT String () Identity (ValueOperation SourcePos)
valueCall = String
-> ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"function call" (ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos))
-> ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser ()
valueSymbolGet
FunctionName
n <- ParsecT String () Identity FunctionName
forall a. ParseFromSource a => Parser a
sourceParser
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> Parser (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ValueOperation SourcePos
-> ParsecT String () Identity (ValueOperation SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueOperation SourcePos
-> ParsecT String () Identity (ValueOperation SourcePos))
-> ValueOperation SourcePos
-> ParsecT String () Identity (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 :: ParsecT String () Identity (ValueOperation SourcePos)
conversion = String
-> ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos)
forall a. String -> Parser a -> Parser a
labeled String
"type conversion" (ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos))
-> ParsecT String () Identity (ValueOperation SourcePos)
-> ParsecT String () Identity (ValueOperation SourcePos)
forall a b. (a -> b) -> a -> b
$ do
SourcePos
c <- ParsecT String () Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Parser ()
valueSymbolGet
TypeInstance
t <- ParsecT String () Identity TypeInstance
forall a. ParseFromSource a => Parser a
sourceParser
Parser ()
typeSymbolGet
FunctionName
n <- ParsecT String () Identity FunctionName
forall a. ParseFromSource a => Parser a
sourceParser
FunctionCall SourcePos
f <- SourcePos -> FunctionName -> Parser (FunctionCall SourcePos)
parseFunctionCall SourcePos
c FunctionName
n
ValueOperation SourcePos
-> ParsecT String () Identity (ValueOperation SourcePos)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValueOperation SourcePos
-> ParsecT String () Identity (ValueOperation SourcePos))
-> ValueOperation SourcePos
-> ParsecT String () Identity (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