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

Function try_parse_mir

src/expr-parser/src/parser.rs:30–50  ·  view source on GitHub ↗

Builds a [mz_expr::MirRelationExpr] from a string.

(catalog: &TestCatalog, s: &str)

Source from the content-addressed store, hash-verified

28
29/// Builds a [mz_expr::MirRelationExpr] from a string.
30pub fn try_parse_mir(catalog: &TestCatalog, s: &str) -> Result<mz_expr::MirRelationExpr, String> {
31 // Define a Parser that constructs a (read-only) parsing context `ctx` and
32 // delegates to `relation::parse_expr` by passing a `ctx` as a shared ref.
33 let parser = move |input: ParseStream| {
34 let ctx = Ctx { catalog };
35 relation::parse_expr(&ctx, input)
36 };
37 // Since the syn lexer doesn't parse comments, we replace all `// {`
38 // occurrences in the input string with `:: {`.
39 let s = s.replace("// {", ":: {");
40 // Call the parser with the given input string.
41 let mut expr = parser.parse_str(&s).map_err(|err| {
42 let (line, column) = (err.span().start().line, err.span().start().column);
43 format!("parse error at {line}:{column}:\n{err}\n")
44 })?;
45 // Fix the types of the local let bindings of the parsed expression in a
46 // post-processing pass.
47 relation::fix_types(&mut expr, &mut relation::FixTypesCtx::default())?;
48 // Return the parsed, post-processed expression.
49 Ok(expr)
50}
51
52/// Builds a source definition from a string.
53pub fn try_parse_def(catalog: &TestCatalog, s: &str) -> Result<Def, String> {

Callers 5

handle_roundtripFunction · 0.85
executeMethod · 0.85
handle_explainFunction · 0.85
handle_typecheckFunction · 0.85
apply_transformFunction · 0.85

Calls 5

fix_typesFunction · 0.85
spanMethod · 0.80
parse_exprFunction · 0.70
replaceMethod · 0.45
startMethod · 0.45

Tested by 3

handle_explainFunction · 0.68
handle_typecheckFunction · 0.68
apply_transformFunction · 0.68