Add support for hex int literals.

pull/3016/head
Jussi Pakkanen 7 years ago
parent 86ee89b400
commit a288b524bc
  1. 6
      docs/markdown/Syntax.md
  2. 5
      docs/markdown/snippets/hexnumbers.md
  3. 4
      mesonbuild/mparser.py
  4. 6
      test cases/common/68 number arithmetic/meson.build

@ -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

@ -0,0 +1,5 @@
## Hexadecimal string literals
Hexadecimal integer literals can now be used in build and option files.
int_255 = 0xFF

@ -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

@ -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.')

Loading…
Cancel
Save