From b131d40702eaff070c6b98ae1b5ed1f246d52540 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 19 Apr 2025 15:13:48 +0300 Subject: [PATCH] Add table expression constructor --- src/ast.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index fefbb48..a6fa7ce 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -88,6 +88,17 @@ impl Expression { pub fn new_variable(name: impl Into) -> Self { Self::Variable(Location::new_variable(name)) } + + pub fn new_table<'a>(fields: impl Iterator) -> Self { + Self::Table(Table { + fields: fields + .map(|(key, value)| Field { + name: Expression::new_constant(key), + init: value, + }) + .collect(), + }) + } } impl From<()> for Constant {