Repository navigation
Conversation
…ywords as clauses
…/RESTRICT as clauses
…em option variants as clauses
… node its own file
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 #996.
Many statements print the same constructs, and each had its own copy: 13 files mapped
ObjectTypeto keywords, with about 250 match arms between them, the window frame was written twice,OPTIONS (...)eight times, the operator class name four times, and so on. Others lived in one node file and were called from others throughsuper::<file>::<helper>. This PR moves them tonodes/clauses/, one file per construct, reached through the prelude likeutils/. No snapshot changes.What changed
nodes/clauses/:object_type.rs:object_type_keywords(ObjectType), the one table ofMATERIALIZED VIEW,TEXT SEARCH PARSER, ... used by DROP, ALTER ... OWNER, RENAME, SET SCHEMA, COMMENT, SECURITY LABEL, GRANT, ALTER TABLE and the rest. Each statement keeps its own fallback (TABLE,OBJECT, ...). COMMENT comparedobjtypeagainst numbers (== 7); it usesObjectTypenow.modifiers.rs:IF EXISTS,IF NOT EXISTS,OR REPLACE(36 copies), andCASCADE/RESTRICT(emit_drop_behavior, 12 copies).options.rs:WITH (...),OPTIONS (...), and the DefElem variants that were exported bydef_elem.rs(generic, sequence, role and grant-role options).window_frame.rs: the frame clause, with the frame option bits, fromwindow_def.rsandwindow_clause.rs.operators.rsandoperator_class.rs:OPERATOR(schema.+)in expressions and ORDER BY ... USING,schema.+in DDL, andname USING method.function_options.rs: the option order and printing of CREATE / ALTER FUNCTION.normalize.rssorts by the same order now.set_clause.rs,filter.rs,grant.rs,case_result.rs,json.rs: the SET list, FILTER, the grant lists, the result of a CASE branch, and the SQL/JSON RETURNING / FORMAT / ON EMPTY / ON ERROR clauses.The JSON nodes get a file each (
json_output.rs,json_format.rs,json_returning.rs,json_behavior.rs,json_argument.rs,json_table_column.rs, ...). The node variants that other files called throughsuper::<file>::take an enum and go throughnodes/mod.rs:emit_type_cast_as(.., CastSpelling::Call),emit_bool_expr_as(.., OperandGroup::Enclosing),emit_window_def_as(.., WindowForm::Named),emit_range_var_as(.., Only::Omitted),emit_case_expr_as(.., BranchPlacement::Indented). No node file callssuper::<file>::any more.Where the copies disagreed
The output stays as it was:
all (a), with a space before the columns (clauses/grant.rs). AnAccessPrivreached throughemit_node(ALTER DEFAULT PRIVILEGES) writesall privileges (a), may break before the column list, and has a group of its own (access_priv.rs).SERVEReverywhere except GRANT and SECURITY LABEL, which writeFOREIGN SERVER.RESTRICT. The others only writeCASCADE(Restrict::Written/Restrict::Omitted).ROWS/UNBOUNDED PRECEDING). The window of a call doesn't (SingleBoundBreak).JsonBehaviornode writescoerceand has a group of its own. The behaviors of JSON_VALUE / JSON_QUERY don't. Both share the keywords.x = ANY (...)keeps only the symbol of a qualified operator (sub_link.rs). The doc comment ofoperators.rspoints there.normalize.rsput it last because it didn't know the option. Normalization sorts both ASTs by the same key, and TRANSFORM was the only option in its class, so sorting by the printer's order compares the same way.normalize.rsusesfunction_option_ordernow.One difference that isn't a pure move: SECURITY LABEL and ALTER EXTENSION ADD/DROP listed fewer object types than the shared table, and wrote
TABLE/OBJECTfor the others (a materialized view, for instance). That output had a different AST, soformat_statementrefused it and left the statement as written. With the shared table they write the right keywords. Where the old copies of DROP, ALTER ... OWNER and RENAME fell back toTABLE, the types in question (a role, a cast, a transform) can't occur in those statements.Tests
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