Repository navigation
Conversation
assert_node_variant!, the unreachable! on parser enums and the unwrap and expect on optional children are gone. A node of an unexpected kind is printed through emit_node, and a missing one is skipped. The output then has a different AST, which format_statement refuses.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #999.
The printer panicked on ASTs the parser doesn't build:
assert_node_variant!(22 call sites) panicked when a list held a node of another kind,unreachable!fired on theUndefinedvalues of parser enums, a NOT with other than one argument panicked, andunwrap/expectwere used on optional children (the offset of a window frame bound, the source of(a, b) = ..., the last argument of a VARIADIC call). A panic in the formatter takes down the request that triggered it.What changed
assert_node_variant!is gone. Where a list holds a node of an unexpected kind, the printer writes it withemit_node.Undefinedset operation, ON CONFLICT action or boolean operator, a constant without a value, a missing frame offset.(a, b) = ...without a source is written as a plain SET item. A source that claims more columns than the list has writes the ones there are, instead of slicing past the end.Either way the output has a different AST than the input, so
format_statementrefuses it and leaves the statement as written, which is what it should do with such an AST.Not changed: the
debug_assert!s that document what the parser builds stay, so debug builds and tests still notice a shape the printer doesn't expect. The renderer's checks that groups are balanced stay too: they check the emitter, not the AST.Tests
tests/malformed_ast.rstakes the ASTs of valid statements, breaks them (an Integer in the values of an enum, a String among ALTER TABLE commands, a NOT with two arguments, a constant without a value, a frame bound without its offset), and checks that they print. Each of them panicked before.cargo test -p pgls_pretty_print: no snapshot changes.cargo test -p pgls_pretty_print --release --test option_matrix -- --ignoredcargo clippy --workspace --all-targets -- -D warnings