module Language.Parser.Ptera.Pipeline.Grammar2Runner where

import           Language.Parser.Ptera.Prelude

import qualified Language.Parser.Ptera.Pipeline.SRB2Parser      as SRB2Parser
import qualified Language.Parser.Ptera.Pipeline.SafeGrammar2SRB as SafeGrammar2SRB
import qualified Language.Parser.Ptera.Runner                   as Runner
import qualified Language.Parser.Ptera.Syntax                   as Syntax

grammar2Runner :: forall initials ctx rules tokens elem
    .  Syntax.GrammarToken tokens elem
    => Syntax.GrammarM ctx rules tokens elem initials
    -> Either [StringLit] (Runner.T ctx rules elem initials)
grammar2Runner :: GrammarM ctx rules tokens elem initials
-> Either [StringLit] (T ctx rules elem initials)
grammar2Runner GrammarM ctx rules tokens elem initials
g = do
    T Int StringLit (Maybe ()) (Action (SemActM ctx))
srb <- GrammarM ctx rules tokens elem initials
-> Either
     [StringLit] (T Int StringLit (Maybe ()) (Action (SemActM ctx)))
forall (action :: [*] -> * -> *) rules tokens elem
       (initials :: [Symbol]).
T action rules tokens elem initials
-> Either [StringLit] (T Int StringLit (Maybe ()) (Action action))
SafeGrammar2SRB.safeGrammar2Srb GrammarM ctx rules tokens elem initials
g
    let parser :: T ctx elem ()
parser = Proxy tokens
-> T Int StringLit (Maybe ()) (Action (SemActM ctx))
-> T ctx elem ()
forall ctx tokens elem altHelp.
GrammarToken tokens elem =>
Proxy tokens
-> T Int StringLit (Maybe altHelp) (Action ctx)
-> T ctx elem altHelp
SRB2Parser.srb2Parser
            do Proxy tokens
forall k (t :: k). Proxy t
Proxy @tokens
            do T Int StringLit (Maybe ()) (Action (SemActM ctx))
srb
    T ctx rules elem initials
-> Either [StringLit] (T ctx rules elem initials)
forall (f :: * -> *) a. Applicative f => a -> f a
pure do T ctx elem () -> T ctx rules elem initials
forall ctx rules elem (initials :: [Symbol]).
T ctx elem () -> RunnerM ctx rules elem initials
Runner.UnsafeRunnerM T ctx elem ()
parser