Repository navigation
Conversation
…nd a prelude lib.rs keeps only the public API, config.rs the options and the one place that builds the renderer config. The helpers that sat in nodes/mod.rs, node_list.rs and string.rs move to nodes/utils, and node files import them with use super::prelude::*. The three implementations of the leading comma become one.
The parenthesis rules of operators, AND/OR and casts move into one needs_parentheses in utils/predicates.rs. Files holding several nodes are split, and files are named after the node's field in pg_query.proto.
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 #987.
The helpers the node emitters share were spread over
nodes/mod.rs,node_list.rs,string.rsand a few node files, and node files reached them throughsuper::node_list::...,super::string::...or the re-exports innodes/mod.rs. This PR gives them one place,nodes/utils/, and one way in, a prelude. It moves code and changes no output: every snapshot stays as it is.What changed
lib.rsholds only the public API. The crate's modules are private.config.rsholdsFormatConfigand its option enums,IndentStyleandKeywordCaseincluded, and builds the renderer's config in one place (From<&FormatConfig> for RenderConfig).format_statementbuilt it a second time by hand.format_statement_unchecked, which does the same through the public API.pgls_configurationimportsIndentStyleandKeywordCasefrom the crate root.nodes/utils/:lists.rs: the list helpers fromnode_list.rs. The three implementations of the leading comma (comma lists, lists that break in expanded layout, grouped function arguments) and the fill separator become oneemit_list_comma. A fill list still leaves own-line comments to the next item, as before.tokens.rs: keywords, identifiers, quoting and literals fromstring.rs.string.rskeeps onlyemit_string.layout.rs: call arguments, clause conditions, parenthesized conditions and the layout break, fromnodes/mod.rs.comments.rs:emit_node_with,emit_with_comments_atandemit_comments_before_keyword, fromnodes/mod.rs.predicates.rs: the shape checks fromnodes/mod.rs, and oneneeds_parentheses(node, Position)in place of the three functions of that name ina_expr.rs,bool_expr.rsandtype_cast.rs. The operator precedence table moves along froma_expr.rs.nodes/prelude.rs: every node file importsuse super::prelude::*;plus its protobuf types.nodes/mod.rsholds the module declarations, the dispatch andemit_statement.pg_query.proto:bitstring.rs→bit_string.rs,checkpoint_stmt.rs→check_point_stmt.rs,sql_value_function.rs→sqlvalue_function.rs, and six more.DistinctExpr,NullIfExpr,AlternativeSubPlan,MergeWhenClause,AlterTableCmdandFunctionParameterget their own files.Not in this PR: the helpers that print a construct shared by several statements and still live in a node file (
emit_filter_clause,emit_set_clause_list,emit_grant_list, the JSON clauses, the function options, ...) move tonodes/clauses/in a later PR of this stack. The JSON node files are split there too, because they share those clauses.The printer's own
needs_quoting*intokens.rswere meant to be replaced bypgls_catalog::quote_identifier/needs_quotesfrom #981, which follow scan.l and gram.y. #981 isn't merged yet, so they stay for now. Swapping them is a small follow-up once it is.Tests
cargo test -p pgls_pretty_print: no snapshot changes.cargo test -p pgls_pretty_print --release --test option_matrix -- --ignoredcargo test -p pgls_workspace -p pgls_configuration formatandcargo test -p pgls_cli formatcargo clippy --workspace --all-targets -- -D warnings