Accept many more prefixes and suffixes for a constant integer v0.13.0
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 5 Oct 2023 04:31:07 +0000 (00:31 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 6 Oct 2023 17:56:14 +0000 (13:56 -0400)
commitfc21bb27ebb58b9b1dcd2184685d928ffabcc252
tree6b28cb416de4c45fc0aa2e7d164deb2e88b40557
parent25ca454b64791de0b9c2754894bec408bd2f2f9b
Accept many more prefixes and suffixes for a constant integer

This patch makes Normand accept the `0o`/`0O` and `0b`/`0B` prefixes for
a constant integer, as well as the `h`/`H`/`q`/`Q`/`o`/`O`/`b`/`B`
suffixes.

Those suffixes are common in tools such as MASM [1]:

> You can also specify hexadecimal numbers by adding an h after the
> number. You can use uppercase or lowercase letters within numbers. For
> example, "0x4AB3", "0X4aB3", "4AB3h", "4ab3h", and "4aB3H" have the
> same meaning.

as well as NASM [2]:

> NASM allows you to specify numbers in a variety of number bases, in a
> variety of ways: you can suffix `H`, `Q` or `O`, and `B` for hex,
> octal, and binary, or you can prefix `0x` for hex in the style of C,
> [...]

This constant integer form is available anywhere outside a Python
expression string, for example:

    55 * 28Fh

    +0o755~11010001b

    m:my_macro(-126q, 0b101)

Internally, the _norm_const_int() function transforms any suffix form
into a Python prefix form (for int()), keeping the negative `-` if
present.

[1]: https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/masm-numbers-and-operators
[2]: https://www.tortall.net/projects/yasm/manual/html/nasm-const.html

Change-Id: I708494e84080b9f4292397c6a81e67e335d330cd
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
README.adoc
normand/normand.py
pyproject.toml
tests/pass-const-int-bin.nt [new file with mode: 0644]
tests/pass-const-int-dec.nt [new file with mode: 0644]
tests/pass-const-int-hex.nt [new file with mode: 0644]
tests/pass-const-int-oct.nt [new file with mode: 0644]
tests/pass-readme-intro-fill.nt
tests/pass-readme-learn-rep-blk-1.nt
This page took 0.024707 seconds and 4 git commands to generate.