module Language.Parser.Ptera.Runner.Parser (
    T,

    StartNum,
    StateNum,
    TokenNum,
    VarNum,
    AltNum,
    AltKind (..),

    RunnerParser (..),
    Syntax.GrammarToken (..),
    ActionM (..),
    ReduceArgument (..),
    Syntax.ActionTask (..),
    Syntax.getAction,
    Syntax.modifyAction,
    Syntax.failAction,
    Trans (..),
    TransOp (..),

    eosToken,
) where

import           Language.Parser.Ptera.Prelude

import           Language.Parser.Ptera.Machine.PEG (AltKind (..))
import qualified Language.Parser.Ptera.Syntax      as Syntax

type StartNum = Int
type StateNum = Int
type TokenNum = Int
type VarNum = Int
type AltNum = Int

type T = RunnerParser

newtype ActionM ctx = ActionM
    { ActionM ctx -> [ReduceArgument] -> ActionTask ctx ReduceArgument
runActionM :: [ReduceArgument] -> Syntax.ActionTask ctx ReduceArgument
    }

data ReduceArgument where
    ReduceArgument :: a -> ReduceArgument

data RunnerParser ctx elem altHelp = RunnerParser
    { RunnerParser ctx elem altHelp -> StartNum -> Maybe StartNum
parserInitial     :: StartNum -> Maybe StateNum
    , RunnerParser ctx elem altHelp -> elem -> StartNum
parserGetTokenNum :: elem -> TokenNum
    , RunnerParser ctx elem altHelp -> StartNum -> StartNum -> Trans
parserTrans       :: StateNum -> TokenNum -> Trans
    , RunnerParser ctx elem altHelp -> StartNum -> AltKind
parserAltKind     :: AltNum -> AltKind
    , RunnerParser ctx elem altHelp -> StartNum -> [(StartNum, StartNum)]
parserStateHelp   :: StateNum -> [(AltNum, Int)]
    , RunnerParser ctx elem altHelp
-> StartNum -> (StringLit, Maybe altHelp)
parserAltHelp     :: AltNum -> (StringLit, Maybe altHelp)
    , RunnerParser ctx elem altHelp -> StartNum -> ActionM ctx
parserAction      :: AltNum -> ActionM ctx
    }

data Trans = Trans
    { Trans -> StartNum
transState :: StateNum
    , Trans -> [TransOp]
transOps   :: [TransOp]
    }
    deriving (Trans -> Trans -> Bool
(Trans -> Trans -> Bool) -> (Trans -> Trans -> Bool) -> Eq Trans
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Trans -> Trans -> Bool
$c/= :: Trans -> Trans -> Bool
== :: Trans -> Trans -> Bool
$c== :: Trans -> Trans -> Bool
Eq, StartNum -> Trans -> ShowS
[Trans] -> ShowS
Trans -> StringLit
(StartNum -> Trans -> ShowS)
-> (Trans -> StringLit) -> ([Trans] -> ShowS) -> Show Trans
forall a.
(StartNum -> a -> ShowS)
-> (a -> StringLit) -> ([a] -> ShowS) -> Show a
showList :: [Trans] -> ShowS
$cshowList :: [Trans] -> ShowS
show :: Trans -> StringLit
$cshow :: Trans -> StringLit
showsPrec :: StartNum -> Trans -> ShowS
$cshowsPrec :: StartNum -> Trans -> ShowS
Show)

data TransOp
    = TransOpEnter VarNum Bool StateNum
    | TransOpPushBackpoint StateNum
    | TransOpHandleNot AltNum
    | TransOpShift
    | TransOpReduce AltNum
    deriving (TransOp -> TransOp -> Bool
(TransOp -> TransOp -> Bool)
-> (TransOp -> TransOp -> Bool) -> Eq TransOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransOp -> TransOp -> Bool
$c/= :: TransOp -> TransOp -> Bool
== :: TransOp -> TransOp -> Bool
$c== :: TransOp -> TransOp -> Bool
Eq, StartNum -> TransOp -> ShowS
[TransOp] -> ShowS
TransOp -> StringLit
(StartNum -> TransOp -> ShowS)
-> (TransOp -> StringLit) -> ([TransOp] -> ShowS) -> Show TransOp
forall a.
(StartNum -> a -> ShowS)
-> (a -> StringLit) -> ([a] -> ShowS) -> Show a
showList :: [TransOp] -> ShowS
$cshowList :: [TransOp] -> ShowS
show :: TransOp -> StringLit
$cshow :: TransOp -> StringLit
showsPrec :: StartNum -> TransOp -> ShowS
$cshowsPrec :: StartNum -> TransOp -> ShowS
Show)

eosToken :: TokenNum
eosToken :: StartNum
eosToken = StartNum
-1