-- 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.3.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.List -- | Reverse a type level list. type Reverse as = Reverse' as '[] type family Reverse' (as :: [k]) (acc :: [k]) :: [k] -- | Data types and type synonyms for parsers and their defun symbols. module Data.Type.Symbol.Parser.Types -- | Parse a Char with the given state. -- -- The action is always consuming. For this reason, you may need to look -- ahead for the final case, so as to not consume an extra Char. -- This prevents many zero-length parsers. It's a bit weird. See -- Drop for an example. type ParserCh s r = Char -> s -> Result s r -- | The result of a single step of a parser. data Result s r -- | OK, continue with the given state Cont :: s -> Result s r -- | OK, parse successful with result r Done :: r -> Result s r -- | parse error Err :: E -> Result s r -- | What a parser should do at the end of a Symbol. type ParserEnd s r = s -> Either E r -- | Parser error. data E -- | Base parser error. EBase :: Symbol -> ErrorMessage -> E -- | Inner parser error inside combinator. EIn :: Symbol -> E -> E -- | A parser you can pass (heh) around. -- -- Parsers are defined by the product of a ParserCh character -- parser, ParserEnd end handler, and s starting state. type Parser s r = (ParserChSym s r, ParserEndSym s r, s) -- | A defunctionalization symbol for a ParserCh. type ParserChSym s r = Char ~> s ~> Result s r -- | A defunctionalization symbol for a ParserEnd. type ParserEndSym s r = s ~> Either E r module Data.Type.Symbol.Parser.Run -- | Run the given parser on the given Symbol. type family Run p sym module Data.Type.Symbol.Parser.Parser.Then.VoidRight type family ThenVR pl pr module Data.Type.Symbol.Parser.Parser.Then.VoidLeft type family ThenVL pl pr module Data.Type.Symbol.Parser.Parser.Then type family Then pl pr -- | Choice operator. Try left; if it fails, try right. -- -- This is a problematic combinator: -- -- module Data.Type.Symbol.Parser.Parser.Or type family Or pl pr module Data.Type.Symbol.Parser.Common data FailChSym name e f data FailEndSym name e s -- | Emit state directly on end of input. data EmitEndSym r type ErrParserLimitation msg = Text "parser limitation: " :<>: Text msg module Data.Type.Symbol.Parser.Parser.Take type family Take n module Data.Type.Symbol.Parser.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, EmitEndSym, 0) module Data.Type.Symbol.Parser.Parser.Literal type Literal sym = Literal' (UnconsSymbol sym) module Data.Type.Symbol.Parser.Parser.Isolate type family Isolate n p module Data.Type.Symbol.Parser.Parser.End type End = '(EndChSym, EmitEndSym, '()) module Data.Type.Symbol.Parser.Parser.Drop type family Drop n -- | Unsafe Drop which doesn't check for 0. May get stuck. type Drop' n = '(DropChSym, DropEndSym, n) module Data.Type.Symbol.Parser -- | A parser you can pass (heh) around. -- -- Parsers are defined by the product of a ParserCh character -- parser, ParserEnd end handler, and s starting state. type Parser s r = (ParserChSym s r, ParserEndSym s r, s) -- | Run the given parser on the given Symbol. type family Run p sym type family Isolate n p -- | Sequence parsers, returning both values in a tuple. type pl :<*>: pr = Then pl pr -- | Sequence parsers, discarding the return value of the left parser type pl :*>: pr = ThenVL pl pr -- | Sequence parsers, discarding the return value of the right parser. -- -- Consider using :*>: instead, which is simpler and -- potentially faster since we parse L->R. type pl :<*: pr = ThenVR pl pr type pl :<|>: pr = Or pl pr type family Take n type family Drop n type Literal sym = Literal' (UnconsSymbol sym) type End = '(EndChSym, EmitEndSym, '()) 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, EmitEndSym, 0)