rune/ast/
expr_tuple.rs

1use crate::ast::prelude::*;
2
3#[test]
4#[cfg(not(miri))]
5fn ast_parse() {
6    rt::<ast::ExprTuple>("()");
7    rt::<ast::ExprTuple>("(1,)");
8    rt::<ast::ExprTuple>("(1, \"two\")");
9    rt::<ast::ExprTuple>("(1, 2,)");
10    rt::<ast::ExprTuple>("(1, 2, foo())");
11}
12
13/// An expression to construct a literal tuple.
14///
15/// * `(<expr>,*)`.
16#[derive(Debug, TryClone, PartialEq, Eq, Parse, ToTokens, Spanned)]
17#[non_exhaustive]
18pub struct ExprTuple {
19    /// Attributes associated with tuple.
20    #[rune(iter, meta)]
21    pub attributes: Vec<ast::Attribute>,
22    /// Items in the tuple.
23    pub items: ast::Parenthesized<ast::Expr, T![,]>,
24}
25
26impl ExprTuple {
27    /// Start parsing literal tuple from the middle of an expression.
28    pub(crate) fn parse_from_first_expr(
29        parser: &mut Parser<'_>,
30        attributes: Vec<ast::Attribute>,
31        open: ast::OpenParen,
32        expr: ast::Expr,
33    ) -> Result<Self> {
34        Ok(Self {
35            attributes,
36            items: ast::Parenthesized::parse_from_first(parser, open, expr)?,
37        })
38    }
39}