use dynamic precedence to fix 'is' and allow not not
This commit is contained in:
1 parent
9701fab04a
commit
b239bf6509
5 files changed
+40132
-39901
No files matched your search
@@ -79,7 +79,11 @@ Consequences worth knowing before editing a rule:
|
||||
fail at generate time; it shows up as `MISSING` nodes in a passing-looking parse.
|
||||
- **`conflicts` entries are the normal fix, not precedence.** With explicit separators the lookahead at a
|
||||
part boundary is `SEP` instead of the meaningful token, so LR(1) loses its discriminator. That is why
|
||||
`predicate` and `[$.library, $.load]` are listed there.
|
||||
`predicate`, `binaryOperator` and `[$.library, $.load]` are listed there. Where two readings both stay
|
||||
valid to the end — `is not` as one operator or as `is` and a prefix `not` — the conflict needs a
|
||||
`prec.dynamic` alongside it to settle which wins; a static `prec` resolves the shift/reduce while the
|
||||
table is built and discards the other parse outright, which is how a bare `{% if x is y %}` came to be
|
||||
an error.
|
||||
|
||||
### A tag group is a sequence of clauses
|
||||
|
||||
|
||||
+5
-4
@@ -359,6 +359,7 @@ const django = grammar({
|
||||
[$.timezone_clause],
|
||||
[$.with_clause],
|
||||
[$.predicate],
|
||||
[$.binaryOperator],
|
||||
[$.library, $.load],
|
||||
[$._translate_option],
|
||||
[$._filtered_value_spaced],
|
||||
@@ -426,18 +427,18 @@ const django = grammar({
|
||||
"<=",
|
||||
">=",
|
||||
"in",
|
||||
prec(1, joined("not", "in")),
|
||||
prec.dynamic(1, joined("not", "in")),
|
||||
"is",
|
||||
prec(1, joined("is", "not")),
|
||||
prec.dynamic(1, joined("is", "not")),
|
||||
),
|
||||
predicate: ($) =>
|
||||
seq(
|
||||
optional(seq("not", SEP)),
|
||||
repeat(seq("not", SEP)),
|
||||
$.filtered_value,
|
||||
repeat(
|
||||
seq(
|
||||
part($.binaryOperator),
|
||||
optional(part("not")),
|
||||
repeat(part("not")),
|
||||
part($.filtered_value),
|
||||
),
|
||||
),
|
||||
|
||||
+9
-16
@@ -493,7 +493,7 @@
|
||||
"value": "in"
|
||||
},
|
||||
{
|
||||
"type": "PREC",
|
||||
"type": "PREC_DYNAMIC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
@@ -518,7 +518,7 @@
|
||||
"value": "is"
|
||||
},
|
||||
{
|
||||
"type": "PREC",
|
||||
"type": "PREC_DYNAMIC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
@@ -544,9 +544,8 @@
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
@@ -558,11 +557,7 @@
|
||||
"value": "[ \\t\\r\\n]+"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
@@ -587,9 +582,8 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
@@ -601,11 +595,7 @@
|
||||
"value": "not"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
@@ -8598,6 +8588,9 @@
|
||||
[
|
||||
"predicate"
|
||||
],
|
||||
[
|
||||
"binaryOperator"
|
||||
],
|
||||
[
|
||||
"library",
|
||||
"load"
|
||||
|
||||
+39967
-39880
File diff suppressed because it is too large.
Load diff
@@ -182,3 +182,149 @@ If Is Not None
|
||||
(template
|
||||
(content))))
|
||||
(content))
|
||||
|
||||
==================
|
||||
If Is
|
||||
==================
|
||||
|
||||
{% if x is y %}a{% endif %}
|
||||
|
||||
---
|
||||
|
||||
(template
|
||||
(content)
|
||||
(if_group
|
||||
(if_clause
|
||||
(predicate
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier))))
|
||||
(binaryOperator)
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier)))))
|
||||
(template
|
||||
(content))))
|
||||
(content))
|
||||
|
||||
==================
|
||||
If Is Not
|
||||
==================
|
||||
|
||||
{% if x is not y %}a{% endif %}
|
||||
|
||||
---
|
||||
|
||||
(template
|
||||
(content)
|
||||
(if_group
|
||||
(if_clause
|
||||
(predicate
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier))))
|
||||
(binaryOperator)
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier)))))
|
||||
(template
|
||||
(content))))
|
||||
(content))
|
||||
|
||||
==================
|
||||
If Is Not Not
|
||||
==================
|
||||
|
||||
{% if x is not not y %}a{% endif %}
|
||||
|
||||
---
|
||||
|
||||
(template
|
||||
(content)
|
||||
(if_group
|
||||
(if_clause
|
||||
(predicate
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier))))
|
||||
(binaryOperator)
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier)))))
|
||||
(template
|
||||
(content))))
|
||||
(content))
|
||||
|
||||
==================
|
||||
If With A Repeated Not
|
||||
==================
|
||||
|
||||
{% if not not x %}a{% endif %}
|
||||
|
||||
---
|
||||
|
||||
(template
|
||||
(content)
|
||||
(if_group
|
||||
(if_clause
|
||||
(predicate
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier)))))
|
||||
(template
|
||||
(content))))
|
||||
(content))
|
||||
|
||||
==================
|
||||
If Not Before A Name Beginning With In
|
||||
==================
|
||||
|
||||
{% if not in_stock %}a{% endif %}
|
||||
|
||||
---
|
||||
|
||||
(template
|
||||
(content)
|
||||
(if_group
|
||||
(if_clause
|
||||
(predicate
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier)))))
|
||||
(template
|
||||
(content))))
|
||||
(content))
|
||||
|
||||
==================
|
||||
If Is Before A Name Beginning With Not
|
||||
==================
|
||||
|
||||
{% if x is nothing %}a{% endif %}
|
||||
|
||||
---
|
||||
|
||||
(template
|
||||
(content)
|
||||
(if_group
|
||||
(if_clause
|
||||
(predicate
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier))))
|
||||
(binaryOperator)
|
||||
(filtered_value
|
||||
(value
|
||||
(variable_attribute
|
||||
(identifier)))))
|
||||
(template
|
||||
(content))))
|
||||
(content))
|
||||
Reference in new issue
Block a user