(.require
 [library
  [lux (.except)
   ["$" documentation]
   [control
    ["[0]" io]]
   [data
    ["[0]" text (.only \n)
     ["%" \\format (.only format)]]
    [collection
     ["[0]" list]]]]]
 ["[0]" \\parser]
 [\\library
  ["[0]" /]])

(def \\parser
  (List $.Documentation)
  (list ($.module \\parser._
                  "")
        ($.definition (\\parser.Parser it)
          "A command-line interface parser.")

        ($.definition \\parser.result
          "Executes the parser and verifies that all inputs are processed."
          [(result parser inputs)])

        ($.definition \\parser.any
          "Just returns the next input without applying any logic.")

        ($.definition \\parser.parse
          "Parses the next input with a parsing function."
          [(parse parser)])

        ($.definition \\parser.this
          "Checks that a token is in the inputs."
          [(this reference)])

        ($.definition \\parser.somewhere
          "Given a parser, tries to parse it somewhere in the inputs (i.e. not necessarily parsing the immediate inputs)."
          [(somewhere cli)])

        ($.definition \\parser.end
          "Ensures there are no more inputs.")

        ($.definition \\parser.named
          "Parses a named parameter and yields its value."
          [(named name value)])

        ($.definition \\parser.parameter
          "Parses a parameter that can have either a short or a long name."
          [(parameter [short long] value)])
        ))

(def .public documentation
  (List $.Documentation)
  (list.partial ($.module /._
                          "")

                ($.definition /.program
                  "Defines the entry-point to a program (similar to the 'main' function/method in other programming languages)."
                  ["Can take a list of all the input parameters to the program."
                   (def _
                     (program all_arguments
                       (do io.monad
                         [foo (initialize program)]
                         (do_something_with all_arguments))))]
                  ["Can also parse them using CLI parsers from the library/lux/control/parser/cli module."
                   (def _
                     (program [config configuration_parser]
                       (do io.monad
                         [data (initialize program with config)]
                         (do_something_with data))))])

                ..\\parser
                ))
