(.require
 [library
  [lux (.except)
   ["$" documentation]
   [data
    [text (.only \n)
     ["%" \\format (.only format)]]
    [collection
     ["[0]" list (.use "[1]#[0]" monoid)]]]
   [meta
    [macro
     ["[0]" template]]]]]
 ["[0]" \\parser]
 [\\library
  ["[0]" /]])

(`` (def \\parser
      (List $.Documentation)
      (list ($.module \\parser._
                      "")

            ($.definition \\parser.cannot_parse)
            ($.definition \\parser.unconsumed_input)
            ($.definition \\parser.expected_empty_input)
            ($.definition \\parser.wrong_arity)
            ($.definition \\parser.empty_input)

            ($.definition (\\parser.Parser it)
              "A parser for the Lux compiler's synthesis nodes using during optimization.")

            ($.definition \\parser.result
              (format "Executes the parser against the inputs."
                      \n "Ensures all inputs are consumed by the parser.")
              [(result parser input)])

            ($.definition \\parser.any
              "Yields a synthesis node without subjecting it to any analysis.")

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

            ($.definition \\parser.end?
              "Checks whether there are no more inputs.")

            (,, (with_template [<query> <assertion>]
                  [($.definition <query>
                     (format "Queries for a " (template.text [<query>]) " synthesis node."))
                   ($.definition <assertion>
                     (format "Checks for a specific " (template.text [<query>]) " synthesis node."))]

                  [\\parser.bit \\parser.this_bit]
                  [\\parser.i64 \\parser.this_i64]
                  [\\parser.f64 \\parser.this_f64]
                  [\\parser.text \\parser.this_text]
                  [\\parser.local \\parser.this_local]
                  [\\parser.foreign \\parser.this_foreign]
                  [\\parser.constant \\parser.this_constant]
                  ))

            ($.definition \\parser.tuple
              "Parses the contents of a tuple."
              [(tuple parser)])

            ($.definition \\parser.function
              "Parses the body of a function with the 'expected' arity."
              [(function expected parser)])

            ($.definition \\parser.loop
              "Parses the initial values and the body of a loop."
              [(loop init_parsers iteration_parser)])
            )))

(def all_templates
  (List $.Documentation)
  (list ($.definition /.path/pop)
        ($.definition /.path/side)
        ($.definition /.path/member)
        ($.definition /.side/left)
        ($.definition /.side/right)
        ($.definition /.member/left)
        ($.definition /.member/right)
        ($.definition /.path/bind)
        ($.definition /.path/then)
        ($.definition /.path/alt)
        ($.definition /.path/seq)
        ($.definition /.unit)
        ($.definition /.bit)
        ($.definition /.i64)
        ($.definition /.f64)
        ($.definition /.text)
        ($.definition /.variant)
        ($.definition /.tuple)
        ($.definition /.variable)
        ($.definition /.constant)
        ($.definition /.variable/local)
        ($.definition /.variable/foreign)
        ($.definition /.branch/when)
        ($.definition /.branch/let)
        ($.definition /.branch/if)
        ($.definition /.branch/get)
        ($.definition /.loop/again)
        ($.definition /.loop/scope)
        ($.definition /.function/abstraction)
        ($.definition /.function/apply)
        ($.definition /.!bind_top)
        ($.definition /.!multi_pop)
        ($.definition /.simple_left_side)
        ($.definition /.simple_right_side)
        ))

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

                ($.definition /.Resolver)
                ($.definition /.State)
                ($.definition /.fresh_resolver)
                ($.definition /.init)
                ($.definition /.Fork)
                ($.definition /.Path')
                ($.definition /.Abstraction')
                ($.definition /.Apply')
                ($.definition /.Branch)
                ($.definition /.Scope)
                ($.definition /.Loop)
                ($.definition /.Function)
                ($.definition /.Control)
                ($.definition /.Synthesis)
                ($.definition /.State+)
                ($.definition /.Operation)
                ($.definition /.Phase)
                ($.definition /.Handler)
                ($.definition /.Bundle)
                ($.definition /.Path)
                ($.definition /.Abstraction)
                ($.definition /.Apply)
                ($.definition /.with_locals)
                ($.definition /.locals)
                ($.definition /.with_currying?)
                ($.definition /.currying?)
                ($.definition /.with_new_local)
                ($.definition /.%path')
                ($.definition /.%synthesis)
                ($.definition /.%path)
                ($.definition /.equivalence)
                ($.definition /.hash)

                (all list#composite
                     ..all_templates
                     ..\\parser
                     )
                ))
