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

(documentation: (/.Parser it)
  "A parser for the Lux compiler's synthesis nodes using during optimization.")

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

(documentation: /.any
  "Yields a synthesis node without subjecting it to any analysis.")

(documentation: /.end!
  "Ensures there are no more inputs.")

(documentation: /.end?
  "Checks whether there are no more inputs.")

(template [<query> <assertion>]
  [(`` (documentation: <query>
         (format "Queries for a " (~~ (template.text [<query>])) " synthesis node.")))
   (`` (documentation: <assertion>
         (format "Checks for a specific " (~~ (template.text [<query>])) " synthesis node.")))]

  [/.bit /.bit!]
  [/.i64 /.i64!]
  [/.f64 /.f64!]
  [/.text /.text!]
  [/.local /.local!]
  [/.foreign /.foreign!]
  [/.constant /.constant!]
  )

(documentation: /.tuple
  "Parses the contents of a tuple."
  [(tuple parser)])

(documentation: /.function
  "Parses the body of a function with the 'expected' arity."
  [(function expected parser)])

(documentation: /.loop
  "Parses the initial values and the body of a loop."
  [(loop init_parsers iteration_parser)])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Parser
             ..result
             ..any
             ..end!
             ..end?

             ..bit ..bit!
             ..i64 ..i64!
             ..f64 ..f64!
             ..text ..text!
             ..local ..local!
             ..foreign ..foreign!
             ..constant ..constant!
             
             ..tuple
             ..function
             ..loop
             ($.default /.cannot_parse)
             ($.default /.unconsumed_input)
             ($.default /.expected_empty_input)
             ($.default /.wrong_arity)
             ($.default /.empty_input)]
            []))
