Z      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~#Data types and Types for HsOptions portablestable,Jose Raymundo Cruz (jose.r.cruz01@gmail.com) Safe-Inferred&CType that contains a map from flag name to default flag operation. 6Data type that represents a flag stream using tokens. EToken for a positional argument. Contains the value of the argument. 6Token for a flag. Contains name, operation and value. DData type that represents the value for a flag when parsed from the  input stream. #Data types for the flag operations =Data type that represents a generic flag type configuration. It is mapped from the ( of each flag so that it can be bundled  together with all other flag'$s data. It is used at the validation/parsing  phase of the process/ method to verify that the input flag value is K valid for each flag (i.e. if a required flag was not provided by the user B but this flag has a default value then an error does not occur).  It has a direct mapping of each + to a non-generic version. Exactly the same as  Exactly the same as  Determines if a flag has a  empty value configured. It is mapped from an . Exactly the same as  ?Determines if a flag has a dependent default value configured. *Corresponds just to the predicate part of . 6Determines if a flag value is valid for a given flag. Corresponds to  and returns  if the result value  of the  is  , returns  otherwise /Data type that represent a flag configuration. IIt is used when a flag is created to set the type of the flag, how it is 3 parsed, if the flag is required or optional, etc. ;Default operation for flag when no operation is specified. +runhaskell Program.hs --user_name += batman3Operation was specified: Operation = "Append value"(runhaskell Program.hs --user_name batman@Operation not specified: Operation = 'FlagConf_DefaultOperation'CAlias for the flags. Allows the user to specify multiple names for 0 the same flag, such as short name or synonyms. BDefault value for the flag when the flag was provided by the user  but not the flag value ($i.e. runhaskell Program.hs --user_id). In this example user_id- will take the default value configured with ! this flag configuration since it' s value is & Function that given a ( constraints the flag to be " either required or not required. EIf this function returns true then the flag will be required, and if  not present a flag is required( message will be displayed to the user. GIf this function returns false then the flag presence will be ignored. :Function that sets a dependent default value to the flag. BIf the flag was not provided by the user this will be the default A value for the flag if the default value getter function returns  . 6Function that parses the input value of the flag to it's  corresponding type, see  charParser for an example of this  type of function. The flag input text is of type $, so you can determine  how to map the value if it's missing or it's value is missing or if  it's value was provided. The function returns a 'Maybe a' type,  > if the string value cannot be parsed from the input text and   value if it can be parsed. FType that specifies whether a given validation was successful or not. 'If it was not successful it contains a , that explains what  failed. 'Type that represents the result of the tokenize function and it's  sub-functions. >It returns either a list of errors or a valid list of tokens. 4Type that represents a global validation rule for a (. IIt is used to create global validation after the flags are processed. If  the result is a & then the rule passed. Otherwise if a   err'4 is returned then the ruled failed with the message "err". *Type that represents a pipeline validation/processing function. IIt takes a previous state as a parameter and does a set of modifications  to this state. 8It returns a list of errors (if any error occurred) and E a modified state that will be passed in to the next function in the  pipeline. ! Type of the return value of the process function and it's sub-functions. "Type that holds the ( and # together. #HType that is the list of remaining positional arguments after the parse $ process is completed. For example:  3 ./runhaskell Program.hs --user_id 8 one two three # will contain the list ["one", "two", "three"] $2Data type that represents an input flag argument. It'Fs type will vary depending on the user input. For example if the user $ calls the program that expects the user_id flag: ./runhaskell Program.hs$FlagArgument = FlagMissing "user_id"!./runhaskell Program.hs --user_id*FlagArgument = FlagValueMissing "user_id"'#./runhaskell Program.hs --user_id 8&FlagArgument = FlagValue "user_id" "8"%argument with value  provided &argument provided but  not it's value 'argument not provided (<Type that represents the final result of the parse process. It maps a flag name to it's value. This value is of type $, * which means that it can be empty or not. KThis type is used by the user to get each flag value in the main method by  using the get% method and passing a flag variable. )4Type that holds a map from flag alias to flag name. FIt is used to identify the corresponding flag given a flag alias. For , example if the user_id flag has two alias, u and uid, this map will  have these entries: { uid => user_id, u => user_id }. *+Type that holds a collection of all flags. It'Es a map from flag name to flag data. The flag data holds all defined F configuration for each flag such as flag type, parser, default, etc. +8Type that represents a collection of all defined flags. It has three components: E A flag map: The key is the flag name and the value is the flag data > * An alias map: A map that connects any flag alias with it's unique flag 7 name. This is used to convert each flag alias to it's flag name when  parsing. ( * A list of global validation rules ,BData type for a flag error. It will contain the error message and  what kind of error occurred: ) FatalError: an error that the system can't recover from = * NonFatalError: an error that does not stop the process /*Data type that represents a defined flag.  It contains:  the name of the flag  * help text for the flag N * list of configurations for the flags such as type, default values, etc. Making , an instance of  2  !"#$%&'()*+,-./01  !"#$%&'()*+,-./01/0,.-+*)($'&%#"!      !"#$'&%()*+,.-/0#Core features of the Parser module portablestable,Jose Raymundo Cruz (jose.r.cruz01@gmail.com) Safe-Inferred1@Map of operation keywords to the corresponding operation token. 2*Returns a list of all operation keywords. 3AReturns the corresponding operation token for the input keyword. 4Parses a flag. A flag consist of a name, followed by an 7 and  a value.  Returns:  A . 5Parses the name of a flag. %The name must follow the pattern of: "6   ?".  Returns: 8 A string with the flag name (without the prefix part). 6Parses the flag prefix. :A flag prefix is a double dash (--) or a single dash (-). 7Parses a flag operation. @Flag operations will be parsed from the keywords defined in the  1. 8-Parses a space or the end of file character. 9"Parses a word that is not a flag. " Not a flag"' parses anything that is not parsed by 4 parser. :!Parses a quoted string using the  character for quotes.  Arguments:  character : the character used as quotes. ;Parses a flag value. A flag value is parsed with 9. If this parser fails then   is returned. <.Parses all characters until a space is found. = Parses a command line argument. 6A command argument is an argument that is not a flag (9). >Parses a flag operation. 2Returns: a token representing for that operation. ?=Parses and returns the characters that are valid for a flag. @Parses many flags and/or many positional arguments.  Returns:  A list of tokens. ARuns parser with the @ parser. BDParses the flags from the input stream of characters to a stream of  tokens. Based on the syntax of the  flags input this parser should not fail. F If there is any kind of errors while parsing an exception is thrown.  Arguments: default_operations-: a map from flag name to default operation. input": the input stream of characters.  Returns:  A stream of tokens. Throws: 4 An exception if some error with the parser occurs. 123456789:;<=>?@AB123456789:;<=>?@AB123456789:;<=>?@AB123456789:;<=>?@AB5Parses the flags from the input stream for HsOptions portablestable,Jose Raymundo Cruz (jose.r.cruz01@gmail.com) Safe-InferredBBCore HsOptions source portablestable,Jose Raymundo Cruz (jose.r.cruz01@gmail.com)NonedC Takes a flag'6s name and an error message and builds a proper error  for the flag.  Arguments:   flag_name: the name of the flag  error: the error message  Returns: + A pretty error message for the flag name. DThe keyword for the  usingFile flag and its aliases. IThis flag is used to include a configuration text file for flag parsing. EThe keyword for the help flag and its aliases. $When the user pass in this flag the  display error function is called. FThe keyword for the inherit feature. *This keyword allows the user to set a flag's value based on it' s previous  value. GRegex used to match the F. HGHolds all words that are reserved on by the library and cannot be used  as flag names. I>Creates a flag configuration that makes the flag as optional. "Since the flag is optional then it' s type must  bet / ( a), so that it can be  if the flag was not  provided by the user or  value if it was provided.  Returns: 7 A flag configuration that marks the flag as optional. , This method is a specification of the N method. Is is  equivalent to: requiredIf (const False)JJCreates a flag configuration that defines the default value when the flag  is empty. GSets the value a flag should take if it is the case that this flag was  provided by the user but not it' s value (i.e. runhaskell Program.hs  --user_id).  Arguments:   empty_value/: the value to use if the flag value is empty.  Returns: ( A flag configuration that sets the flag's empty value. KICreates a flag configuration that sets sets the default value for a flag * if the flag is not provided by the user.  Arguments:   default value!: the default value of the flag.  Returns: ( A flag configuration that sets the flag's default value. , This method is a specification of the K method. Is is  equivalent to: defaultIf a (const True)LGCreates a flag configuration that sets a dependent default value for a  flag. 7This configuration requires a function that takes in a ( as  argument and returns a `Maybe a` value,  says that there is no  default value and `Just something`% says that there is a default value.  Arguments: default_getter: function that given a ( returns the  default value () or  if no default value exist;  Returns: D A flag configuration that sets the dependent default value for the  flag. M:Creates a flag configuration for the aliases of the flag. 'Sets multiple alias for a single flag. (i.e. --user_id alias:  ["u", "uid","user_identifier"])#. These aliases can be used to set  the flag value, so  --user_id = 8 is equivalent to -u = 8.  Arguments: aliases: the alias list for the flag.  Returns: > A flag configuration that sets the aliases for a given flag. NJCreates a flag configuration that marks a flag as conditionally required. /The flag will be required from the user if the  condition returns  @ and the user does not provides the flag in the input stream, a "flag is  required"& error is displayed in this scenario. The flag type must be  a , if the  condition returns  and ! the flag is not provided then it' s value is . On the other hand  if the flag is provided it's value will be  value.  Arguments:  condition6: the condition to determine if the flag is required.  Returns: > A flag configuration that sets the conditional flag required  constraint. O Sets the flag's parser configuration. LIt takes the function that will parse the string input to the corresponding 3 flag type value. A set of this functions, such as , was created $ to provide a basic set of parsers.  Arguments: parser_function4: a function that takes a flag argument and returns  8 if the argument can not be parsed or the parsed value () - if the argument can be parsed correctly.  Returns: B A flag configuration that defines how to parse the string input. PCombination of the O and W for syntactic sugar since ! this is a very common scenario. Basically is defined as:  & maybeParser = parser . toMaybeParser So instead of always doing: Fuser_id = make ("user_id", "help", [parser $ toMaybeParser intParser]) You can do: :user_id = make ("user_id", "help", [maybePaser intParser]) Arguments: parser_function0: parser function that defines how to parse the  string input to the flag' s value.  Returns: ? A flag configuration that sets how to parse the string input. QDCreates a flag configuration for the default operation of the flag. CDefines the default operation for the flag if no operation is made E explicit by the user. If this method is not called then the default  operation is always V. +runhaskell Program.hs --user_name += batman6Operation was explicit: Operation = "Append operation"(runhaskell Program.hs --user_name batman8Operation not specified: Operation = @default_operation@ Arguments: default_operation3: operation to use if no operation is provided for " the flag in the input stream.  Returns: C A flag configuration that sets the default operation of the flag. R=Append operation (+=). One of the available flag operations. "The flag value is appended with it'"s previous value using a space in / between values. It is used as the argument of Q function: operation append1Sets the default operation for the flag to append Returns:  Append flag operation. SAppend'8 operation (+=!). One of the available flag operations. Same as R5 but appends with no space in between. It is used as  the argument of Q function: operation append'2Sets the default operation for the flag to append' Returns:  Append' flag operation. T>Prepend operation (=+). One of the available flag operations. #The flag value is prepended with it'"s previous value using a space in / between values. It is used as the argument of Q function: operation prepend2Sets the default operation for the flag to prepend Returns:  Prepend flag operation. UPrepend'8 operation (=+!). One of the available flag operations. Same as T5 but appends with no space in between. It is used as  the argument of Q function: operation prepend'3Sets the default operation for the flag to prepend' Returns:  Prepend' flag operation. VEAssign operation (=). Default flag operation if no operation is set. ISets the flag value to the current value, overwriting any previous value  the flag may have. operation assign1Sets the default operation for the flag to assign Returns:  Assign flag operation. W%Wraps a parser function that takes a $ and returns a  " a". and converts it to a function that returns a  " ( a)". EThis new function does will never fail if the argument is missing or # if the argument value is missing (' or &), 2 instead this function maps any of these two to a  value.  If the flag argument is of type % then the original parser  is used. 6It is a convenient way to reuse current parsers, like  , without ' having to redefine them. For instance "" is of type  $ -> ( ), but "toMaybeParser intParser" is of  type $ -> ( ( )). Usage example:   user_id :: Flag (Maybe Int) H user_id = make ("user_id", "help", [parser (toMaybeParser intParser)]) As you can observe  intParser was reused.  Arguments: original_parser%: the original parser to be wrapped.  Returns: @ A new parser that changes the result type to an optional type. X$Method to get a flag value out of a (. HThis is the method used to get the proper value for each flag after the & input stream has been processed. The  method will create the  (, data structure for a set of defined flags. .This is an example on how to use this method:   user_id :: Flag Int 7 user_id = make ("user_id", "help", [parser intParser]  5 main_success :: (FlagResults, ArgsResults) -> IO () 9 main_success (flags, _) = putStrLn ("Next user id: " ++ E show ((get flags user_id) + 1)))  Arguments:  flag_results: the ( created from the input stream.  Returns:  The value of the given flag. Throws: 6 An exception is raised if flag does not exist in the (.  At this point, the X- method should always succeed parsing a flag J value. If the flag is not found then that means that the flag was not L processed by the parser, possibly because the flag was not added to the  + sent to the processor. Y#Finds the default value from a flag' s list of configurations if the , default value was configured for the flag. LIf a dependent default value was configured for the flag then it is matched  agains the  flag_results, if the match returns  then the default  value is returned, otherwise  is returned.  Arguments:  flag_results: the current (. configurations+: the list of configurations for the flag.  Returns: : Nothing: if there is no dependent default configuration. B Nothing: if the depedent default configuration predicate returns    Just  defaultValue3: if the dependent default configuration predicate  returns  Z8Returns the list of flag alias configured for the flag.  Arguments: configurations+: the list of configurations for the flag.  Returns: 7 A list of all the flag alias configured for the flag. [8Returns the list of flag alias configured for the flag.  Similar to Z but for   instead.  Arguments: configurations+: the list of configurations for the flag.  Returns: 7 A list of all the flag alias configured for the flag. \*Finds the default operation for the flag. .If the default operation is not found the the V operation is used  as the default.  Arguments: configurations+: the list of configurations for the flag.  Returns: % The default operation for the flag. ]3Finds the value to use if the flag value is empty.  Arguments: configurations+: the list of configurations for the flag.  Returns: = Nothing: if there is no empty value configured for the flag / * Just value: if the empty value is found. ^FFinds the parser for the flags and runs it against the flag argument.  Arguments: configurations+: the list of configurations for the flag.  flag_argument: the argument of the flag.  Returns:  The parsed value of the  flag_argument by using the original flag  parser Throws: D An exception if no parser is found. This method depend on previous < validation that the parser was configured for the flag. _6Runs the parser for the flag depending on the type of $. KTakes into considerations scenarios where the flag argument is missing but J the user defined a default value for the flag or if the flag argument is 9 empty and the user defined an empty value for the flag.  Arguments:  flag_results: the current (. configurations+: the list of configurations for the flag.  flag_argument: the argument of the flag.  Returns: G The default value for the flag: if a default value was configured and  the flag argument is '. D The empty value for the flag: if an empty value was configured and  the flag argument is & C Otherwise: The result of the real parser configured for the flag. `Takes a list of +* and combines them together into a single  +. CValidates that a flag name is not repeated in the incoming list of  flag data. Usage example:  ) flagData = combine [ flagToData user_id , , flagToData user_name, * , flagToData database  ]  Arguments:  flag_data_list : list of flag data to combine.  Returns:  A combined + result Throws: @ An exception if any two flag names are duplicated in the input  flag_data_list. a Constructs a + out of a . BThis global rule will be used in the last validation stage of the  { method. Usage example:  ) flagData = combine [ flagToData user_id > , validate (\fr -> if get fr user_id < 0 J then Just "user id negative error" 5 else Nothing)  ] %Multiple validation rules can exist.  Arguments:  global_rule: global validation rule  Returns:  A + representation of the  global_rule. b Converts a / to a +. +< is the general form of the flag that is not bounded by the  type "a" of the "/ a"" input, thus it can be added to a  collection of flags later.  Arguments: flag: the flag to be mapped.  Returns:  A corresponding + for the flag. cMaps a  a to a   data type.  Arguments:  flag_conf+: the flag configuration to be mapped to a  .  Returns:  A corresponding   mapped from the input. dChecks if a flag is invalid. IAmong the validation rules checks that the file name follows the correct $ convention, as well as all the flag' s aliases.  Arguments: (flag_name, flag_configuration)#: the data of the flag required to  validate it.  Returns:   if the flag is valid.  An error message () if the flag failed. eReturns  if the flag name is value,  otherwise. +Enforces the convention for the flag name: "Letter followed by many ( 3 Letters - Numbers - Dashes (-) - Underscores (_) ).  Arguments:  flag_name: the name of the flag.  Returns:  * if the flag name follows the convention,  otherwise. f)Maps a flag alias to the real flag name. For example if the flag  --user_id has the -uid alias configured in the  flag_alias_map then: mapAlias flag_alias_map "uid"will return "user_id"!If the alias is not found in the flag_alias_map then the  flag_alias " argument is returned unmodified.  Arguments: flag_alias_map&: the map of flag alias to flag name.  flag_alias0: the alias to be mapped to the real flag name.  Returns:  The real flag name for the  flag_alias if found or the same argument  unmodified if not found. g Replaces the  sub_string with the replacement_string in the input   input_string. +replaceStr "One two three@" ("two", "four")"One four three" Arguments:  input_string: the string to be searched.  sub_string#: the string to be replaced in the  input_string. replacement_string,: the string to be used as a replacement of   sub_string.  Returns:  The  input_string with any  sub_string replaced for  replacement_string. hICreates the flag argument from the parser results for a given flag based ) on the operation performed on the flag. IMaps the flag opereration to the respective method that will produce the  flag value, such as j" (that produces the flag value by 7 appending the current value with the previous value).  Arguments:  parse_results*: the current state of the parse process. "(flag_name, operation, flag_value)#: flag and flag value information, : as well as the operation being performed to the flag.  Returns: C A flag argument containing the final value for the flag after the  operation was performed. i$Performs the assign flag operation. IAssigns the current value to the flag disregarding any previous state of  the flag.  Arguments:  parse_results*: the current state of the parse process. (flag_name, flag_value)+: name and value of the current operation.  Returns:  %5 if the flag is being assigned to a not empty value,  & otherwise. j$Performs the append flag operation. IAppends the current value of the flag to the previous value of the flag. 8 A space is used as a separator between the two values. FIf the current value for the flag is empty then the previous value is  taken as the new flag value.  Arguments:  parse_results*: the current state of the parse process. (flag_name, flag_value)+: name and value of the current operation.  Returns: E The current value of the flag appended to the previous value of the % flag using a space as separator. kPerforms the append' flag operation.  Similar to R( but does not use a space as separator. FIf the current value for the flag is empty then the previous value is  taken as the new flag value.  Arguments:  parse_results*: the current state of the parse process. (flag_name, flag_value)+: name and value of the current operation.  Returns: E The current value of the flag appended to the previous value of the 1 flag without using any in between separator. l%Performs the prepend flag operation. JPrepends the current value of the flag to the previous value of the flag. 8 A space is used as a separator between the two values. FIf the current value for the flag is empty then the previous value is  taken as the new flag value.  Arguments:  parse_results*: the current state of the parse process. (flag_name, flag_value)+: name and value of the current operation.  Returns: F The current value of the flag prepended to the previous value of the % flag using a space as separator. mPerforms the prepend' flag operation.  Similar to T( but does not use a space as separator. FIf the current value for the flag is empty then the previous value is  taken as the new flag value.  Arguments:  parse_results*: the current state of the parse process. (flag_name, flag_value)+: name and value of the current operation.  Returns: D The current value of the flag prepend to the previous value of the 1 flag without using any in between separator. n3Tries to find the previous result of a flag in the (.  Arguments:  parse_results: the current parsed flags.  flag_name!: flag name used to find the flag' s value.  Returns: " The value of the flag inside the  parse_results if it exists or  & otherwise. oEChecks if the value for the flag includes the $(inherit) keyword and : replaces this keyword by the previous value of the flag. IIt is a generalization of the append or prepend features, you can insert B the previous value of the flag in any position of the new value. ,For example, if the previous flag value was "batman" and the new value  was "a-$(inherit)-z"( then the new value will be expanded to  " a-batman-z".  Arguments:  parse_results: the current parsed flags. argument: the value of the flag.  Returns: H A new flag value by expanding any $(inherit) keyword with the previous  value of the flag. pTakes a  and produces a ". "= contains the final result of the flag after being analysed. If the token is an # then it is mapped unmodified to a  ". If the token is a  then the flag operation is 7 performed and the inherit keyword is expanded, then a " is % created with this final flag value.  Arguments: (parse_results, token)+: the parse results so far and the current  token to parse.  Returns: 5 A parse results after evaluating the current token. q#Takes a list of tokens, an initial " and returns a  complete merge  ParsedResults$ after parsing each token in order.  Every token is parsed using the p and it' s result is 4 continuously merged until all tokens are consumed.  Arguments: tokens: the list of tokens to parse. initial_parse_result*: the initial state of the parse process.  Returns:  A complete "* after parsing all of the input tokens in  order. rConcatenates two  together. If both are errors ($) then the errors are concatenated. If only one of them is errors ( ) then that result is returned. If non are errors, but tokens ($), then the tokens are concatenated  and returned.  Arguments: tokenize_result1: first result. tokenize_result2: second result.  Returns:  tokenize_result1 concatenated with tokenize_result2 sAReads a file from disk and returns the file content or an error.  Arguments: filename): the filename of the file to be opened.  Returns:  Either an exception () or the file content (). t,Parses the content of a configuration file. CIf there is an error reading the file then that error is returned, 8 otherwise the file content is processed and tokenized. HA preprocessor stage is performed on the content to remove the comments 0 in the text file (comments starts with a hash (#) ).  Arguments: (parents, flag_data)0: the parents is the tree of configuraiton file E parents of this current configuration file. The flag_data is the 5 information about the flags defined in the code. configuration_filename1: the path of the configuration file to include.  Returns: C The tokenized version of the content of the configuration file or  an error (*) if any errors found during the process. u Removes all the comments of the  input_text. 4A comment is a string that begins with hash symbol (#) and ends with a  line change ('\n').  Arguments:  input_text: the input text.  Returns: 4 The same input text but with all comments removed. v Checks if the token is the flag ' --usingFile'.  Arguments: token: the token to evaluate.  Returns:   if the token is not for the  --usingFile flag. / The canonical path of the configuration file () if the token is  for the flag  --usingFile. wARecursively expands all the configuration file includes from the  input token stream. ?It takes the input tokens and searches for any instance of the   --usingFile9 flag. If this flag is found then that flag is consumed, H the configuration file defined by that flag is tokenized and these new D tokens are inserted in the current spot of the input token stream. 8This is a recurvise process that will stop once all the  --usingFile = have been consumed and we got a stream of pure flag tokens. HIf a circular dependency is detected then an error is reported to user.  parents; has the current tree of parents so we can check if we are M including one parent configuration file, which will cause an infinite loop.  Arguments: (parents, flag_data)0: the parents is the tree of configuraiton file E parents of this current configuration file. The flag_data is the 5 information about the flags defined in the code.  input_tokens: the input token stream.  Returns: G A new token stream with all the configuration file includes expanded, J or an error if any error is found (either with circular dependency or  invalid flag values). x>Creates an error message when a circular dependency is found. =Creates a pretty error highlighting the circular dependency.  Arguments: tree;: the tree of configuration files that caused the problem.  Returns:  An error showing the problem. yCTakes an input string and creates a stream of tokens after parsing  the input with the B. FAfter the initial token stream is created all the configuration files 7 includes are expanded to create a clean token stream.  Arguments: (parents, flag_data)0: the parents is the tree of configuraiton file E parents of this current configuration file. The flag_data is the 5 information about the flags defined in the code.  input_string : the input string to tokenize.  Returns: 5 A tokenized stream processed from the input string. z6Creates a map of flag name to flag default operation. >This map is used in the parser to correctly retrieve which is G the default operation for each flag when the user does not explicitly  specifies the flag operation.  Arguments:  flag_list0: all the flags in the code (including the flag  configuration).  Returns: ' A map from flag to default operation. {Does the actual flag parsing. FIt begins by parsing the entire input stream and creating a tokenized F input stream. A recursive search is done in these tokens to find any H configuration files includes. Each conf file include is expanded until J the tokenized stream is just composed of flags and positional arguments. KThis tokenized stream is validated then by the rules of each flag, such as 4 type validation, required flags, constraints, etc. IThis method is an IO action because it needs to expand the configuration ( file includes (open the file and get it's content). When the stream is ( tokenized and no more IO is needed the  'process\'' method is called. JThe validation is divided in two, local validation and global validation. GLocal validation handled things like reserved words, unknown flags and  correct flag types. LGlobal validation happens at the end and does all the validation that needs J a context, such as global validation constraints, conditionally required J flags and dependent default. Global validation only happens if the local  validation succeeds.  Arguments:  flag_data%: a set of all the flags to process.  input_stream!: the command line input stream.  Returns:  Either a list of errors () or a successful result (). |HDoes the actual flag parsing after the input stream have been tokenized 1 and the configuration files have been expanded. IUpdates the tokenized input stream and changes any flag alias set by the ? user to the actual name of the flag, meaning if the user sent  --uid = 8  then the token is changed to  --user_id = 8 (considering uid is an alias  for user_id<). This means from this point forward the flag name is used A as the flag identifier (any alias was mapped to the flag name). Performs local validation: 6 Verifies that no reserved words was used for the flag's name. 6 Validates that no unknown flag was sent by the user. G Validates that for every value set to a flag this value can be parsed K to the type the flag is expecting. (i.e. checks the string value of an  # flag can be parsed from string to  correctly). Performs global validation:  Validates the N constraints.  Validates the L constraints. E Validates all global validation rules are passing (rules created by  using the a function)  Arguments:  flag_data%: a set of all the flags to process. tokenized_input_stream-: the complete input stream after tokenized.  Returns:  * Either a list of errors () or a successful result (). }HMaps the flag alias to the real flag name for each of the input tokens. The alias is mapped using the f method.  Arguments:  flag_data3: contains information for the configured aliases. tokens: the list of tokens.  Returns: A An update list of tokens with each flag alias replaced with the  real name of the flag. ~8Gets the flag name from a token if the token is a flag.  Arguments: token : the token.  Returns:  The flag name () if the token is a .   otherwise. -Replaces the name of a flag with a new name.  Arguments: token : the token. name: the new name for the flag.  Returns: H An updated token with the name replaced with the new name if the token  is a ". The unmodified token otherwise. .Checks if the help flag was sent by the user.  Arguments:  arguments: the arguments from the user.  Returns:   if the user sent the --help or the -h flags. 8Processes the input arguments and parses all the flags. EStarts the process flags pipeline. First checks if the user wants to G display the help text of the program. This is done by looking for the  flag "--help" or "-h"+ flag in the input stream. If this flag is  found then the  display_help* function is called with all the compiled ' helptext and the program description. 8If the user does not wants to display the help then the { function J is called to do the actual flag parsing. This function can return errors  or a success result ((, #). If any error is found  then the failure; function is called with the list of errors, otherwise the  success& function is called with the results. See the {7 documentation to see the rules and conditions of flag  parsing.  Arguments:  description.: the description of the program. Sent to the   display_help function.  flag_data5: a collection of all the flags defined in the code. success>: a success callback function. Called if no errors were found , while parsing the flags from the input. failure:: a failure callback function. Called if some errors were # found while parsing the input.  display_help4: a display help callback function. Called when the  "--help" or "-h" flag was sent by the user.  Returns:  An IO action. (Returns the arguments sent by the user. 4Double quote any argument that contains whitespace.  Returns: B The list of the command line arguments quoting any argument with  whitespace. "Checks if a fatal error occurred.  Arguments: errors: all flag errors.  Returns:   if a - is found.  otherwise. Merges a list of pipelines. DIf any pipeline returns an error then the error is returned without % processing the remaining pipelines.  Arguments:  pipelines: a list of pipelines.  Returns: 6 A pipeline function that merges a list of pipelines. *Executes the pipeline functions in order. IThe result of the current pipeline function is sent to the next function  in the list. GThe functions are evaluated until the list is consumed or any function  returns a fatal error.  Arguments:  pipelines!: the list of pipeline functions  Returns: C A pipeline function that executes the list of pipelines in order. EPipeline function that validates no flag is using a reserved word as  it's name.  Arguments: (flag_data, flag_results)%: the flag data and the current flag  results.  Returns: 4 An error if any flag is using a reserved word as it' s name. The   flag_results1 is not modified for the next pipeline function. &Applies the predicate if the value is .  Arguments: value: value to apply the predicate  predicate: the predicate to apply.  Returns:   if the value is . 3 The predicate applied to the internal value if is . EPipeline function that modifies the results by inserting all missing  flags into it. BAt this point the flags have been processed by the parser, so the  (: will have only the flags sent by the user. The remaining  flags are inserted into the ( with a ' value. 4This is useful so that future pipeline functions don't need to worry F about any flag not present in the flag results, as all defined flags 9 will be there, and missing flags will be there with the '  value.  Arguments: (flag_data, flag_results)%: the flag data and the current flag  results.  Returns:  The modified  flag_results. HPipeline function that checks if any unknown flag was sent by the user. If a flag exists in the  flag_results that does not exist in the   flag_data then an error is returned.  Arguments: (flag_data, flag_results)%: the flag data and the current flag  results.  Returns: ' An error if an unknown flag is found.  Pipeline function that runs the  on all the  define flags on  flag_data.  Arguments: (flag_data, flag_results)%: the flag data and the current flag  results.  Returns: ' An error if the flag validator fails.  Pipeline function that runs the  on all the  define flags on  flag_data.  Arguments: (flag_data, flag_results)%: the flag data and the current flag  results.  Returns: ( * An error if the flag is required.  Pipeline function that runs the  on all the  define flags on  flag_data.  Arguments: (flag_data, flag_results)%: the flag data and the current flag  results.  Returns: ( * An error if the flag is required. @Pipeline function that runs all the global rules defined in the   flag_data.  Arguments: (flag_data, flag_results)%: the flag data and the current flag  results.  Returns: . * An error if any validation rules fails. 8Validates if the flag should be conditionally required. DIf the flag is missing, was marked as conditionally required (using  N/) and the required predicate returns true then  a " flag required" error is reported. @In any other condition a success validation result is returned.  Arguments: flag_configurations!: the configurations for a flag.  flag_results: current state of the flags.  flag_argument: the flag argument.  Returns:   if the flag is not required.  An error () if it is not. BValidates if the flag has a default value or the flag is optional  when the flag is missing. DIf the flag is missing and it is not optional or it does not have a ! default value configured then a " flag required" error is reported. @In any other condition a success validation result is returned.  Arguments: flag_configurations!: the configurations for a flag.  flag_results: current state of the flags.  Returns:  2 if the flag is valid with respect to the default  value. An error () if it is not. Defines a flag. @A defined flag consist of a name, a helptext and a list of flag K configurations. The name is the flag identifier, it must be unique among  all other defined flags. !The name must follow the pattern " 'Letter' followed by many  '3Letters || Numbers || Dashes (-) || Underscores (_)' ". ' If the name of the flag is invalid an  exception is thrown. )A parser for the flag must be set in the  configuration by using O  or P3. If a parser is not found an exception is thrown.  Arguments:  (name, helptext, configurations)%: A triple containing the flag name, . the helptext and the flag configurations.  Returns:  A flag. Throws: E An exception if the name is invalid (does not follows the pattern). / An exception if the parser was not set in the configurations. =Prints the help text to the screen using an standard format.  Arguments:  description": the description of the program. flag_helptexts3: A list of triples (name, aliases, helptext) that 2 contains an entry for each flag, with the flag's name, aliases and  helptext. ;Creates an option description from the names and helptext.  Arguments: names: the names for the flag. helptext: the helptext for the flag.  Returns:  An  that describes the flag. ,Takes the single character strings from the  input_list and  separates them from the list. &splitShortName ["one", "a", "two","b"]("ab", ["one", "two"]) Arguments:  input_list: a list of strings.  Returns: C A tuple where the first element is a list of the single character  strings from the  input_list) and the second if the remaining strings  from the  input_list. +Displaye the list of errors to the screen.  Arguments: errors: list of errors to display. ACreates a data structure with all the flag helptext information.  Arguments:  flag_data&: all configured flags in the system.  Returns: @ A list of triples. Each triple contains (flag_name, [flag_alias], ' flag_helptext). After all flags in  flag_data are processed the  two system flags (help and  usingFile) are appended to the end of  the list. EReturns whether the flag configuration marked this flag as optional.  Arguments: flag_configurations!: the configurations for a flag.  Returns:  " if the flag is an optional flag.  otherwise. EReturns whether the flag should be required to the user based on the  current results. LFirst checks if the flag was configured as conditionally required (with the  use of the N function). BIf it was, this required condition is checked against the current  state.  Arguments: flag_configurations!: the configurations for a flag.  flag_results: current state of the flags.  Returns:  - if the flag should be required to the user. Returns  if any of the  returns  . =For all the configured default values of the flag (like when  using K or L! checks if any of the predicates  returns true for the given (.  Arguments: flag_configurations!: the configurations for a flag.  flag_results: current state of the flags.  Returns:  8 if there is any default value configured for the flag.   otherwise. FChecks if a dependent default value was configured for the flag, like  when the L or K functions are used.  Arguments: flag_configurations!: the configurations for a flag.  Returns:  5 if a dependent default was configured for the flag.   otherwise. ;Checks if an empty value was configured for the flag, like  when the J function is used.  Arguments: flag_configurations!: the configurations for a flag.  Returns:  0 if an empty value was configured for the flag.   otherwise. Finds the flag validator () in the list of < flag configurations and runs it against the flag argument.  Arguments: flag_configurations!: the configurations for a flag.  flag_argument: the argument for the flag.  Returns: A The result of the validator when run against the flag argument. /Creates a failed validation result for a flag. @Constructor method to easily created a failed validation result  ().  Arguments:  flag_name#: flag name that caused the error.  error_message: error message.  Returns: ' A validation result for a flag error. %Checks if the flag value provided in $ is valid by using  the validation found in the flag_configurations. =The configured flag validator will only be used if required. ;Under these conditions the flag is considered valid, and a  / is returned, without the need to use the flag  validator: 1 The flag is missing but was marked as optional. . The flag is missing but has a default value. 6 The flag is empty but has an empty value configured. AIf none of the above applies, then this is the expected results:  The flag is missing: A "flag is required" error is reported.  The flag is empty: A "flag value is empty" error is reported. F The flag has a value: The configured flag validator is run with this  value. If it fails a "flag value invalid" error is reported.  Arguments: flag_configurations!: the configurations for a flag.  flag_argument: the argument for the flag.  Returns:  $ if the flag is valid or an error (  ) if it is not. Helper parser function. (Parses any type that is instance of the  class.  Arguments: argument: the input argument.  Returns:  $ if the argument is missing or if it's value is missing.  Otherwise it calls % on the argument value and returns a "   a" with the result of read.  Parses an  from the input $  Arguments: argument: the input argument  Returns:  5 if the argument cannot be parsed to the type or the parsed  value () if it can.  Parses an  from the input $  Arguments: argument: the input argument  Returns:  5 if the argument cannot be parsed to the type or the parsed  value () if it can.  Parses an  from the input $  Arguments: argument: the input argument  Returns:  5 if the argument cannot be parsed to the type or the parsed  value () if it can.  Parses an Array from the input $  Arguments: argument: the input argument  Returns:  5 if the argument cannot be parsed to the type or the parsed  value () if it can.  Parses a  from the input $  Arguments: argument: the input argument  Returns:  5 if the argument cannot be parsed to the type or the parsed  value () if it can.  Parses a  from the input $  Arguments: argument: the input argument  Returns:  5 if the argument cannot be parsed to the type or the parsed  value () if it can.  Parses a  from the input $  Arguments: argument: the input argument  Returns:   () if the flag is missing.   () if the flag value is missing.  5 if the argument cannot be parsed to the type or the parsed  value () if it can. <A predefined set of flag configurations for a boolean flag. 0Defines a set of configurations that specifies:  The parser to be .  The default value to be .  The empty value to be  FThis defines a default boolean flag behavior such that if the flag is  missing then it is treated as , if the flag is present (i.e  --help ) then it is . dCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~dCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~dCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~dCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~%Command line flag parser for Haskell portablestable,Jose Raymundo Cruz (jose.r.cruz01@gmail.com)None/!#$%&'(+,-./IJKLMNOPQRSTUVWX`ab{|/X{|b`OPIJKLMNWaQVRSTU/+,.-($'&%!#       !"#$%&'()*+,-./01234456789:;<=>?@ABCDEFGHIJKLMNOPQRSTBUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~hsoptions-1.0.0.0System.Console.HsOptions.Types#System.Console.HsOptions.ParserCoreSystem.Console.HsOptions.CoreSystem.Console.HsOptions.ParserSystem.Console.HsOptions DefaultOpTokenArgToken FlagTokenFlagValueTokenFlagValueTokenEmptyOperationTokenOperationTokenPrepend'OperationTokenPrependOperationTokenAppend'OperationTokenAppendOperationTokenAssign FlagDataConfFlagDataConf_DefaultOperationFlagDataConf_AliasFlagDataConf_HasEmptyValueFlagDataConf_RequiredIfFlagDataConf_HasDefaultFlagDataConf_ValidatorFlagConfFlagConf_DefaultOperationFlagConf_AliasFlagConf_EmptyValueIsFlagConf_RequiredIfFlagConf_DefaultIfFlagConf_ParserValidationResultValidationSuccessValidationErrorTokenizeResult GlobalRulePipelineFunctionProcessResults ParseResults ArgsResults FlagArgument FlagValueFlagValueMissing FlagMissing FlagResults FlagAliasMap FlagDataMapFlagData FlagErrorFlagFatalErrorFlagNonFatalErrorFlagoperationsKeyMapoperationKeywordsoperationTokenForflagflagName flagPrefix flagOperation spaceOrEofnotFlag quotedString flagValue allButSpace cmdLineArg operationvalidFlagChars manyToken parseInput' parseInput flagError usingFileKwhelpKw inheritKw inheritRegex reservedWords isOptional emptyValueIs defaultIs defaultIfaliasIs requiredIfparser maybeParserappendappend'prependprepend'assign toMaybeParserget flagDefault flagAlias flagDAliasflagDDefaultOperationflagEmptyValue runRealParser runParsercombinevalidate flagToDatafConfToFDataConf invalidFlaginvalidFlagNamemapAlias replaceStr executeOp execAssign execAppend execAppend' execPrepend execPrepend'previousOrEmpty applyInherit parseToken parseArgs concatToks readFile' parseConfFileremoveCommentsisUsingConfFlag includeConfigreportCircularDependencytokenize mkDefaultOpprocessprocess'updateFlagAlias getFlagName updateName anyArgIsHelp processMain getQuotedArgs hasFatalError pipelinespipelinevalidateReservedWordsifIsJustaddMissingFlagsvalidateUnknownFlagsvalidateFlagParsersvalidateRequiredIfvalidateDependentDefaultvalidateGlobalRulesrequiredIfValidatordefaultIfValidatormakedefaultDisplayHelp mapOptOptionsplitShortNamedefaultDisplayErrors getFlagHelpflagDIsOptionalflagDIsRequiredIfflagDHasDefaultForResultsflagDHasDefaultflagDHasEmptyValue runDValidatorvalidationErrorcheckValidator valueParser intParser doubleParser floatParser arrayParser charParser stringParser boolParserboolFlagghc-prim GHC.TypesTruebase Data.MaybeJustFalseNothing$fShowFlagErrorGHC.ShowShow parsec-3.1.3Text.Parsec.CharletterMaybeInt Data.EitherLeftRightSystem.Console.GetOptOptDescrGHC.ReadRead Text.ReadreadDoubleFloatCharGHC.BaseStringBool