{-|
  Copyright  :  (C) 2012-2016, University of Twente,
                    2017     , Myrtle Software Ltd
  License    :  BSD2 (see the file LICENSE)
  Maintainer :  Christiaan Baaij <christiaan.baaij@gmail.com>

  Parser definitions for BlackBox templates
-}

{-# LANGUAGE OverloadedStrings #-}

module Clash.Netlist.BlackBox.Parser
  (runParse)
where

import           Control.Applicative          ((<|>))
import           Data.Text.Lazy               (Text, pack, unpack)
import qualified Data.Text.Lazy               as Text
import           Text.Parser.Combinators
import           Text.Trifecta                hiding (Err)
import           Text.Trifecta.Delta

import qualified Clash.Signal.Internal        as Signal
import           Clash.Netlist.BlackBox.Types

-- | Parse a text as a BlackBoxTemplate, returns a list of errors in case
-- parsing fails
-- runParse :: Text -> (BlackBoxTemplate, [Error LineColPos])
-- runParse = PCC.parse ((,) <$> pBlackBoxD <*> pEnd)
--          . createStr (LineColPos 0 0 0)
runParse :: Text -> Result BlackBoxTemplate
runParse :: Text -> Result BlackBoxTemplate
runParse = Parser BlackBoxTemplate
-> Delta -> String -> Result BlackBoxTemplate
forall a. Parser a -> Delta -> String -> Result a
parseString Parser BlackBoxTemplate
pBlackBoxD (ByteString -> Int64 -> Int64 -> Int64 -> Int64 -> Delta
Directed "" 0 0 0 0) (String -> Result BlackBoxTemplate)
-> (Text -> String) -> Text -> Result BlackBoxTemplate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
unpack

-- | Parse a BlackBoxTemplate (Declarations and Expressions)
pBlackBoxD :: Parser BlackBoxTemplate
pBlackBoxD :: Parser BlackBoxTemplate
pBlackBoxD = Parser Element -> Parser BlackBoxTemplate
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser Element
pElement

-- | Parse a single Template Element
pElement :: Parser Element
pElement :: Parser Element
pElement  =  Parser Element
pTagD
         Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Element
Text (Text -> Element) -> Parser Text -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
pText
         Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Element
Text (Text -> Element) -> Parser Text -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Text
pack (String -> Text) -> Parser String -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ ")

-- | Parse the Text part of a Template
pText :: Parser Text
pText :: Parser Text
pText = String -> Text
pack (String -> Text) -> Parser String -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Char -> Parser String
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some (Char -> Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> Char -> m Char
satisfyRange '\000' '\125')

pEdge :: Parser Signal.ActiveEdge
pEdge :: Parser ActiveEdge
pEdge =
  (ActiveEdge -> Parser ActiveEdge
forall (f :: * -> *) a. Applicative f => a -> f a
pure ActiveEdge
Signal.Rising Parser ActiveEdge -> Parser String -> Parser ActiveEdge
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "Rising") Parser ActiveEdge -> Parser ActiveEdge -> Parser ActiveEdge
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
  (ActiveEdge -> Parser ActiveEdge
forall (f :: * -> *) a. Applicative f => a -> f a
pure ActiveEdge
Signal.Falling Parser ActiveEdge -> Parser String -> Parser ActiveEdge
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "Falling")


-- | Parse a Declaration or Expression element
pTagD :: Parser Element
pTagD :: Parser Element
pTagD =  Element -> BlackBoxTemplate -> BlackBoxTemplate -> Element
IF (Element -> BlackBoxTemplate -> BlackBoxTemplate -> Element)
-> Parser Element
-> Parser (BlackBoxTemplate -> BlackBoxTemplate -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "~IF" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element
pTagE)
            Parser (BlackBoxTemplate -> BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser (BlackBoxTemplate -> Element)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ()
forall (m :: * -> *). CharParsing m => m ()
spaces Parser () -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~THEN" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate
pBlackBoxD))
            Parser (BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ELSE" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate
pBlackBoxD Parser BlackBoxTemplate -> Parser String -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~FI")
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Decl -> Element
Component (Decl -> Element) -> Parser Decl -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Decl
pDecl
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Element
pTagE

-- | Parse a Declaration
pDecl :: Parser Decl
pDecl :: Parser Decl
pDecl = Int -> [(BlackBoxTemplate, BlackBoxTemplate)] -> Decl
Decl (Int -> [(BlackBoxTemplate, BlackBoxTemplate)] -> Decl)
-> Parser Int
-> Parser ([(BlackBoxTemplate, BlackBoxTemplate)] -> Decl)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "~INST" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural') Parser ([(BlackBoxTemplate, BlackBoxTemplate)] -> Decl)
-> Parser [(BlackBoxTemplate, BlackBoxTemplate)] -> Parser Decl
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        ((:) ((BlackBoxTemplate, BlackBoxTemplate)
 -> [(BlackBoxTemplate, BlackBoxTemplate)]
 -> [(BlackBoxTemplate, BlackBoxTemplate)])
-> Parser (BlackBoxTemplate, BlackBoxTemplate)
-> Parser
     ([(BlackBoxTemplate, BlackBoxTemplate)]
      -> [(BlackBoxTemplate, BlackBoxTemplate)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (BlackBoxTemplate, BlackBoxTemplate)
pOutput Parser
  ([(BlackBoxTemplate, BlackBoxTemplate)]
   -> [(BlackBoxTemplate, BlackBoxTemplate)])
-> Parser [(BlackBoxTemplate, BlackBoxTemplate)]
-> Parser [(BlackBoxTemplate, BlackBoxTemplate)]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (BlackBoxTemplate, BlackBoxTemplate)
-> Parser [(BlackBoxTemplate, BlackBoxTemplate)]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser (BlackBoxTemplate, BlackBoxTemplate)
pInput) Parser Decl -> Parser String -> Parser Decl
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~INST"

-- | Parse the output tag of Declaration
pOutput :: Parser (BlackBoxTemplate,BlackBoxTemplate)
pOutput :: Parser (BlackBoxTemplate, BlackBoxTemplate)
pOutput = String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "~OUTPUT" Parser String -> Parser String -> Parser String
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "<=" Parser String
-> Parser (BlackBoxTemplate, BlackBoxTemplate)
-> Parser (BlackBoxTemplate, BlackBoxTemplate)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((,) (BlackBoxTemplate
 -> BlackBoxTemplate -> (BlackBoxTemplate, BlackBoxTemplate))
-> Parser BlackBoxTemplate
-> Parser
     (BlackBoxTemplate -> (BlackBoxTemplate, BlackBoxTemplate))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser BlackBoxTemplate
pBlackBoxE Parser BlackBoxTemplate -> Parser String -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "~") Parser (BlackBoxTemplate -> (BlackBoxTemplate, BlackBoxTemplate))
-> Parser BlackBoxTemplate
-> Parser (BlackBoxTemplate, BlackBoxTemplate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser BlackBoxTemplate
pBlackBoxE) Parser (BlackBoxTemplate, BlackBoxTemplate)
-> Parser String -> Parser (BlackBoxTemplate, BlackBoxTemplate)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "~"

-- | Parse the input tag of Declaration
pInput :: Parser (BlackBoxTemplate,BlackBoxTemplate)
pInput :: Parser (BlackBoxTemplate, BlackBoxTemplate)
pInput = String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "~INPUT" Parser String -> Parser String -> Parser String
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "<=" Parser String
-> Parser (BlackBoxTemplate, BlackBoxTemplate)
-> Parser (BlackBoxTemplate, BlackBoxTemplate)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((,) (BlackBoxTemplate
 -> BlackBoxTemplate -> (BlackBoxTemplate, BlackBoxTemplate))
-> Parser BlackBoxTemplate
-> Parser
     (BlackBoxTemplate -> (BlackBoxTemplate, BlackBoxTemplate))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser BlackBoxTemplate
pBlackBoxE Parser BlackBoxTemplate -> Parser String -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "~") Parser (BlackBoxTemplate -> (BlackBoxTemplate, BlackBoxTemplate))
-> Parser BlackBoxTemplate
-> Parser (BlackBoxTemplate, BlackBoxTemplate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser BlackBoxTemplate
pBlackBoxE) Parser (BlackBoxTemplate, BlackBoxTemplate)
-> Parser String -> Parser (BlackBoxTemplate, BlackBoxTemplate)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> Parser String
forall (m :: * -> *). TokenParsing m => String -> m String
symbol "~"

-- | Parse an Expression element
pTagE :: Parser Element
pTagE :: Parser Element
pTagE =  Bool -> Element
Result Bool
True       Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ERESULT"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> Element
Result Bool
False      Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~RESULT"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Int -> Element
ArgGen            (Int -> Int -> Element) -> Parser Int -> Parser (Int -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ARGN" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural') Parser (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural'
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> Int -> Element
Arg Bool
True          (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~EARG" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> Int -> Element
Arg Bool
False         (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ARG" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
Const             (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~CONST" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
Lit               (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~LIT" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
Name              (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~NAME" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BlackBoxTemplate -> Int -> Element
Var               (BlackBoxTemplate -> Int -> Element)
-> Parser BlackBoxTemplate -> Parser (Int -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (m :: * -> *) a. Parsing m => m a -> m a
try (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~VAR" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD) Parser (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural'
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Int -> Element
Sym Text
Text.empty)  (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~SYM" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> Element
Typ Maybe Int
forall a. Maybe a
Nothing       Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~TYPO"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Maybe Int -> Element
Typ (Maybe Int -> Element) -> (Int -> Maybe Int) -> Int -> Element
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Int
forall a. a -> Maybe a
Just)      (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Int -> Parser Int
forall (m :: * -> *) a. Parsing m => m a -> m a
try (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~TYP" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> Element
TypM Maybe Int
forall a. Maybe a
Nothing      Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~TYPMO"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Maybe Int -> Element
TypM (Maybe Int -> Element) -> (Int -> Maybe Int) -> Int -> Element
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Int
forall a. a -> Maybe a
Just)     (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~TYPM" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> Element
Err Maybe Int
forall a. Maybe a
Nothing       Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ERRORO"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Maybe Int -> Element
Err (Maybe Int -> Element) -> (Int -> Maybe Int) -> Int -> Element
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Int
forall a. a -> Maybe a
Just)      (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ERROR" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Element
TypElem           (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~TYPEL" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Element
IndexType         (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~INDEXTYPE" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element
CompName          Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~COMPNAME"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
IncludeName       (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~INCLUDENAME" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Element
Size              (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~SIZE" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Element
Length            (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~LENGTH" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Element
Depth             (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~DEPTH" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Element
MaxIndex          (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~MAXINDEX" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Element
FilePath          (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~FILE" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> Element
Gen               (Bool -> Element) -> Parser Bool -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Bool
True Bool -> Parser String -> Parser Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~GENERATE")
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> Element
Gen               (Bool -> Element) -> Parser Bool -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Bool
False Bool -> Parser String -> Parser Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ENDGENERATE")
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (BlackBoxTemplate -> Maybe Int -> Element
`SigD` Maybe Int
forall a. Maybe a
Nothing)  (BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~SIGDO" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BlackBoxTemplate -> Maybe Int -> Element
SigD              (BlackBoxTemplate -> Maybe Int -> Element)
-> Parser BlackBoxTemplate -> Parser (Maybe Int -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~SIGD" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD) Parser (Maybe Int -> Element)
-> Parser (Maybe Int) -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Parser Int -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural'))
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element
IW64              Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~IW64"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Element -> Element
CmpLE             (Element -> Element -> Element)
-> Parser Element -> Parser (Element -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Element -> Parser Element
forall (m :: * -> *) a. Parsing m => m a -> m a
try (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~CMPLE" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE) Parser (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (HdlSyn -> Element
HdlSyn HdlSyn
Vivado)   Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~VIVADO"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (HdlSyn -> Element
HdlSyn HdlSyn
Other)    Element -> Parser String -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$  String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~OTHERSYN"
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> BlackBoxTemplate -> Element -> Element
BV Bool
True)         (BlackBoxTemplate -> Element -> Element)
-> Parser BlackBoxTemplate -> Parser (Element -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~TOBV" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD) Parser (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> BlackBoxTemplate -> Element -> Element
BV Bool
False)        (BlackBoxTemplate -> Element -> Element)
-> Parser BlackBoxTemplate -> Parser (Element -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~FROMBV" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD) Parser (Element -> Element) -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Element -> Int -> Element
Sel               (Element -> Int -> Element)
-> Parser Element -> Parser (Int -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~SEL" Parser String -> Parser Element -> Parser Element
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Element -> Parser Element
forall a. Parser a -> Parser a
brackets' Parser Element
pTagE) Parser (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural'
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
IsLit             (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ISLIT" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
IsVar             (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ISVAR" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
IsActiveHigh      (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ISACTIVEHIGH" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
IsActiveEnable    (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ISACTIVEENABLE" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BlackBoxTemplate -> Int -> Element
StrCmp            (BlackBoxTemplate -> Int -> Element)
-> Parser BlackBoxTemplate -> Parser (Int -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~STRCMP" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD) Parser (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural'
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
OutputWireReg     (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~OUTPUTWIREREG" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BlackBoxTemplate -> Int -> Element
GenSym            (BlackBoxTemplate -> Int -> Element)
-> Parser BlackBoxTemplate -> Parser (Int -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~GENSYM" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD) Parser (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural'
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BlackBoxTemplate -> BlackBoxTemplate -> Element
Template          (BlackBoxTemplate -> BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser (BlackBoxTemplate -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~TEMPLATE" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD) Parser (BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BlackBoxTemplate -> BlackBoxTemplate -> Element
Repeat            (BlackBoxTemplate -> BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser (BlackBoxTemplate -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~REPEAT" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD) Parser (BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BlackBoxTemplate -> Element
DevNull           (BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~DEVNULL" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' Parser BlackBoxTemplate
pSigD)
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BlackBoxTemplate -> Element
And               (BlackBoxTemplate -> Element)
-> Parser BlackBoxTemplate -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~AND" Parser String -> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser BlackBoxTemplate -> Parser BlackBoxTemplate
forall a. Parser a -> Parser a
brackets' (Parser Element -> Parser BlackBoxTemplate
forall (m :: * -> *) a. TokenParsing m => m a -> m [a]
commaSep Parser Element
pTagE))
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
Vars              (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~VARS" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')

     -- Domain attributes:
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
Tag               (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~TAG" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
Period            (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~PERIOD" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ActiveEdge -> Int -> Element
ActiveEdge        (ActiveEdge -> Int -> Element)
-> Parser ActiveEdge -> Parser (Int -> Element)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ACTIVEEDGE" Parser String -> Parser ActiveEdge -> Parser ActiveEdge
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ActiveEdge -> Parser ActiveEdge
forall (m :: * -> *) a. TokenParsing m => m a -> m a
brackets Parser ActiveEdge
pEdge) Parser (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural'
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
IsSync            (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ISSYNC" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')
     Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Element
IsInitDefined     (Int -> Element) -> Parser Int -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "~ISINITDEFINED" Parser String -> Parser Int -> Parser Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Int -> Parser Int
forall a. Parser a -> Parser a
brackets' Parser Int
forall (m :: * -> *). TokenParsing m => m Int
natural')

natural' :: TokenParsing m => m Int
natural' :: m Int
natural' = (Integer -> Int) -> m Integer -> m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Int
forall a. Num a => Integer -> a
fromInteger m Integer
forall (m :: * -> *). TokenParsing m => m Integer
natural

-- | Parse a bracketed text
brackets' :: Parser a -> Parser a
brackets' :: Parser a -> Parser a
brackets' p :: Parser a
p = Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char '[' Parser Char -> Parser a -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser a
p Parser a -> Parser Char -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char ']'

-- | Parse the expression part of Blackbox Templates
pBlackBoxE :: Parser BlackBoxTemplate
pBlackBoxE :: Parser BlackBoxTemplate
pBlackBoxE = Parser Element -> Parser BlackBoxTemplate
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser Element
pElemE

-- | Parse an Expression or Text
pElemE :: Parser Element
pElemE :: Parser Element
pElemE = Parser Element
pTagE
      Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Element
Text (Text -> Element) -> Parser Text -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
pText

-- | Parse SigD
pSigD :: Parser [Element]
pSigD :: Parser BlackBoxTemplate
pSigD = Parser Element -> Parser BlackBoxTemplate
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some (Parser Element
pTagE Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Element
Text (String -> Text
pack "[") Element -> Parser Text -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (String -> Text
pack (String -> Text) -> Parser String -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "[\\"))
                    Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Element
Text (String -> Text
pack "]") Element -> Parser Text -> Parser Element
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (String -> Text
pack (String -> Text) -> Parser String -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
string "\\]"))
                    Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Element
Text (Text -> Element) -> Parser Text -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Text
pack (String -> Text) -> Parser String -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Char -> Parser String
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some (Char -> Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> Char -> m Char
satisfyRange '\000' '\90')))
                    Parser Element -> Parser Element -> Parser Element
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Element
Text (Text -> Element) -> Parser Text -> Parser Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Text
pack (String -> Text) -> Parser String -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Char -> Parser String
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some (Char -> Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> Char -> m Char
satisfyRange '\94' '\125'))))