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

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

(documentation: /.any
  "Yields the next input without applying any logic.")

(template [<query> <check>]
  [(`` (documentation: <query>
         (format "Parses the next " (~~ (template.text [<query>])) " input.")))
   (`` (documentation: <check>
         (format "Checks for a specific " (~~ (template.text [<query>])) " input.")))]

  [/.bit    /.bit!]
  [/.nat    /.nat!]
  [/.int    /.int!]
  [/.rev    /.rev!]
  [/.frac   /.frac!]
  [/.text   /.text!]
  [/.symbol /.symbol!]
  )

(documentation: /.this!
  "Ensures the given Code is the next input."
  [(this! code)])

(template [<query> <check> <desc>]
  [(documentation: <query>
     (format "Parse a local " <desc> " (a " <desc> " that has no module prefix)."))
   (documentation: <check>
     (format "Checks for a specific local " <desc> " (a " <desc> " that has no module prefix)."))]

  [/.local_symbol /.local_symbol! "local symbol"]
  )

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

  [/.form]
  [/.variant]
  [/.tuple]
  )

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

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

(documentation: /.result
  "Executes a parser against a stream of code, and verifies all the inputs are consumed."
  [(result parser inputs)])

(documentation: /.local
  "Runs parser against the given list of inputs."
  [(local inputs parser)])

(documentation: /.not
  "Yields the next Code token if the parser fails."
  [(not expected_to_fail)])

(documentation: /.next
  "Yields the next Code token without consuming it from the input stream.")

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

             ..bit
             ..bit!
             ..nat
             ..nat!
             ..int
             ..int!
             ..rev
             ..rev!
             ..frac
             ..frac!
             ..text
             ..text!
             ..symbol
             ..symbol!
             
             ..this!

             ..local_symbol
             ..local_symbol!
             
             ..form
             ..tuple
             
             ..variant
             ..end!
             ..end?
             ..result
             ..local
             ..not
             ..next]
            []))
