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

(documentation: /.Offset
  "An offset for reading within binary data.")

(documentation: (/.Parser it)
  "A parser for raw binary data.")

(documentation: /.result
  "Runs a parser and checks that all the binary data was read by it."
  [(result parser input)])

(documentation: /.end?
  "Checks whether there is no more data to read.")

(documentation: /.offset
  "The current offset (i.e. how much data has been read).")

(documentation: /.remaining
  "How much of the data remains to be read.")

(documentation: /.Size
  "The size of a chunk of data within a binary array.")

(documentation: /.rec
  "Tie the knot for a recursive parser.")

(documentation: /.any
  "Does no parsing, and just returns a dummy value.")

(documentation: /.segment
  "Parses a chunk of data of a given size."
  [(segment size)])

(template [<size> <name>]
  [(documentation: <name>
     (format "Parses a block of data prefixed with a size that is " (%.nat <size>) " bytes long."))]

  [08 /.binary/8]
  [16 /.binary/16]
  [32 /.binary/32]
  [64 /.binary/64]
  )

(template [<size> <name>]
  [(documentation: <name>
     (format "Parses a block of (UTF-8 encoded) text prefixed with a size that is " (%.nat <size>) " bytes long."))]

  [08 /.utf8/8]
  [16 /.utf8/16]
  [32 /.utf8/32]
  [64 /.utf8/64]
  )

(template [<size> <name>]
  [(documentation: <name>
     (format "Parses a sequence of values prefixed with a size that is " (%.nat <size>) " bytes long."))]

  [08 /.sequence/8]
  [16 /.sequence/16]
  [32 /.sequence/32]
  [64 /.sequence/64]
  )

(documentation: /.list
  "Parses an arbitrarily long list of values."
  [(list value)])

(documentation: /.set
  ""
  [(set hash value)])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Offset
             ..Parser
             ..result
             ..end?
             ..offset
             ..remaining
             ..Size
             ..rec
             ..any
             ..segment

             ..binary/8
             ..binary/16
             ..binary/32
             ..binary/64
             
             ..utf8/8
             ..utf8/16
             ..utf8/32
             ..utf8/64
             
             ..sequence/8
             ..sequence/16
             ..sequence/32
             ..sequence/64
             
             ..list
             ..set
             ($.default /.binary_was_not_fully_read)
             ($.default /.size/8)
             ($.default /.size/16)
             ($.default /.size/32)
             ($.default /.size/64)
             ($.default /.bits/8)
             ($.default /.bits/16)
             ($.default /.bits/32)
             ($.default /.bits/64)
             ($.default /.nat)
             ($.default /.int)
             ($.default /.rev)
             ($.default /.frac)
             ($.default /.invalid_tag)
             ($.default /.or)
             ($.default /.not_a_bit)
             ($.default /.bit)
             ($.default /.text)
             ($.default /.maybe)
             ($.default /.set_elements_are_not_unique)
             ($.default /.symbol)
             ($.default /.type)
             ($.default /.location)
             ($.default /.code)]
            []))
