aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/parser/binary.lux
blob: 7a890c8270fb8c8b163a9444825aeedb30281686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
(.using
 [library
  [lux (.except list)
   ["$" documentation (.only documentation:)]
   [data
    [text (.only \n)
     ["%" format (.only 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)])

(with_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]
  )

(with_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]
  )

(with_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)]
            []))