extension. :issue:`441`
- The ``|indent`` filter's ``width`` argument can be a string to
indent by. :pr:`1167`
+- The parser understands hex, octal, and binary integer literals.
+ :issue:`1170`
Version 2.11.3
string_re = re.compile(
r"('([^'\\]*(?:\\.[^'\\]*)*)'" r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S
)
-integer_re = re.compile(r"(\d+_)*\d+")
+integer_re = re.compile(
+ r"""
+ (
+ 0b(_?[0-1])+ # binary
+ |
+ 0o(_?[0-7])+ # octal
+ |
+ 0x(_?[\da-f])+ # hex
+ |
+ [1-9](_?\d)* # decimal
+ |
+ 0(_?0)* # decimal zero
+ )
+ """,
+ re.IGNORECASE | re.VERBOSE,
+)
float_re = re.compile(
r"""
(?<!\.) # doesn't start with a .
msg = str(e).split(":")[-1].strip()
raise TemplateSyntaxError(msg, lineno, name, filename)
elif token == TOKEN_INTEGER:
- value = int(value.replace("_", ""))
+ value = int(value.replace("_", ""), 0)
elif token == TOKEN_FLOAT:
# remove all "_" first to support more Python versions
value = literal_eval(value.replace("_", ""))
("2.5e+100", "2.5e+100"),
("25.6e-10", "2.56e-09"),
("1_2.3_4e5_6", "1.234e+57"),
+ ("0", "0"),
+ ("0_00", "0"),
+ ("0b1001_1111", "159"),
+ ("0o123", "83"),
+ ("0o1_23", "83"),
+ ("0x123abc", "1194684"),
+ ("0x12_3abc", "1194684"),
),
)
def test_numeric_literal(self, env, value, expect):