1 // Show ToC at a specific location for a GitHub rendering
10 // This is to mimic what GitHub does so that anchors work in an offline
21 image::normand-logo.png[]
24 image:https://img.shields.io/pypi/v/normand.svg?label=Latest%20version[link="https://pypi.python.org/pypi/normand"]
27 _**Normand**_ is a text-to-binary processor with its own language.
29 This package offers both a portable {py3} module and a command-line
32 WARNING: This version of Normand is 0.5, meaning both the Normand
33 language and the module/CLI interface aren't stable.
36 // ToC location for a GitHub rendering
42 The purpose of Normand is to consume human-readable text representing
43 bytes and to produce the corresponding binary data.
47 Consider the following Normand input:
50 4f 55 32 bb $167 fe %10100111 a9 $-32
53 The generated nine bytes are:
56 4f 55 32 bb a7 fe a7 a9 e0
60 As you can see in the last example, the fundamental unit of the Normand
61 language is the _byte_. The order in which you list bytes will be the
62 order of the generated data.
64 The Normand language is more than simple lists of bytes, though. Its
67 Comments, including a bunch of insignificant symbols which may improve readability::
72 ff bb %1101:0010 # This is a comment
73 78 29 af $192 # This too # 99 $-80
74 fe80::6257:18ff:fea3:4229
76 10839636-5d65-4a68-8e6a-21608ddf7258
82 ff bb d2 78 29 af c0 99 b0 fe 80 62 57 18 ff fe
83 a3 42 29 60 57 18 a3 42 29 10 83 96 36 5d 65 4a
84 68 8e 6a 21 60 8d df 72 58
87 Hexadecimal, decimal, and binary byte constants::
92 aa bb $247 $-89 %0011_0010 %11.01= 10/10
101 UTF-8, UTF-16, and UTF-32 literal strings::
107 u16le"stress\nverdict 🤣"
113 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 00 73 00 74 ┆ hello world!•s•t
114 00 72 00 65 00 73 00 73 00 0a 00 76 00 65 00 72 ┆ •r•e•s•s•••v•e•r
115 00 64 00 69 00 63 00 74 00 20 00 3e d8 23 dd ┆ •d•i•c•t• •>•#•
118 Labels: special variables holding the offset where they're defined::
121 <beg> b2 52 e3 bc 91 05
122 $100 $50 <chair> 33 9f fe
129 5e 65 {tower = 47} c6 7f f2 c4
130 44 {hurl = tower - 14} b5 {tower = hurl} 26 2d
133 The value of a variable assignment is the evaluation of a valid {py3}
134 expression which may include label and variable names.
136 Fixed-length integer with a given length (8{nbsp}bits to 64{nbsp}bits) and byte order::
142 {be} 67 <lbl> 44 $178 {(end - lbl) * 8 + strength : 16} $99 <end>
149 67 44 b2 00 2c 63 37 f8 ff ff
152 The encoded integer is the evaluation of a valid {py3} expression which
153 may include label and variable names.
155 https://en.wikipedia.org/wiki/LEB128[LEB128] integer::
160 aa bb cc {-1993 : sleb128} <meow> dd ee ff
161 {meow * 199 : uleb128}
167 aa bb cc b7 70 dd ee ff e3 07
170 The encoded integer is the evaluation of a valid {py3} expression which
171 may include label and variable names.
178 aa bb * 5 cc <zoom> "yeah\0" * {zoom * 3}
184 aa bb bb bb bb bb cc 79 65 61 68 00 79 65 61 68 ┆ •••••••yeah•yeah
185 00 79 65 61 68 00 79 65 61 68 00 79 65 61 68 00 ┆ •yeah•yeah•yeah•
186 79 65 61 68 00 79 65 61 68 00 79 65 61 68 00 79 ┆ yeah•yeah•yeah•y
187 65 61 68 00 79 65 61 68 00 79 65 61 68 00 79 65 ┆ eah•yeah•yeah•ye
188 61 68 00 79 65 61 68 00 79 65 61 68 00 79 65 61 ┆ ah•yeah•yeah•yea
189 68 00 79 65 61 68 00 79 65 61 68 00 79 65 61 68 ┆ h•yeah•yeah•yeah
190 00 79 65 61 68 00 79 65 61 68 00 79 65 61 68 00 ┆ •yeah•yeah•yeah•
194 Multilevel grouping::
199 ff ((aa bb "zoom" cc) * 5) * 3 $-34 * 4
205 ff aa bb 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa ┆ •••zoom•••zoom••
206 bb 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa bb 7a ┆ •zoom•••zoom•••z
207 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa bb 7a 6f 6f ┆ oom•••zoom•••zoo
208 6d cc aa bb 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc ┆ m•••zoom•••zoom•
209 aa bb 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa bb ┆ ••zoom•••zoom•••
210 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa bb 7a 6f ┆ zoom•••zoom•••zo
211 6f 6d cc aa bb 7a 6f 6f 6d cc de de de de ┆ om•••zoom•••••
214 Precise error reporting::
217 /tmp/meow.normand:10:24 - Expecting a bit (`0` or `1`).
221 /tmp/meow.normand:32:6 - Unexpected character `k`.
225 /tmp/meow.normand:24:19 - Illegal (unknown or unreachable) variable/label name `meow` in expression `(meow - 45) // 8`; the legal names are {`mix`, `zoom`}.
229 /tmp/meow.normand:18:9 - Value 315 is outside the 8-bit range when evaluating expression `end - ICITTE` at byte offset 45.
232 You can use Normand to track data source files in your favorite VCS
233 instead of raw binary files. The binary files that Normand generates can
234 be used to test file format decoding, including malformatted data, for
235 example, as well as for education.
237 See <<learn-normand>> to explore all the Normand features.
241 Normand requires Python ≥ 3.4.
246 $ python3 -m pip install --user normand
250 https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-to-the-user-site[Installing to the User Site]
251 to learn more about a user site installation.
255 Normand has a single module file, `normand.py`, which you can copy as is
256 to your project to use it (both the <<python3-api,`normand.parse()`>>
257 function and the <<command-line-tool,command-line tool>>).
259 `normand.py` has _no external dependencies_, but if you're using
260 Python{nbsp}3.4, you'll need a local copy of the standard `typing`
266 A Normand text input is a sequence of items which represent a sequence
269 [[state]] During the processing of items to data, Normand relies on a
274 |State variable |Description |Initial value: <<python3-api,{py3} API>> |Initial value: <<command-line-tool,CLI>>
276 |[[cur-offset]] Current offset
278 The current offset has an effect on the value of <<label,labels>> and of
279 the special `ICITTE` name in <<fixed-length-integer,fixed-length
280 integer>>, <<leb-128-integer,LEB128 integer>>, and
281 <<variable-assignment,variable assignment>> expression evaluation.
283 Each generated byte increments the current offset.
285 A <<current-offset-setting,current offset setting>> may change the
287 |`init_offset` parameter of the `parse()` function.
290 |[[cur-bo]] Current byte order
292 The current byte order has an effect on the encoding of
293 <<fixed-length-integer,fixed-length integers>>.
295 A <<current-byte-order-setting,current byte order setting>> may change
296 the current byte order.
297 |`init_byte_order` parameter of the `parse()` function.
298 |`--byte-order` option.
301 |Mapping of label names to integral values.
302 |`init_labels` parameter of the `parse()` function.
303 |One or more `--label` options.
305 |<<variable-assignment,Variables>>
306 |Mapping of variable names to integral values.
307 |`init_variables` parameter of the `parse()` function.
308 |One or more `--var` options.
311 The available items are:
313 * A <<byte-constant,constant integer>> representing a single byte.
315 * A <<literal-string,literal string>> representing a sequence of bytes
316 encoding UTF-8, UTF-16, or UTF-32 data.
318 * A <<current-byte-order-setting,current byte order setting>> (big or
321 * A <<fixed-length-integer,fixed-length integer>> using the
322 <<cur-bo,current byte order>> and of which the value is the result of
325 * An <<leb128-integer,LEB128 integer>> of which the value is the result
326 of a {py3} expression.
328 * A <<current-offset-setting,current offset setting>>.
330 * A <<label,label>>, that is, a named constant holding the current
333 This is similar to an assembly label.
335 * A <<variable-assignment,variable assignment>> associating a name to
336 the integral result of an evaluated {py3} expression.
338 * A <<group,group>>, that is, a scoped sequence of items.
340 Moreover, you can <<repetition,repeat>> any item above, except an offset
341 or a label, a given fixed or variable number of times. This is called a
344 A Normand comment may exist:
346 * Between items, possibly within a group.
347 * Between the nibbles of a constant hexadecimal byte.
348 * Between the bits of a constant binary byte.
349 * Between the last item and the ``pass:[*]`` character of a repetition,
350 and between that ``pass:[*]`` character and the following number
353 A comment is anything between two ``pass:[#]`` characters on the same
354 line, or from ``pass:[#]`` until the end of the line. Whitespaces and
355 the following symbol characters are also considered comments where a
359 ! @ / \ ? & : ; . , + [ ] _ = | -
362 The latter serve to improve readability so that you may write, for
363 example, a MAC address or a UUID as is.
365 You can test the examples of this section with the `normand`
366 <<command-line-tool,command-line tool>> as such:
369 $ normand file | hexdump -C
372 where `file` is the name of a file containing the Normand input.
376 A _byte constant_ represents a single byte.
381 Two consecutive hexits.
384 A decimal number after the `$` prefix.
387 Eight bits after the `%` prefix.
407 $192 %1100/0011 $ -77
421 58f64689-6316-4d55-8a1a-04cada366172
422 fe80::6257:18ff:fea3:4229
428 58 f6 46 89 63 16 4d 55 8a 1a 04 ca da 36 61 72 ┆ X•F•c•MU•••••6ar
429 fe 80 62 57 18 ff fe a3 42 29 ┆ ••bW••••B)
437 %01110011 %01100001 %01101100 %01110101 %01110100
443 73 61 6c 75 74 ┆ salut
449 A _literal string_ represents the UTF-8-, UTF-16-, or UTF-32-encoded
452 The string to encode isn't implicitly null-terminated: use `\0` at the
453 end of the string to add a null character.
457 . **Optional**: one of the following encodings instead of UTF-8:
467 . The ``pass:["]`` prefix.
469 . A sequence of zero or more characters, possibly containing escape
472 An escape sequence is the ``\`` character followed by one of:
478 `b`:: Backspace (U+0008)
479 `e`:: Escape (U+001B)
480 `f`:: Form feed (U+000C)
481 `n`:: End of line (U+000A)
482 `r`:: Carriage return (U+000D)
483 `t`:: Character tabulation (U+0009)
484 `v`:: Line tabulation (U+000B)
485 ``\``:: Reverse solidus (U+005C)
486 ``pass:["]``:: Quotation mark (U+0022)
489 . The ``pass:["]`` suffix.
495 "coucou tout le monde!"
501 63 6f 75 63 6f 75 20 74 6f 75 74 20 6c 65 20 6d ┆ coucou tout le m
502 6f 6e 64 65 21 ┆ onde!
510 u16le"I am not young enough to know everything."
516 49 00 20 00 61 00 6d 00 20 00 6e 00 6f 00 74 00 ┆ I• •a•m• •n•o•t•
517 20 00 79 00 6f 00 75 00 6e 00 67 00 20 00 65 00 ┆ •y•o•u•n•g• •e•
518 6e 00 6f 00 75 00 67 00 68 00 20 00 74 00 6f 00 ┆ n•o•u•g•h• •t•o•
519 20 00 6b 00 6e 00 6f 00 77 00 20 00 65 00 76 00 ┆ •k•n•o•w• •e•v•
520 65 00 72 00 79 00 74 00 68 00 69 00 6e 00 67 00 ┆ e•r•y•t•h•i•n•g•
529 u32be "\"illusion is the first\nof all pleasures\" 🦉"
535 00 00 00 22 00 00 00 69 00 00 00 6c 00 00 00 6c ┆ •••"•••i•••l•••l
536 00 00 00 75 00 00 00 73 00 00 00 69 00 00 00 6f ┆ •••u•••s•••i•••o
537 00 00 00 6e 00 00 00 20 00 00 00 69 00 00 00 73 ┆ •••n••• •••i•••s
538 00 00 00 20 00 00 00 74 00 00 00 68 00 00 00 65 ┆ ••• •••t•••h•••e
539 00 00 00 20 00 00 00 66 00 00 00 69 00 00 00 72 ┆ ••• •••f•••i•••r
540 00 00 00 73 00 00 00 74 00 00 00 0a 00 00 00 6f ┆ •••s•••t•••••••o
541 00 00 00 66 00 00 00 20 00 00 00 61 00 00 00 6c ┆ •••f••• •••a•••l
542 00 00 00 6c 00 00 00 20 00 00 00 70 00 00 00 6c ┆ •••l••• •••p•••l
543 00 00 00 65 00 00 00 61 00 00 00 73 00 00 00 75 ┆ •••e•••a•••s•••u
544 00 00 00 72 00 00 00 65 00 00 00 73 00 00 00 22 ┆ •••r•••e•••s•••"
545 00 00 00 20 00 01 f9 89 ┆ ••• ••••
549 === Current byte order setting
551 This special item sets the <<cur-bo,_current byte order_>>.
553 The two accepted forms are:
556 ``pass:[{be}]``:: Set the current byte order to big endian.
557 ``pass:[{le}]``:: Set the current byte order to little endian.
559 === Fixed-length integer
561 A _fixed-length integer_ represents a fixed number of bytes encoding an
562 unsigned or signed integer which is the result of evaluating a {py3}
563 expression using the <<cur-bo,current byte order>>.
565 A fixed-length integer is:
567 . The ``pass:[{]`` prefix.
569 . A valid {py3} expression.
571 For a fixed-length integer at some source location{nbsp}__**L**__, this
572 expression may contain the name of any accessible <<label,label>> (not
573 within a nested group), including the name of a label defined
574 after{nbsp}__**L**__, as well as the name of any
575 <<variable-assignment,variable>> known at{nbsp}__**L**__.
577 The value of the special name `ICITTE` in this expression is the
578 <<cur-offset,current offset>> (before encoding the integer).
582 . An encoding length in bits amongst `8`, `16`, `24`, `32`, `40`,
583 `48`, `56`, and `64`.
608 # String length in bits
609 {8 * (str_end - str_beg) : 16}
620 00 60 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 ┆ •`hello world!
628 {20 - ICITTE : 8} * 10
634 14 13 12 11 10 0f 0e 0d 0c 0b
640 An _LEB128 integer_ represents a variable number of bytes encoding an
641 unsigned or signed integer which is the result of evaluating a {py3}
642 expression following the https://en.wikipedia.org/wiki/LEB128[LEB128]
645 An LEB128 integer is:
647 . The ``pass:[{]`` prefix.
649 . A valid {py3} expression.
651 For an LEB128 integer at some source location{nbsp}__**L**__, this
652 expression may contain:
655 * The name of any <<label,label>> defined before{nbsp}__**L**__.
656 * The name of any <<variable-assignment,variable>> known at{nbsp}__**L**__
657 which doesn't, directly or indirectly, refer to a label
658 defined after{nbsp}__**L**__.
661 The value of the special name `ICITTE` in this expression is the
662 <<cur-offset,current offset>> (before encoding the integer).
670 `uleb128`:: Use the unsigned LEB128 format.
671 `sleb128`:: Use the signed LEB128 format.
697 {-981238311 + (meow * -23) : sleb128}
704 aa bb cc dd ee ff fd fa 8d ac 7c 68 65 6c 6c 6f ┆ ••••••••••|hello
708 === Current offset setting
710 This special item sets the <<cur-offset,_current offset_>>.
712 A current offset setting is:
716 . A positive integer (hexadecimal starting with `0x` or `0X` accepted)
717 which is the new current offset.
726 <0x61> {ICITTE : 8} * 8
732 00 01 02 03 04 05 06 07 61 62 63 64 65 66 67 68 ┆ ••••••••abcdefgh
740 aa bb cc dd <meow> ee ff
741 <12> 11 22 33 <mix> 44 55
748 aa bb cc dd ee ff 11 22 33 44 55 04 0f ┆ •••••••"3DU••
754 A _label_ associates a name to the <<cur-offset,current offset>>.
756 All the labels of a whole Normand input must have unique names.
758 A label must not share the name of a <<variable-assignment,variable>>
765 . A valid {py3} name which is not `ICITTE` (see
766 <<fixed-length-integer>>, <<leb128-integer>>, and
767 <<variable-assignment>> to learn more).
771 === Variable assignment
773 A _variable assignment_ associates a name to the integral result of an
774 evaluated {py3} expression.
776 A variable assignment is:
778 . The ``pass:[{]`` prefix.
780 . A valid {py3} name which is not `ICITTE` (see
781 <<fixed-length-integer>>, <<leb128-integer>>, and
782 <<variable-assignment>> to learn more).
786 . A valid {py3} expression.
788 For a variable assignment at some source location{nbsp}__**L**__, this
789 expression may contain the name of any accessible <<label,label>> (not
790 within a nested group), including the name of a label defined
791 after{nbsp}__**L**__, as well as the name of any
792 <<variable-assignment,variable>> known at{nbsp}__**L**__.
794 The value of the special name `ICITTE` in this expression is the
795 <<cur-offset,current offset>>.
804 {meow = 42} 11 22 {meow:8} 33 {meow = ICITTE + 17}
805 "yooo" {meow + mix : 16}
811 11 22 2a 33 79 6f 6f 6f 7a 00 ┆ •"*3yoooz•
817 A _group_ is a scoped sequence of items.
819 The <<label,labels>> within a group aren't visible outside of it.
821 The main purpose of a group is to <<repetition,repeat>> more than a
828 . Zero or more items.
836 ((aa bb cc) dd () ee) "leclerc"
842 aa bb cc dd ee 6c 65 63 6c 65 72 63 ┆ •••••leclerc
850 ((aa bb cc) * 3 dd ee) * 5
856 aa bb cc aa bb cc aa bb cc dd ee aa bb cc aa bb
857 cc aa bb cc dd ee aa bb cc aa bb cc aa bb cc dd
858 ee aa bb cc aa bb cc aa bb cc dd ee aa bb cc aa
869 <str_beg> u16le"sébastien diaz" <str_end>
870 {ICITTE - str_beg : 8}
871 {(end - str_beg) * 5 : 24}
879 73 00 e9 00 62 00 61 00 73 00 74 00 69 00 65 00 ┆ s•••b•a•s•t•i•e•
880 6e 00 20 00 64 00 69 00 61 00 7a 00 1c 00 01 e0 ┆ n• •d•i•a•z•••••
881 73 00 e9 00 62 00 61 00 73 00 74 00 69 00 65 00 ┆ s•••b•a•s•t•i•e•
882 6e 00 20 00 64 00 69 00 61 00 7a 00 1c 00 01 40 ┆ n• •d•i•a•z••••@
883 73 00 e9 00 62 00 61 00 73 00 74 00 69 00 65 00 ┆ s•••b•a•s•t•i•e•
884 6e 00 20 00 64 00 69 00 61 00 7a 00 1c 00 00 a0 ┆ n• •d•i•a•z•••••
890 A _repetition_ represents the bytes of an item repeated a given number
897 . The ``pass:[*]`` character.
901 ** A positive integer (hexadecimal starting with `0x` or `0X` accepted)
902 which is the number of times to repeat the previous item.
904 ** The ``pass:[{]`` prefix, a valid {py3} expression, and the
907 For a repetition at some source location{nbsp}__**L**__, this expression
911 * The name of any <<label,label>> defined before{nbsp}__**L**__ and
912 which isn't part of its repeated item.
913 * The name of any <<variable-assignment,variable>> known
914 at{nbsp}__**L**__, which isn't part of its repeated item, and which
915 doesn't, directly or indirectly, refer to a label defined
916 after{nbsp}__**L**__.
919 This expression must not contain the special name `ICITTE`.
925 {end - ICITTE - 1 : 8} * 0x100 <end>
931 ff fe fd fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ┆ ••••••••••••••••
932 ef ee ed ec eb ea e9 e8 e7 e6 e5 e4 e3 e2 e1 e0 ┆ ••••••••••••••••
933 df de dd dc db da d9 d8 d7 d6 d5 d4 d3 d2 d1 d0 ┆ ••••••••••••••••
934 cf ce cd cc cb ca c9 c8 c7 c6 c5 c4 c3 c2 c1 c0 ┆ ••••••••••••••••
935 bf be bd bc bb ba b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 ┆ ••••••••••••••••
936 af ae ad ac ab aa a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 ┆ ••••••••••••••••
937 9f 9e 9d 9c 9b 9a 99 98 97 96 95 94 93 92 91 90 ┆ ••••••••••••••••
938 8f 8e 8d 8c 8b 8a 89 88 87 86 85 84 83 82 81 80 ┆ ••••••••••••••••
939 7f 7e 7d 7c 7b 7a 79 78 77 76 75 74 73 72 71 70 ┆ •~}|{zyxwvutsrqp
940 6f 6e 6d 6c 6b 6a 69 68 67 66 65 64 63 62 61 60 ┆ onmlkjihgfedcba`
941 5f 5e 5d 5c 5b 5a 59 58 57 56 55 54 53 52 51 50 ┆ _^]\[ZYXWVUTSRQP
942 4f 4e 4d 4c 4b 4a 49 48 47 46 45 44 43 42 41 40 ┆ ONMLKJIHGFEDCBA@
943 3f 3e 3d 3c 3b 3a 39 38 37 36 35 34 33 32 31 30 ┆ ?>=<;:9876543210
944 2f 2e 2d 2c 2b 2a 29 28 27 26 25 24 23 22 21 20 ┆ /.-,+*)('&%$#"!
945 1f 1e 1d 1c 1b 1a 19 18 17 16 15 14 13 12 11 10 ┆ ••••••••••••••••
946 0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 ┆ ••••••••••••••••
968 aa bb cc dd ee ff ee ff ee ff ee ff ee ff 11 22 ┆ •••••••••••••••"
969 33 ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee ┆ 3•••••••••••••••
970 ff ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee ┆ ••••••••••••••••
971 ff ee ff ee ff 11 22 33 33 ee ff ee ff ee ff ee ┆ ••••••"33•••••••
972 ff ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee ┆ ••••••••••••••••
973 ff ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee ┆ ••••••••••••••••
974 ff ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee ┆ ••••••••••••••••
975 ff ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee ┆ ••••••••••••••••
976 ff ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee ┆ ••••••••••••••••
977 ff ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee ┆ ••••••••••••••••
978 ff ee ff ee ff ee ff ee ff ee ff ee ff 11 22 33 ┆ ••••••••••••••"3
979 33 33 63 6f 75 63 6f 75 21 ┆ 33coucou!
984 This example shows how to use a repetition as a conditional section
985 depending on some predefined variable.
991 (ee ff "meow mix" 00) * {cond}
995 Output (`cond` is 0):
1001 Output (`cond` is 1):
1004 aa bb cc dd ee ff 6d 65 6f 77 20 6d 69 78 00 f8 ┆ ••••••meow mix••
1009 == Command-line tool
1011 If you <<install-normand,installed>> the `normand` package, then you
1012 can use the `normand` command-line tool:
1015 $ normand <<< '"ma gang de malades"' | hexdump -C
1019 00000000 6d 61 20 67 61 6e 67 20 64 65 20 6d 61 6c 61 64 |ma gang de malad|
1023 If you copy the `normand.py` module to your own project, then you can
1024 run the module itself:
1027 $ python3 -m normand <<< '"ma gang de malades"' | hexdump -C
1031 00000000 6d 61 20 67 61 6e 67 20 64 65 20 6d 61 6c 61 64 |ma gang de malad|
1035 Without a path argument, the `normand` tool reads from the standard
1038 The `normand` tool prints the generated binary data to the standard
1041 Various options control the initial <<state,state>> of the processor:
1042 use the `--help` option to learn more.
1046 The whole `normand` package/module API is:
1050 class ByteOrder(enum.Enum):
1061 def line_no(self) -> int:
1066 def col_no(self) -> int:
1070 class ParseError(RuntimeError):
1071 # Source text location.
1073 def text_loc(self) -> TextLoc:
1077 SymbolsT = typing.Dict[str, int]
1083 def data(self) -> bytearray:
1086 # Updated variable values.
1088 def variables(self) -> SymbolsT:
1091 # Updated main group label values.
1093 def labels(self) -> SymbolsT:
1098 def offset(self) -> int:
1103 def byte_order(self) -> typing.Optional[ByteOrder]:
1107 def parse(normand: str,
1108 init_variables: typing.Optional[SymbolsT] = None,
1109 init_labels: typing.Optional[SymbolsT] = None,
1110 init_offset: int = 0,
1111 init_byte_order: typing.Optional[ByteOrder] = None) -> ParseResult:
1115 The `normand` parameter is the actual <<learn-normand,Normand input>>
1116 while the other parameters control the initial <<state,state>>.
1118 The `parse()` function raises a `ParseError` instance should it fail to
1119 parse the `normand` string for any reason.
1123 Normand is a https://python-poetry.org/[Poetry] project.
1125 To develop it, install it through Poetry and enter the virtual
1131 $ normand <<< '"lol" * 10 0a'
1134 `normand.py` is processed by:
1136 * https://microsoft.github.io/pyright/[Pyright]
1137 * https://github.com/psf/black[Black]
1138 * https://pycqa.github.io/isort/[isort]
1142 Use https://docs.pytest.org/[pytest] to test Normand once the package is
1143 part of your virtual environment, for example:
1147 $ poetry run pip3 install pytest
1151 The `pytest` project is currently not a development dependency in
1152 `pyproject.toml` due to backward compatibiliy issues with
1155 In the `tests` directory, each `*.nt` file is a test. The file name
1156 prefix indicates what it's meant to test:
1159 Everything above the `---` line is the valid Normand input
1162 Everything below the `---` line is the expected data
1163 (whitespace-separated hexadecimal bytes).
1166 Everything above the `---` line is the invalid Normand input
1169 Everything below the `---` line is the expected error message having
1178 Normand uses https://review.lttng.org/admin/repos/normand,general[Gerrit]
1181 To report a bug, https://github.com/efficios/normand/issues/new[create a