From 733851eda019579ef98efd6b81aaa4cfffb0f4f2 Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 23 Jul 2019 11:07:09 -0700 Subject: [PATCH] clean up numeric underscore support add changelog clean up docs parametrize tests explain float regex --- CHANGES.rst | 2 ++ jinja2/lexer.py | 19 +++++++++--- tests/test_filters.py | 64 +++++++++++++++++++++++++++-------------- tests/test_lexnparse.py | 27 +++++++---------- 4 files changed, 70 insertions(+), 42 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0ee53241..7852bec3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,6 +23,8 @@ unreleased :func:`meta.find_undeclared_variables`. #931 - Float literals can be written with scientific notation, like ``{{ 2.56e-3 }}``. #912, #922 +- Int and float literals can be written with the '_' separator for + legibility, like ``{{ 12_345 }}``. #923 .. _#557: https://github.com/pallets/jinja/issues/557 .. _#765: https://github.com/pallets/jinja/issues/765 diff --git a/jinja2/lexer.py b/jinja2/lexer.py index a387cf92..d1d59440 100644 --- a/jinja2/lexer.py +++ b/jinja2/lexer.py @@ -31,9 +31,23 @@ _lexer_cache = LRUCache(50) # static regular expressions whitespace_re = re.compile(r'\s+', re.U) +newline_re = re.compile(r'(\r\n|\r|\n)') string_re = re.compile(r"('([^'\\]*(?:\\.[^'\\]*)*)'" r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S) -integer_re = re.compile(r'(\d+_)*(\d+)') +integer_re = re.compile(r'(\d+_)*\d+') +float_re = re.compile( + r""" + (?