1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Builds [`crate::ast::Node`] trees from [`crate::lexer::Token`] streams.
//!
//! `{{ … }}` bodies are parsed with [`parse_expr`] (nom-driven, Nunjucks-style precedence; see [`expr`]).
//! `{% … %}` supports `if` / `elif` / `else` / `endif`, `switch` / `case` / `default` / `endswitch`, `for` / `else` / `endfor` (multi-var / tuple unpack), `set` (incl. `endset` capture), `include` (expression + `ignore missing` + `with`/`without context`), `import` / `from` (macro libraries), `extends` (expression), `block` / `endblock`, `macro` / `endmacro` (defaults + call kwargs), `filter` / `endfilter`, `call` / `endcall`, and `raw` / `endraw` / `verbatim` / `endverbatim` (see [`template`]).
//! For unimplemented tags, use [`crate::tag_lex::tokenize_tag_body`] for tokenization only.
use crate;
use crateResult;
use crateExtensionTagMeta;
use crateToken;
use ;
/// Parses a token stream into a single [`Node::Root`] containing child nodes.
///
/// # Errors
///
/// Returns an error on malformed `{% %}` blocks, unknown tag keywords, or invalid expressions.
///
/// # Examples
///
/// ```
/// use runjucks_core::lexer::tokenize;
/// use runjucks_core::parser::parse;
///
/// let tokens = tokenize("a{{x}}b").unwrap();
/// let root = parse(&tokens).unwrap();
/// ```
/// Parse with custom extension tags registered on the [`crate::Environment`].
pub use is_reserved_tag_keyword;
/// Parses the inside of a `{{` … `}}` region into an [`Expr`].
///
/// # Errors
///
/// Invalid syntax or trailing garbage (after trim) yields [`RunjucksError`].
///
/// # Examples
///
/// ```
/// use runjucks_core::parser::parse_expr;
/// use runjucks_core::ast::Expr;
///
/// match parse_expr("foo").unwrap() {
/// Expr::Variable(name) => assert_eq!(name, "foo"),
/// _ => panic!("expected variable"),
/// }
/// ```