!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGH I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~  The  PolyParse. class is an abstraction over all the current B concrete representations of monadic 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. 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. CCommit 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. p  f applies the transformation f to any error message  generated in p, having no effect if p succeeds. 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. @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. +Apply a parsed function to a parsed value. B Rather like ordinary function application lifted into parsers. CWhen a simple fail is not strong enough, use failBad for emphasis. ? An emphasised (severe) error cannot be overridden by choice  operators. x  y4 parses both x and y, but discards the result of y.  Rather like const lifted into parsers.  adjustErrBad is just like  adjustErr except it also raises the  severity of the error. 7Parse the first alternative in the list that succeeds. KHelper for formatting error messages: indents all lines by a fixed amount.  @ indicates whether the parser succeeded through the Maybe type. ' exactly n p'< parses precisely n items, using the parser p, in sequence. 'many p'5 parses a list of elements with individual parser p. = Cannot fail, since an empty list is a valid return value. !Parse a non-empty list of items. 3Parse a list of items separated by discarded junk. =Parse a non-empty list of items separated by discarded junk. @Parse a list of items, discarding the start, end, and separator  items. 1Parse a bracketed item, discarding the brackets. 'manyFinally e t'& parses a possibly-empty sequence of e's, E 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.    This Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just H String input. (If you require a running state, use module PolyState  instead) +Apply a parser to an input token sequence. 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.  The Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just L String input. (If you require a running state, use module PolyStateLazy  instead.) EApply a parser to an input token sequence. The parser cannot return K an error value explicitly, so errors raise an exception. Thus, results B can be partial (lazily constructed, but containing undefined).  Next token  One token satifying a predicate 'manyFinally e t'& parses a possibly-empty sequence of e's, A terminated by a t. Any parse failures could be due either to A a badly-formed terminator or a badly-formed element, so raise  both possible errors. 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.      ?A return type like Either, that distinguishes not only between B right and wrong answers, but also had gradations of wrongness. !The Parser7 datatype is a fairly generic parsing monad with error F reporting and a running state. It can be used for arbitrary token ! types, not just String input. "#=Apply a parser to an initial state and input token sequence. %&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.  !"#$%&'() !"#$%&'()!""#%&'() ?A return type like Either, that distinguishes not only between B right and wrong answers, but also had gradations of wrongness. 9 Not used in this library. !!!!!!!!!!!!!!!!!!!!!!!!!! *The Parser7 datatype is a fairly generic parsing monad with error F reporting and a running state. It can be used for arbitrary token ! types, not just String input. +,=Apply a parser to an initial state and input token sequence. A The parser cannot return an error value explicitly, so errors J raise an exception. Thus, results can be partial (lazily constructed,  but containing undefined). -Yield one token. .-Yield one token if it satisfies a predicate. /Update the internal state. 0Query the internal state. 1#Deliver the entire internal state. 2FPush 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.  *+,-./012 *+,-./012 *++,-./012    3This Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just H String input. (If you require a running state, use module PolyState  instead) 45+Apply a parser to an input token sequence. 678FPush 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.  3456783456783445678   9This Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just H String input. (If you require a running state, use module PolyState  instead) :;+Apply a parser to an input token sequence. <=>Update the internal state. ?Query the internal state. @#Deliver the entire internal state. AFPush 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.  9:;<=>?@A 9:;<=>?@A 9::;<=>?@A BThis Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just H String input. (If you require a running state, use module PolyState  instead) CD+Apply a parser to an input token sequence. EFGFPush 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.  BCDEFGBCDEFGBCCDEFG HThis Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just H String input. (If you require a running state, use module PolyState  instead) IJ+Apply a parser to an input token sequence. KLMNUpdate the internal state. OQuery the internal state. P#Deliver the entire internal state. QFPush 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.  HIJKLMNOPQ HIJLMKNOPQ HIIJKLMNOPQ ?A return type like Either, that distinguishes not only between B right and wrong answers, but also had gradations of wrongness. 9 Not used in this library. !!!!!!!!!!!!!!!!!!!!!!!!!! RThe Parser7 datatype is a fairly generic parsing monad with error F reporting and a running state. It can be used for arbitrary token ! types, not just String input. ST=Apply a parser to an initial state and input token sequence. A The parser cannot return an error value explicitly, so errors J raise an exception. Thus, results can be partial (lazily constructed,  but containing undefined). UFSimple failure can be corrected, but when a simple fail is not strong K enough, use failBad for emphasis. It guarantees parsing will terminate  with an exception. VCCommit 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. W One token X One token satifying a predicate Y*Apply a parsed function to a parsed value Zx Z y3 parses both x and y, but discards the result of y [p [ f applies the transformation f to any error message  generated in p, having no effect if p succeeds. \ adjustErrBad is just like  adjustErr except it also raises the  severity of the error. ]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.) 7 However, a *severe* failure in p cannot be ignored. ^7Parse the first alternative in the list that succeeds. _@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. `KHelper for formatting error messages: indents all lines by a fixed amount. aa@ indicates whether the parser succeeded through the Maybe type. b' exactly n p'7 parses a precise number of items, n, using the parser  p, in sequence. c'many p'5 parses a list of elements with individual parser p. = Cannot fail, since an empty list is a valid return value. d!Parse a non-empty list of items. e3Parse a list of items separated by discarded junk. f=Parse a non-empty list of items separated by discarded junk. g@Parse a list of items, discarding the start, end, and separator  items. h1Parse a bracketed item, discarding the brackets. i'manyFinally e t'& parses a possibly-empty sequence of e's, A terminated by a t. Any parse failures could be due either to A a badly-formed terminator or a badly-formed element, so raise  both possible errors. jUpdate the internal state. kQuery the internal state. l#Deliver the entire internal state. mFPush 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. RSTUVWXYZ[\]^_`abcdefghijklmRSTUVWXYZ[\`]^_abcdefghijklmRSSTUVWXYZ[\]^_`abcdefghijklm nThe Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just L String input. (If you require a running state, use module PolyStateLazy  instead.) opEApply a parser to an input token sequence. The parser cannot return K an error value explicitly, so errors raise an exception. Thus, results B can be partial (lazily constructed, but containing undefined). qFSimple failure can be corrected, but when a simple fail is not strong A enough, use failBad for emphasis. It guarantees parsing will  terminate with an exception. rCCommit 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. s One token t One token satifying a predicate u*Apply a parsed function to a parsed value vx v y3 parses both x and y, but discards the result of y wp w f applies the transformation f to any error message  generated in p, having no effect if p succeeds. x adjustErrBad is just like  adjustErr except it also raises the  severity of the error. yp y 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.) 7 However, a *severe* failure in p cannot be ignored. z7Parse the first alternative in the list that succeeds. {@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. |KHelper for formatting error messages: indents all lines by a fixed amount. }}@ indicates whether the parser succeeded through the Maybe type. ~' exactly n p'7 parses a precise number of items, n, using the parser  p, in sequence. 'many p'5 parses a list of elements with individual parser p. = Cannot fail, since an empty list is a valid return value. !Parse a non-empty list of items. 3Parse a list of items separated by discarded junk. =Parse a non-empty list of items separated by discarded junk. @Parse a list of items, discarding the start, end, and separator  items. 1Parse a bracketed item, discarding the brackets. 'manyFinally e t'& parses a possibly-empty sequence of e's, A terminated by a t. Any parse failures could be due either to A a badly-formed terminator or a badly-formed element, so raise  both possible errors. 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. nopqrstuvwxyz{|}~nopqrstuvwx|yz{}~noopqrstuvwxyz{|}~ ?A return type like Either, that distinguishes not only between B right and wrong answers, but also had gradations of wrongness. The Parser7 datatype is a fairly generic parsing monad with error F reporting and a running state. It can be used for arbitrary token ! types, not just String input. =Apply a parser to an initial state and input token sequence. CWhen a simple fail is not strong enough, use failBad for emphasis. L An emphasised (severe) error can propagate out through choice operators. CCommit 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.  One token  One token satifying a predicate *Apply a parsed function to a parsed value x  y3 parses both x and y, but discards the result of y p  f applies the transformation f to any error message  generated in p, having no effect if p succeeds.  adjustErrBad is just like  adjustErr except it also raises the  severity of the error. 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. 7Parse the first alternative in the list that succeeds. @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. KHelper for formatting error messages: indents all lines by a fixed amount. ' exactly n p'7 parses a precise number of items, n, using the parser  p, in sequence. 'many p'5 parses a list of elements with individual parser p. = Cannot fail, since an empty list is a valid return value. !Parse a non-empty list of items. 3Parse a list of items separated by discarded junk. =Parse a non-empty list of items separated by discarded junk. @Parse a list of items, discarding the start, end, and separator  items. 1Parse a bracketed item, discarding the brackets. 'manyFinally e t'& parses a possibly-empty sequence of e's, A terminated by a t. Any parse failures could be due either to A a badly-formed terminator or a badly-formed element, so raise  both possible errors. 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.  The Parser7 datatype is a fairly generic parsing monad with error B reporting. It can be used for arbitrary token types, not just H String input. (If you require a running state, use module PolyState  instead) +Apply a parser to an input token sequence. CWhen a simple fail is not strong enough, use failBad for emphasis. L An emphasised (severe) error can propagate out through choice operators. CCommit 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.  One token  One token satifying a predicate *Apply a parsed function to a parsed value x  y3 parses both x and y, but discards the result of y p  f applies the transformation f to any error message  generated in p, having no effect if p succeeds.  adjustErrBad is just like  adjustErr except it also raises the  severity of the error. 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.) 7 However, a *severe* failure in p cannot be ignored. 7Parse the first alternative in the list that succeeds. @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. KHelper for formatting error messages: indents all lines by a fixed amount. @ indicates whether the parser succeeded through the Maybe type. ' exactly n p'7 parses a precise number of items, n, using the parser  p, in sequence. 'many p'5 parses a list of elements with individual parser p. = Cannot fail, since an empty list is a valid return value. !Parse a non-empty list of items. 3Parse a list of items separated by discarded junk. =Parse a non-empty list of items separated by discarded junk. @Parse a list of items, discarding the start, end, and separator  items. 1Parse a bracketed item, discarding the brackets. 'manyFinally e t'& parses a possibly-empty sequence of e's, A terminated by a t. Any parse failures could be due either to A a badly-formed terminator or a badly-formed element, so raise  both possible errors. 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.   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. 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 8 a Parser for it, but with only poor error-reporting. *One lexical chunk (Haskell-style lexing). FEnsure that the next input word is the given string. (Note the input @ is lexed as haskell, so wordbreaks at spaces, symbols, etc.) )Allow true string parens around an item. 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. $ :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>%The parser monad &$$$' !"#$%&'()*%&'()$*%&'()+,-*%&'()+,-*%&'()*%&'()+,-*%&'()* % & ' $ ( ) + , - * % & '   ( )             ! " # $ + , - * % & '   ( )             ! " # $ * % & '   ( )            ! " # $ + , - * % & '   ( )             ! " # $ *./012345678%&9:;<=>?@ABCDEF#GHIJK*%&9L;=M@ABCDEF#NOPQRSTUVWXYZ[\]^_`abaabcdefcdefcdefb c d e f b a b a b a aghLijkMlmn polyparse-1.1 Text.ParserCombinators.Poly.Base!Text.ParserCombinators.Poly.Plain Text.ParserCombinators.Poly.Lazy!Text.ParserCombinators.Poly.State%Text.ParserCombinators.Poly.StateLazy(Text.ParserCombinators.Poly.NoLeak.Plain(Text.ParserCombinators.Poly.NoLeak.State'Text.ParserCombinators.Poly.NoLeak.Lazy,Text.ParserCombinators.Poly.NoLeak.StateLazy$Text.ParserCombinators.PolyStateLazyText.ParserCombinators.PolyLazy Text.ParserCombinators.PolyStateText.ParserCombinators.Poly Text.Parse*Text.ParserCombinators.HuttonMeijerWallace#Text.ParserCombinators.HuttonMeijer PolyParsecommit adjustErronFailoneOf'applyfailBaddiscard adjustErrBadoneOfindentoptionalexactlymanymany1sepBysepBy1 bracketSepbracket manyFinallyParserP runParsernextsatisfyreparsestUpdatestQuerystGetParseparse parseList TextParser parseByReadwordisWordoptionalParensfield constructors enumerationitemeofpapplypapply'+++toknottoksepbysepby1chainlchainl1chainrchainr1opstoEOFelserrorstupdstquerystgetfirstsatchardigitlowerupperletteralphanumstringidentnatintspacescommentjunkskiptokennaturalintegersymbol identifierEitherEthrowEResult CommittedFailureSuccess ParseResult joinresultsbaseGHC.Errerror parseerrorToken