diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-02-03 21:51:45 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-02-03 22:44:19 +0200 |
commit | e48b2238577921de946a029aa5654bd2dac0dfe1 (patch) | |
tree | 6a96a78452cb5c8b80dd453db825730430a6edd8 | |
parent | f25070ec089719a607c545c1b44a678c6bbce5c9 (diff) | |
download | meson-hex.tar.gz |
Add support for hex int literals.hex
-rw-r--r-- | docs/markdown/Syntax.md | 6 | ||||
-rw-r--r-- | docs/markdown/snippets/hexnumbers.md | 5 | ||||
-rw-r--r-- | mesonbuild/mparser.py | 4 | ||||
-rw-r--r-- | test cases/common/68 number arithmetic/meson.build | 6 |
4 files changed, 21 insertions, 0 deletions
diff --git a/docs/markdown/Syntax.md b/docs/markdown/Syntax.md index 84403f438..1005100fe 100644 --- a/docs/markdown/Syntax.md +++ b/docs/markdown/Syntax.md @@ -58,6 +58,12 @@ y = 3 * 4 d = 5 % 3 # Yields 2. ``` +Hexadecimal literals are supported since version 0.45.0: + +```meson +int_255 = 0xFF +``` + Strings can be converted to a number like this: ```meson diff --git a/docs/markdown/snippets/hexnumbers.md b/docs/markdown/snippets/hexnumbers.md new file mode 100644 index 000000000..840c0cb3b --- /dev/null +++ b/docs/markdown/snippets/hexnumbers.md @@ -0,0 +1,5 @@ +## Hexadecimal string literals + +Hexadecimal integer literals can now be used in build and option files. + + int_255 = 0xFF diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index 5df056f82..94d56e510 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -71,6 +71,7 @@ class Lexer: # Need to be sorted longest to shortest. ('ignore', re.compile(r'[ \t]')), ('id', re.compile('[_a-zA-Z][_0-9a-zA-Z]*')), + ('hexnumber', re.compile('0[xX][0-9a-fA-F]+')), ('number', re.compile(r'\d+')), ('eol_cont', re.compile(r'\\\n')), ('eol', re.compile(r'\n')), @@ -152,6 +153,9 @@ class Lexer: line_start = mo.end() - len(lines[-1]) elif tid == 'number': value = int(match_text) + elif tid == 'hexnumber': + tid = 'number' + value = int(match_text, base=16) elif tid == 'eol' or tid == 'eol_cont': lineno += 1 line_start = loc diff --git a/test cases/common/68 number arithmetic/meson.build b/test cases/common/68 number arithmetic/meson.build index 495a83e36..f2e84a8b2 100644 --- a/test cases/common/68 number arithmetic/meson.build +++ b/test cases/common/68 number arithmetic/meson.build @@ -56,3 +56,9 @@ assert(3 >= 3, 'Gte broken') assert(true.to_int() == 1,'bool to_int() broken') assert(false.to_int() == 0,'bool to_int() broken') + +hex_255 = 0xff +hex2_255 = 0XFF + +assert(hex_255 == 255, 'Hex parsing is broken.') +assert(hex2_255 == 255, 'Uppercase hex parsing is broken.') |