{-# LANGUAGE DeriveFunctor     #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData        #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# LANGUAGE DeriveGeneric     #-}
module Language.GLSL.Parser where

import           Control.Applicative              ((<|>))
import           Data.Attoparsec.ByteString.Char8 (IResult (..), Parser, char,
                                                   decimal, endOfInput, many1,
                                                   option, parse, parseOnly,
                                                   rational, scientific, sepBy1)
import qualified Data.Scientific                  as Sci
import qualified Data.Text.Encoding               as T
import qualified Data.Text.Lazy                   as LT
import           Language.GLSL.AST


parseShader :: Annot a => LT.Text -> Either String (GLSL a)
parseShader :: Text -> Either String (GLSL a)
parseShader = Parser (GLSL a) -> ByteString -> Either String (GLSL a)
forall a. Parser a -> ByteString -> Either String a
parseOnly Parser (GLSL a)
forall a. Annot a => Parser (GLSL a)
parseGLSL (ByteString -> Either String (GLSL a))
-> (Text -> ByteString) -> Text -> Either String (GLSL a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
T.encodeUtf8 (Text -> ByteString) -> (Text -> Text) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
LT.toStrict

-- | Parse GLSL

parseGLSL :: Annot a => Parser (GLSL a)
parseGLSL :: Parser (GLSL a)
parseGLSL = Version -> [TopDecl a] -> GLSL a
forall a. Version -> [TopDecl a] -> GLSL a
GLSL
  (Version -> [TopDecl a] -> GLSL a)
-> Parser ByteString Version
-> Parser ByteString ([TopDecl a] -> GLSL a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Version
parseVersion
  Parser ByteString ([TopDecl a] -> GLSL a)
-> Parser ByteString [TopDecl a] -> Parser (GLSL a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"\n" Parser ByteString ByteString
-> Parser ByteString [TopDecl a] -> Parser ByteString [TopDecl a]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString (TopDecl a) -> Parser ByteString [TopDecl a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 Parser ByteString (TopDecl a)
forall a. Annot a => Parser (TopDecl a)
parseTopDecl Parser ByteString [TopDecl a]
-> ([TopDecl a] -> Parser ByteString [TopDecl a])
-> Parser ByteString [TopDecl a]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ()
forall t. Chunk t => Parser t ()
endOfInput Parser ByteString ()
-> Parser ByteString [TopDecl a] -> Parser ByteString [TopDecl a]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString [TopDecl a] -> Parser ByteString [TopDecl a])
-> ([TopDecl a] -> Parser ByteString [TopDecl a])
-> [TopDecl a]
-> Parser ByteString [TopDecl a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [TopDecl a] -> Parser ByteString [TopDecl a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure)

-- | Parse Version

parseVersion :: Parser Version
parseVersion :: Parser ByteString Version
parseVersion = Int -> Version
Version (Int -> Version)
-> Parser ByteString Int -> Parser ByteString Version
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"#version " Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Int
forall a. Integral a => Parser a
decimal)

-- | Parse TopDecl

parseTopDecl :: Annot a => Parser (TopDecl a)
parseTopDecl :: Parser (TopDecl a)
parseTopDecl = Parser (TopDecl a)
forall a. Parser ByteString (TopDecl a)
layoutDecl Parser (TopDecl a) -> Parser (TopDecl a) -> Parser (TopDecl a)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser (TopDecl a)
forall a. Parser ByteString (TopDecl a)
globalDecl Parser (TopDecl a) -> Parser (TopDecl a) -> Parser (TopDecl a)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser (TopDecl a)
procDecl
  where
    layoutDecl :: Parser ByteString (TopDecl a)
layoutDecl = LayoutSpec -> GlobalDecl -> TopDecl a
forall a. LayoutSpec -> GlobalDecl -> TopDecl a
LayoutDecl
      (LayoutSpec -> GlobalDecl -> TopDecl a)
-> Parser ByteString LayoutSpec
-> Parser ByteString (GlobalDecl -> TopDecl a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"layout(" Parser ByteString ByteString
-> Parser ByteString LayoutSpec -> Parser ByteString LayoutSpec
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString LayoutSpec
parseLayoutSpec)
      Parser ByteString (GlobalDecl -> TopDecl a)
-> Parser ByteString GlobalDecl -> Parser ByteString (TopDecl a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
") " Parser ByteString ByteString
-> Parser ByteString GlobalDecl -> Parser ByteString GlobalDecl
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString GlobalDecl
parseGlobalDecl)

    globalDecl :: Parser ByteString (TopDecl a)
globalDecl = GlobalDecl -> TopDecl a
forall a. GlobalDecl -> TopDecl a
GlobalDecl
      (GlobalDecl -> TopDecl a)
-> Parser ByteString GlobalDecl -> Parser ByteString (TopDecl a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString GlobalDecl
parseGlobalDecl

    procDecl :: Parser (TopDecl a)
procDecl = ProcName -> [ParamDecl] -> [StmtAnnot a] -> TopDecl a
forall a. ProcName -> [ParamDecl] -> [StmtAnnot a] -> TopDecl a
ProcDecl
      (ProcName -> [ParamDecl] -> [StmtAnnot a] -> TopDecl a)
-> Parser ByteString ProcName
-> Parser ByteString ([ParamDecl] -> [StmtAnnot a] -> TopDecl a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"void " Parser ByteString ByteString
-> Parser ByteString ProcName -> Parser ByteString ProcName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString ProcName
parseProcName)
      Parser ByteString ([ParamDecl] -> [StmtAnnot a] -> TopDecl a)
-> Parser ByteString [ParamDecl]
-> Parser ByteString ([StmtAnnot a] -> TopDecl a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"() " Parser ByteString ByteString
-> Parser ByteString [ParamDecl] -> Parser ByteString [ParamDecl]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [ParamDecl] -> Parser ByteString [ParamDecl]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [])
      -- <*> ("{\n" >> many1 parseStmtAnnot)
      Parser ByteString ([StmtAnnot a] -> TopDecl a)
-> Parser ByteString [StmtAnnot a] -> Parser (TopDecl a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"{\n" Parser ByteString ByteString
-> Parser ByteString [StmtAnnot a]
-> Parser ByteString [StmtAnnot a]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString (StmtAnnot a) -> Parser ByteString [StmtAnnot a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 Parser ByteString (StmtAnnot a)
forall a. Annot a => Parser (StmtAnnot a)
parseStmtAnnot Parser ByteString [StmtAnnot a]
-> ([StmtAnnot a] -> Parser ByteString [StmtAnnot a])
-> Parser ByteString [StmtAnnot a]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
"}\n" Parser ByteString ByteString
-> Parser ByteString [StmtAnnot a]
-> Parser ByteString [StmtAnnot a]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString [StmtAnnot a]
 -> Parser ByteString [StmtAnnot a])
-> ([StmtAnnot a] -> Parser ByteString [StmtAnnot a])
-> [StmtAnnot a]
-> Parser ByteString [StmtAnnot a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [StmtAnnot a] -> Parser ByteString [StmtAnnot a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure)

-- | Parse ProcName

parseProcName :: Parser ProcName
parseProcName :: Parser ByteString ProcName
parseProcName =
  (Parser ByteString ByteString
"main" Parser ByteString ByteString
-> Parser ByteString ProcName -> Parser ByteString ProcName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ProcName -> Parser ByteString ProcName
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProcName
ProcMain)
  Parser ByteString ProcName
-> Parser ByteString ProcName -> Parser ByteString ProcName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"p" Parser ByteString ByteString
-> Parser ByteString ProcName -> Parser ByteString ProcName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> NameId -> ProcName
ProcName (NameId -> ProcName)
-> Parser ByteString NameId -> Parser ByteString ProcName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString NameId
parseNameId)

-- | Parse LayoutSpec

parseLayoutSpec :: Parser LayoutSpec
parseLayoutSpec :: Parser ByteString LayoutSpec
parseLayoutSpec =
  (Parser ByteString ByteString
"std140" Parser ByteString ByteString
-> Parser ByteString LayoutSpec -> Parser ByteString LayoutSpec
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LayoutSpec -> Parser ByteString LayoutSpec
forall (f :: * -> *) a. Applicative f => a -> f a
pure LayoutSpec
LayoutStd140)
  Parser ByteString LayoutSpec
-> Parser ByteString LayoutSpec -> Parser ByteString LayoutSpec
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"location = " Parser ByteString ByteString
-> Parser ByteString LayoutSpec -> Parser ByteString LayoutSpec
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> LayoutSpec
LayoutLocation (Int -> LayoutSpec)
-> Parser ByteString Int -> Parser ByteString LayoutSpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Int
forall a. Integral a => Parser a
decimal)

-- | Parse ParamDecl

parseParamDecl :: Parser ParamDecl
parseParamDecl :: Parser ParamDecl
parseParamDecl = ParamKind -> LocalDecl -> ParamDecl
Param
  (ParamKind -> LocalDecl -> ParamDecl)
-> Parser ByteString ParamKind
-> Parser ByteString (LocalDecl -> ParamDecl)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString ParamKind
parseParamKind
  Parser ByteString (LocalDecl -> ParamDecl)
-> Parser ByteString LocalDecl -> Parser ParamDecl
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
" " Parser ByteString ByteString
-> Parser ByteString LocalDecl -> Parser ByteString LocalDecl
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString LocalDecl
parseLocalDecl)

-- | Parse ParamKind

parseParamKind :: Parser ParamKind
parseParamKind :: Parser ByteString ParamKind
parseParamKind = (Char -> Parser Char
char Char
' ' Parser Char -> Parser Char -> Parser Char
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser Char
forall (f :: * -> *) a. Applicative f => a -> f a
pure Char
' ') Parser Char
-> Parser ByteString ParamKind -> Parser ByteString ParamKind
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  (Parser ByteString ByteString
"in" Parser ByteString ByteString
-> Parser ByteString ParamKind -> Parser ByteString ParamKind
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParamKind -> Parser ByteString ParamKind
forall (m :: * -> *) a. Monad m => a -> m a
return ParamKind
PkIn) Parser ByteString ParamKind
-> Parser ByteString ParamKind -> Parser ByteString ParamKind
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
  (Parser ByteString ByteString
"out" Parser ByteString ByteString
-> Parser ByteString ParamKind -> Parser ByteString ParamKind
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParamKind -> Parser ByteString ParamKind
forall (m :: * -> *) a. Monad m => a -> m a
return ParamKind
PkOut) Parser ByteString ParamKind
-> Parser ByteString ParamKind -> Parser ByteString ParamKind
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
  (Parser ByteString ByteString
"inout" Parser ByteString ByteString
-> Parser ByteString ParamKind -> Parser ByteString ParamKind
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParamKind -> Parser ByteString ParamKind
forall (m :: * -> *) a. Monad m => a -> m a
return ParamKind
PkInout)

-- | Parse LocalDecl

parseLocalDecl :: Parser LocalDecl
parseLocalDecl :: Parser ByteString LocalDecl
parseLocalDecl = Type -> NameId -> Maybe Expr -> LocalDecl
LDecl
  (Type -> NameId -> Maybe Expr -> LocalDecl)
-> Parser ByteString Type
-> Parser ByteString (NameId -> Maybe Expr -> LocalDecl)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Type
parseType
  Parser ByteString (NameId -> Maybe Expr -> LocalDecl)
-> Parser ByteString NameId
-> Parser ByteString (Maybe Expr -> LocalDecl)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
" t" Parser ByteString ByteString
-> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString NameId
parseNameId)
  Parser ByteString (Maybe Expr -> LocalDecl)
-> Parser ByteString (Maybe Expr) -> Parser ByteString LocalDecl
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe Expr
-> Parser ByteString (Maybe Expr) -> Parser ByteString (Maybe Expr)
forall (f :: * -> *) a. Alternative f => a -> f a -> f a
option Maybe Expr
forall a. Maybe a
Nothing (Parser ByteString ByteString
" = " Parser ByteString ByteString
-> Parser ByteString (Maybe Expr) -> Parser ByteString (Maybe Expr)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> Maybe Expr
forall a. a -> Maybe a
Just (Expr -> Maybe Expr)
-> Parser ByteString Expr -> Parser ByteString (Maybe Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Expr
parseExpr) Parser ByteString (Maybe Expr)
-> (Maybe Expr -> Parser ByteString (Maybe Expr))
-> Parser ByteString (Maybe Expr)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
";\n" Parser ByteString ByteString
-> Parser ByteString (Maybe Expr) -> Parser ByteString (Maybe Expr)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString (Maybe Expr) -> Parser ByteString (Maybe Expr))
-> (Maybe Expr -> Parser ByteString (Maybe Expr))
-> Maybe Expr
-> Parser ByteString (Maybe Expr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Expr -> Parser ByteString (Maybe Expr)
forall (f :: * -> *) a. Applicative f => a -> f a
pure)

-- | Parse GlobalDecl

parseGlobalDecl :: Parser GlobalDecl
parseGlobalDecl :: Parser ByteString GlobalDecl
parseGlobalDecl = GDeclKind -> Type -> Name -> GlobalDecl
GDecl
  (GDeclKind -> Type -> Name -> GlobalDecl)
-> Parser ByteString GDeclKind
-> Parser ByteString (Type -> Name -> GlobalDecl)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString GDeclKind
parseGDeclKind
  Parser ByteString (Type -> Name -> GlobalDecl)
-> Parser ByteString Type -> Parser ByteString (Name -> GlobalDecl)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
" " Parser ByteString ByteString
-> Parser ByteString Type -> Parser ByteString Type
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Type
parseType)
  Parser ByteString (Name -> GlobalDecl)
-> Parser ByteString Name -> Parser ByteString GlobalDecl
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
" " Parser ByteString ByteString
-> Parser ByteString Name -> Parser ByteString Name
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Name
parseName Parser ByteString Name
-> (Name -> Parser ByteString Name) -> Parser ByteString Name
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
";\n" Parser ByteString ByteString
-> Parser ByteString Name -> Parser ByteString Name
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString Name -> Parser ByteString Name)
-> (Name -> Parser ByteString Name)
-> Name
-> Parser ByteString Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Parser ByteString Name
forall (f :: * -> *) a. Applicative f => a -> f a
pure)

-- | Parse GDeclKind

parseGDeclKind :: Parser GDeclKind
parseGDeclKind :: Parser ByteString GDeclKind
parseGDeclKind =
  (Parser ByteString ByteString
"in" Parser ByteString ByteString
-> Parser ByteString GDeclKind -> Parser ByteString GDeclKind
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> GDeclKind -> Parser ByteString GDeclKind
forall (m :: * -> *) a. Monad m => a -> m a
return GDeclKind
GkIn) Parser ByteString GDeclKind
-> Parser ByteString GDeclKind -> Parser ByteString GDeclKind
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
  (Parser ByteString ByteString
"out" Parser ByteString ByteString
-> Parser ByteString GDeclKind -> Parser ByteString GDeclKind
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> GDeclKind -> Parser ByteString GDeclKind
forall (m :: * -> *) a. Monad m => a -> m a
return GDeclKind
GkOut) Parser ByteString GDeclKind
-> Parser ByteString GDeclKind -> Parser ByteString GDeclKind
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
  (Parser ByteString ByteString
"uniform" Parser ByteString ByteString
-> Parser ByteString GDeclKind -> Parser ByteString GDeclKind
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> GDeclKind -> Parser ByteString GDeclKind
forall (m :: * -> *) a. Monad m => a -> m a
return GDeclKind
GkUniform)

-- | Parse Type

parseType :: Parser Type
parseType :: Parser ByteString Type
parseType =
  (Parser ByteString ByteString
"bool" Parser ByteString ByteString
-> Parser ByteString Type -> Parser ByteString Type
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Type -> Parser ByteString Type
forall (m :: * -> *) a. Monad m => a -> m a
return Type
TyBool)
  Parser ByteString Type
-> Parser ByteString Type -> Parser ByteString Type
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"float" Parser ByteString ByteString
-> Parser ByteString Type -> Parser ByteString Type
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Type -> Parser ByteString Type
forall (m :: * -> *) a. Monad m => a -> m a
return Type
TyFloat)
  Parser ByteString Type
-> Parser ByteString Type -> Parser ByteString Type
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"sampler2D" Parser ByteString ByteString
-> Parser ByteString Type -> Parser ByteString Type
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Type -> Parser ByteString Type
forall (m :: * -> *) a. Monad m => a -> m a
return Type
TySampler2D)
  Parser ByteString Type
-> Parser ByteString Type -> Parser ByteString Type
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"vec" Parser ByteString ByteString
-> Parser ByteString Type -> Parser ByteString Type
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Type
TyVec (Int -> Type) -> Parser ByteString Int -> Parser ByteString Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Int
forall a. Integral a => Parser a
decimal)
  Parser ByteString Type
-> Parser ByteString Type -> Parser ByteString Type
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"mat" Parser ByteString ByteString
-> Parser ByteString Type -> Parser ByteString Type
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Int -> Type
TyMat (Int -> Int -> Type)
-> Parser ByteString Int -> Parser ByteString (Int -> Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Int
forall a. Integral a => Parser a
decimal Parser ByteString (Int -> Type)
-> Parser ByteString Int -> Parser ByteString Type
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"x" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Int
forall a. Integral a => Parser a
decimal))
  Parser ByteString Type
-> Parser ByteString Type -> Parser ByteString Type
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ByteString Type
tyStruct
  where
    tyStruct :: Parser ByteString Type
tyStruct = NameId -> [(Type, NameId)] -> Type
TyStruct
      (NameId -> [(Type, NameId)] -> Type)
-> Parser ByteString NameId
-> Parser ByteString ([(Type, NameId)] -> Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"uBlock" Parser ByteString ByteString
-> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString NameId
parseNameId)
      Parser ByteString ([(Type, NameId)] -> Type)
-> Parser ByteString [(Type, NameId)] -> Parser ByteString Type
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
" {\n" Parser ByteString ByteString
-> Parser ByteString [(Type, NameId)]
-> Parser ByteString [(Type, NameId)]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString (Type, NameId)
-> Parser ByteString [(Type, NameId)]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 Parser ByteString (Type, NameId)
parseStructMember Parser ByteString [(Type, NameId)]
-> ([(Type, NameId)] -> Parser ByteString [(Type, NameId)])
-> Parser ByteString [(Type, NameId)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
"}" Parser ByteString ByteString
-> Parser ByteString [(Type, NameId)]
-> Parser ByteString [(Type, NameId)]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString [(Type, NameId)]
 -> Parser ByteString [(Type, NameId)])
-> ([(Type, NameId)] -> Parser ByteString [(Type, NameId)])
-> [(Type, NameId)]
-> Parser ByteString [(Type, NameId)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Type, NameId)] -> Parser ByteString [(Type, NameId)]
forall (f :: * -> *) a. Applicative f => a -> f a
pure)

    parseStructMember :: Parser (Type, NameId)
    parseStructMember :: Parser ByteString (Type, NameId)
parseStructMember = (,)
      (Type -> NameId -> (Type, NameId))
-> Parser ByteString Type
-> Parser ByteString (NameId -> (Type, NameId))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Type
parseType
      Parser ByteString (NameId -> (Type, NameId))
-> Parser ByteString NameId -> Parser ByteString (Type, NameId)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
" u" Parser ByteString ByteString
-> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString NameId
parseNameId Parser ByteString NameId
-> (NameId -> Parser ByteString NameId) -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
";\n" Parser ByteString ByteString
-> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString NameId -> Parser ByteString NameId)
-> (NameId -> Parser ByteString NameId)
-> NameId
-> Parser ByteString NameId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NameId -> Parser ByteString NameId
forall (f :: * -> *) a. Applicative f => a -> f a
pure)

-- | Parse NameId

parseNameId :: Parser NameId
parseNameId :: Parser ByteString NameId
parseNameId = Int -> NameId
NameId
  (Int -> NameId)
-> Parser ByteString Int -> Parser ByteString NameId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Int
forall a. Integral a => Parser a
decimal

-- | Parse Name

parseName :: Parser Name
parseName :: Parser ByteString Name
parseName = Namespace -> NameId -> Name
Name
  (Namespace -> NameId -> Name)
-> Parser ByteString Namespace
-> Parser ByteString (NameId -> Name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Namespace
parseNamespace
  Parser ByteString (NameId -> Name)
-> Parser ByteString NameId -> Parser ByteString Name
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ByteString NameId
parseNameId

-- | Parse Namespace

parseNamespace :: Parser Namespace
parseNamespace :: Parser ByteString Namespace
parseNamespace =
  (Parser ByteString ByteString
"in" Parser ByteString ByteString
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace
NsIn)
  Parser ByteString Namespace
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"out" Parser ByteString ByteString
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace
NsOut)
  Parser ByteString Namespace
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"vf" Parser ByteString ByteString
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace
NsVF)
  Parser ByteString Namespace
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
't' Parser Char
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace
NsT)
  Parser ByteString Namespace
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'u' Parser Char
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace
NsU)
  Parser ByteString Namespace
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
's' Parser Char
-> Parser ByteString Namespace -> Parser ByteString Namespace
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Namespace -> Parser ByteString Namespace
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace
NsS)

-- | Parse FunName

parseFunName :: Parser FunName
parseFunName :: Parser FunName
parseFunName =
  (Parser ByteString ByteString
"abs" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimAbs)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"asin" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimAsin)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"atan" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimAtan)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"cos" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimCos)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"cross" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimCross)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"dot" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimDot)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"floor" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimFloor)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"fract" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimFract)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"length" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimLength)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"mat3x3" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimMat3x3)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"mat4x4" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimMat4x4)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"mod" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimMod)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"normalize" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimNormalize)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"pow" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimPow)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"sin" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimSin)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"smoothstep" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimSmoothstep)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"sqrt" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimSqrt)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"step" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimStep)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"tan" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimTan)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"vec2" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimVec2)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"vec3" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimVec3)
  Parser FunName -> Parser FunName -> Parser FunName
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"vec4" Parser ByteString ByteString -> Parser FunName -> Parser FunName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FunName -> Parser FunName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunName
PrimVec4)

-- | Parse Swizzle

parseSwizzle :: Parser Swizzle
parseSwizzle :: Parser Swizzle
parseSwizzle =
  (Char -> Parser Char
char Char
'x' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure Swizzle
X)
  Parser Swizzle -> Parser Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'y' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure Swizzle
Y)
  Parser Swizzle -> Parser Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'z' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure Swizzle
Z)
  Parser Swizzle -> Parser Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'w' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure Swizzle
W)

-- | Parse VecIndex (Swizzle)

parseVecIndex :: Parser Swizzle
parseVecIndex :: Parser Swizzle
parseVecIndex =
  (Char -> Parser Char
char Char
'0' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure Swizzle
X)
  Parser Swizzle -> Parser Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'1' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure Swizzle
Y)
  Parser Swizzle -> Parser Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'2' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure Swizzle
Z)
  Parser Swizzle -> Parser Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'3' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure Swizzle
W)

-- | Parse NameExpr

parseNameExpr :: Parser NameExpr
parseNameExpr :: Parser NameExpr
parseNameExpr =
  NameId -> NameId -> NameExpr
UniformExpr (NameId -> NameId -> NameExpr)
-> Parser ByteString NameId
-> Parser ByteString (NameId -> NameExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> Parser Char
char Char
'u' Parser Char -> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString NameId
parseNameId) Parser ByteString (NameId -> NameExpr)
-> Parser ByteString NameId -> Parser NameExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
".u" Parser ByteString ByteString
-> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString NameId
parseNameId)
  Parser NameExpr -> Parser NameExpr -> Parser NameExpr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Name -> NameExpr
NameExpr (Name -> NameExpr) -> Parser ByteString Name -> Parser NameExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Name
parseName

-- | Parse ExprAtom

parseExprAtom :: Parser ExprAtom
parseExprAtom :: Parser ExprAtom
parseExprAtom =
  Scientific -> ExprAtom
litNumber (Scientific -> ExprAtom)
-> Parser ByteString Scientific -> Parser ExprAtom
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Scientific
scientific
  Parser ExprAtom -> Parser ExprAtom -> Parser ExprAtom
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Cast -> Int -> ExprAtom
LitIntExpr Cast
Cast (Int -> ExprAtom) -> Parser ByteString Int -> Parser ExprAtom
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"int(" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Int
forall a. Integral a => Parser a
decimal Parser ByteString Int
-> (Int -> Parser ByteString Int) -> Parser ByteString Int
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
")" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString Int -> Parser ByteString Int)
-> (Int -> Parser ByteString Int) -> Int -> Parser ByteString Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Parser ByteString Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  Parser ExprAtom -> Parser ExprAtom -> Parser ExprAtom
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Cast -> Float -> ExprAtom
LitFloatExpr Cast
Cast (Float -> ExprAtom) -> Parser ByteString Float -> Parser ExprAtom
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"float(" Parser ByteString ByteString
-> Parser ByteString Float -> Parser ByteString Float
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Float
forall a. Fractional a => Parser a
rational Parser ByteString Float
-> (Float -> Parser ByteString Float) -> Parser ByteString Float
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
")" Parser ByteString ByteString
-> Parser ByteString Float -> Parser ByteString Float
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString Float -> Parser ByteString Float)
-> (Float -> Parser ByteString Float)
-> Float
-> Parser ByteString Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Parser ByteString Float
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  Parser ExprAtom -> Parser ExprAtom -> Parser ExprAtom
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NameId -> Swizzle -> ExprAtom
SwizzleExpr (NameId -> Swizzle -> ExprAtom)
-> Parser ByteString NameId
-> Parser ByteString (Swizzle -> ExprAtom)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> Parser Char
char Char
't' Parser Char -> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString NameId
parseNameId) Parser ByteString (Swizzle -> ExprAtom)
-> Parser Swizzle -> Parser ExprAtom
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Parser Char
char Char
'.' Parser Char -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Swizzle
parseSwizzle)
  Parser ExprAtom -> Parser ExprAtom -> Parser ExprAtom
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NameExpr -> Swizzle -> Swizzle -> ExprAtom
MatIndexExpr (NameExpr -> Swizzle -> Swizzle -> ExprAtom)
-> Parser NameExpr
-> Parser ByteString (Swizzle -> Swizzle -> ExprAtom)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NameExpr
parseNameExpr Parser ByteString (Swizzle -> Swizzle -> ExprAtom)
-> Parser Swizzle -> Parser ByteString (Swizzle -> ExprAtom)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"[" Parser ByteString ByteString -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Swizzle
parseVecIndex) Parser ByteString (Swizzle -> ExprAtom)
-> Parser Swizzle -> Parser ExprAtom
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"][" Parser ByteString ByteString -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Swizzle
parseVecIndex Parser Swizzle -> (Swizzle -> Parser Swizzle) -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
"]" Parser ByteString ByteString -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser Swizzle -> Parser Swizzle)
-> (Swizzle -> Parser Swizzle) -> Swizzle -> Parser Swizzle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  Parser ExprAtom -> Parser ExprAtom -> Parser ExprAtom
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NameExpr -> Swizzle -> ExprAtom
VecIndexExpr (NameExpr -> Swizzle -> ExprAtom)
-> Parser NameExpr -> Parser ByteString (Swizzle -> ExprAtom)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NameExpr
parseNameExpr Parser ByteString (Swizzle -> ExprAtom)
-> Parser Swizzle -> Parser ExprAtom
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"[" Parser ByteString ByteString -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Swizzle
parseVecIndex Parser Swizzle -> (Swizzle -> Parser Swizzle) -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
"]" Parser ByteString ByteString -> Parser Swizzle -> Parser Swizzle
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser Swizzle -> Parser Swizzle)
-> (Swizzle -> Parser Swizzle) -> Swizzle -> Parser Swizzle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Swizzle -> Parser Swizzle
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  Parser ExprAtom -> Parser ExprAtom -> Parser ExprAtom
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NameExpr -> ExprAtom
IdentifierExpr (NameExpr -> ExprAtom) -> Parser NameExpr -> Parser ExprAtom
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NameExpr
parseNameExpr
  where
    litNumber :: Scientific -> ExprAtom
litNumber Scientific
s =
      let e :: Int
e = Scientific -> Int
Sci.base10Exponent Scientific
s
          c :: Integer
c = Scientific -> Integer
Sci.coefficient Scientific
s
      in if Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0
          then Cast -> Int -> ExprAtom
LitIntExpr Cast
NoCast (Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Integer
c Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
10 Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
e))
          else Cast -> Float -> ExprAtom
LitFloatExpr Cast
NoCast (Scientific -> Float
forall a. RealFloat a => Scientific -> a
Sci.toRealFloat Scientific
s)

-- | Parse Expr

parseExpr :: Parser Expr
parseExpr :: Parser ByteString Expr
parseExpr =
  (Char -> Parser Char
char Char
'(' Parser Char -> Parser ByteString Expr -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Expr
operatorExpr Parser ByteString Expr
-> (Expr -> Parser ByteString Expr) -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Char -> Parser Char
char Char
')' Parser Char -> Parser ByteString Expr -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString Expr -> Parser ByteString Expr)
-> (Expr -> Parser ByteString Expr)
-> Expr
-> Parser ByteString Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> Parser ByteString Expr
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  Parser ByteString Expr
-> Parser ByteString Expr -> Parser ByteString Expr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ByteString Expr
textureExpr
  Parser ByteString Expr
-> Parser ByteString Expr -> Parser ByteString Expr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ByteString Expr
funCallExpr
  Parser ByteString Expr
-> Parser ByteString Expr -> Parser ByteString Expr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ExprAtom -> Expr
AtomExpr (ExprAtom -> Expr) -> Parser ExprAtom -> Parser ByteString Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ExprAtom
parseExprAtom

  where
    operatorExpr :: Parser ByteString Expr
operatorExpr =
      ExprAtom -> BinaryOp -> ExprAtom -> Expr
BinaryExpr (ExprAtom -> BinaryOp -> ExprAtom -> Expr)
-> Parser ExprAtom
-> Parser ByteString (BinaryOp -> ExprAtom -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ExprAtom
parseExprAtom Parser ByteString (BinaryOp -> ExprAtom -> Expr)
-> Parser ByteString BinaryOp
-> Parser ByteString (ExprAtom -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ByteString BinaryOp
parseBinaryOp Parser ByteString (ExprAtom -> Expr)
-> Parser ExprAtom -> Parser ByteString Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ExprAtom
parseExprAtom
      Parser ByteString Expr
-> Parser ByteString Expr -> Parser ByteString Expr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> UnaryOp -> ExprAtom -> Expr
UnaryExpr (UnaryOp -> ExprAtom -> Expr)
-> Parser ByteString UnaryOp
-> Parser ByteString (ExprAtom -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString UnaryOp
parseUnaryOp Parser ByteString (ExprAtom -> Expr)
-> Parser ExprAtom -> Parser ByteString Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ExprAtom
parseExprAtom

    textureExpr :: Parser ByteString Expr
textureExpr = ExprAtom -> ExprAtom -> ExprAtom -> Expr
TextureExpr
      (ExprAtom -> ExprAtom -> ExprAtom -> Expr)
-> Parser ExprAtom
-> Parser ByteString (ExprAtom -> ExprAtom -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"texture(" Parser ByteString ByteString -> Parser ExprAtom -> Parser ExprAtom
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ExprAtom
parseExprAtom)
      Parser ByteString (ExprAtom -> ExprAtom -> Expr)
-> Parser ExprAtom -> Parser ByteString (ExprAtom -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
",vec2(" Parser ByteString ByteString -> Parser ExprAtom -> Parser ExprAtom
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ExprAtom
parseExprAtom)
      Parser ByteString (ExprAtom -> Expr)
-> Parser ExprAtom -> Parser ByteString Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"," Parser ByteString ByteString -> Parser ExprAtom -> Parser ExprAtom
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ExprAtom
parseExprAtom Parser ExprAtom -> (ExprAtom -> Parser ExprAtom) -> Parser ExprAtom
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
"))" Parser ByteString ByteString -> Parser ExprAtom -> Parser ExprAtom
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ExprAtom -> Parser ExprAtom)
-> (ExprAtom -> Parser ExprAtom) -> ExprAtom -> Parser ExprAtom
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExprAtom -> Parser ExprAtom
forall (f :: * -> *) a. Applicative f => a -> f a
pure)

    funCallExpr :: Parser ByteString Expr
funCallExpr = FunName -> [ExprAtom] -> Expr
FunCallExpr
      (FunName -> [ExprAtom] -> Expr)
-> Parser FunName -> Parser ByteString ([ExprAtom] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser FunName
parseFunName
      Parser ByteString ([ExprAtom] -> Expr)
-> Parser ByteString [ExprAtom] -> Parser ByteString Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Parser Char
char Char
'(' Parser Char
-> Parser ByteString [ExprAtom] -> Parser ByteString [ExprAtom]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ExprAtom -> Parser Char -> Parser ByteString [ExprAtom]
forall (f :: * -> *) a s. Alternative f => f a -> f s -> f [a]
sepBy1 Parser ExprAtom
parseExprAtom (Char -> Parser Char
char Char
',') Parser ByteString [ExprAtom]
-> ([ExprAtom] -> Parser ByteString [ExprAtom])
-> Parser ByteString [ExprAtom]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Char -> Parser Char
char Char
')' Parser Char
-> Parser ByteString [ExprAtom] -> Parser ByteString [ExprAtom]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString [ExprAtom] -> Parser ByteString [ExprAtom])
-> ([ExprAtom] -> Parser ByteString [ExprAtom])
-> [ExprAtom]
-> Parser ByteString [ExprAtom]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ExprAtom] -> Parser ByteString [ExprAtom]
forall (f :: * -> *) a. Applicative f => a -> f a
pure)

-- | Parse BinaryOp

parseBinaryOp :: Parser BinaryOp
parseBinaryOp :: Parser ByteString BinaryOp
parseBinaryOp =
  (Char -> Parser Char
char Char
'+' Parser Char
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpPlus)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'-' Parser Char
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpMinus)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'*' Parser Char
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpMul)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'/' Parser Char
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpDiv)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
">=" Parser ByteString ByteString
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpGE)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
">" Parser ByteString ByteString
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpGT)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"<=" Parser ByteString ByteString
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpLE)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"<" Parser ByteString ByteString
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpLT)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"&&" Parser ByteString ByteString
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpAnd)
  Parser ByteString BinaryOp
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"||" Parser ByteString ByteString
-> Parser ByteString BinaryOp -> Parser ByteString BinaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinaryOp -> Parser ByteString BinaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure BinaryOp
BOpOr)

-- | Parse UnaryOp

parseUnaryOp :: Parser UnaryOp
parseUnaryOp :: Parser ByteString UnaryOp
parseUnaryOp =
  (Char -> Parser Char
char Char
'-' Parser Char
-> Parser ByteString UnaryOp -> Parser ByteString UnaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> UnaryOp -> Parser ByteString UnaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure UnaryOp
UOpMinus)
  Parser ByteString UnaryOp
-> Parser ByteString UnaryOp -> Parser ByteString UnaryOp
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
char Char
'!' Parser Char
-> Parser ByteString UnaryOp -> Parser ByteString UnaryOp
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> UnaryOp -> Parser ByteString UnaryOp
forall (f :: * -> *) a. Applicative f => a -> f a
pure UnaryOp
UOpMinus)

-- | Parse StmtAnnot

parseStmtAnnot :: Annot a => Parser (StmtAnnot a)
parseStmtAnnot :: Parser (StmtAnnot a)
parseStmtAnnot = a -> Stmt a -> StmtAnnot a
forall a. a -> Stmt a -> StmtAnnot a
SA (a -> Stmt a -> StmtAnnot a)
-> Parser ByteString a -> Parser ByteString (Stmt a -> StmtAnnot a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString a
forall a. Annot a => Parser a
parseAnnot Parser ByteString (Stmt a -> StmtAnnot a)
-> Parser ByteString (Stmt a) -> Parser (StmtAnnot a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ByteString (Stmt a)
forall a. Annot a => Parser (Stmt a)
parseStmt

-- | Parse Stmt

parseStmt :: Annot a => Parser (Stmt a)
parseStmt :: Parser (Stmt a)
parseStmt =
  NameId -> [StmtAnnot a] -> [StmtAnnot a] -> Stmt a
forall a. NameId -> [StmtAnnot a] -> [StmtAnnot a] -> Stmt a
IfStmt (NameId -> [StmtAnnot a] -> [StmtAnnot a] -> Stmt a)
-> Parser ByteString NameId
-> Parser ByteString ([StmtAnnot a] -> [StmtAnnot a] -> Stmt a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"if(t" Parser ByteString ByteString
-> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString NameId
parseNameId Parser ByteString NameId
-> (NameId -> Parser ByteString NameId) -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
"){\n" Parser ByteString ByteString
-> Parser ByteString NameId -> Parser ByteString NameId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString NameId -> Parser ByteString NameId)
-> (NameId -> Parser ByteString NameId)
-> NameId
-> Parser ByteString NameId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NameId -> Parser ByteString NameId
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
         Parser ByteString ([StmtAnnot a] -> [StmtAnnot a] -> Stmt a)
-> Parser ByteString [StmtAnnot a]
-> Parser ByteString ([StmtAnnot a] -> Stmt a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ByteString (StmtAnnot a) -> Parser ByteString [StmtAnnot a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 Parser ByteString (StmtAnnot a)
forall a. Annot a => Parser (StmtAnnot a)
parseStmtAnnot
         Parser ByteString ([StmtAnnot a] -> Stmt a)
-> Parser ByteString [StmtAnnot a] -> Parser (Stmt a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"} else {\n" Parser ByteString ByteString
-> Parser ByteString [StmtAnnot a]
-> Parser ByteString [StmtAnnot a]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString (StmtAnnot a) -> Parser ByteString [StmtAnnot a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 Parser ByteString (StmtAnnot a)
forall a. Annot a => Parser (StmtAnnot a)
parseStmtAnnot Parser ByteString [StmtAnnot a]
-> ([StmtAnnot a] -> Parser ByteString [StmtAnnot a])
-> Parser ByteString [StmtAnnot a]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
"}\n" Parser ByteString ByteString
-> Parser ByteString [StmtAnnot a]
-> Parser ByteString [StmtAnnot a]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString [StmtAnnot a]
 -> Parser ByteString [StmtAnnot a])
-> ([StmtAnnot a] -> Parser ByteString [StmtAnnot a])
-> [StmtAnnot a]
-> Parser ByteString [StmtAnnot a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [StmtAnnot a] -> Parser ByteString [StmtAnnot a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  Parser (Stmt a) -> Parser (Stmt a) -> Parser (Stmt a)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Name -> Expr -> Stmt a
forall a. Name -> Expr -> Stmt a
AssignStmt (Name -> Expr -> Stmt a)
-> Parser ByteString Name -> Parser ByteString (Expr -> Stmt a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Name
parseName Parser ByteString (Expr -> Stmt a)
-> Parser ByteString Expr -> Parser (Stmt a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
" = " Parser ByteString ByteString
-> Parser ByteString Expr -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Expr
parseExpr Parser ByteString Expr
-> (Expr -> Parser ByteString Expr) -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
";\n" Parser ByteString ByteString
-> Parser ByteString Expr -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString Expr -> Parser ByteString Expr)
-> (Expr -> Parser ByteString Expr)
-> Expr
-> Parser ByteString Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> Parser ByteString Expr
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  Parser (Stmt a) -> Parser (Stmt a) -> Parser (Stmt a)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LocalDecl -> Stmt a
forall a. LocalDecl -> Stmt a
DeclStmt (LocalDecl -> Stmt a)
-> Parser ByteString LocalDecl -> Parser (Stmt a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString LocalDecl
parseLocalDecl
  Parser (Stmt a) -> Parser (Stmt a) -> Parser (Stmt a)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Emit -> Stmt a
forall a. Emit -> Stmt a
EmitStmt (Emit -> Stmt a) -> Parser ByteString Emit -> Parser (Stmt a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Emit
parseEmit

-- | Parse Emit

parseEmit :: Parser Emit
parseEmit :: Parser ByteString Emit
parseEmit =
  Expr -> Emit
EmitPosition (Expr -> Emit) -> Parser ByteString Expr -> Parser ByteString Emit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"gl_Position = " Parser ByteString ByteString
-> Parser ByteString Expr -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString Expr
parseExpr Parser ByteString Expr
-> (Expr -> Parser ByteString Expr) -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Parser ByteString ByteString
";\n" Parser ByteString ByteString
-> Parser ByteString Expr -> Parser ByteString Expr
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) (Parser ByteString Expr -> Parser ByteString Expr)
-> (Expr -> Parser ByteString Expr)
-> Expr
-> Parser ByteString Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> Parser ByteString Expr
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  Parser ByteString Emit
-> Parser ByteString Emit -> Parser ByteString Emit
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser ByteString ByteString
"gl_FragDepth = gl_FragCoord[2];\n" Parser ByteString ByteString
-> Parser ByteString Emit -> Parser ByteString Emit
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Emit -> Parser ByteString Emit
forall (f :: * -> *) a. Applicative f => a -> f a
pure Emit
EmitFragDepth)

------------------

parseTest :: Show a => Parser a -> LT.Text -> IO ()
parseTest :: Parser a -> Text -> IO ()
parseTest Parser a
p Text
input =
  let r :: String
r = IResult ByteString a -> String
forall a. Show a => a -> String
show (IResult ByteString a -> String)
-> (Text -> IResult ByteString a) -> Text -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IResult ByteString a -> IResult ByteString a
forall i r. Monoid i => IResult i r -> IResult i r
fromPartial (IResult ByteString a -> IResult ByteString a)
-> (Text -> IResult ByteString a) -> Text -> IResult ByteString a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser a -> ByteString -> IResult ByteString a
forall a. Parser a -> ByteString -> Result a
parse Parser a
p (ByteString -> IResult ByteString a)
-> (Text -> ByteString) -> Text -> IResult ByteString a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
T.encodeUtf8 (Text -> ByteString) -> (Text -> Text) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
LT.toStrict (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ Text
input in
  if String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
r Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
600
    then
      let start :: String
start = Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
500 String
r
          end :: String
end = String -> String
forall a. [a] -> [a]
reverse (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
100 (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String
forall a. [a] -> [a]
reverse String
r
      in
      String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
start String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" ... " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
end
    else String -> IO ()
putStrLn String
r
  where
    fromPartial :: IResult i r -> IResult i r
fromPartial (Partial i -> IResult i r
cont) = i -> IResult i r
cont i
forall a. Monoid a => a
mempty
    fromPartial IResult i r
r              = IResult i r
r

t :: Show a => Parser a -> String -> IO ()
t :: Parser a -> String -> IO ()
t Parser a
p = Parser a -> Text -> IO ()
forall a. Show a => Parser a -> Text -> IO ()
parseTest Parser a
p (Text -> IO ()) -> (String -> Text) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
LT.pack