73 Commits

Author SHA1 Message Date
Andrew Dona-Couch
6cbfde0451 Derive Clone for Expr and Target 2023-11-13 20:24:02 +01:00
Guillaume Gomez
76462255ea Create a type alias for all IResult to simplify code reading 2023-10-25 16:26:36 +02:00
Guillaume Gomez
d48ac76f0a Improve error for elif keyword 2023-10-25 14:54:14 +02:00
Guillaume Gomez
c056d6287b Improve error for invalid name used in endmacro 2023-10-25 14:30:35 +02:00
Guillaume Gomez
c3281e353d Improve error for invalid name used in endblock 2023-10-25 14:30:35 +02:00
Guillaume Gomez
6dae920a45 Create ErrorContext type 2023-10-25 14:30:35 +02:00
Dirkjan Ochtman
a6bc14c8ca Advertise Discord channel instead of Gitter 2023-10-03 17:39:03 +02:00
Dirkjan Ochtman
22ec6c95a1 parser: version bump to 0.1.1 2023-09-29 17:07:12 +02:00
Dirkjan Ochtman
1ce939a729 parser: add rudimentary README 2023-09-29 17:07:12 +02:00
Dirkjan Ochtman
daa8d89b57 Add MSRV checking in CI
Bump MSRV to 1.65 for the use of let .. else.
2023-09-29 16:13:24 +02:00
René Kijewski
eef38cea67 Pass Node parsing level to expressions 2023-09-28 17:28:26 +02:00
René Kijewski
238e4bbad7 Limit nesting in parser nodes, too 2023-09-28 17:28:26 +02:00
Dirkjan Ochtman
36f4442978 Require Expr::parse() callers to supply Level 2023-09-28 17:28:26 +02:00
Dirkjan Ochtman
5718175291 Move Level into the crate root 2023-09-28 17:28:26 +02:00
Dirkjan Ochtman
5ab8813fe2 Yield a parser error when defining a macro named 'super' 2023-09-28 15:40:57 +02:00
Dirkjan Ochtman
c8530493a1 Limit expression nesting level to avoid stack overflows 2023-09-28 14:43:44 +02:00
manunio
2ef2b9db9e fuzz: remove input limit
While working on https://github.com/djc/askama/pull/862 fuzz_parser was
crashing and failing oss-fuzz build_checks. so a limit of 500 was placed, this pr removes that.
2023-09-18 15:57:17 +02:00
manunio
8f3140a33f fuzz: Add fuzz for askama_parser 2023-09-13 14:48:08 +02:00
Dirkjan Ochtman
2e8e42af45 Use char_indices() to get byte indices for characters 2023-09-11 12:19:16 +02:00
Dirkjan Ochtman
dd9635ace6 Rename some variables 2023-09-11 12:19:16 +02:00
René Kijewski
d4fbad1db2 Optimize parsing boolean literals, too 2023-08-03 00:02:04 +02:00
René Kijewski
95ff27c087 Parse paths and identifiers only once
In the old implementation each variable in an expression would be parsed
up to three times:

* Try to parse a path because it contains a leading double colon, or
  infix double colons.
* Try to parse it as path again by scanning for an identifier that
  contains an upper case character.
* Fall back to scanning for any identifier.

This PR turns all three steps into one, without the need for
backtracking.
2023-08-03 00:02:04 +02:00
René Kijewski
d38e2b4e26 parser: fix white space issues in macro parsing 2023-08-02 11:09:05 +02:00
René Kijewski
06ad86b1e1 parser: allow negative numbers in patterns 2023-08-02 11:09:05 +02:00
René Kijewski
50745e41c2 parser: don't truncates whitespaces after arrays 2023-08-02 11:09:05 +02:00
René Kijewski
d09041bd0a parser: better error message for unknown nodes 2023-08-02 11:09:05 +02:00
René Kijewski
04e585b9d2 parser: import parser::{Expr, Node} 2023-08-01 13:04:41 +02:00
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