(.using
  [library
   [lux {"-" local function}
    ["$" documentation {"+" documentation:}]
    [data
     [text {"+" \n}
      ["%" format {"+" format}]]]
    [macro
     ["[0]" template]]]]
  [\\library
   ["[0]" /]])

(documentation: /.Env
  "An environment for type parsing.")

(documentation: (/.Parser it)
  "A parser of Lux types.")

(documentation: /.fresh
  "An empty parsing environment.")

(documentation: /.result
  (format "Applies a parser against a type."
          \n "Verifies that the parser fully consumes the type's information.")
  [(result poly type)])

(documentation: /.env
  "Yields the current parsing environment.")

(documentation: /.next
  "Inspect a type in the input stream without consuming it.")

(documentation: /.any
  "Yields a type, without examination.")

(documentation: /.local
  "Apply a parser to the given inputs."
  [(local types poly)])

(documentation: /.with_extension
  ""
  [(with_extension type poly)])

(template [<name>]
  [(`` (documentation: <name>
         (format "Parses the contents of a " (~~ (template.text [<name>])) " type.")))]

  [/.variant]
  [/.tuple]
  )

(documentation: /.polymorphic
  ""
  [(polymorphic poly)])

(documentation: /.function
  "Parses a function's inputs and output."
  [(function in_poly out_poly)])

(documentation: /.applied
  "Parses a type application."
  [(applied poly)])

(template [<name> <doc>]
  [(documentation: <name>
     <doc>)]

  [/.exactly "Parses a type exactly."]
  [/.sub "Parses a sub type."]
  [/.super "Parses a super type."]
  )

(documentation: /.adjusted_idx
  ""
  [(adjusted_idx env idx)])

(documentation: /.parameter!
  ""
  [(parameter! id)])

(documentation: /.existential
  "Yields an existential type.")

(documentation: /.named
  "Yields a named type.")

(documentation: /.recursive
  ""
  [(recursive poly)])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            (format "Parsing of Lux types."
                    \n "Used mostly for polytypic programming.")
            [..Env
             ..Parser
             ..fresh
             ..result
             ..env
             ..next
             ..any
             ..local
             ..with_extension

             ..variant
             ..tuple
             
             ..polymorphic
             ..function
             ..applied

             ..exactly
             ..sub
             ..super
             
             ..adjusted_idx
             ..parameter!
             ..existential
             ..named
             ..recursive

             ($.default /.not_existential)
             ($.default /.not_recursive)
             ($.default /.not_named)
             ($.default /.not_parameter)
             ($.default /.unknown_parameter)
             ($.default /.not_function)
             ($.default /.not_application)
             ($.default /.not_polymorphic)
             ($.default /.not_variant)
             ($.default /.not_tuple)
             ($.default /.types_do_not_match)
             ($.default /.wrong_parameter)
             ($.default /.empty_input)
             ($.default /.unconsumed_input)
             ($.default /.parameter)
             ($.default /.recursive_self)
             ($.default /.recursive_call)]
            []))
