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

Method fmt

src/sql-parser/src/ast/defs/expr.rs:204–548  ·  view source on GitHub ↗
(&self, f: &mut AstFormatter<W>)

Source from the content-addressed store, hash-verified

202
203impl<T: AstInfo> AstDisplay for Expr<T> {
204 fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
205 match self {
206 Expr::Identifier(s) => f.write_node(&display::separated(s, ".")),
207 Expr::QualifiedWildcard(q) => {
208 f.write_node(&display::separated(q, "."));
209 f.write_str(".*");
210 }
211 Expr::FieldAccess { expr, field } => {
212 write_dot_receiver(f, expr);
213 f.write_str(".");
214 f.write_node(field);
215 }
216 Expr::WildcardAccess(expr) => {
217 write_dot_receiver(f, expr);
218 f.write_str(".*");
219 }
220 Expr::Parameter(n) => f.write_str(&format!("${}", n)),
221 Expr::Not { expr } => {
222 f.write_str("NOT ");
223 // `NOT` binds tighter than `AND`/`OR`, so an operand exposing a
224 // looser operator on its left spine (`NOT (a OR b)`) must keep its
225 // parens once `Nested` is stripped. We use `left_edge`, since the
226 // `NOT` sits to the operand's left.
227 write_binary_operand(f, expr, left_edge(expr) < prec::NOT);
228 }
229 Expr::And { left, right } => {
230 write_binary_operand(f, left, right_edge(left) < prec::AND);
231 f.write_str(" AND ");
232 write_binary_operand(f, right, left_edge(right) <= prec::AND);
233 }
234 Expr::Or { left, right } => {
235 write_binary_operand(f, left, right_edge(left) < prec::OR);
236 f.write_str(" OR ");
237 write_binary_operand(f, right, left_edge(right) <= prec::OR);
238 }
239 Expr::IsExpr {
240 expr,
241 negated,
242 construct,
243 } => {
244 write_binary_operand(f, expr, right_edge(expr) < prec::IS);
245 f.write_str(" IS ");
246 if *negated {
247 f.write_str("NOT ");
248 }
249 // `IS DISTINCT FROM <rhs>` parses the RHS at the `IS` precedence
250 // (see `Parser::parse_is`), so a RHS whose left spine binds at or
251 // below `IS` re-associates out of the `IS` unless parenthesized
252 // (`a IS DISTINCT FROM b OR c` is `(a IS DISTINCT FROM b) OR c`).
253 // The other constructs (`NULL`/`TRUE`/…) are bare keywords.
254 if let IsExprConstruct::DistinctFrom(rhs) = construct {
255 f.write_str("DISTINCT FROM ");
256 write_binary_operand(f, rhs, left_edge(rhs) <= prec::IS);
257 } else {
258 f.write_node(construct);
259 }
260 }
261 Expr::InList {

Callers

nothing calls this directly

Calls 15

write_dot_receiverFunction · 0.85
write_binary_operandFunction · 0.85
left_edgeFunction · 0.85
right_edgeFunction · 0.85
write_between_boundFunction · 0.85
binary_op_precedenceFunction · 0.85
prints_self_delimitingFunction · 0.85
write_quantified_leftFunction · 0.85
write_subscript_receiverFunction · 0.85
write_nodeMethod · 0.80
is_someMethod · 0.80

Tested by

no test coverage detected