196 Commits

Author SHA1 Message Date
René Kijewski
c8399c75ed parser: node::Loop is much bigger than the other variants 2023-08-01 13:04:41 +02:00
René Kijewski
11f3d0714c parser: move test for completeness 2023-08-01 13:04:41 +02:00
René Kijewski
4315773676 parser: add type for Node::Comment 2023-08-01 13:04:41 +02:00
René Kijewski
32cd2825c4 parser: add expr::Loop::parse() 2023-08-01 13:04:41 +02:00
René Kijewski
cdfe287b73 parser: remove re-exports parser::{node,expr}::* 2023-08-01 13:04:41 +02:00
René Kijewski
1521a08a20 parser: add type for Node::Extends 2023-08-01 13:04:41 +02:00
René Kijewski
14df8e16c1 parser: add type for Node::Include 2023-08-01 13:04:41 +02:00
René Kijewski
c5c46ada40 parser: rename Node::Cond into If and add type 2023-08-01 13:04:41 +02:00
René Kijewski
fa3a3271ee parser: add type for Node::Let 2023-08-01 13:04:41 +02:00
René Kijewski
6323b5e171 parser: add type for Node::Raw 2023-08-01 13:04:41 +02:00
René Kijewski
7b7c38b377 parser: add type for Node::Lit 2023-08-01 13:04:41 +02:00
René Kijewski
26f598c0d1 parser: add type for Node::BlockDef 2023-08-01 13:04:41 +02:00
René Kijewski
108c4a6a33 parser: add type for Node::Match 2023-08-01 13:04:41 +02:00
René Kijewski
4f52dbe8be parser: add type for Node::Call 2023-08-01 13:04:41 +02:00
René Kijewski
cd075630ea parser: add type for Node::Import 2023-08-01 13:04:41 +02:00
René Kijewski
222c42917a parser: let Macro know its name 2023-08-01 13:04:41 +02:00
René Kijewski
ffe267be7a parser: add Ast::nodes() method 2023-08-01 10:51:57 +02:00
René Kijewski
cbf766fa1f parser: impement PartialEq for Ast 2023-08-01 10:51:57 +02:00
René Kijewski
cfed9274e2 parser: implement Debug for Parsed 2023-08-01 10:51:57 +02:00
René Kijewski
382c3239f2 parser: use ? 2023-08-01 10:51:57 +02:00
René Kijewski
b3843d90a8 parser: ensure correct drop order for Parsed
According to [RFC 1857] the fields of a struct are dropped in the same
order as they are declared. For `struct S { a: A, b: B }` field `a` is
dropped before field `b`.

Our struct `Parsed` is self referencial. Its field `ast` depends on
`source`, so `source` must outlife `ast`. This PR changes the order of
the fields to reflect this requirement. In practice it should not
matter, because we know that the variant of `Node` won't access the
string data during their `Drop`, but better safe than sorry - maybe
`Node` changes in the future.

[RFC 1857]: https://rust-lang.github.io/rfcs/1857-stabilize-drop-order.html
2023-08-01 10:51:57 +02:00
René Kijewski
7c3a85de4f parser: remove panicking From<&str> for Whitespace 2023-08-01 07:06:30 +02:00
René Kijewski
985eb8955f Fix parsing arrays
This change

* allows using empty arrays `[]` in expessions,
* adds a cut when the leading `[` was encountered, and
* fixes the interaction between arrays and boolean OR.

IMO the restriction that you couldn't use empty arrays is not needed.
The missing cut made error messages slictly worse if you forget to add
the closing `]`.

Filter expressions must not have white spaces before the pipe `|`. The
white space is used to tell a filter expressions, and `std::ops::Or`
apart.
2023-07-31 21:29:35 +02:00
René Kijewski
107bdfdd76 Fix parsing calls
This change:

* adds a cut when the leading `(` was encountered, and
* fixed the interaction between call expressions and boolean OR.
2023-07-31 21:29:35 +02:00
Dirkjan Ochtman
266cefc321 parser: rename block to nodes 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
f9b2259cb7 parser: reorder items in node module 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
447aab0f10 parser: move Expr parser helpers into callers 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
40239f0f20 parser: move single expr parsers into Expr impl 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
ea1b4f9c41 parser: move binary operator parsers into Expr impl 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
8d8391543c parser: flatten top-level Expr interface 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
c5174eb829 parser: move suffix parsers into impl block 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
f4aa2e149c parser: move cond parsers into type impls 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
09865151e4 parser: move parser helpers into callers 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
997c5e1930 parser: move when parsers into impl block 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
65fb563082 parser: define a struct for Match 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
f16ddb14f0 parser: define a struct for Cond 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
cdbe8ef39f parser: move node parsers into impl block 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
aa22236a60 parser: move Whitespace parser into method 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
a50212a097 parser: move impl blocks closer to type definitions 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
dcfa5e1c69 parser: simplify top-level parser match 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
faf2e34cbf parser: add top-level Ast type 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
2376cc6815 parser: move nested_parenthesis() helper into node module 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
1677fd6f57 parser: move helper functions into State impl 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
17ee42cb6a parser: move trait impl closer to type definition 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
3603d43761 parser: move single-use functions into caller 2023-07-31 10:27:15 +02:00
Dirkjan Ochtman
e40e93796f Extract askama_parser crate 2023-07-31 10:27:15 +02:00