5      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~  Safe-Inferred:The parser type is parametrised on the types of the state s,  the input tokens t , error-type e, and the result value a. A The state and remaining input are threaded through the monad. #Deliver the first remaining token. $Fail if end of input is not reached CDeliver the first parse result only, eliminating any backtracking. CApply the parser to some real input, given an initial state value.  If the parser fails, raise  to halt the program. E (This is the original exported behaviour - to allow the caller to ( deal with the error differently, see papply'.) CApply the parser to some real input, given an initial state value. C If the parser fails, return a diagnostic message to the caller. 8A choice between parsers. Keep only the first success. 5Deliver the first token if it satisfies a predicate. 3Deliver the first token if it equals the argument. ;Deliver the first token if it does not equal the argument. Deliver zero or more values of a. Deliver one or more values of a. Deliver zero or more values of a separated by b's. Deliver one or more values of a separated by b's. >Accept a complete parse of the input only, no partial parses. GReturn an error using the supplied diagnostic string, and a token type ( which includes position information. 0If the parser fails, generate an error message. Update the internal state. Query the internal state. #Deliver the entire internal state. ;This is useful for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. !     All A LIBRARY OF MONADIC PARSER COMBINATORS 29th July 1996 Graham Hutton Erik Meijer University of Nottingham University of UtrechtStable/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-InferredThe parser monad ( !"#$%&'()*+,-./0123456789:;<$ !"#$%&'()*+,-./0123456789:;<$ !"#$%&'()*+,-./0123456789:;<' !"#$%&'()*+,-./0123456789:;< Safe-Inferred=?A return type like Either, that distinguishes not only between G right and wrong answers, but also has commitment, so that a failure J cannot be undone. This should only be used for writing very primitive = parsers - really it is an internal detail of the library. 1 The z type is the remaining unconsumed input. AKConvert a Result to an Either, paired with the remaining unconsumed input. =>?@A=>?@A=@?>A=@?>A Safe-InferredBThe  PolyParse5 class is an abstraction gathering all of the common = features that a two-level error-handling parser requires: M the applicative parsing interface, the monadic interface, and commitment. LThere are two additional basic combinators that we expect to be implemented E afresh for every concrete type, but which (for technical reasons) & cannot be class methods. They are next and satisfy. CThe  Commitment. class is an abstraction over all the current & concrete representations of monadic/'applicative parser combinators in this = package. The common feature is two-level error-handling. D Some primitives must be implemented specific to each parser type A (e.g. depending on whether the parser has a running state, or F whether it is lazy). But given those primitives, large numbers of F combinators do not depend any further on the internal structure of  the particular parser. DCCommit is a way of raising the severity of any errors found within K its argument. Used in the middle of a parser definition, it means that I any operations prior to commitment fail softly, but after commitment,  they fail hard. Ep E f applies the transformation f to any error message  generated in p, having no effect if p succeeds. F@Parse the first alternative that succeeds, but if none succeed, D report only the severe errors, and if none of those, then report  all the soft errors. G+Apply a parsed function to a parsed value. B Rather like ordinary function application lifted into parsers. Hx H y4 parses both x and y, but discards the result of y.  Rather like const lifted into parsers. ICWhen a simple fail is not strong enough, use failBad for emphasis. ? An emphasised (severe) error cannot be overridden by choice  operators. J adjustErrBad is just like  adjustErr except it also raises the  severity of the error. K7Parse the first alternative in the list that succeeds. LKHelper for formatting error messages: indents all lines by a fixed amount. M' exactly n p'< parses precisely n items, using the parser p, in sequence. N'upto n p'; parses n or fewer items, using the parser p, in sequence. O!Parse a non-empty list of items. P3Parse a list of items separated by discarded junk. Q=Parse a non-empty list of items separated by discarded junk. R@Parse a list of items, discarding the start, end, and separator  items. S1Parse a bracketed item, discarding the brackets. TmanyFinally e t% parses a possibly-empty sequence of e's,  terminated by a t . The final t# is discarded. Any parse failures F could be due either to a badly-formed terminator or a badly-formed / element, so it raises both possible errors. U manyFinally' is like  manyFinally, except when the terminator 0 parser overlaps with the element parser. In manyFinally e t,  the parser t is tried only when parser e fails, whereas in   manyFinally' e t , the parser t is always tried first, then  parser e5 only if the terminator is not found. For instance,  manyFinally (accept 01 ) (accept 0) on input 0101010 returns  [01,01,01] , whereas  manyFinally' with the same arguments  and input returns []. BCDEFGHIJKLMNOPQRSTUBCDEFGHIJKLMNOPQRSTUCDEFBGHIJLKMNOPQRSTUBCDEFGHIJKLMNOPQRSTU Safe-Inferred VThis Parser4 datatype is a specialised parsing monad with error F reporting. Whereas the standard version can be used for arbitrary F token types, this version is specialised to ByteString input only. X+Apply a parser to an input token sequence. Y7Simply return the next token in the input tokenstream. ZSucceed if the end of file/(input has been reached, fail otherwise. [;Return the next token if it satisfies the given predicate. \p \ q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored. ] manySatisfy p& is a more efficient fused version of many (satisfy p) ^many1Satisfy p& is a more efficient fused version of many1 (satisfy p) _FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. VWXYZ[\]^_"=>?@BCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_VW=@?>XYZ[\]^_VWXYZ[\]^_ Safe-Inferred` The class Parse is a replacement for Read, operating over String input. M Essentially, it permits better error messages for why something failed to ' parse. It is rather important that parse can read back exactly what 1 is generated by the corresponding instance of show. To apply a parser  to some text, use  runParser. a@A straightforward parser for an item. (A minimal definition of I a class instance requires either |parse| or |parsePrec|. In general, F for a type that never needs parens, you should define |parse|, but F for a type that _may_ need parens, you should define |parsePrec|.) b>A straightforward parser for an item, given the precedence of ? any surrounding expression. (Precedence determines whether + parentheses are mandatory or optional.) c0Parsing a list of items by default accepts the [] and comma syntax, ; except when the list is really a character string using "". dDA synonym for a ByteString Parser, i.e. bytestring input (no state) eEIf there already exists a Read instance for a type, then we can make M a Parser for it, but with only poor error-reporting. The string argument J is the expected type or value (for error-reporting only). Use of this F wrapper function is NOT recommended with ByteString, because there 6 is a lot of inefficiency in repeated conversions to/ from String. fAIf you have a TextParser for a type, you can easily make it into F a Read instance, by throwing away any error messages. Use of this F wrapper function is NOT recommended with ByteString, because there - is a lot of inefficiency in conversions to/ from String. gAIf you have a TextParser for a type, you can easily make it into F a Read instance, by throwing away any error messages. Use of this F wrapper function is NOT recommended with ByteString, because there - is a lot of inefficiency in conversions to/ from String. h*One lexical chunk (Haskell-style lexing). iFEnsure that the next input word is the given string. (Note the input @ is lexed as haskell, so wordbreaks at spaces, symbols, etc.) j4Allow optional nested string parens around an item. kIAllow nested parens around an item (one set required when Bool is True). lFDeal with named field syntax. The string argument is the field name, 2 and the parser returns the value of the field. mIParse one of a bunch of alternative constructors. In the list argument, > the first element of the pair is the constructor name, and K the second is the parser for the rest of the value. The first matching  parse is returned. n>Parse one of the given nullary constructors (an enumeration). F The string argument is the name of the type, and the list argument : should contain all of the possible enumeration values. o?For any numeric parser, permit a negation sign in front of it. p/Parse any (unsigned) Integral numeric literal. + Needs a base, radix, isDigit predicate, = and digitToInt converter, appropriate to the result type. qLParse a decimal, octal, or hexadecimal (unsigned) Integral numeric literal. rLParse a decimal, octal, or hexadecimal (unsigned) Integral numeric literal. sLParse a decimal, octal, or hexadecimal (unsigned) Integral numeric literal. tDparseUnsignedInteger uses the underlying ByteString readInteger, so J will be a lot faster than the generic character-by-character parseInt. uEParse any (unsigned) Floating numeric literal, e.g. Float or Double. v#Parse a Haskell character literal. w.Simply return the remaining input ByteString. x/Simply return the remaining input as a String. &`abcdefghijklmnopqrstuvwx;=>?@BCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxd`abcefghijklmnopqrstuvwx#`abcdefghijklmnopqrstuvwxNone yThis Parser4 datatype is a specialised parsing monad with error F reporting. Whereas the standard version can be used for arbitrary @ token types, this version is specialised to Text input only. {+Apply a parser to an input token sequence. |7Simply return the next token in the input tokenstream. }Succeed if the end of file/(input has been reached, fail otherwise. ~;Return the next token if it satisfies the given predicate. p  q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored.  manySatisfy p& is a more efficient fused version of many (satisfy p) many1Satisfy p& is a more efficient fused version of many1 (satisfy p) FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. yz{|}~ ?     !"#$%&=>?@BCDEFGHIJKLMNOPQRSTUyz{|}~yz=@?>{|}~yz{|}~ None This Parser4 datatype is a specialised parsing monad with error F reporting. Whereas the standard version can be used for arbitrary @ token types, this version is specialised to Text input only. +Apply a parser to an input token sequence. 7Simply return the next token in the input tokenstream. Succeed if the end of file/(input has been reached, fail otherwise. ;Return the next token if it satisfies the given predicate. p  q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored.  manySatisfy p& is a more efficient fused version of many (satisfy p) many1Satisfy p& is a more efficient fused version of many1 (satisfy p) Update the internal state. Query the internal state. #Deliver the entire internal state. FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. '()*+,B     !"#$%&=>?@BCDEFGHIJKLMNOPQRSTU=@?>'()*+,  Safe-InferredThis Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just I String input. (If you require a running state, use module Poly.State  instead) p  q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored. 7Simply return the next token in the input tokenstream. Succeed if the end of file/(input has been reached, fail otherwise. ;Return the next token if it satisfies the given predicate. FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. -./ =>?@ =@?> -./  Safe-Inferred+Apply a parser to an input token sequence. 012=     !"#$%&=>?@BCDEFGHIJKLMNOPQRSTU =@?>012 NoneHThe only differences between a Plain and a Lazy parser are the instance C of Applicative, and the type (and implementation) of runParser.  We therefore need to newtype' the original Parser type, to allow it ! to have a different instance. +Apply a parser to an input token sequence. 7Simply return the next token in the input tokenstream. Succeed if the end of file/(input has been reached, fail otherwise. ;Return the next token if it satisfies the given predicate. p  q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored. FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. 3456=     !"#$%&=>?@BCDEFGHIJKLMNOPQRSTU =@?> 3456  Safe-Inferred This Parser7 datatype is a fairly generic parsing monad with error ! reporting, and running state. D It can be used for arbitrary token types, not just String input. J (If you do not require a running state, use module Poly.Plain instead) p  q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored. 7Simply return the next token in the input tokenstream. Succeed if the end of file/(input has been reached, fail otherwise. ;Return the next token if it satisfies the given predicate. Update the internal state. Query the internal state. #Deliver the entire internal state. FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. 789=>?@=@?> 789  Safe-Inferred+Apply a parser to an input token sequence. :;<@     !"#$%&=>?@BCDEFGHIJKLMNOPQRSTU=@?>:;<None DThe only differences between a State and a StateLazy parser are the L instance of Applicative, and the type (and implementation) of runParser.  We therefore need to newtype' the original Parser type, to allow it ! to have a different instance. +Apply a parser to an input token sequence. 7Simply return the next token in the input tokenstream. Succeed if the end of file/(input has been reached, fail otherwise. ;Return the next token if it satisfies the given predicate. p  q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored. FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. Update the internal state. Query the internal state. #Deliver the entire internal state. =>?@@     !"#$%&=>?@BCDEFGHIJKLMNOPQRSU=@?>=>?@ Safe-InferredThis Parser4 datatype is a specialised parsing monad with error F reporting. This version is specialised to pre-lexed String input, / where the lexer has been written to yield a  LexReturn. EIn a strict language, where creating the entire input list of tokens 4 in one shot may be infeasible, we can use a lazy callback kind of F architecture instead. The lexer returns a single token at a time, & together with a continuation. The next parser is responsible for K pulling on the token stream, applying the continuation where necessary. +Apply a parser to an input token sequence. p  q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored. 7Simply return the next token in the input tokenstream. Succeed if the end of file/(input has been reached, fail otherwise. ;Return the next token if it satisfies the given predicate. FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. ABCDEF@     !"#$%&=>?@BCDEFGHIJKLMNOPQRSTU=@?>ABCDEF Safe-Inferred This Parser4 datatype is a specialised parsing monad with error F reporting. Whereas the standard version can be used for arbitrary F token types, this version is specialised to ByteString input only. +Apply a parser to an input token sequence. 7Simply return the next token in the input tokenstream. Succeed if the end of file/(input has been reached, fail otherwise. ;Return the next token if it satisfies the given predicate. p  q. means parse p, unless p fails, in which case  parse q instead. I Can be chained together to give multiple attempts to parse something. K (Note that q could itself be a failing parser, e.g. to change the error ; message from that defined in p to something different.) 5 However, a severe failure in p cannot be ignored.  manySatisfy p& is a more efficient fused version of many (satisfy p) many1Satisfy p& is a more efficient fused version of many1 (satisfy p) FPush some tokens back onto the front of the input stream and reparse. C This is useful e.g. for recursively expanding macros. When the ? user-parser recognises a macro use, it can lookup the macro > expansion from the parse state, lex it, and then stuff the . lexed expansion back down into the parser. GHIJKL"=>?@BCDEFGHIJKLMNOPQRSTU=@?>GHIJKL Safe-Inferred=     !"#$%&=>?@BCDEFGHIJKLMNOPQRSTU Safe-Inferred The class Parse is a replacement for Read, operating over String input. M Essentially, it permits better error messages for why something failed to ' parse. It is rather important that parse can read back exactly what 1 is generated by the corresponding instance of show. To apply a parser  to some text, use  runParser. @A straightforward parser for an item. (A minimal definition of = a class instance requires either |parse| or |parsePrec|.) >A straightforward parser for an item, given the precedence of ? any surrounding expression. (Precedence determines whether + parentheses are mandatory or optional.) 0Parsing a list of items by default accepts the [] and comma syntax, ; except when the list is really a character string using "". 8A synonym for Parser Char, i.e. string input (no state) EIf there already exists a Read instance for a type, then we can make M a Parser for it, but with only poor error-reporting. The string argument = is the expected type or value (for error-reporting only). AIf you have a TextParser for a type, you can easily make it into 9 a Read instance, by throwing away any error messages. AIf you have a TextParser for a type, you can easily make it into 9 a Read instance, by throwing away any error messages. #One lexical chunk. This is Haskell'98-style lexing - the result ? should match Prelude.lex apart from better error-reporting. MOne lexical chunk (Haskell'*98-style lexing - the result should match , Prelude.lex apart from error-reporting). FEnsure that the next input word is the given string. (Note the input @ is lexed as haskell, so wordbreaks at spaces, symbols, etc.) $Allow nested parens around an item. IAllow nested parens around an item (one set required when Bool is True). FDeal with named field syntax. The string argument is the field name, 2 and the parser returns the value of the field. IParse one of a bunch of alternative constructors. In the list argument, > the first element of the pair is the constructor name, and K the second is the parser for the rest of the value. The first matching  parse is returned. >Parse one of the given nullary constructors (an enumeration). F The string argument is the name of the type, and the list argument : should contain all of the possible enumeration values. 1Simply return the entire remaining input String. %MNOPQRSTUVWXYZT     !"#$%&=>?@BCDEFGHIJKLMNOPQRSTU"MNOPQRSTUVWXYZ[ !"#$%&'()*+,- !"#$%./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTU%VWXYZ[\]+^_`abcdefghijklmnopqrstuvXYZ[\]+XYZ[\]wxy+   [ Y  Z + X   X Y  Z [ +   [ Y  Z w x y + XXYZ[+wxyVz{zX[YZ+XYZ[\]+^_`abcdefghijklmnopqstv,|}~-|||||||||||||||||||||||||||||  polyparse-1.8*Text.ParserCombinators.HuttonMeijerWallace#Text.ParserCombinators.HuttonMeijer"Text.ParserCombinators.Poly.Result Text.ParserCombinators.Poly.Base*Text.ParserCombinators.Poly.ByteStringCharText.Parse.ByteString Text.ParserCombinators.Poly.Text%Text.ParserCombinators.Poly.StateText"Text.ParserCombinators.Poly.Parser!Text.ParserCombinators.Poly.Plain Text.ParserCombinators.Poly.Lazy'Text.ParserCombinators.Poly.StateParser!Text.ParserCombinators.Poly.State%Text.ParserCombinators.Poly.StateLazyText.ParserCombinators.Poly.Lex&Text.ParserCombinators.Poly.ByteString Text.ParseText.ParserCombinators.PolyParserPitemeofpapplypapply'+++toknottokmanymany1sepbysepby1chainlchainl1chainrchainr1opsbrackettoEOFelserrorstupdstquerystgetreparsefirstsatchardigitlowerupperletteralphanumstringidentnatintspacescommentjunkskiptokennaturalintegersymbol identifierResult CommittedFailureSuccessresultToEither PolyParse Commitmentcommit adjustErroneOf'applydiscardfailBad adjustErrBadoneOfindentexactlyuptosepBysepBy1 bracketSep manyFinally manyFinally' runParsernextsatisfyonFail manySatisfy many1SatisfyParseparse parsePrec parseList TextParser parseByRead readByParsereadsPrecByParsePrecwordisWordoptionalParensparensfield constructors enumeration parseSignedparseIntparseDecparseOctparseHexparseUnsignedInteger parseFloat parseLitCharallAsByteString allAsStringstUpdatestQuerystGet LexReturn LexFinishbaseGHC.Errerror parseerror ParseResult joinresults$fMonadPlusParser $fMonadParser$fFunctorParserToken$fFunctorResult$fPolyParseParser$fAlternativeParser$fApplicativeParser$fCommitmentParser $fParse[] $fParseEither $fParseMaybe $fParse(,,) $fParse(,) $fParse()$fParseOrdering $fParseBool $fParseChar $fParseDouble $fParseFloat$fParseInteger $fParseIntControl.Applicative ApplicativeoptionalliftA3liftA2liftA<**><**><*>puresome<|>empty AlternativegetConstConst unwrapMonad WrapMonad WrappedMonad unwrapArrow WrapArrow WrappedArrow getZipListZipList Data.Functor<$>GHC.Base<$throwEoldword