]> git.ipfire.org Git - thirdparty/jinja.git/log
thirdparty/jinja.git
5 years agoOnly support implicit tuples in variable expressions GH-1194-formal-grammar
Kevin Brown [Sat, 16 May 2020 21:54:52 +0000 (17:54 -0400)] 
Only support implicit tuples in variable expressions

They cause super inconsistent parsing behaviour if they show up
pretty much anywhere else because there is no difference between an
implicit tuple and a set of comma-separated parameters.

5 years agoSwitch to parameterizing api tests
Kevin Brown [Sat, 16 May 2020 21:17:51 +0000 (17:17 -0400)] 
Switch to parameterizing api tests

5 years agoProperly handle implicit tuples
Kevin Brown [Sat, 16 May 2020 21:09:24 +0000 (17:09 -0400)] 
Properly handle implicit tuples

This adds support for implicit tuple literals and removes support for
identifier tuples for now.

5 years agoAdd proper parsing for {% for %} parameters
Kevin Brown [Sat, 16 May 2020 19:55:56 +0000 (15:55 -0400)] 
Add proper parsing for {% for %} parameters

Previously a lot of the parsing was done through implicit variable
tuples, but that ended up causing a lot of special cases because we
were only allowing variables in those tuples. Now that we are going
to move towards having tuples be handled consitently, whether they
are identifier tuples or tuple literals, the logic for handling the
`{% for %}` block needed to be cleaned up.

5 years agoRaise expected syntax errors on bad calls
Kevin Brown [Sat, 16 May 2020 19:17:48 +0000 (15:17 -0400)] 
Raise expected syntax errors on bad calls

5 years agoProperly handle signed variables
Kevin Brown [Sat, 16 May 2020 19:03:57 +0000 (15:03 -0400)] 
Properly handle signed variables

Previously we were only handling signed numbers but we were handling
them as constants. Jinja implements a full system for unarary
operators that can be customized, so this switches the grammar and
the parser to use that system instead.

5 years agoSwitch some tests to be parameterized
Kevin Brown [Sat, 16 May 2020 19:02:53 +0000 (15:02 -0400)] 
Switch some tests to be parameterized

Right now they are using a for loop which makes it more difficult
to properly trace what iteration failed on. Additionally, it hides
cases where multiple items in the loop fail but not all do.

5 years agoRequire at least one space between line block parameters
Kevin Brown [Sat, 16 May 2020 02:29:01 +0000 (22:29 -0400)] 
Require at least one space between line block parameters

5 years agoDo not require a newline before line statements
Kevin Brown [Sat, 16 May 2020 02:27:06 +0000 (22:27 -0400)] 
Do not require a newline before line statements

As we discovered in the tests, the logic for line statements only
enforces that when they are found, the remaining portion of the line
is treated as a statement declaration. This means that a line statement
can follow things such as text, which the grammar did not previously
allow. The grammar also did not allow a line statement to be the first
line in a file, wich this change also now supports. All non-newline
whitespace preceding the line statement will continue to be stripped.

5 years agoImplement proper line block closing logic
Kevin Brown [Sat, 16 May 2020 02:21:55 +0000 (22:21 -0400)] 
Implement proper line block closing logic

The documentation implies that line statements are terminated once a
newline statement is found, which would make sense when you think of
what a line block does. The lexer though does not quite implement this
logic, and instead will strip out additional whitespace past the newline
when the line statement is the last non-whitespace in the file.

This has to do with how the current regex is "\s*(\n|$)" which means
"strip any whitespace until a newline or end of file is reached".
Because the regex is greedy, this will strip any whitespace (including
newlines) to the end of the file, or it will only strip whitespace to
the first newline found if the end of the file is not possible. In
order to remain consistent with the old parser, the grammar has been
updated to reflect this behaviour.

5 years agoProperly split up line blocks from line block pairs
Kevin Brown [Sat, 16 May 2020 02:20:51 +0000 (22:20 -0400)] 
Properly split up line blocks from line block pairs

This is necessary for us to do proper pairing of line blocks since
otherwise the rejection would disallow line blocks of any type.

5 years agoAllow assignment values to be complex expressions
Kevin Brown [Sat, 16 May 2020 02:19:28 +0000 (22:19 -0400)] 
Allow assignment values to be complex expressions

5 years agoFix print block
Kevin Brown [Sat, 16 May 2020 02:18:48 +0000 (22:18 -0400)] 
Fix print block

The print block would not actually print the value before because it
was not able to properly parse the variable that needed to be printed.

5 years agoAdd line block pair checking
Kevin Brown [Sat, 16 May 2020 02:17:46 +0000 (22:17 -0400)] 
Add line block pair checking

Similar to how it is done in regular Jinja blocks, line blocks will
now check to make sure that start and end blocks are properly paired
together. When they are not paired together, it will fall back to
parsing them separately like one would expect.

5 years agoFix parsing math1 expressions in comparisons
Kevin Brown [Fri, 15 May 2020 23:05:42 +0000 (19:05 -0400)] 
Fix parsing math1 expressions in comparisons

When a math1 expression was used in a comparison before, the right
side would consume the comparison instead of letting it fall back to
the comparison being above it in the AST. This was fixed by restricting
the right side of math1 comparisons to be complex operations only, so
that is any operation that does not involve a comparison, since it's
unlikely that you are looking to do math expressions on the result of
a comparison.

Additionally, this also allows conditional expressions involving basic
operators to consume a complex expression on the left side. Previously
they were restricted to only allowing variables on the left side, so
this allows for more complex comparisons to be made.

Because of the way that conditional expressions with parentheses are
consumed, they have been moved to be the last check within conditional
expressions. This should help to guard against other conditional
expressions which can consume parenthese themselves from being blocked
from parsing because the parentheses have already been consumed.

In order to make things generally easier to understand, the complex
expressions wihch return an actual value (instread of just comparisons)
are now grouped together within the grammar.

5 years agoFix parsing of the {% from %} block
Kevin Brown [Fri, 15 May 2020 22:06:31 +0000 (18:06 -0400)] 
Fix parsing of the {% from %} block

There was an issue in the parser before where it was not properly
hanlding variable tuples within the parameters. Additionally, it was
not validating that "import" came after the template name, or that
when it did that any variables were actually specified. Both of those
are now being enforced properly.

5 years agoFix grammar parsing for block separators
Kevin Brown [Fri, 15 May 2020 22:03:35 +0000 (18:03 -0400)] 
Fix grammar parsing for block separators

Previously this allows blocks to be separated by commas and have one
trailing off. Now this only allows blocks to be properly separated
by commas and trailing comms are no longer allowed. This also now
enforces that when parameters are not separated by commas, they are
spearated by at least one space.

5 years agoFix "not" expressions consuming variable starting with not
Kevin Brown [Fri, 15 May 2020 21:17:39 +0000 (17:17 -0400)] 
Fix "not" expressions consuming variable starting with not

The `not` expression should have a space between the word "not" and
the expression which is being negated. Otherwise it will incorrectly
pick up things like "nothing" as "not thing" because it technically
meets the criteria.

5 years agoAdd support for dot accessors to be numbers
Kevin Brown [Fri, 15 May 2020 21:07:10 +0000 (17:07 -0400)] 
Add support for dot accessors to be numbers

This is an interesting special case in the old parser where numbers
are allowed as dot accessors, but they are specifically convertred
to being an item accessor during the parsing phase. We now support
numbers being parsed for dot accessors in the new parser.

5 years agoAdd support for the filter block
Kevin Brown [Fri, 15 May 2020 20:15:46 +0000 (16:15 -0400)] 
Add support for the filter block

5 years agoAdd support for negative numbers
Kevin Brown [Fri, 15 May 2020 19:52:16 +0000 (15:52 -0400)] 
Add support for negative numbers

This also fixes a bug where the exponent was not being properly
captured as well, just the sign of the number

5 years agoAllow symbols to be overwritten by the environment
Kevin Brown [Fri, 15 May 2020 16:27:10 +0000 (12:27 -0400)] 
Allow symbols to be overwritten by the environment

This introduces a change to both the grammar and the parsing
environment that allows people to override start/end symbols in the
grammar through the environment. This finally brings the parser on
the same level as the old parser and lexer when it comes to handling
those customizations.

This means that the grammar must be compiled dynamically to account
for these customizations per environment. A module-level LRU cache
has been implemented to handle this fact, so grammars can be cached
instead of compiled every time. This should handle most cases other
than the unit tests, since most people aren't frequently changing up
their environment within their applications.

This also adds proper handling to the closing line block statement
so it waits for the end of a line or the end of the expression.

5 years agoSupport chained comparisons in parser
Kevin Brown [Fri, 15 May 2020 14:32:07 +0000 (10:32 -0400)] 
Support chained comparisons in parser

5 years agoAdd support for complex math expressions with +/-
Kevin Brown [Fri, 15 May 2020 03:49:34 +0000 (23:49 -0400)] 
Add support for complex math expressions with +/-

Support for complex math expressions with other operators will come
eventually.

5 years agoFix broken arguments for call blocks
Kevin Brown [Fri, 15 May 2020 03:41:22 +0000 (23:41 -0400)] 
Fix broken arguments for call blocks

5 years agoSupport for dyanamic args and kwargs in calls
Kevin Brown [Fri, 15 May 2020 03:35:38 +0000 (23:35 -0400)] 
Support for dyanamic args and kwargs in calls

5 years agoFix call argument parsing
Kevin Brown [Fri, 15 May 2020 03:34:06 +0000 (23:34 -0400)] 
Fix call argument parsing

This temporarily break how `{% call %}` blocks work when arguments
are passed into them because it did not work consistently before. It
only worked for a single argument being passed in because of how
conditional expressions stripped out the parentheses if they were
present. Now they are properly captured but the parser does not yet
put them into the correct location within the Jinja AST.

5 years agoAdd undocumented print block support
Kevin Brown [Fri, 15 May 2020 02:55:34 +0000 (22:55 -0400)] 
Add undocumented print block support

5 years agoSupport variables in lists
Kevin Brown [Fri, 15 May 2020 01:19:49 +0000 (21:19 -0400)] 
Support variables in lists

5 years agoFix whitespace handling on blocks
Kevin Brown [Fri, 15 May 2020 00:22:26 +0000 (20:22 -0400)] 
Fix whitespace handling on blocks

Because of the way it was ordered, it was properly picking up the
non-whitespace stripping block in some cases and failing to parse
as a result.

5 years agoHandle undocumented whitespace parsing in variables
Kevin Brown [Fri, 15 May 2020 00:15:15 +0000 (20:15 -0400)] 
Handle undocumented whitespace parsing in variables

5 years agoParse test variable as conditional expression
Kevin Brown [Fri, 15 May 2020 00:05:43 +0000 (20:05 -0400)] 
Parse test variable as conditional expression

This was necessary to fix some of the tests for tests which relied
on parentheses in place.

5 years agoFix handling of tests which check constants
Kevin Brown [Fri, 15 May 2020 00:04:57 +0000 (20:04 -0400)] 
Fix handling of tests which check constants

Because of how the parser works, it does not differentiate between
constants and function names, so this needs to convert it back.

5 years agoFix parsing of the ** operator
Kevin Brown [Fri, 15 May 2020 00:04:02 +0000 (20:04 -0400)] 
Fix parsing of the ** operator

5 years agoFix blank iterables not parsing correctly
Kevin Brown [Thu, 14 May 2020 15:43:05 +0000 (11:43 -0400)] 
Fix blank iterables not parsing correctly

The AST returns `None` instead of an empty array of the value of an
empty iterable literal, so we need to special case when that happens
to get them to parse consistently.

5 years agoAdd support for math expressions to grammar/parser
Kevin [Thu, 14 May 2020 15:21:20 +0000 (11:21 -0400)] 
Add support for math expressions to grammar/parser

5 years agoTuples must contain a comma
Kevin [Thu, 14 May 2020 14:00:09 +0000 (10:00 -0400)] 
Tuples must contain a comma

This fixes an issue where parentheses-wrapped variables were being
interpreted by the grammar as tuples. This was because we were lacking
a definiiton for variable wrapped in parentheses and because the grammar
wasn't enforcing multiple values to be present in tuples.

5 years agoTest function single parameter should a variable
Kevin [Thu, 14 May 2020 13:55:37 +0000 (09:55 -0400)] 
Test function single parameter should a variable

Previusly we were expecting it to be a conditional expression which
allowed it to swallow conditional expressions as if they were a single
variable. This fixes that issue so it only swallows variables.

5 years agoFix parsing of filters to allow chained calls
Kevin [Thu, 14 May 2020 03:06:25 +0000 (23:06 -0400)] 
Fix parsing of filters to allow chained calls

5 years agoProperly set environment on parsed template
Kevin [Thu, 14 May 2020 03:05:52 +0000 (23:05 -0400)] 
Properly set environment on parsed template

5 years agoSupport filters being call chained
Kevin [Thu, 14 May 2020 03:04:32 +0000 (23:04 -0400)] 
Support filters being call chained

Previously filters were not treated the same as variable, as a
result it was not possible to call the result of a filter. Since
filters are treated as regular variable and therefore can be called
any number of times, this change was necessary to allow them to be
parsed the same way.

5 years agoSwitch testing to use jinja internals
Kevin [Thu, 14 May 2020 02:03:42 +0000 (22:03 -0400)] 
Switch testing to use jinja internals

5 years agoSwap out the old parser with the new one
Kevin [Thu, 14 May 2020 01:50:10 +0000 (21:50 -0400)] 
Swap out the old parser with the new one

This will allow us to figure out where the gaps are within the test
suite and also start running a comparison on the timing changes.

5 years agoAdd TatSu as a depdendency
Kevin [Thu, 14 May 2020 01:48:39 +0000 (21:48 -0400)] 
Add TatSu as a depdendency

5 years agoMove semantics object into new_parser
Kevin [Thu, 14 May 2020 00:39:32 +0000 (20:39 -0400)] 
Move semantics object into new_parser

5 years agoMoved new_parser into jinja package
Kevin [Thu, 14 May 2020 00:38:31 +0000 (20:38 -0400)] 
Moved new_parser into jinja package

5 years agoRemove empty extra files
Kevin [Thu, 14 May 2020 00:36:17 +0000 (20:36 -0400)] 
Remove empty extra files

5 years agoAdd support for test function arguments
Kevin [Thu, 14 May 2020 00:33:56 +0000 (20:33 -0400)] 
Add support for test function arguments

5 years agoAdd support for scoped blocks
Kevin [Thu, 14 May 2020 00:23:19 +0000 (20:23 -0400)] 
Add support for scoped blocks

5 years agoAdd support for tests in `{% for %}`
Kevin [Thu, 14 May 2020 00:14:40 +0000 (20:14 -0400)] 
Add support for tests in `{% for %}`

5 years agoAdd full support for `{% if %}` block
Kevin [Wed, 13 May 2020 22:48:17 +0000 (18:48 -0400)] 
Add full support for `{% if %}` block

5 years agoAdd support for call block
Kevin [Wed, 13 May 2020 02:24:40 +0000 (22:24 -0400)] 
Add support for call block

5 years agoAdd support for parsing `{% else %}` blocks in for loops
Kevin [Wed, 13 May 2020 02:10:49 +0000 (22:10 -0400)] 
Add support for parsing `{% else %}` blocks in for loops

5 years agoAdded semantics for pairing blocks together
Kevin [Wed, 13 May 2020 01:27:40 +0000 (21:27 -0400)] 
Added semantics for pairing blocks together

This required us to modify how the parser works so that once it
detects a pair of blocks, it kicks it back to our specific function
which allows us to detect if the pair of blocks it detected were a
matching pair. This is required in order to allow single blocks to
be included within paired blocks, as otherwise it would always match
the last single block to the end block.

This required changing the grammar so the pair blocks had their own
named expression. This allows us to reject the parse as invalid with
incorrect semantics and allows it to try to just parse the first
block alone.

5 years agoAdd support for `{% include ignore missing %}`
Kevin [Tue, 12 May 2020 20:56:53 +0000 (16:56 -0400)] 
Add support for `{% include ignore missing %}`

5 years agoFix with_context defaulting to false on include block
Kevin [Tue, 12 May 2020 03:03:30 +0000 (23:03 -0400)] 
Fix with_context defaulting to false on include block

5 years agoAdd support for import block parsing
Kevin [Tue, 12 May 2020 03:00:29 +0000 (23:00 -0400)] 
Add support for import block parsing

5 years agoAdd support for parsing `{% include %}` tags
Kevin [Tue, 12 May 2020 02:48:12 +0000 (22:48 -0400)] 
Add support for parsing `{% include %}` tags

This does not yet support the `ignore_missing` flag that can be
passed as a parameter to an `{% include %}` tag

5 years agoAdd support for `{% from with context %}`
Kevin [Tue, 12 May 2020 02:32:43 +0000 (22:32 -0400)] 
Add support for `{% from with context %}`

5 years agoAdd support for not() expressions in parser
Kevin [Tue, 12 May 2020 02:28:11 +0000 (22:28 -0400)] 
Add support for not() expressions in parser

5 years agoAdd support for parentheses grouping in expressions
Kevin [Tue, 12 May 2020 02:27:51 +0000 (22:27 -0400)] 
Add support for parentheses grouping in expressions

5 years agoAdd support for negated test expressions
Kevin [Tue, 12 May 2020 02:27:38 +0000 (22:27 -0400)] 
Add support for negated test expressions

5 years agoAdd support for not() expressions to grammar
Kevin [Tue, 12 May 2020 02:26:09 +0000 (22:26 -0400)] 
Add support for not() expressions to grammar

This allows for boolean expressions to be negated on the fly

5 years agoAdd support for "not in"/"notin" to grammar/parser
Kevin [Tue, 12 May 2020 02:01:15 +0000 (22:01 -0400)] 
Add support for "not in"/"notin" to grammar/parser

5 years agoFix `{% for in %}` loop parsing
Kevin [Tue, 12 May 2020 01:50:57 +0000 (21:50 -0400)] 
Fix `{% for in %}` loop parsing

This fixes the fact that most `{% for in %}` loops will be parsed
using the `in` operator now, so that operator must be detected and
extracted out in order to make it parse the same way as before. This
is the start of the special cases within the parser for handling
Jinja's previous parsing style.

5 years agoSupport in/notin operator expressions in parser
Kevin [Tue, 12 May 2020 01:49:56 +0000 (21:49 -0400)] 
Support in/notin operator expressions in parser

5 years agoSupport "in" operator in grammar
Kevin [Tue, 12 May 2020 01:45:43 +0000 (21:45 -0400)] 
Support "in" operator in grammar

This changes the previous comparison operations from being marked
as solely comparion expressions and expands them out to be generation
operator expressions. This allows us to easily support the "in"
operator, which in the current Jinja parser is handled exactly the
same as the other operations, but it does require us to special case
the automated conversion of the "not ... in" expression to a "notin"
expression.

5 years agoAdd concat expression support to grammar and parser
Kevin [Tue, 12 May 2020 01:25:29 +0000 (21:25 -0400)] 
Add concat expression support to grammar and parser

This is probably going to be reclassified in the grammar and parser
as something different from the conditional expressions once more
support for math operators is added in.

5 years agoSimplify variable values in grammars
Kevin [Tue, 12 May 2020 01:11:32 +0000 (21:11 -0400)] 
Simplify variable values in grammars

Now that variable identifers are able to be used as conditional
expressions, we can just specify that variable expressions in the
grammar are looking for a conditional expression as the name of the
variable.

5 years agoAdd support for the extends block
Kevin [Tue, 12 May 2020 01:10:26 +0000 (21:10 -0400)] 
Add support for the extends block

5 years agoSupport if/else expressions in parser
Kevin [Tue, 12 May 2020 01:10:08 +0000 (21:10 -0400)] 
Support if/else expressions in parser

5 years agoAllow variable identifiers to be conditionals
Kevin [Tue, 12 May 2020 01:08:06 +0000 (21:08 -0400)] 
Allow variable identifiers to be conditionals

This aligns with the Python behaviour and pre-existing Jinja behaviour
where a variable expression can be used as a test for a conditional.
This was necessary to allow variable identifiers to be used in places
which was expecting a possible conditional expression, like in a if/else
expression.

5 years agoRestrict where conditional expressions are allowed
Kevin [Tue, 12 May 2020 01:05:37 +0000 (21:05 -0400)] 
Restrict where conditional expressions are allowed

Previously conditional expressions were only allowed in things which
accepted parameters to call accessors, which is most things, but this
was found to be too broad. Many contexts to not actually allow conditional
expressions so this was restricted back to block parameters and variable
calls.

5 years agoAdd support for if/else expressions in grammar
Kevin [Tue, 12 May 2020 01:03:45 +0000 (21:03 -0400)] 
Add support for if/else expressions in grammar

These fall under a special type of conditional expression and can
only be used in certain places. The grammar for test functions
needed to be updated to rejected test function parameters if they
are only called "else", since that is likely to be for an if/else
expression. This matches the existing behaviour of the Jinja parser.

5 years agoAdd support for "None" and "none" to grammar/parser
Kevin [Tue, 12 May 2020 00:19:42 +0000 (20:19 -0400)] 
Add support for "None" and "none" to grammar/parser

5 years agoAdd support for parsing dictionary literals
Kevin [Tue, 12 May 2020 00:15:28 +0000 (20:15 -0400)] 
Add support for parsing dictionary literals

5 years agoAdd support dictionary literals to grammar
Kevin [Tue, 12 May 2020 00:14:40 +0000 (20:14 -0400)] 
Add support dictionary literals to grammar

This also allows dictionary values to be variables instead of just
regular identifiers, a change which might be made to other literals
such as lists and tuples in the future as we determine what those
also support.

5 years agoSupport single-parameter tests without parentheses
Kevin [Tue, 12 May 2020 00:02:48 +0000 (20:02 -0400)] 
Support single-parameter tests without parentheses

This adds support for the optional parantheses in tests that are only
being supplied a single parameter. Tests which use parantheses are
currently not supported in the parser, but are supported in the grammar.

5 years agoRemove unused variable_tests from grammar
Kevin [Mon, 11 May 2020 23:54:10 +0000 (19:54 -0400)] 
Remove unused variable_tests from grammar

5 years agoSupport the autoescape block
Kevin [Mon, 11 May 2020 23:40:15 +0000 (19:40 -0400)] 
Support the autoescape block

5 years agoAdd parsing of conditional expressions
Kevin [Sun, 10 May 2020 21:36:33 +0000 (17:36 -0400)] 
Add parsing of conditional expressions

5 years agoFix AST for conditional expressions
Kevin [Sun, 10 May 2020 21:34:50 +0000 (17:34 -0400)] 
Fix AST for conditional expressions

Previously all conditional expressions were left associative which
produced an AST that was nothing like the one in Jinja and one which
did not respect order of operations within conditions. The conditional
expression part of the grammar has been rewritten to be more explicit
about what can and cannot match which appears to have fixed those
issues with the AST.

5 years agoFix macros not marking args as params
Kevin [Sun, 10 May 2020 21:06:49 +0000 (17:06 -0400)] 
Fix macros not marking args as params

It was only marking keyword arguments as params which is not totally
correct.

5 years agoFix block set params being marked for load
Kevin [Sun, 10 May 2020 21:03:35 +0000 (17:03 -0400)] 
Fix block set params being marked for load

5 years agoFix macro params being marked to load
Kevin [Sun, 10 May 2020 21:02:21 +0000 (17:02 -0400)] 
Fix macro params being marked to load

These are being used as variables within the macro itself so these
should be marked as parameters so they do not escape the scope of the
block.

5 years agoFixed elif/else sections of if node being None
Kevin [Sun, 10 May 2020 21:01:33 +0000 (17:01 -0400)] 
Fixed elif/else sections of if node being None

The default should be an empty list to match the existing AST but
we were incorrectly setting it to `None`.

5 years agoCombine common template data/outputs in AST
Kevin [Sun, 10 May 2020 20:44:08 +0000 (16:44 -0400)] 
Combine common template data/outputs in AST

This makes it easier to compare the AST generated by the old Jinja
parser and the AST generated by the new one, since the new AST
separates out template data character by character currently.

5 years agoFilter out `None` from parsed blocks
Kevin [Sun, 10 May 2020 20:30:58 +0000 (16:30 -0400)] 
Filter out `None` from parsed blocks

This allows for comments to not appear in the generated AST.

5 years agoAllow variable identifiers to be aliased in block params
Kevin [Sun, 10 May 2020 20:24:12 +0000 (16:24 -0400)] 
Allow variable identifiers to be aliased in block params

This is only really supported on the `{% from %}` block currently,
but the ability exists to use this elsewhere if someone is looking
for the ability to alias variable identifiers. This also allows
value-only parameters to be comma-separated within the block
parameters, since before that was only allows for key-value parameters.

5 years agoMark with targets as parameters
Kevin [Sun, 10 May 2020 19:52:07 +0000 (15:52 -0400)] 
Mark with targets as parameters

This fixes a bug where the targets of a `{% with %}` block would not
be marked as a parameter. This is because they were not being marked
at all as a variable which results in an invalid AST. For reference
counting purposes, this must also be marked specifically as a parameter
variable instead of as a stored variable to ensure it does not leak
out of the block.

5 years agoProperly mark set target as variable
Kevin [Sun, 10 May 2020 19:50:15 +0000 (15:50 -0400)] 
Properly mark set target as variable

Previously it wasn't being marked as a variable at all if it was just
a string literal, so this fixes it so Jinja knows that the assignment
should be stored on the target variable.

5 years agoSwitch From node to use constructor
Kevin [Sun, 10 May 2020 19:49:26 +0000 (15:49 -0400)] 
Switch From node to use constructor

This ensures that `with_context` is properly initialized even though
we don't currently support it.

5 years agoAllow optional comma after block keyword parameters
Kevin [Sun, 10 May 2020 19:47:53 +0000 (15:47 -0400)] 
Allow optional comma after block keyword parameters

It looks like this is only currently support within `{% with %}`
blocks in Jinja, instead of space-separating the parameters, but
this may also be happening in extensions as well.

5 years agoParse macro blocks
Kevin [Sun, 10 May 2020 18:29:54 +0000 (14:29 -0400)] 
Parse macro blocks

5 years agoSupport assignment blocks using `{% set %}`
Kevin [Sun, 10 May 2020 18:08:48 +0000 (14:08 -0400)] 
Support assignment blocks using `{% set %}`

This adds support for the usage of `{% set %}` where the contents of
the block are assigned to the variable instead of handling that within
the block parameters.

Because Jinja separates the filter from the variable within the
`AssignBlock` node, we have to detect when there is a wrapping filter
and extract it so that it can slot in properly.

5 years agoParse isolated set blocks
Kevin [Sun, 10 May 2020 17:59:23 +0000 (13:59 -0400)] 
Parse isolated set blocks

This adds support for set blocks where a key-value pair is being
sent in so there is no matching pair of statement.

5 years agoParse arguments to calls
Kevin [Sun, 10 May 2020 16:54:08 +0000 (12:54 -0400)] 
Parse arguments to calls

This can be combined with the logic for parsing arguments to filters
then they both generate the same AST.

5 years agoInitial support for if blocks
Kevin [Sun, 10 May 2020 16:42:22 +0000 (12:42 -0400)] 
Initial support for if blocks

This currently only supports tests which are a simple condition and
do not span multiple sides of a comparison.

5 years agoAdd parsing of boolean literals
Kevin [Sun, 10 May 2020 16:41:31 +0000 (12:41 -0400)] 
Add parsing of boolean literals

This should finish off all of the parsing of currently supported
literals.

5 years agoSupport parsing `{% block %}` blocks
Kevin [Sun, 10 May 2020 16:27:20 +0000 (12:27 -0400)] 
Support parsing `{% block %}` blocks

This does not currently parse out the scoped parameter but that will
come soon enough.