MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_let_or_letrec

Function parse_let_or_letrec

src/expr-parser/src/parser.rs:221–245  ·  view source on GitHub ↗

Parses a Let or a LetRec with the new order: CTEs first in ascending order, and then Return.

(ctx: CtxRef, input: ParseStream)

Source from the content-addressed store, hash-verified

219
220 /// Parses a Let or a LetRec with the new order: CTEs first in ascending order, and then Return.
221 fn parse_let_or_letrec(ctx: CtxRef, input: ParseStream) -> Result {
222 let with = input.parse::<kw::With>()?;
223 let recursive = input.eat2(kw::Mutually, kw::Recursive);
224 let parse_ctes = ParseChildren::new(input, with.span().start());
225 let ctes = parse_ctes.parse_many(ctx, parse_cte)?;
226
227 let return_ = input.parse::<kw::Return>()?;
228 let parse_body = ParseChildren::new(input, return_.span().start());
229 let body = parse_body.parse_one(ctx, parse_expr)?;
230
231 if ctes.is_empty() {
232 let msg = "At least one `let cte` binding expected";
233 Err(Error::new(input.span(), msg))?
234 }
235
236 let cte_ids = ctes.iter().map(|(id, _, _)| id);
237 if !cte_ids.clone().is_sorted() {
238 let msg = format!(
239 "Error parsing Let/LetRec: seen With before Return, but cte ids are not ordered ascending: {:?}",
240 cte_ids.collect::<Vec<_>>()
241 );
242 Err(Error::new(input.span(), msg))?
243 }
244 build_let_or_let_rec(ctes, body, recursive, with)
245 }
246
247 fn build_let_or_let_rec(
248 ctes: Vec<(LocalId, Analyses, MirRelationExpr)>,

Callers 1

parse_exprFunction · 0.85

Calls 11

build_let_or_let_recFunction · 0.85
eat2Method · 0.80
spanMethod · 0.80
parse_manyMethod · 0.80
parse_oneMethod · 0.80
is_sortedMethod · 0.80
startMethod · 0.45
is_emptyMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected