From 986535fc958c0d19c10fd6fc5781fe0b2dcdd442 Mon Sep 17 00:00:00 2001 From: Lars Erik Rosengren Date: Sun, 3 Sep 2017 18:07:55 +0200 Subject: Changed implementation of precedence rules This implementation resolves djc/askama#44 by changing the precedence implementation. The previous solution was very slow because it had to try to parse all combinations of precedence layers leading to 2^9 iterations for each expr_any. This is solved by reusing the left operand instead of reparsing it when the operator isn't found. This implementation also solves another related issue that expressions with multiple operators couldn't be parsed, for example {{1 * 2 * 3}}. This is handled by using expr_any for the right operand instead of only using higher level precedence layers. --- testing/templates/precedence.html | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 testing/templates/precedence.html (limited to 'testing/templates/precedence.html') diff --git a/testing/templates/precedence.html b/testing/templates/precedence.html new file mode 100644 index 0000000..e5d12dd --- /dev/null +++ b/testing/templates/precedence.html @@ -0,0 +1,7 @@ +{{ 3 * 4 / 2 -}} +{{ 26 / 2 % 7 -}} +{{ 3 % 2 * 6 -}} +{{ 1 * 2 + 4 -}} +{{ 11 - 15 / 3 -}} +{{ 4 + 5 % 3 -}} +{{ 4 | 2 + 5 & 2 -}} -- cgit