-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Type level string parser combinators
--
-- Please see README.md.
@package symbol-parser
@version 0.1.0
-- | Parse digits from type-level Chars.
--
-- A Nothing indicates the given Char was not a valid digit
-- for the given base.
module Data.Type.Char.Digits
-- | Parse a binary digit (0 or 1).
type family ParseBinaryDigit (ch :: Char) :: Maybe Natural
-- | Parse an octal digit (0-7).
type family ParseOctalDigit (ch :: Char) :: Maybe Natural
-- | Parse a decimal digit (0-9).
type family ParseDecimalDigit (ch :: Char) :: Maybe Natural
-- | Parse a hexadecimal digit (0-9A-Fa-f).
--
-- Both upper and lower case are permitted.
type family ParseHexDigit (ch :: Char) :: Maybe Natural
module Data.Type.Symbol
-- | Get the length of a symbol.
type Length sym = Length' 0 (UnconsSymbol sym)
type family Length' len mchsym
-- | Parse Naturals from type-level Symbols.
--
-- The type functions here may return errors. Use the provided and throw
-- with TypeError, or wrap in your own error handling.
--
-- TODO
--
--
-- - Oh dear. Oh dear. Oh dear. If I want to get proper working
-- composition with meaningful errors, where the index pays attention to
-- what we Drop... then I need to write a type-level parser monad. That's
-- it. These parsers need to take in parser state (well, just character
-- index is OK), and emit that state on success. Oh dear. Oh no.
--
module Data.Type.Symbol.Natural
-- | Parse a Symbol describing a binary (base 2) natural to its
-- Natural value.
type ParseBinarySymbol sym = ParseSymbolDigits 2 ParseBinaryDigitSym sym
-- | Parse a Symbol describing an octal (base 8) natural to its
-- Natural value.
type ParseOctalSymbol sym = ParseSymbolDigits 8 ParseOctalDigitSym sym
-- | Parse a Symbol describing a decimal (base 10) natural to its
-- Natural value.
type ParseDecimalSymbol sym = ParseSymbolDigits 10 ParseDecimalDigitSym sym
-- | Parse a Symbol describing a hexadecimal (base 16) natural to
-- its Natural value.
type ParseHexSymbol sym = ParseSymbolDigits 16 ParseHexDigitSym sym
type family PrettyE e
type family MapLeftPrettyE e
type family FromRightParseResult sym eab
data E
EBadDigit :: Natural -> Char -> Natural -> E
EEmptySymbol :: E
type PrettyEBadDigit base ch idx = 'Text "could not parse character as base " :<>: 'ShowType base :<>: 'Text " digit" :$$: 'ShowType ch :<>: 'Text " at index " :<>: 'ShowType idx
-- | Parse a symbol to a Natural using the given base and digit
-- parser.
type ParseSymbolDigits base tfDigitValue sym = If (Length sym == 0) ('Left 'EEmptySymbol) (WrapEBadDigit base (ParseSymbolDigits' base tfDigitValue ('Just 0) '\0' 0 (Length sym - 1) (UnconsSymbol sym)))
type family WrapEBadDigit base eab
type family ParseSymbolDigits' base tfParseDigit mn prevCh idx expo mchsym
type family ParseSymbolDigits'Inc mult n mDigit
data ParseBinaryDigitSym a
data ParseOctalDigitSym a
data ParseDecimalDigitSym a
data ParseHexDigitSym a
module Data.Type.Symbol.Parser.Internal
type ParserCh s r = Char -> s -> Result s r
type ParserEnd s r = s -> Either ErrorMessage r
data Result s r
Cont :: s -> Result s r
Done :: r -> Result s r
Err :: ErrorMessage -> Result s r
type ParserChSym s r = Char ~> s ~> Result s r
type ParserEndSym s r = s ~> Either ErrorMessage r
type Parser s r = (ParserChSym s r, ParserEndSym s r, s)
type family RunParser p sym
type family RunParser' pCh pEnd idx s msym
type family RunParserEnd idx end
type family RunParser'' pCh pEnd idx ch res sym
module Data.Type.Symbol.Parser.Drop
type Drop n = '(DropChSym, DropEndSym, n)
module Data.Type.Symbol.Parser.Isolate
type family Isolate n p
type family IsolateCh pCh pEnd ch s
type family IsolateInnerEnd' pEnd res
type family IsolateInnerEnd a
type family IsolateInner n a
type family IsolateEnd s
data IsolateChSym pCh pEnd f
data IsolateChSym1 pCh pEnd ch s
data IsolateEndSym s
module Data.Type.Symbol.Parser.Natural
type NatBin = NatBase 2 ParseBinaryDigitSym
type NatOct = NatBase 8 ParseOctalDigitSym
type NatDec = NatBase 10 ParseDecimalDigitSym
type NatHex = NatBase 16 ParseHexDigitSym
type NatBase base parseDigit = '(NatBaseChSym base parseDigit, NatBaseEndSym, 0)
type family NatBaseCh base parseDigit ch n
type family NatBaseCh' base n mDigit
type NatBaseEnd n = 'Right n
data NatBaseChSym base parseDigit f
data NatBaseChSym1 base parseDigit ch n
data NatBaseEndSym n
data ParseBinaryDigitSym a
data ParseOctalDigitSym a
data ParseDecimalDigitSym a
data ParseHexDigitSym a
module Data.Type.Symbol.Parser.Then
type family Then pl pr
type family ThenCh plCh prCh sr ch s
type family ThenL sr resl
type family ThenR rl resr
type family ThenEnd prEnd s
type family ThenEnd' rl s
data ThenChSym plCh prCh sr f
data ThenChSym1 plCh prCh sr ch s
data ThenEndSym prEnd s
module Data.Type.Symbol.Parser.Then.VoidLeft
type family ThenVL pl pr
type family ThenVLCh plCh prCh sr ch s
type family ThenVLL sr resl
type family ThenVLR resr
type family ThenVLEnd prEnd s
type family ThenVLEnd' s
data ThenVLChSym plCh prCh sr f
data ThenVLChSym1 plCh prCh sr ch s
data ThenVLEndSym prEnd s
module Data.Type.Symbol.Parser.Then.VoidRight
type family ThenVR pl pr
type family ThenVRCh plCh prCh sr ch s
type family ThenVRL sr resl
type family ThenVRR rl resr
type family ThenVREnd prEnd s
type family ThenVREnd' rl s
data ThenVRChSym plCh prCh sr f
data ThenVRChSym1 plCh prCh sr ch s
data ThenVREndSym prEnd s
module Data.Type.Symbol.Parser
type Parser s r = (ParserChSym s r, ParserEndSym s r, s)
type family RunParser p sym
type family Isolate n p
type pl :<*>: pr = Then pl pr
type pl :*>: pr = ThenVL pl pr
type pl :<*: pr = ThenVR pl pr
type Drop n = '(DropChSym, DropEndSym, n)
type NatDec = NatBase 10 ParseDecimalDigitSym
type NatHex = NatBase 16 ParseHexDigitSym
type NatBin = NatBase 2 ParseBinaryDigitSym
type NatOct = NatBase 8 ParseOctalDigitSym
type NatBase base parseDigit = '(NatBaseChSym base parseDigit, NatBaseEndSym, 0)