!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 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.     ?A return type like Either, that distinguishes not only between B right and wrong answers, but also has gradations of wrongness. 7 This should only be used for writing very primitive = parsers - really it is an internal detail of the library. 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.     ?A return type like Either, that distinguishes not only between B right and wrong answers, but also has gradations of wrongness. 7 This should only be used for writing very primitive = parsers - really it is an internal detail of the library.  !"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. %&'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 has gradations of wrongness. 7 This should only be used for writing very primitive = parsers - really it is an internal detail of the library. ,-./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) 01+Apply a parser to an input token sequence. 2345Update the internal state. 6Query the internal state. 7#Deliver the entire internal state. 8FPush 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. ! +,-./012345678/0+.-,13425678+.-,,-./0012345678 9?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. :;<=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. @ABFPush 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:;<=>?@AB =>9<;:?@AB 9<;::;<=>>?@AB  9:;<=>?@ABC 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. D@A straightforward parser for an item. (A minimal definition of = a class instance requires either |parse| or |parsePrec|.) E>A straightforward parser for an item, given the precedence of ? any surrounding expression. (Precedence determines whether + parentheses are mandatory or optional.) F0Parsing a list of items by default accepts the [] and comma syntax, ; except when the list is really a character string using "". G8A synonym for Parser Char, i.e. string input (no state) HEIf 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). I*One lexical chunk (Haskell-style lexing). JFEnsure that the next input word is the given string. (Note the input @ is lexed as haskell, so wordbreaks at spaces, symbols, etc.) K)Allow true string parens around an item. LIAllow nested parens around an item (one set required when Bool is True). MFDeal with named field syntax. The string argument is the field name, 2 and the parser returns the value of the field. NIParse 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. O>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. PQRSTUV2 9:;<=>?@ABCDEFGHIJKLMNOPQRSTUVGCDEFHIJKLMNOPQRSTUVCDEFDEFGHIJKLMNOPQRSTUVWX: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. Y#Deliver the first remaining token. Z$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. aDeliver one or more values of a. bDeliver zero or more values of a separated by b's. cDeliver one or more values of a separated by b's. defghij>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. k0If the parser fails, generate an error message. lUpdate the internal state. mQuery the internal state. n#Deliver the entire internal state. o;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. WXYZ[\]^_`abcdefghijklmnoWXYZ[\]^_`abcdefghijklmnoWXXYZ[\]^_`abcdefghijklmnoAll 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>%pThe parser monad qrstuvwxyz{|}~$pqrstuvwxyz{|}~$pqrstuvwxyz{|}~$pqqrstuvwxyz{|}~     !"#$%&' !"#$%&()*' !"#$%&()*' !"#$%&'+,-./0123456789:;<=>"#?@ABCDEFGHIJKLMNOPQ'"#?RACSFGHIJKLTUVWXYZ[\]^_`abcdefgghiRjklSmno polyparse-1.2 Text.ParserCombinators.Poly.Base Text.ParserCombinators.Poly.Lazy!Text.ParserCombinators.Poly.State%Text.ParserCombinators.Poly.StateLazy!Text.ParserCombinators.Poly.Plain Text.Parse*Text.ParserCombinators.HuttonMeijerWallace#Text.ParserCombinators.HuttonMeijerText.ParserCombinators.Poly PolyParsecommit adjustErronFailoneOf'applyfailBaddiscard adjustErrBadoneOfindentoptionalexactlymanymany1sepBysepBy1 bracketSepbracket manyFinallyResult CommittedFailureSuccessParserP runParsernextsatisfyreparsestUpdatestQuerystGetParseparse parsePrec parseList TextParser parseByReadwordisWordoptionalParensparensfield constructors enumeration parseSignedparseIntparseDecparseOctparseHex parseFloat parseLitCharitemeofpapplypapply'+++toknottoksepbysepby1chainlchainl1chainrchainr1opstoEOFelserrorstupdstquerystgetfirstsatchardigitlowerupperletteralphanumstringidentnatintspacescommentjunkskiptokennaturalintegersymbol identifierthrowE ParseResult joinresultsbaseGHC.Errerror parseerrorToken