symparsec-1.1.1: Type level string parser combinators
Safe HaskellSafe-Inferred
LanguageGHC2021

Symparsec.Run

Synopsis

Documentation

type Run p sym = MapLeftRender (Run' p sym) Source #

Run the given parser on the given Symbol, returning an ErrorMessage on failure.

type family MapLeftRender eer where ... Source #

type family Run' p str where ... Source #

Run the given parser on the given Symbol, returning a PERun on failure.

Equations

Run' ('PParser pCh pEnd s0) str = RunStart pCh pEnd s0 (UnconsSymbol str) 

type RunTest p sym = MapLeftTypeError (Run p sym) Source #

Run the given parser on the given Symbol, emitting a type error on failure.

This would be useful for :k! runs, but it doesn't work properly with TypeErrors, printing = (TypeError ...) instead of the error message. Alas! Instead, do something like > Proxy @(RunTest ...).

type Run'_ p str = Run'_Inner (Run' p str) Source #

Run the given parser on the given Symbol, returning a PERun on failure, and ignoring any remaining non-consumed characters.

type family Run'_Inner eeab where ... Source #

Equations

Run'_Inner (Right '(a, b)) = Right a 
Run'_Inner (Left e) = Left (RenderPDoc (PrettyERun e)) 

run' :: forall {s} {r} (p :: PParser s r) r'. SingParser p => (forall a. PR p a -> r') -> String -> Either (ERun String) (r', String) Source #

Run the singled version of type-level parser on the given String, returning an ERun on failure.

You must provide a function for demoting the singled return type. (demote can do this for you automatically.)

runTest :: forall {s} {r} (p :: PParser s r). (SingParser p, Demotable (PR p)) => String -> (Demote (PR p), String) Source #

sRun' :: SParser ss sr p -> SSymbol str -> SEither SERun (STuple2 sr SSymbol) (Run' p str) Source #

type family RunStart pCh pEnd s0 mstr where ... Source #

Equations

RunStart pCh pEnd s0 (Just '(ch, str)) = RunCh pCh pEnd 0 ch (UnconsSymbol str) ((pCh @@ ch) @@ s0) 
RunStart pCh pEnd s0 Nothing = RunEnd0 (pEnd @@ s0) 

sRunStart :: SParserChSym ss sr pCh -> SParserEndSym ss sr pEnd -> ss s0 -> SMaybe (STuple2 SChar SSymbol) mstr -> SEither SERun (STuple2 sr SSymbol) (RunStart pCh pEnd s0 mstr) Source #

type family MapLeftTypeError eea where ... Source #

type family RunCh pCh pEnd idx ch' mstr res where ... Source #

Inspect character parser result.

This is purposely written so that the main case is at the top, and a single equation (we parse, prepare next character and inspect character parser result at the same time). My hope is that this keeps GHC fast.

Equations

RunCh pCh pEnd idx ch' (Just '(ch, sym)) (Cont s) = RunCh pCh pEnd (idx + 1) ch (UnconsSymbol sym) ((pCh @@ ch) @@ s) 
RunCh pCh pEnd idx ch' Nothing (Cont s) = RunEnd idx ch' (pEnd @@ s) 
RunCh pCh pEnd idx ch' mstr (Done r) = Right '(r, ConsSymbol ch' (ReconsSymbol mstr)) 
RunCh pCh pEnd idx ch' mstr (Err e) = Left ('ERun idx ch' e) 

sRunCh :: SParserChSym ss sr pCh -> SParserEndSym ss sr pEnd -> SNat idx -> SChar chPrev -> SMaybe (STuple2 SChar SSymbol) mstr -> SResult ss sr res -> SEither SERun (STuple2 sr SSymbol) (RunCh pCh pEnd idx chPrev mstr res) Source #

type family RunEnd idx ch res where ... Source #

Inspect end parser result.

Equations

RunEnd idx ch (Right r) = Right '(r, "") 
RunEnd idx ch (Left e) = Left ('ERun idx ch e) 

sRunEnd :: SNat idx -> SChar ch -> SEither SE sr res -> SEither SERun (STuple2 sr SSymbol) (RunEnd idx ch res) Source #

type family RunEnd0 res where ... Source #

Inspect end parser result for the empty string, where we have no previous character or (meaningful) index.

Equations

RunEnd0 (Right r) = Right '(r, "") 
RunEnd0 (Left e) = Left (ERun0 e) 

type family PrettyERun e where ... Source #

Equations

PrettyERun (ERun0 e) = Text "parse error on empty string" :$$: PrettyE e 
PrettyERun ('ERun idx ch e) = ((((Text "parse error at index " :<>: Text (ShowNatDec idx)) :<>: Text ", char '") :<>: Text (ShowChar ch)) :<>: Text "'") :$$: PrettyE e 

type family PrettyE e where ... Source #

Equations

PrettyE (EBase name emsg) = (Text name :<>: Text ": ") :<>: emsg 
PrettyE (EIn name e) = (Text name :<>: Text ": ") :<>: PrettyE e 

data ERun s Source #

Error while running parser.

Constructors

ERun Natural Char (E s)

Parser error at index X, character C.

ERun0 (E s)

Parser error on the empty string.

Instances

Instances details
Demotable SERun Source # 
Instance details

Defined in Symparsec.Run

Associated Types

type Demote SERun #

Methods

demote :: forall (k1 :: k). SERun k1 -> Demote SERun #

Show s => Show (ERun s) Source # 
Instance details

Defined in Symparsec.Run

Methods

showsPrec :: Int -> ERun s -> ShowS #

show :: ERun s -> String #

showList :: [ERun s] -> ShowS #

type Demote SERun Source # 
Instance details

Defined in Symparsec.Run

type PERun = ERun Symbol Source #

Promoted ERun.

data SERun (erun :: PERun) where Source #

Constructors

SERun :: SNat idx -> SChar ch -> SE e -> SERun ('ERun idx ch e) 
SERun0 :: SE e -> SERun (ERun0 e) 

Instances

Instances details
Demotable SERun Source # 
Instance details

Defined in Symparsec.Run

Associated Types

type Demote SERun #

Methods

demote :: forall (k1 :: k). SERun k1 -> Demote SERun #

type Demote SERun Source # 
Instance details

Defined in Symparsec.Run