rune/ast/
local.rs

1use crate::ast::prelude::*;
2
3#[test]
4#[cfg(not(miri))]
5fn ast_parse() {
6    rt::<ast::Local>("let x = 1;");
7    rt::<ast::Local>("#[attr] let a = f();");
8    rt::<ast::Local>("let a = b{}().foo[0].await;");
9}
10
11/// A local variable declaration.
12///
13/// * `let <pattern> = <expr>;`
14#[derive(Debug, TryClone, PartialEq, Eq, ToTokens, Parse, Spanned)]
15#[non_exhaustive]
16pub struct Local {
17    /// The attributes for the let expression
18    #[rune(iter, meta)]
19    pub attributes: Vec<ast::Attribute>,
20    /// The `let` keyword.
21    pub let_token: T![let],
22    /// The `mut` token.
23    #[rune(iter)]
24    pub mut_token: Option<T![mut]>,
25    /// The name of the binding.
26    pub pat: ast::Pat,
27    /// The equality keyword.
28    pub eq: T![=],
29    /// The expression the binding is assigned to.
30    #[rune(parse_with = "parse_expr")]
31    pub expr: ast::Expr,
32    /// Trailing semicolon of the local.
33    pub semi: T![;],
34}
35
36fn parse_expr(p: &mut Parser<'_>) -> Result<ast::Expr> {
37    ast::Expr::parse_with(
38        p,
39        ast::expr::EAGER_BRACE,
40        ast::expr::EAGER_BINARY,
41        ast::expr::CALLABLE,
42    )
43}