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

Function parse_let_or_letrec_old

src/expr-parser/src/parser.rs:193–218  ·  view source on GitHub ↗

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

(ctx: CtxRef, input: ParseStream)

Source from the content-addressed store, hash-verified

191
192 /// Parses a Let or a LetRec with the old order: Return first, and then CTEs in descending order.
193 fn parse_let_or_letrec_old(ctx: CtxRef, input: ParseStream) -> Result {
194 let return_ = input.parse::<kw::Return>()?;
195 let parse_body = ParseChildren::new(input, return_.span().start());
196 let body = parse_body.parse_one(ctx, parse_expr)?;
197
198 let with = input.parse::<kw::With>()?;
199 let recursive = input.eat2(kw::Mutually, kw::Recursive);
200 let parse_ctes = ParseChildren::new(input, with.span().start());
201 let mut ctes = parse_ctes.parse_many(ctx, parse_cte)?;
202
203 if ctes.is_empty() {
204 let msg = "At least one Let/LetRec cte binding expected";
205 Err(Error::new(input.span(), msg))?
206 }
207
208 ctes.reverse();
209 let cte_ids = ctes.iter().map(|(id, _, _)| id);
210 if !cte_ids.clone().is_sorted() {
211 let msg = format!(
212 "Error parsing Let/LetRec: seen Return before With, but cte ids are not ordered descending: {:?}",
213 cte_ids.collect::<Vec<_>>()
214 );
215 Err(Error::new(input.span(), msg))?
216 }
217 build_let_or_let_rec(ctes, body, recursive, with)
218 }
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 {

Callers 1

parse_exprFunction · 0.85

Calls 11

build_let_or_let_recFunction · 0.85
spanMethod · 0.80
parse_oneMethod · 0.80
eat2Method · 0.80
parse_manyMethod · 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