From fd00805ca76808197758800d9d19ee2d6ac708ae Mon Sep 17 00:00:00 2001 From: CleoQc Date: Mon, 12 Nov 2018 13:56:41 -0500 Subject: [PATCH] support scientific notation --- docs/templates.rst | 13 ++++++++++--- jinja2/lexer.py | 10 ++++++++-- tests/test_filters.py | 4 +++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/templates.rst b/docs/templates.rst index 6d3bf367..9da05773 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -1177,12 +1177,19 @@ for Python objects such as strings and numbers. The following literals exist: arguments to function calls and filters, or just to extend or include a template). -42 / 42.23: - Integers and floating point numbers are created by just writing the - number down. If a dot is present, the number is a float, otherwise an +42: + Integers numbers are created by just writing the number down. + If a dot is present, the number will be considered a float, otherwise an integer. Keep in mind that, in Python, ``42`` and ``42.0`` are different (``int`` and ``float``, respectively). +42.23 / 42e2 / 42E2 / 1e0: + Floating point numbers are created by just writing the + number down. Floating points can be written using the dot as a decimal mark, + or they can be written in scientific notation in which + case you can use lower case 'e' or upper case 'E' to indicate the exponent + part. + ['list', 'of', 'objects']: Everything between two brackets is a list. Lists are useful for storing sequential data to be iterated over. For example, you can easily diff --git a/jinja2/lexer.py b/jinja2/lexer.py index e23a9987..119dc99d 100644 --- a/jinja2/lexer.py +++ b/jinja2/lexer.py @@ -22,6 +22,8 @@ from jinja2._compat import implements_iterator, intern, iteritems, text_type from jinja2.exceptions import TemplateSyntaxError from jinja2.utils import LRUCache +from ast import literal_eval # to support scientific notation + # cache for the lexers. Exists in order to be able to have multiple # environments with the same lexer _lexer_cache = LRUCache(50) @@ -52,7 +54,11 @@ else: del jinja2._identifier del _identifier -float_re = re.compile(r'(?