The earliest commit (also Normand 0.1.0)
[normand.git] / README.adoc
CommitLineData
71aaa3f7
PP
1= Normand
2Philippe Proulx
3:toc: left
4
5:py3: Python{nbsp}3
6
7[.normal]
8image:https://img.shields.io/pypi/v/normand.svg?label=Latest%20version[link="https://pypi.python.org/pypi/normand"]
9
10[.lead]
11_**Normand**_ is a text-to-binary processor with its own language.
12
13This package offers both a portable {py3} module and a command-line
14tool.
15
16WARNING: This version of Normand is 0.1, meaning both the Normand
17language and the module/CLI interface aren't stable.
18
19== Introduction
20
21The purpose of Normand is to consume human-readable text representing
22bytes and to produce the corresponding binary data.
23
24.Simple bytes input.
25====
26Consider the following Normand input:
27
28----
294f 55 32 bb $167 fe %10100111 a9 $-32
30----
31
32The generated nine bytes are:
33
34----
354f 55 32 bb a7 fe a7 a9 e0
36----
37====
38
39As you can see in the last example, the fundamental unit of the Normand
40language is the _byte_. The order in which you list bytes will be the
41order of the generated data.
42
43The Normand language is more than simple lists of bytes, though. Its
44main features are:
45
46Comments, including a bunch of insignificant symbols which may improve readability::
47+
48Input:
49+
50----
51ff bb %1101:0010 # This is a comment
5278 29 af $192 # This too # 99 $-80
53fe80::6257:18ff:fea3:4229
5460:57:18:a3:42:29
5510839636-5d65-4a68-8e6a-21608ddf7258
56----
57+
58Output:
59+
60----
61ff bb d2 78 29 af c0 99 b0 fe 80 62 57 18 ff fe
62a3 42 29 60 57 18 a3 42 29 10 83 96 36 5d 65 4a
6368 8e 6a 21 60 8d df 72 58
64----
65
66Hexadecimal, decimal, and binary byte constants::
67+
68Input:
69+
70----
71aa bb $247 $-89 %0011_0010 %11.01= 10/10
72----
73+
74Output:
75+
76----
77aa bb f7 a7 32 da
78----
79
80UTF-8, UTF-16, and UTF-32 literal strings::
81+
82Input:
83+
84----
85"hello world!" 00
86u16le"stress\nverdict 🤣"
87----
88+
89Output:
90+
91----
9268 65 6c 6c 6f 20 77 6f 72 6c 64 21 00 73 00 74 ┆ hello world!•s•t
9300 72 00 65 00 73 00 73 00 0a 00 76 00 65 00 72 ┆ •r•e•s•s•••v•e•r
9400 64 00 69 00 63 00 74 00 20 00 3e d8 23 dd ┆ •d•i•c•t• •>•#•
95----
96
97Labels: special variables holding the offset where they're defined::
98+
99----
100<beg> b2 52 e3 bc 91 05
101$100 $50 <chair> 33 9f fe
10225 e9 89 8a <end>
103----
104
105Variables::
106+
107----
1085e 65 {tower = 47} c6 7f f2 c4
10944 {hurl = tower - 14} b5 {tower = hurl} 26 2d
110----
111+
112The value of a variable assignment is the evaluation of a valid {py3}
113expression which may include label and variable names.
114
115Value encoding with a specific length (8{nbsp}bits to 64{nbsp}bits) and byte order::
116+
117Input:
118+
119----
120{strength = 4}
121{be} 67 <lbl> 44 $178 {(end - lbl) * 8 + strength : 16} $99 <end>
122{le} {-1993 : 32}
123----
124+
125Output:
126+
127----
12867 44 b2 00 2c 63 37 f8 ff ff
129----
130+
131The encoded value is the evaluation of a valid {py3} expression which
132may include label and variable names.
133
134Repetition::
135+
136Input:
137+
138----
139aa bb * 5 cc "yeah\0" * 8
140----
141+
142Output:
143+
144----
145aa bb bb bb bb bb cc 79 65 61 68 00 79 65 61 68 ┆ •••••••yeah.yeah
14600 79 65 61 68 00 79 65 61 68 00 79 65 61 68 00 ┆ •yeah•yeah•yeah•
14779 65 61 68 00 79 65 61 68 00 79 65 61 68 00 ┆ yeah•yeah•yeah•
148----
149
150
151Multilevel grouping::
152+
153Input:
154+
155----
156ff ((aa bb "zoom" cc) * 5) * 3 $-34 * 4
157----
158+
159Output:
160+
161----
162ff aa bb 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa ┆ •••zoom•••zoom••
163bb 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa bb 7a ┆ •zoom•••zoom•••z
1646f 6f 6d cc aa bb 7a 6f 6f 6d cc aa bb 7a 6f 6f ┆ oom•••zoom•••zoo
1656d cc aa bb 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc ┆ m•••zoom•••zoom•
166aa bb 7a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa bb ┆ ••zoom•••zoom•••
1677a 6f 6f 6d cc aa bb 7a 6f 6f 6d cc aa bb 7a 6f ┆ zoom•••zoom•••zo
1686f 6d cc aa bb 7a 6f 6f 6d cc de de de de ┆ om•••zoom•••••
169----
170
171Precise error reporting::
172+
173----
174/tmp/meow.normand:10:24 - Expecting a bit (`0` or `1`).
175----
176+
177----
178/tmp/meow.normand:32:6 - Unexpected character `k`.
179----
180+
181----
182/tmp/meow.normand:24:19 - Unknown variable/label name `meow` in expression `(meow - 45) // 8`.
183----
184+
185----
186/tmp/meow.normand:18:9 - Value 315 is outside the 8-bit range when evaluating expression `end - ICITTE` at byte offset 45.
187----
188
189You can use Normand to track data source files in your favorite VCS
190instead of raw binary files. The binary files that Normand generates can
191be used to test file format decoding, including malformatted data, for
192example, as well as for education.
193
194See <<learn-normand>> to explore all the Normand features.
195
196== Install Normand
197
198Normand requires Python ≥ 3.4.
199
200To install Normand:
201
202----
203$ python3 -m pip install --user normand
204----
205
206See
207https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-to-the-user-site[Installing to the User Site]
208to learn more about a user site installation.
209
210[NOTE]
211====
212Normand has a single module file, `normand.py`, which you can copy as is
213to your project to use it (both the <<python-3-api,`normand.parse()`>>
214function and the <<command-line-tool,command-line tool>>).
215
216`normand.py` has _no external dependencies_, but if you're using
217Python{nbsp}3.4, you'll need a local copy of the standard `typing`
218module.
219====
220
221== Learn Normand
222
223A Normand text input is a sequence of items which represent a sequence
224of raw bytes.
225
226[[state]] During the processing of items to data, Normand relies on a
227current state:
228
229[%header%autowidth]
230|===
231|State variable |Description |Initial value: <<python-3-api,{py3} API>> |Initial value: <<command-line-tool,CLI>>
232
233|[[cur-offset]] Current offset
234|
235The current offset has an effect on the value of
236<<label,labels>> and of the special `ICITTE` name in <<value,value>> and
237<<variable-assignment,variable assignment>> expression evaluation.
238
239Each generated byte increments the current offset.
240
241A <<current-offset-setting,current offset setting>> may change the
242current offset.
243|`init_offset` parameter of the `parse()` function.
244|`--offset` option.
245
246|[[cur-bo]] Current byte order
247|
248The current byte order has an effect on the encoding of <<value,values>>.
249
250A <<current-byte-order-setting,current byte order setting>> may change
251the current byte order.
252|`init_byte_order` parameter of the `parse()` function.
253|`--byte-order` option.
254
255|<<label,Labels>>
256|Mapping of label names to integral values.
257|`init_labels` parameter of the `parse()` function.
258|One or more `--label` options.
259
260|<<variable-assignment,Variables>>
261|Mapping of variable names to integral values.
262|`init_variables` parameter of the `parse()` function.
263|One or more `--var` options.
264|===
265
266The available items are:
267
268* A <<byte-constant,constant integer>> representing a single byte.
269
270* A <<literal-string,literal string>> representing a sequence of bytes
271 encoding UTF-8, UTF-16, or UTF-32 data.
272
273* A <<current-byte-order-setting,current byte order setting>> (big or
274 little endian).
275
276* A <<value,{py3} expression to be evaluated>> as an unsigned or signed
277 integer to be encoded on one or more bytes using the current byte
278 order.
279
280* A <<current-offset-setting,current offset setting>>.
281
282* A <<label,label>>, that is, a named constant holding the current
283 offset.
284+
285This is similar to an assembly label.
286
287* A <<variable-assignment,variable assignment>> associating a name to
288 the integral result of an evaluated {py3} expression.
289
290* A <<group,group>>, that is, a scoped sequence of items.
291
292Moreover, you can <<repetition,repeat>> any item above, except an offset
293or a label, a given number of times. This is called a repetition.
294
295A Normand comment may exist:
296
297* Between items, possibly within a group.
298* Between the nibbles of a constant hexadecimal byte.
299* Between the bits of a constant binary byte.
300* Between the last item and the ``pass:[*]`` character of a repetition,
301 and between that ``pass:[*]`` character and the following number.
302
303A comment is anything between two ``pass:[#]`` characters on the same
304line, or from ``pass:[#]`` until the end of the line. Whitespaces and
305the following symbol characters are also considered comments where a
306comment may exist:
307
308----
309! @ / \ ? & : ; . , + [ ] _ = | -
310----
311
312The latter serve to improve readability so that you may write, for
313example, a MAC address or a UUID as is.
314
315You can test the examples of this section with the `normand`
316<<command-line-tool,command-line tool>> as such:
317
318----
319$ normand file | hexdump -C
320----
321
322where `file` is the name of a file containing the Normand input.
323
324=== Byte constant
325
326A _byte constant_ represents a single byte.
327
328A byte constant is:
329
330Hexadecimal form::
331 Two consecutive hexits.
332
333Decimal form::
334 A decimal number after the `$` prefix.
335
336Binary form::
337 Eight bits after the `%` prefix.
338
339====
340Input:
341
342----
343ab cd [3d 8F] CC
344----
345
346Output:
347
348----
349ab cd 3d 8f cc
350----
351====
352
353====
354Input:
355
356----
357$192 %1100/0011 $ -77
358----
359
360Output:
361
362----
363c0 c3 b3
364----
365====
366
367====
368Input:
369
370----
37158f64689-6316-4d55-8a1a-04cada366172
372fe80::6257:18ff:fea3:4229
373----
374
375Output:
376
377----
37858 f6 46 89 63 16 4d 55 8a 1a 04 ca da 36 61 72 ┆ X•F•c•MU•••••6ar
379fe 80 62 57 18 ff fe a3 42 29 ┆ ••bW••••B)
380----
381====
382
383====
384Input:
385
386----
387%01110011 %01100001 %01101100 %01110101 %01110100
388----
389
390Output:
391
392----
39373 61 6c 75 74 ┆ salut
394----
395====
396
397=== Literal string
398
399A _literal string_ represents the UTF-8-, UTF-16-, or UTF-32-encoded
400bytes of a string.
401
402The string to encode isn't implicitly null-terminated: use `\0` at the
403end of the string to add a null character.
404
405A literal string is:
406
407. **Optional**: one of the following encodings instead of UTF-8:
408+
409--
410[horizontal]
411`u16be`:: UTF-16BE.
412`u16le`:: UTF-16LE.
413`u32be`:: UTF-32BE.
414`u32le`:: UTF-32LE.
415--
416
417. The ``pass:["]`` prefix.
418
419. A sequence of zero or more characters, possibly containing escape
420 sequences.
421+
422An escape sequence is the ``\`` character followed by one of:
423+
424--
425[horizontal]
426`0`:: Null (U+0000)
427`a`:: Alert (U+0007)
428`b`:: Backspace (U+0008)
429`e`:: Escape (U+001B)
430`f`:: Form feed (U+000C)
431`n`:: End of line (U+000A)
432`r`:: Carriage return (U+000D)
433`t`:: Character tabulation (U+0009)
434`v`:: Line tabulation (U+000B)
435``\``:: Reverse solidus (U+005C)
436``pass:["]``:: Quotation mark (U+0022)
437--
438
439. The ``pass:["]`` suffix.
440
441====
442Input:
443
444----
445"coucou tout le monde!"
446----
447
448Output:
449
450----
45163 6f 75 63 6f 75 20 74 6f 75 74 20 6c 65 20 6d ┆ coucou tout le m
4526f 6e 64 65 21 ┆ onde!
453----
454====
455
456====
457Input:
458
459----
460u16le"I am not young enough to know everything."
461----
462
463Output:
464
465----
46649 00 20 00 61 00 6d 00 20 00 6e 00 6f 00 74 00 ┆ I• •a•m• •n•o•t•
46720 00 79 00 6f 00 75 00 6e 00 67 00 20 00 65 00 ┆ •y•o•u•n•g• •e•
4686e 00 6f 00 75 00 67 00 68 00 20 00 74 00 6f 00 ┆ n•o•u•g•h• •t•o•
46920 00 6b 00 6e 00 6f 00 77 00 20 00 65 00 76 00 ┆ •k•n•o•w• •e•v•
47065 00 72 00 79 00 74 00 68 00 69 00 6e 00 67 00 ┆ e•r•y•t•h•i•n•g•
4712e 00 ┆ .•
472----
473====
474
475====
476Input:
477
478----
479u32be "\"illusion is the first\nof all pleasures\" 🦉"
480----
481
482Output:
483
484----
48500 00 00 22 00 00 00 69 00 00 00 6c 00 00 00 6c ┆ •••"•••i•••l•••l
48600 00 00 75 00 00 00 73 00 00 00 69 00 00 00 6f ┆ •••u•••s•••i•••o
48700 00 00 6e 00 00 00 20 00 00 00 69 00 00 00 73 ┆ •••n••• •••i•••s
48800 00 00 20 00 00 00 74 00 00 00 68 00 00 00 65 ┆ ••• •••t•••h•••e
48900 00 00 20 00 00 00 66 00 00 00 69 00 00 00 72 ┆ ••• •••f•••i•••r
49000 00 00 73 00 00 00 74 00 00 00 0a 00 00 00 6f ┆ •••s•••t•••••••o
49100 00 00 66 00 00 00 20 00 00 00 61 00 00 00 6c ┆ •••f••• •••a•••l
49200 00 00 6c 00 00 00 20 00 00 00 70 00 00 00 6c ┆ •••l••• •••p•••l
49300 00 00 65 00 00 00 61 00 00 00 73 00 00 00 75 ┆ •••e•••a•••s•••u
49400 00 00 72 00 00 00 65 00 00 00 73 00 00 00 22 ┆ •••r•••e•••s•••"
49500 00 00 20 00 01 f9 89 ┆ ••• ••••
496----
497====
498
499=== Current byte order setting
500
501This special item sets the <<cur-bo,_current byte order_>>.
502
503The two accepted forms are:
504
505[horizontal]
506``pass:[{be}]``:: Set the current byte order to big endian.
507``pass:[{le}]``:: Set the current byte order to little endian.
508
509=== Value
510
511A _value_ represents a fixed number of bytes encoding an unsigned or
512signed integer which is the result of evaluating a {py3} expression
513using the <<cur-bo,current byte order>>.
514
515For a value at some source location{nbsp}__**L**__, its {py3} expression
516may contain the name of any accessible <<label,label>>, including the
517name of a label defined after{nbsp}__**L**__, as well as the name of any
518<<variable-assignment,variable>> known at{nbsp}__**L**__.
519
520An accessible label is either:
521
522* Outside of the current <<group,group>>.
523* Within the same immediate group (not within a nested group).
524
525In the {py3} expression of a value, the value of the special name
526`ICITTE` is the <<cur-offset,current offset>> (before encoding the
527value).
528
529A value is:
530
531. The ``pass:[{]`` prefix.
532
533. A valid {py3} expression.
534
535. The `:` character.
536
537. An encoding length in bits amongst `8`, `16`, `24`, `32`, `40`,
538 `48`, `56`, and `64`.
539
540. The `}` suffix.
541
542====
543Input:
544
545----
546{le} {345:16}
547{be} {-0xabcd:32}
548----
549
550Output:
551
552----
55359 01 ff ff 54 33
554----
555====
556
557====
558Input:
559
560----
561{be}
562
563# String length in bits
564{8 * (str_end - str_beg) : 16}
565
566# String
567<str_beg>
568 "hello world!"
569<str_end>
570----
571
572Output:
573
574----
57500 60 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 ┆ •`hello world!
576----
577====
578
579====
580Input:
581
582----
583{20 - ICITTE : 8} * 10
584----
585
586Output:
587
588----
58914 13 12 11 10 0f 0e 0d 0c 0b
590----
591====
592
593=== Current offset setting
594
595This special item sets the <<cur-offset,_current offset_>>.
596
597A current offset setting is:
598
599. The `<` prefix.
600
601. A positive integer (hexadecimal starting with `0x` or `0X` accepted)
602 which is the new current offset.
603
604. The `>` suffix.
605
606====
607Input:
608
609----
610 {ICITTE : 8} * 8
611<0x61> {ICITTE : 8} * 8
612----
613
614Output:
615
616----
61700 01 02 03 04 05 06 07 61 62 63 64 65 66 67 68 ┆ ••••••••abcdefgh
618----
619====
620
621====
622Input:
623
624----
625aa bb cc dd <meow> ee ff
626<12> 11 22 33 <mix> 44 55
627{meow : 8} {mix : 8}
628----
629
630Output:
631
632----
633aa bb cc dd ee ff 11 22 33 44 55 04 0f ┆ •••••••"3DU••
634----
635====
636
637=== Label
638
639A _label_ associates a name to the <<cur-offset,current offset>>.
640
641All the labels of a whole Normand input must have unique names.
642
643A label may not share the name of a <<variable-assignment,variable>>
644name.
645
646A label name may not be `ICITTE` (see <<value>> and
647<<variable-assignment>> to learn more).
648
649A label is:
650
651. The `<` prefix.
652
653. A valid {py3} name which is not `ICITTE`.
654
655. The `>` suffix.
656
657=== Variable assignment
658
659A _variable assignment_ associates a name to the integral result of an
660evaluated {py3} expression.
661
662For a variable assignment at some source location{nbsp}__**L**__, its
663{py3} expression may contain the name of any accessible <<label,label>>,
664including the name of a label defined after{nbsp}__**L**__, as well as
665the name of any variable known at{nbsp}__**L**__.
666
667An accessible label is either:
668
669* Outside of the current <<group,group>>.
670* Within the same immediate group (not within a nested group).
671
672A variable name may not be `ICITTE` (see <<value>> and
673<<variable-assignment>> to learn more).
674
675In the {py3} expression of a variable assignment, the special name
676`ICITTE` is the <<cur-offset,current offset>>.
677
678A variable is:
679
680. The ``pass:[{]`` prefix.
681
682. A valid {py3} name which is not `ICITTE`.
683
684. The `=` character.
685
686. A valid {py3} expression.
687
688. The `}` suffix.
689
690====
691Input:
692
693----
694{mix = 101} {le}
695{meow = 42} 11 22 {meow:8} 33 {meow = ICITTE + 17}
696"yooo" {meow + mix : 16}
697----
698
699Output:
700
701----
70211 22 2a 33 79 6f 6f 6f 7a 00 ┆ •"*3yoooz•
703----
704====
705
706=== Group
707
708A _group_ is a scoped sequence of items.
709
710The <<label,labels>> within a group aren't visible outside of it.
711
712The main purpose of a group is to <<repetition,repeat>> more than a
713single item.
714
715A group is:
716
717. The `(` prefix.
718
719. Zero or more items.
720
721. The `)` suffix.
722
723====
724Input:
725
726----
727((aa bb cc) dd () ee) "leclerc"
728----
729
730Output:
731
732----
733aa bb cc dd ee 6c 65 63 6c 65 72 63 ┆ •••••leclerc
734----
735====
736
737====
738Input:
739
740----
741((aa bb cc) * 3 dd ee) * 5
742----
743
744Output:
745
746----
747aa bb cc aa bb cc aa bb cc dd ee aa bb cc aa bb
748cc aa bb cc dd ee aa bb cc aa bb cc aa bb cc dd
749ee aa bb cc aa bb cc aa bb cc dd ee aa bb cc aa
750bb cc aa bb cc dd ee
751----
752====
753
754====
755Input:
756
757----
758{be}
759(
760 <str_beg> u16le"sébastien diaz" <str_end>
761 {ICITTE - str_beg : 8}
762 {(end - str_beg) * 5 : 24}
763) * 3
764<end>
765----
766
767Output:
768
769----
77073 00 e9 00 62 00 61 00 73 00 74 00 69 00 65 00 ┆ s•••b•a•s•t•i•e•
7716e 00 20 00 64 00 69 00 61 00 7a 00 1c 00 01 e0 ┆ n• •d•i•a•z•••••
77273 00 e9 00 62 00 61 00 73 00 74 00 69 00 65 00 ┆ s•••b•a•s•t•i•e•
7736e 00 20 00 64 00 69 00 61 00 7a 00 1c 00 01 40 ┆ n• •d•i•a•z••••@
77473 00 e9 00 62 00 61 00 73 00 74 00 69 00 65 00 ┆ s•••b•a•s•t•i•e•
7756e 00 20 00 64 00 69 00 61 00 7a 00 1c 00 00 a0 ┆ n• •d•i•a•z•••••
776----
777====
778
779=== Repetition
780
781A _repetition_ represents the bytes of an item repeated a given number
782of times.
783
784A repetition is:
785
786. Any item.
787
788. The ``pass:[*]`` character.
789
790. A positive integer (hexadecimal starting with `0x` or `0X` accepted)
791 which is the number of times to repeat the previous item.
792
793====
794Input:
795
796----
797{end - ICITTE - 1 : 8} * 0x100 <end>
798----
799
800Output:
801
802----
803ff fe fd fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ┆ ••••••••••••••••
804ef ee ed ec eb ea e9 e8 e7 e6 e5 e4 e3 e2 e1 e0 ┆ ••••••••••••••••
805df de dd dc db da d9 d8 d7 d6 d5 d4 d3 d2 d1 d0 ┆ ••••••••••••••••
806cf ce cd cc cb ca c9 c8 c7 c6 c5 c4 c3 c2 c1 c0 ┆ ••••••••••••••••
807bf be bd bc bb ba b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 ┆ ••••••••••••••••
808af ae ad ac ab aa a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 ┆ ••••••••••••••••
8099f 9e 9d 9c 9b 9a 99 98 97 96 95 94 93 92 91 90 ┆ ••••••••••••••••
8108f 8e 8d 8c 8b 8a 89 88 87 86 85 84 83 82 81 80 ┆ ••••••••••••••••
8117f 7e 7d 7c 7b 7a 79 78 77 76 75 74 73 72 71 70 ┆ •~}|{zyxwvutsrqp
8126f 6e 6d 6c 6b 6a 69 68 67 66 65 64 63 62 61 60 ┆ onmlkjihgfedcba`
8135f 5e 5d 5c 5b 5a 59 58 57 56 55 54 53 52 51 50 ┆ _^]\[ZYXWVUTSRQP
8144f 4e 4d 4c 4b 4a 49 48 47 46 45 44 43 42 41 40 ┆ ONMLKJIHGFEDCBA@
8153f 3e 3d 3c 3b 3a 39 38 37 36 35 34 33 32 31 30 ┆ ?>=<;:9876543210
8162f 2e 2d 2c 2b 2a 29 28 27 26 25 24 23 22 21 20 ┆ /.-,+*)('&%$#"!
8171f 1e 1d 1c 1b 1a 19 18 17 16 15 14 13 12 11 10 ┆ ••••••••••••••••
8180f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 ┆ ••••••••••••••••
819----
820====
821
822== Command-line tool
823
824If you <<install-normand,installed>> the `normand` package, then you
825can use the `normand` command-line tool:
826
827----
828$ normand <<< '"ma gang de malades"' | hexdump -C
829----
830
831----
83200000000 6d 61 20 67 61 6e 67 20 64 65 20 6d 61 6c 61 64 |ma gang de malad|
83300000010 65 73 |es|
834----
835
836If you copy the `normand.py` module to your own project, then you can
837run the module itself:
838
839----
840$ python3 -m normand <<< '"ma gang de malades"' | hexdump -C
841----
842
843----
84400000000 6d 61 20 67 61 6e 67 20 64 65 20 6d 61 6c 61 64 |ma gang de malad|
84500000010 65 73 |es|
846----
847
848Without a path argument, the `normand` tool reads from the standard
849input.
850
851The `normand` tool prints the generated binary data to the standard
852output.
853
854Various options control the initial <<state,state>> of the processor:
855use the `--help` option to learn more.
856
857== {py3} API
858
859The whole `normand` package/module API is:
860
861[source,python]
862----
863class ByteOrder(enum.Enum):
864 # Big endian.
865 BE = ...
866
867 # Little endian.
868 LE = ...
869
870
871VarsT = typing.Dict[str, int]
872
873
874class TextLoc:
875 # Line number.
876 @property
877 def line_no(self) -> int:
878 ...
879
880 # Column number.
881 @property
882 def col_no(self) -> int:
883 ...
884
885
886class ParseError(RuntimeError):
887 # Source text location.
888 @property
889 def text_loc(self) -> TextLoc:
890 ...
891
892
893class ParseResult:
894 # Generated data.
895 @property
896 def data(self) -> bytearray:
897 ...
898
899 # Updated variable values.
900 @property
901 def variables(self) -> VarsT:
902 ...
903
904 # Updated main group label values.
905 @property
906 def labels(self) -> VarsT:
907 ...
908
909 # Final offset.
910 @property
911 def offset(self) -> int:
912 ...
913
914 # Final byte order.
915 @property
916 def byte_order(self) -> typing.Optional[int]:
917 ...
918
919def parse(normand: str,
920 init_variables: typing.Optional[VarsT] = None,
921 init_labels: typing.Optional[VarsT] = None,
922 init_offset: int = 0,
923 init_byte_order: typing.Optional[ByteOrder] = None) -> ParseResult:
924 ...
925----
926
927The `normand` parameter is the actual <<learn-normand,Normand input>>
928while the other parameters control the initial <<state,state>>.
929
930The `parse()` function raises a `ParseError` instance should it fail to
931parse the `normand` string for any reason.
This page took 0.055856 seconds and 4 git commands to generate.