-- those generated (see for instance 'joinNext').
module Symantic.Parser.Machine.Program where
-import Control.Monad (Monad(..), (<=<), (=<<), liftM, liftM2, sequence)
-import Data.Function (($))
-import System.IO (IO)
-import Type.Reflection (Typeable)
import Control.DeepSeq (NFData)
+import Control.Monad (Monad(..), (<=<), (=<<), liftM, liftM2, sequence)
import Data.Bool (Bool(..))
import Data.Eq (Eq)
+import Data.Function (($))
import Data.Function ((.))
import Data.Ord (Ord)
+import Data.Semigroup (Semigroup(..))
+import System.IO (IO)
import Text.Show (Show(..))
+import Type.Reflection (Typeable)
import qualified Data.Functor as Functor
import qualified Data.Set as Set
import qualified Data.Traversable as Traversable
import qualified Language.Haskell.TH as TH
import qualified Language.Haskell.TH.Syntax as TH
-import qualified Symantic.Lang as Prod
+import qualified Symantic.Class as Prod
import Symantic.Derive
import Symantic.Parser.Grammar
instance
( Cursorable (Cursor inp)
, InstrBranchable repr
+ , InstrComment repr
, InstrExceptionable repr
, InstrInputable repr
, InstrJoinable repr
try (Program x) = Program $ \next ->
liftM2 (catch ExceptionFailure)
(x (commit ExceptionFailure next))
- -- On exception, reset the input, and propagate the failure.
+ -- On 'ExceptionFailure', reset the input, and propagate the failure.
(return $ loadInput $ fail Set.empty)
-- | @(raiseAgainIfConsumed exn ok)@
raiseAgainIfConsumed ::
Cursorable (Cursor inp) =>
InstrBranchable repr =>
+ InstrComment repr =>
InstrExceptionable repr =>
InstrInputable repr =>
InstrValuable repr =>
SomeInstr repr inp vs ret ->
SomeInstr repr inp (Cursor inp ': vs) ret
raiseAgainIfConsumed exn ok =
- pushInput $
+ comment "raiseAgainIfConsumed" $
+ saveInput $
lift2Value (splice sameOffset) $
ifBranch ok $
case exn of
( Cursorable (Cursor inp)
, InstrBranchable repr
, InstrCallable repr
+ , InstrComment repr
, InstrExceptionable repr
, InstrInputable repr
, InstrIterable repr
) => CombLookable (Program repr inp) where
look (Program x) = Program $ \next ->
liftM (comment "look") $
- liftM pushInput (x (swapValue (loadInput next)))
+ liftM saveInput (x (swapValue (loadInput next)))
eof =
negLook (satisfy (Prod.const Prod..@ Prod.bool True))
-- This sets a better failure message
-- and (negLook x) fail.
(
liftM (comment "negLook.ahead") $
- liftM pushInput $ x $
+ liftM saveInput $ x $
popValue $ commit ExceptionFailure $
loadInput $ fail Set.empty
)
) => CombSatisfiable tok (Program repr inp) where
satisfyOrFail fs p = Program $ \next ->
return $
- comment "satisfy" $
+ comment ("satisfy "<>showsPrec 11 (prodCode p) "") $
read fs (prodCode p) next
instance
( InstrBranchable repr