úÎ šN      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM Safe-Infered7Gets the command-line arguments supplied by the program's  user. If the base. package is older than version 4.4, then this A function assumes the command line is encoded in UTF-8, which is C true for many newer Unix systems; however, many older systems may > use single-byte encodings like ISO-8859. In such cases, this ' function will give erroneous results. If the base2 package is version 4.4.0 or newer, this function ) simply uses the getArgs that comes with base. That getArgs  detects the system'/s default encoding and uses that, so it should ( give accurate results on most systems. 8Gets the name of the program that the user invoked. See  documentation for ' for important caveats that also apply  to this function.  Safe-Infered?Long options. Options that are preceded with two dashes on the E command line and typically consist of an entire mnemonic word, such  as lines8. However, anything that is at least one letter long is ? fine for a long option name. The name must not have a dash as B either the first or second character and it must be at least one > character long. It cannot have an equal sign anywhere in its : name. Otherwise any Unicode character is good (including # pathological ones like newlines). ?Short options. Options that are preceded with a single dash on E the command line and consist of a single letter. That single letter B cannot be a dash. Any other Unicode character is good (including # pathological ones like newlines). @Creates a short option. Returns Nothing if the character is not  valid for a short option. BMakes a long option. Returns Nothing if the string is not a valid  long option.       Safe-Infered ?Parsers. Internally the parser tracks what input remains to be D parsed, whether there are any pending short options, and whether a A stopper has been seen. A parser can return a value of any type. ?The parser also includes the notion of failure. Any parser can C fail; a failed parser affects the behavior of combinators such as  combine. Error messages. Any other error; used by . HA previous list of error messages was replaced with this error message. The  fromString function was applied. :The parser expected to see one thing, but it actually saw 9 something else. The string indicates what was expected. =An Error contains a list of Messages and a String indicating  where the error happened. >Runs a parser. This is the only way to change a value of type  Parser a into a value of type a! (that is, it is the only way to  "get out of the Parser monad" or to "escape the Parser monad".) ACombines two parsers into a single parser. The second parser can : optionally depend upon the result from the first parser. =This applies the first parser. If the first parser succeeds, B combine then takes the result from the first parser, applies the > function given to the result from the first parser, and then  applies the resulting parser. =If the first parser fails, combine will not apply the second 5 function but instead will bypass the second parser. %This provides the implementation for N in  .  lookAhead p4 runs parser p. If p succeeds, lookAhead p succeeds ? without consuming any input. If p fails without consuming any D input, so does lookAhead. If p fails and consumes input, lookAhead E also fails and consumes input. If this is undesirable, combine with  try. good a5 always succeeds without consuming any input and has 0 result a. This provides the implementation for    and   .  throwString s/ always fails without consuming any input. The > failure contains a record of the string passed in by s. This ! provides the implementation for  .  parserMap f p, applies function f to the result of parser D p. First parser p is run. If it succeeds, function f is applied to B the result and another parser is returned with the result. If it ? fails, f is not applied and a failed parser is returned. This ! provides the implementation for . Bapply l r applies the function found in parser l to the result of ? parser r. First the l parser is run. If it succeeds, it has a C resulting function. Then the r parser is run. If it succeeds, the > function from the l parser is applied to the result of the r A parser, and a new parser is returned with the result. If either D parser l or parser r fails, then a failed parser is returned. This ! provides the implementation for <*> in  O. <Fail with an unhelpful error message. Usually throw is more B useful, but this is handy to implement some typeclass instances. ?throw e always fails without consuming any input and returns a # failed parser with error state e. @Runs the first parser. If it fails without consuming any input, A then runs the second parser. If the first parser succeeds, then C returns the result of the first parser. If the first parser fails : and consumes input, then returns the result of the first . parser. This provides the implementation for  <|> in P. #Runs the parser given. If it fails without consuming any input, F then applies the given function to the list of messages and replaces 4 the list of messages with the list returned by the 8 function. Otherwise, returns the result of the parser. ?Parses only pending short options. Fails without consuming any > input if there has already been a stopper or if there are no C pending short options. Fails without consuming any input if there C is a pending short option, but it does not match the short option C given. Succeeds and consumes a pending short option if it matches  the short option given. ?Parses only non-pending short options. Fails without consuming  any input if, in order: ! there are pending short options " there has already been a stopper & there are no arguments left to parse & the next argument is an empty string . the next argument does not begin with a dash $ the next argument is a single dash ; the next argument is a short option but it does not match  the one given  the next argument is a stopper BOtherwise, consumes the next argument, puts any remaining letters D from the argument into a pending short, and removes the first word ( from remaining arguments to be parsed. !6Parses an exact long option. That is, the text of the 8 command-line option must exactly match the text of the B option. Returns the option, and any argument that is attached to > the same word of the option with an equal sign (for example,   --follow=/dev/random will return Just "/dev/random" for the ? argument.) If there is no equal sign, returns Nothing for the D argument. If there is an equal sign but there is nothing after it,  returns Just "" for the argument. <If you do not want your long option to have equal signs and E GNU-style option arguments, wrap this parser in something that will & fail if there is an option argument. &Fails without consuming any input if: ! there are pending short options  a stopper has been parsed 1 there are no arguments left on the command line ; the next argument on the command line does not begin with  two dashes * the next argument on the command line is -- (a stopper) ; the next argument on the command line does begin with two 5 dashes but its text does not match the argument we're looking for "8Examines the next word. If it matches a Text in the set C unambiguously, returns a tuple of the word actually found and the D matching word in the set and the accompanying text after the equal C sign (if any). If the Set is empty, this parser will always fail. #AParses only pending short option arguments. For example, for the  tail" command, if you enter the option -c25, then after parsing  the -c option the 25) becomes a pending short option argument 9 because it was in the same command line argument as the -c. &Fails without consuming any input if: # a stopper has already been parsed - there are no pending short option arguments DOn success, returns the String of the pending short option argument $ (this String will never be empty). $ Parses a "stopper"0 - that is, a double dash. Changes the internal > state of the parser to reflect that a stopper has been seen. %>If a stopper has already been seen, change the internal state 3 back to indicating that no stopper has been seen. &Btry p behaves just like p, but if p fails, try p will not consume  any input. 'AReturns the next string on the command line as long as there are D no pendings. Be careful - this will return the next string even if D it looks like an option (that is, it starts with a dash.) Consider C whether you should be using nonOptionPosArg instead. However this B can be useful when parsing command line options after a stopper. (GIf there are pending short options, fails without consuming any input. BOtherwise, if a stopper has NOT already been parsed, then returns D the next word if it is either a single dash or any other word that B does not begin with a dash. If the next word does not meet these . criteria, fails without consuming any input. BOtherwise, if a stopper has already been parsed, then returns the @ next word, regardless of whether it begins with a dash or not. )?manyTill p e runs parser p repeatedly until parser e succeeds. CMore precisely, first it runs parser e. If parser e succeeds, then D manyTill returns the result of all the preceding successful parses D of p. If parser e fails (it does not matter whether e consumed any @ input or not), manyTill runs parser p again. What happens next D depends on whether p succeeded or failed. If p succeeded, then the B loop starts over by running parser e again. If p failed (it does A not matter whether it consumed any input or not), then manyTill @ fails. The state of the parser is updated to reflect its state ? after the failed run of p, and the parser is left in a failed  state. CShould parser e succeed (as it will on a successful application of = manyTill), then the parser state will reflect that parser e D succeeded--that is, if parser e consumes input, that input will be ; consumed in the parser that is returned. Wrap e inside of   lookAhead if that is undesirable. :Be particularly careful to get the order of the arguments B correct. Applying this function to reversed arguments will yield + bugs that are very difficult to diagnose. *?several p runs parser p zero or more times and returns all the > results. This proceeds like this: parser p is run and, if it 3 succeeds, the result is saved and parser p is run C again. Repeat. Eventually this will have to fail. If the last run D of parser p fails without consuming any input, then several p runs A successfully. The state of the parser is updated to reflect the @ successful runs of p. If the last run of parser p fails but it B consumed input, then several p fails. The state of the parser is ? updated to reflect the state up to and including the run that A partially consumed input. The parser is left in a failed state. DThis semantic can come in handy. For example you might run a parser ; multiple times that parses an option and arguments to the A option. If the arguments fail to parse, then several will fail. .This function provides the implementation for  . +)Succeeds if there is no more input left. ' ?Command line arguments to parse. Presumably you got these from  getArgs2. If there is any chance that you will be parsing + Unicode strings, see the documentation in  System.Console.MultiArg.GetArgs before you use  . Parser to run <Success or failure. Any parser might fail; for example, the B command line might not have any values left to parse. Use of the  8 combinator can lead to a list of failures. If multiple / parsers are tried one after another using the  combinator, A and each fails without consuming any input, then multiple Error $ will result, one for each failure.  !"#$%&'()*+QRSTUV!  !"#$%&'()*+! *)& #!"$%'(+  "   !"#$%&'()*+QRSTUV Safe-Infered,8Specifies how many arguments each option takes. As with  #, there are (at least) two ways to D use this type. You can simply represent each possible option using C different data constructors in an algebraic data type. Or you can E have each ArgSpec yield a function that transforms a record. For an / example that uses an algebraic data type, see  $System.Console.MultiArg.SampleParser. -:This option takes a variable number of arguments--zero or A more. Option arguments continue until the command line contains : a word that begins with a hyphen. For example, if option a , takes a variable number of arguments, then -a one two three  -b will be parsed as a taking three arguments, and -a -b  will be parsed as a) taking no arguments. If the user enters  -a; as the last option on the command line, then the only way & to indicate the end of arguments for a and the beginning of ( positional argments is with a stopper. .5This option takes two arguments. Parsed similarly to /. /0This option takes one argument. Here, if option a takes one  argument, -a -b will be parsed with -b being an argument to  option a, even though -b$ starts with a hyphen and therefore  " looks like" an option. 04This option takes an optional argument. As noted in "The Tao  of Option Parsing"(, optional arguments can result in some  ambiguity. (Read it here:   -http://optik.sourceforge.net/doc/1.5/tao.html ) If option a ! takes an optional argument, and b is also an option, what  does -ab/ mean? SimpleParser resolves this ambiguity by  assuming that b is an argument to a. If the user does not  like this, she can specify -a -b (in such an instance -b is  not parsed as an option to -a , because -b begins with a  hyphen and therefore " looks like" an option.) Certainly < though, optional arguments lead to ambiguity, so if you don't  like it, don't use them :) 1This option takes no arguments 2Specifies options for the : function. Each OptSpec % represents one command-line option. 4-Each String is a single long option, such as version. When ? the user specifies long options on the command line, she must > type two dashes; however, do not include the dashes when you C specify the long option here. Strings you specify as long options 9 cannot include a dash as either the first or the second ? character, and they cannot include an equal sign anywhere. If B your long option does not meet these conditions, a runtime error  will occur. 5,Each Char is a single short option, such as v. The C character cannot be a dash; if it is, a runtime error will occur. 66What to do each time one of the given long options or , short options appears on the command line. 7notFollowedBy p. succeeds only if parser p fails. If p fails, C notFollowedBy succeeds without consuming any input. If p succeeds B and consumes input, notFollowedBy fails and consumes input. If p B succeeds and does not consume any input, notFollowedBy fails and  does not consume any input. 8BRuns the parser given. If it succeeds, then returns the result of C the parser. If it fails and consumes input, returns the result of C the parser. If it fails without consuming any input, then removes A all previous errors, replacing them with a single error of type ' Replaced containing the string given. 9>Examines the possible words in Set. If there are no pendings, B then get the next word and see if it matches one of the words in D Set. If so, returns the word actually parsed and the matching word D from Set. If there is no match, fails without consuming any input. :>Parses a single command line option. Examines all the options ? specified using multiple OptSpec and parses one option on the D command line accordingly. Fails without consuming any input if the B next word on the command line is not a recognized option. Allows = the user to specify the shortest unambiguous match for long + options; for example, the user could type --verb for  --verbose  and --vers for  --version. ,For an example that uses this function, see  $System.Console.MultiArg.SimpleParser. ,-./0123456789:,-./0123456789:7823456,10/.-:9,10/.-23456789: Safe-Infered;4What to do after encountering the first non-option, B non-option-argument word on the command line? In either case, no * more options are parsed after a stopper. <<No additional options will be parsed after encountering the , first positional argument. For example, if a and b are  options, in the command line  -a posarg -b, b will be parsed 4 as a positional argument rather than as an option. =9Additional options are allowed on the command line after = encountering the first positional argument. For example, if a  and b" are options, in the command line  -a posarg -b, b will  be parsed as an option. If b is not an option and the same  command line is entered, then -b will result in an error  because -b$ starts with a hyphen and therefore " looks like" an  option. >Parse a command line. ;<=><What to do after encountering the first positional argument All possible options @How to handle positional arguments. This function is applied to ; the appropriate string every time the parser encounters a  positional argument. ;The command line to parse. This function correctly handles # Unicode strings; however, because  ? does not always correctly handle Unicode strings, consult the  documentation in  and consider C using the functions in there if there is any chance that you will 7 be parsing command lines that have non-ASCII strings.  ,-./0123456;<=>;=<23456,10/.-  >;=<> Safe-Infered?@ABCDEFGHIJKLM;<=?@ABCDEFGHIJKLM?KJIHGFEDCBA@L;=<M? KJIHGFEDCBA@LM Safe-Infered ,-./0123456;<=>W !"#$%&'()**+,-./0123456789:;<=>?@ABCDEFGHIJJKLMNOPQRSR,TUVWXYZ[\]^_`abcdecfgcfhijklmnomultiarg-0.4.0.0$System.Console.MultiArg.SimpleParserSystem.Console.MultiArg.GetArgsSystem.Console.MultiArg.OptionSystem.Console.MultiArg.Prim"System.Console.MultiArg.Combinator$System.Console.MultiArg.SampleParser Control.MonadMonadControl.Monad.MonadreturnControl.Applicative.ApplicativepurefailPrelude.FunctorfmapControl.Applicative.AlternativemanySystem.EnvironmentgetArgsSystem.Console.GetOptArgDescrSystem.Console.MultiArgGetArgsexplicit-exception-0.1.7#Control.Monad.Exception.SynchronousSuccess Exception Exceptional getProgNameLongOpt unLongOptShortOpt unShortOpt makeShortOpt makeLongOptParserMessage UnknownErrorReplacedStrMsgExpectedErrorLocationparsecombine lookAheadgood throwString parserMapapply genericThrowthrowchoicependingShortOptnonPendingShortOpt exactLongOpt approxLongOptpendingShortOptArgstopper resetStoppertrynextArgnonOptionPosArgmanyTillseveralendArgSpec VariableArgTwoArgOneArg OptionalArgNoArgOptSpeclongOpts shortOptsargSpec notFollowedBymatchApproxWord parseOption Intersperse StopOptionsFlagFilenameVersionHelpVerboseSleepQuietPidStatsLinesRetryFollowBytesspecs sampleMainbaseGHC.Base>>=Control.Applicative Applicative Alternative$fMonadPlusParser $fMonadParser$fAlternativeParser$fMonoidParser$fApplicativeParser$fFunctorParser