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

Function write_between_bound

src/sql-parser/src/ast/defs/expr.rs:655–664  ·  view source on GitHub ↗

Write `bound` as a `BETWEEN … AND …` bound. The parser parses both bounds with `parse_subexpr(Precedence::Like)` (see `Parser::parse_between`), starting fresh with nothing to the bound's left, so it walks the bound's *left spine* and stops at the first operator binding at or below `Like`, leaving that operator outside the bound (`x BETWEEN 1 IS NULL AND y` parses `1` as the bound, then expects `AN

(f: &mut AstFormatter<W>, bound: &Expr<T>)

Source from the content-addressed store, hash-verified

653/// `Expr::Nested` (which is `ATOM`, so it prints bare). This re-adds the parens
654/// for ASTs where that wrapper is absent.
655fn write_between_bound<W: fmt::Write, T: AstInfo>(f: &mut AstFormatter<W>, bound: &Expr<T>) {
656 let needs_parens = left_edge(bound) <= prec::LIKE;
657 if needs_parens {
658 f.write_str("(");
659 f.write_node(bound);
660 f.write_str(")");
661 } else {
662 f.write_node(bound);
663 }
664}
665
666/// Output-precedence ranks, derived directly from the parser's [`Precedence`]
667/// ladder (higher binds tighter) so it stays the single source of truth:

Callers 1

fmtMethod · 0.85

Calls 3

left_edgeFunction · 0.85
write_nodeMethod · 0.80
write_strMethod · 0.45

Tested by

no test coverage detected