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

Method doc_function

src/sql-pretty/src/doc.rs:1399–1457  ·  view source on GitHub ↗
(&'a self, v: &'a Function<T>)

Source from the content-addressed store, hash-verified

1397 }
1398
1399 fn doc_function<'a, T: AstInfo>(&'a self, v: &'a Function<T>) -> RcDoc<'a> {
1400 match &v.args {
1401 FunctionArgs::Star => self.doc_display_pass(v),
1402 FunctionArgs::Args { args, order_by } => {
1403 if args.is_empty() {
1404 // Nullary, don't allow newline between parens, so just delegate.
1405 return self.doc_display_pass(v);
1406 }
1407 if v.filter.is_some() || v.over.is_some() || !order_by.is_empty() {
1408 return self.doc_display(v, "function filter or over or order by");
1409 }
1410 let name_stable = v.name.to_ast_string_stable();
1411 let special = match name_stable.as_str() {
1412 r#""extract""# if v.args.len() == Some(2) => true,
1413 r#""position""# if v.args.len() == Some(2) => true,
1414 _ => false,
1415 };
1416 if special {
1417 return self.doc_display(v, "special function");
1418 }
1419 // Mirror the same carve-out as the `AstDisplay for Function`
1420 // impl: function names that clash with a keyword having its
1421 // own special-grammar parser form (`(Kw, LParen)` dispatch in
1422 // parse_prefix) must be quoted on emit, or the reparse goes
1423 // through the special grammar instead of a regular call. (The
1424 // `ANY`/`ALL`/`SOME` quantifier keywords are handled more
1425 // generally by `can_be_printed_bare`, since they're also unsafe
1426 // as bare identifiers.)
1427 let needs_quote = matches!(
1428 name_stable.as_str(),
1429 r#""array""#
1430 | r#""coalesce""#
1431 | r#""exists""#
1432 | r#""extract""#
1433 | r#""greatest""#
1434 | r#""least""#
1435 | r#""list""#
1436 | r#""map""#
1437 | r#""normalize""#
1438 | r#""nullif""#
1439 | r#""position""#
1440 | r#""row""#
1441 | r#""substring""#
1442 | r#""trim""#
1443 );
1444 let printed_name = if needs_quote {
1445 name_stable
1446 } else {
1447 v.name.to_ast_string_simple()
1448 };
1449 let name = format!(
1450 "{}({}",
1451 printed_name,
1452 if v.distinct { "DISTINCT " } else { "" }
1453 );
1454 bracket(name, comma_separate(|e| self.doc_expr(e), args), ")")
1455 }
1456 }

Callers 1

doc_exprMethod · 0.80

Calls 11

bracketFunction · 0.85
comma_separateFunction · 0.85
doc_display_passMethod · 0.80
is_someMethod · 0.80
doc_displayMethod · 0.80
to_ast_string_stableMethod · 0.80
to_ast_string_simpleMethod · 0.80
doc_exprMethod · 0.80
is_emptyMethod · 0.45
as_strMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected