úÎýĖm      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklportable provisional#Antoine Latter <aslatter@gmail.com>The abstract data type  SourcePos! represents source positions. It E contains the name of the source (i.e. file name), a line number and  a column number.  SourcePos is an instance of the m, n and  o class. p Create a new  with the given source name,  line number and column number.  Create a new  with the given source name, = and line number and column number set to 1, the upper left. 8Extracts the name of the source from a source position. 1Extracts the line number from a source position. 3Extracts the column number from a source position. 1Increments the line number of a source position. 3Increments the column number of a source position. Set the name of the source. *Set the line number of a source position. ,Set the column number of a source position. The expression updatePosString pos s updates the source position  pos by calling  on every character in s, ie.  foldl updatePosChar pos string. q   portable provisional#Antoine Latter <aslatter@gmail.com>The abstract data type  ParseError represents parse errors. It  provides the source position () of the error  and a list of error messages (). A  ParseError ! can be returned by the function Text.Parsec.Prim.parse.  ParseError is an  instance of the m class. rCThis abstract data type represents parse error messages. There are  four kinds of messages:  $ data Message = SysUnExpect String ! | UnExpect String  | Expect String  | Message String DThe fine distinction between different kinds of parse errors allows C the system to generate quite good error messages for the user. It < also allows error messages that are formatted in different H languages. Each kind of message is generated by different combinators:  A + message is automatically generated by the  Text.Parsec.Combinator.satisfy! combinator. The argument is the  unexpected input.  A  message is generated by the Text.Parsec.Prim.unexpected . combinator. The argument describes the  unexpected item.  A  message is generated by the Text.Parsec.Prim.<?> = combinator. The argument describes the expected item.  A  message is generated by the s @ combinator. The argument is some general parser message. 1Extract the message string from an error message 2Extracts the source position from the parse error 9Extracts the list of error messages from the parse error  !"#Language independent show function  !"" ! !"portable provisional#Antoine Latter <aslatter@gmail.com>0#$%&'tuvwxy(z)* The parser p  ? msg behaves as parser p, but whenever the  parser p fails without consuming any input, it replaces expect . error messages with the expect error message msg. EThis is normally used at the end of a set alternatives where we want A to return an error message in terms of a higher level construct D rather than returning all possible characters. For example, if the  expr parser from the : example would fail, the error  message is: '...: expecting expression'. Without the (<?>) ' combinator, the message would be like '...: expecting "let" or  letter', which is less friendly. +.This combinator implements choice. The parser p <|> q first  applies p. If it succeeds, the value of p is returned. If p  fails without consuming any input , parser q is tried. This $ combinator is defined equal to the { member of the |  class and the (Control.Applicative.<|> ) member of Control.Applicative.Alternative. The parser is called  predictive since q is only tried when  parser p didn'1t consume any input (i.e.. the look ahead is 1). > This non-backtracking behaviour allows for both an efficient E implementation of the parser combinators and the generation of good  error messages. , Returns the current user state. - setState st set the user state to st. . updateState f applies function f to the user state. Suppose F that we want to count identifiers in a source, we could use the user  state as:  expr = do{ x <- identifier  ; updateState (+1)  ; return (Id x)  } /.Returns the current source position. See also . 0Returns the current input 1setPosition pos% sets the current source position to pos. 2setInput input continues parsing with input. 3#Returns the full parser state as a $# record. 4setParserState st set the full parser state to st. 56The expression parseTest p input applies a parser p against  input input3 and prints the result to stdout. Used for testing  parsers. 7parse p filePath input runs a parser p without user  state. The filePath/ is only used in error messages and may be the  empty string. Returns either a  (})  or a value of type a (~). 3 main = case (parse numbers "" "11, 2, 43") of $ Left err -> print err ) Right xs -> print (sum xs)   numbers = commaSep integer 8&The most general way to run a parser. runParser p state filePath  input runs parser p on the input list of tokens input,  obtained from source filePath with the initial user state st.  The filePath5 is only used in error messages and may be the empty  string. Returns either a  (}) or a  value of type a (~).  parseFromFile p fname " = do{ input <- readFile fname . ; return (runParser p () fname input)  } €‚9ƒ parsecZero+ always fails without consuming any input.  parsecZero is defined  equal to the „ member of the | class and to the Control.Applicative.empty member  of the Control.Applicative.Applicative class. …: The parser try p behaves like parser p, except that it  pretends that it hasn'+t consumed any input when an error occurs. AThis combinator is used whenever arbitrary look ahead is needed.  Since it pretends that it hasn't consumed any input when p fails,  the (+;) combinator will try its second alternative even when the , first parser failed while consuming input. The try3 combinator can for example be used to distinguish E identifiers and reserved words. Both reserved words and identifiers B are a sequence of letters. Whenever we expect a certain reserved @ word where we can also expect an identifier we have to use the try  combinator. Suppose we write:  8 expr = letExpr <|> identifier <?> "expression"  ( letExpr = do{ string "let"; ... }  identifier = many1 letter If the user writes "lexical", the parser fails with:  unexpected  'x' , expecting 't' in "let". Indeed, since the (+ ) combinator 8 only tries alternatives when the first alternative hasn' t consumed  input, the  identifier+ parser is never tried (because the prefix  "le" of the string "let"" parser is already consumed). The / right behaviour can be obtained by adding the try combinator: 8 expr = letExpr <|> identifier <?> "expression"  . letExpr = do{ try (string "let"); ... }  identifier = many1 letter ; The parser  token showTok posFromTok testTok accepts a token t  with result x when the function  testTok t returns † x. The  source position of the t should be returned by  posFromTok t and  the token can be shown using  showTok t. )This combinator is expressed in terms of <. ? It is used to accept user defined token streams. For example, B suppose that we have a stream of basic tokens tupled with source G positions. We can than define a parser that accepts single tokens as:  mytoken x ' = token showTok posFromTok testTok  where # showTok (pos,t) = show t  posFromTok (pos,t) = pos ? testTok (pos,t) = if x == t then Just t else Nothing < The parser token showTok nextPos testTok accepts a token t  with result x when the function  testTok t returns † x. The  token can be shown using  showTok t. The position of the next  token should be returned when nextPos is called with the current  source position pos, the current token t and the rest of the  tokens toks, nextPos pos t toks. @This is the most primitive combinator for accepting tokens. For  example, the Text.Parsec.Char.char! parser could be implemented as:  char c * = tokenPrim showChar nextPos testChar  where * showChar x = "'" ++ x ++ "'" = testChar x = if x == c then Just x else Nothing . nextPos pos x xs = updatePosChar pos x =4The most primitive token recogniser. The expression )tokenPrimEx show nextpos mbnextstate test,  recognises tokens when test returns Just x (and returns the value x). Tokens are shown in  error messages using show#. The position is calculated using nextpos, and finally,  mbnextstate, f can hold a function that updates the user state on every token recognised (nice to count tokens :-).  The function is packed into a ‡ type for performance reasons. >?ˆupdateParserState f applies function f to the parser state. @ The parser unexpected msg' always fails with an unexpected error  message msg without consuming any input.  The parsers s, (*) and  unexpected are the three parsers 2 used to generate error messages. Of these, only (*) is commonly $ used. For an example of the use of  unexpected, see the definition  of $Text.Parsec.Combinator.notFollowedBy. Amany p applies the parser p zero or more times. Returns a # list of the returned values of p. ! identifier = do{ c <- letter 7 ; cs <- many (alphaNum <|> char '_') " ; return (c:cs)  } B skipMany p applies the parser p zero or more times, skipping  its result.  spaces = skipMany space ‰C!#$%&'()*+,-./0123456789:;<=>?@ABC!*+)(8756;C<=:>?@9AB,-./102#$%&'34!#$%&'$%&'()*+,-./0123456789:;<=>?@ABCportable provisional#Antoine Latter <aslatter@gmail.com>DEoneOf cs6 succeeds if the current character is in the supplied  list of characters cs). Returns the parsed character. See also  T.  vowel = oneOf "aeiou" FAs the dual of E,  noneOf cs succeeds if the current  character not$ in the supplied list of characters cs. Returns the  parsed character.  consonant = noneOf "aeiou" GSkips zero* or more white space characters. See also B. H>Parses a white space character (any character which satisfies Š)  Returns the parsed character. IParses a newline character ('\n' ). Returns a newline character. JParses a tab character ('\t'). Returns a tab character. K1Parses an upper case letter (a character between 'A' and 'Z').  Returns the parsed character. L3Parses a lower case character (a character between 'a' and 'z').  Returns the parsed character. M.Parses a letter or digit (a character between '0' and '9').  Returns the parsed character. NEParses a letter (an upper case or lower case character). Returns the  parsed character. O.Parses a digit. Returns the parsed character. P8Parses a hexadecimal digit (a digit or a letter between 'a' and  'f' or 'A' and 'F'!). Returns the parsed character. Q+Parses an octal digit (a character between '0' and '7' ). Returns  the parsed character. Rchar c parses a single character c. Returns the parsed  character (i.e. c).  semiColon = char ';' SFThis parser succeeds for any character. Returns the parsed character. T The parser  satisfy f* succeeds for any character for which the  supplied function f returns ‹ . Returns the character that is  actually parsed.  digit = satisfy isDigit * oneOf cs = satisfy (\c -> c `elem` cs) Ustring s* parses a sequence of characters given by s . Returns  the parsed string (i.e. s).  divOrMod = string "div"  <|> string "mod" DEFGHIJKLMNOPQRSTUDGHIJKLMNOPQRUSEFTDEFGHIJKLMNOPQRSTUportable provisional#Antoine Latter <aslatter@gmail.com>V choice ps( tries to apply the parsers in the list ps in order, A until one of them succeeds. Returns the value of the succeeding  parser. W option x p tries to apply parser p. If p fails without ' consuming input, it returns the value x, otherwise the value  returned by p. ' priority = option 0 (do{ d <- digit 2 ; return (digitToInt d)  }) X optionMaybe p tries to apply parser p. If p fails without  consuming input, it return Œ, otherwise it returns  † the value returned by p. Y optional p tries to apply parser p. It will parse p or nothing.  It only fails if p5 fails after consuming input. It discards the result  of p. Zbetween open close p parses open, followed by p and close.  Returns the value returned by p. . braces = between (symbol "{") (symbol "}") [ skipMany1 p applies the parser p one or more times, skipping  its result. \many1 p applies the parser p one or more times. Returns a  list of the returned values of p.  word = many1 letter ] sepBy p sep parses zero or more occurrences of p , separated  by sep'. Returns a list of values returned by p. ' commaSep p = p `sepBy` (symbol ",") ^ sepBy1 p sep parses one or more occurrences of p , separated  by sep'. Returns a list of values returned by p. _sepEndBy1 p sep parses one or more occurrences of p, # separated and optionally ended by sep. Returns a list of values  returned by p. `sepEndBy p sep parses zero or more occurrences of p, # separated and optionally ended by sep, ie. haskell style 2 statements. Returns a list of values returned by p. 8 haskellStatements = haskellStatement `sepEndBy` semi a endBy1 p sep parses one or more occurrences of p , seperated  and ended by sep'. Returns a list of values returned by p. b endBy p sep parses zero or more occurrences of p , seperated  and ended by sep'. Returns a list of values returned by p. * cStatements = cStatement `endBy` semi c count n p parses n occurrences of p. If n is smaller or % equal to zero, the parser equals to return []. Returns a list of  n values returned by p. d chainr p op x parser zero or more occurrences of p,  separated by op Returns a value obtained by a right associative * application of all functions returned by op to the values returned  by p!. If there are no occurrences of p , the value x is  returned. e chainl p op x parser zero or more occurrences of p,  separated by op . Returns a value obtained by a left associative * application of all functions returned by op to the values returned  by p#. If there are zero occurrences of p , the value x is  returned. fchainl1 p op x parser one or more occurrences of p,  separated by op Returns a value obtained by a left associative * application of all functions returned by op to the values returned  by p:. . This parser can for example be used to eliminate left : recursion which typically occurs in expression grammars. # expr = term `chainl1` addop # term = factor `chainl1` mulop $ factor = parens expr <|> integer  - mulop = do{ symbol "*"; return (*) } - <|> do{ symbol "/"; return (div) }  + addop = do{ symbol "+"; return (+) } + <|> do{ symbol "-"; return (-) } gchainr1 p op x parser one or more occurrences of |p|,  separated by op Returns a value obtained by a right associative * application of all functions returned by op to the values returned  by p. h The parser anyToken. accepts any kind of token. It is for example  used to implement i. Returns the accepted token. iAThis parser only succeeds at the end of the input. This is not a * primitive parser but it is defined using j. 3 eof = notFollowedBy anyToken <?> "end of input" jnotFollowedBy p only succeeds when parser p fails. This parser F does not consume any input. This parser can be used to implement the  ' longest match'3 rule. For example, when recognizing keywords (for  example let7), we want to make sure that a keyword is not followed ? by a legal identifier character, in which case the keyword is % actually an identifier (for example lets). We can program this  behaviour as follows: & keywordLet = try (do{ string "let" 0 ; notFollowedBy alphaNum  }) kmanyTill p end applies parser p zero or more times until  parser end2 succeeds. Returns the list of values returned by p. + This parser can be used to scan comments:  & simpleComment = do{ string "<!--" > ; manyTill anyChar (try (string "-->"))  } Note the overlapping parsers anyChar and string "<!--", and  therefore the use of the : combinator. l lookAhead p parses p without consuming any input. VWXYZ[\]^_`abcdefghijklVcZWXY[\]^ba`_efdgijklhVWXYZ[\]^_`abcdefghijklportable provisional#Antoine Latter <aslatter@gmail.com>X #$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijkl       !"#$%&'())*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstruvruwxryz{|}~~.r€r€‚rƒ„rƒ…†‡ˆ‰Šr€‹ŒrŽr‘r’“”•–r—˜parsec1-1.0.0.2!Text.ParserCombinators.Parsec.Pos#Text.ParserCombinators.Parsec.Error"Text.ParserCombinators.Parsec.Prim"Text.ParserCombinators.Parsec.Char(Text.ParserCombinators.Parsec.CombinatorText.ParserCombinators.Parsec SourcePosColumnLine SourceNamenewPos initialPos sourceName sourceLine sourceColumn incSourceLineincSourceColumn setSourceName setSourceLinesetSourceColumnupdatePosString updatePosChar ParseErrorMessageExpectUnExpect SysUnExpectmessageCompare messageString messageEqerrorPos errorMessageserrorIsUnknownnewErrorUnknownnewErrorMessageaddErrorMessage setErrorPossetErrorMessage mergeErrorshowErrorMessagesState stateInputstatePos stateUser GenParserParser<|>getStatesetState updateState getPositiongetInput setPositionsetInputgetParserStatesetParserState parseFromFile parseTestparse runParserpzerotrytoken tokenPrim tokenPrimExlabellabels unexpectedmanyskipManytokens CharParseroneOfnoneOfspacesspacenewlinetabupperloweralphaNumletterdigithexDigitoctDigitcharanyCharsatisfystringchoiceoption optionMaybeoptionalbetween skipMany1many1sepBysepBy1 sepEndBy1sepEndByendBy1endBycountchainrchainlchainl1chainr1anyTokeneof notFollowedBymanyTill lookAheadbaseGHC.ShowShow GHC.ClassesEqOrdforcePosGHC.BasefailReplyErrorOkConsumedEmpty Control.Monadmplus MonadPlus Data.EitherLeftRight parsecMap parsecReturn parsecBind parsecFail parsecZeromzero parsecPlus Data.MaybeJustMaybeupdateParserState manyAccum GHC.UnicodeisSpaceghc-primGHC.BoolTrueNothing