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

Function parse_case

src/expr-parser/src/parser.rs:992–1010  ·  view source on GitHub ↗

Parses `case when {cond} then {then} else {els} end`.

(input: ParseStream)

Source from the content-addressed store, hash-verified

990
991 /// Parses `case when {cond} then {then} else {els} end`.
992 fn parse_case(input: ParseStream) -> Result {
993 input.parse::<kw::case>()?;
994 if input.peek(kw::when) {
995 input.parse::<kw::when>()?;
996 let cond = parse_expr(input)?;
997 input.parse::<kw::then>()?;
998 let then = parse_expr(input)?;
999 input.parse::<syn::Token![else]>()?;
1000 let els = parse_expr(input)?;
1001 input.parse::<kw::end>()?;
1002 Ok(MirScalarExpr::If {
1003 cond: Box::new(cond),
1004 then: Box::new(then),
1005 els: Box::new(els),
1006 })
1007 } else {
1008 Err(Error::new(input.span(), "expected 'when' after 'case'"))
1009 }
1010 }
1011
1012 pub fn parse_column(input: ParseStream) -> Result {
1013 Ok(MirScalarExpr::column(parse_column_index(input)?))

Callers 1

parse_operandFunction · 0.85

Calls 3

spanMethod · 0.80
parse_exprFunction · 0.70
peekMethod · 0.45

Tested by

no test coverage detected