code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(149 lines)
1 Byte.get_bit:
2 short: check whether a bit is set
3 description: >
4 In the binary representation of a byte, check whether a given bit index is
5 set to 1 or not.
6 note: >
7 The bit index must be between 1-8 or a runtime error will be produced.
8 return:
9 type: 'Bool'
10 description: >
11 Whether or not the given bit index is set to 1 in the byte.
12 args:
13 i:
14 type: 'Byte'
15 description: >
16 The byte whose bits are being inspected.
17 bit_index:
18 type: 'Int'
19 description: >
20 The index of the bit to check (1-indexed, range 1-8).
21 example: |
22 assert Byte(6).get_bit(1) == no
23 assert Byte(6).get_bit(2) == yes
24 assert Byte(6).get_bit(3) == yes
25 assert Byte(6).get_bit(4) == no
27 Byte.hex:
28 short: convert to hexidecimal
29 description: >
30 Convert a byte to a hexidecimal text representation.
31 return:
32 type: 'Text'
33 description: >
34 The byte as a hexidecimal text.
35 args:
36 byte:
37 type: 'Byte'
38 description: >
39 The byte to convert to hex.
40 uppercase:
41 type: 'Bool'
42 default: 'yes'
43 description: >
44 Whether or not to use uppercase hexidecimal letters.
45 prefix:
46 type: 'Bool'
47 default: 'no'
48 description: >
49 Whether or not to prepend a `0x` prefix.
50 example: |
51 assert Byte(18).hex(prefix=yes) == "0x12"
53 Byte.is_between:
54 short: test if inside a range
55 description: >
56 Determines if an integer is between two numbers (inclusive).
57 return:
58 type: 'Bool'
59 description: >
60 `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
61 args:
62 x:
63 type: 'Byte'
64 description: >
65 The integer to be checked.
66 low:
67 type: 'Byte'
68 description: >
69 One end of the range to check (inclusive);
70 high:
71 type: 'Byte'
72 description: >
73 The other end of the range to check (inclusive);
74 example: |
75 assert Byte(7).is_between(1, 10) == yes
76 assert Byte(7).is_between(10, 1) == yes
77 assert Byte(7).is_between(100, 200) == no
78 assert Byte(7).is_between(1, 7) == yes
80 Byte.parse:
81 short: convert text to a byte
82 description: >
83 Parse a byte literal from text.
84 return:
85 type: 'Byte?'
86 description: >
87 The byte parsed from the text, if successful, otherwise `none`.
88 args:
89 text:
90 type: 'Text'
91 description: >
92 The text to parse.
93 base:
94 type: 'Int?'
95 default: 'none'
96 description: >
97 The numeric base to use when parsing the byte. If unspecified, the
98 byte's base will be inferred from the text prefix. After any "+" or "-"
99 sign, if the text begins with "0x", the base will be assumed to be 16,
100 "0o" will assume base 8, "0b" will assume base 2, otherwise the base
101 will be assumed to be 10.
102 remainder:
103 type: '&Text?'
104 default: 'none'
105 description: >
106 If non-none, this argument will be set to the remainder of the text after the matching part.
107 If none, parsing will only succeed if the entire text matches.
108 example: |
109 assert Byte.parse("5") == Byte(5)
110 assert Byte.parse("asdf") == none
111 assert Byte.parse("123xyz") == none
113 remainder : Text
114 assert Byte.parse("123xyz", remainder=&remainder) == Byte(123)
115 assert remainder == "xyz"
117 Byte.to:
118 short: iterate over a range of bytes
119 description: >
120 Returns an iterator function that iterates over the range of bytes specified.
121 return:
122 type: 'func(->Byte?)'
123 description: >
124 An iterator function that returns each byte in the given range (inclusive).
125 args:
126 first:
127 type: 'Byte'
128 description: >
129 The starting value of the range.
130 last:
131 type: 'Byte'
132 description: >
133 The ending value of the range.
134 step:
135 type: 'Int8?'
136 default: 'none'
137 description: >
138 An optional step size to use. If unspecified or `none`, the step will be inferred to be `+1` if `last >= first`, otherwise `-1`.
139 example: |
140 iter := Byte(2).to(4)
141 assert iter() == Byte(2)
142 assert iter() == Byte(3)
143 assert iter() == Byte(4)
144 assert iter() == none
146 assert [x for x in Byte(2).to(5)] == [Byte(2), Byte(3), Byte(4), Byte(5)]
147 assert [x for x in Byte(5).to(2)] == [Byte(5), Byte(4), Byte(3), Byte(2)]
148 assert [x for x in Byte(2).to(5, step=2)] == [Byte(2), Byte(4)]