Skip to content

Support for curly-curly syntactic sugar - #528

Merged
lorenzwalthert merged 7 commits into
r-lib:masterfrom
lorenzwalthert:feature-curly-curly
Jun 30, 2019
Merged

lorenzwalthert merged 7 commits into
r-lib:masterfrom
lorenzwalthert:feature-curly-curly

Conversation

@lorenzwalthert

Copy link
Copy Markdown
Collaborator

Closes #526. Affecting both line break rules and spacing rules. Preserve testing of previous code (mostly focussed on indention) related to using two curly braces in a sequence was preserved, as we need this to work independently of the rule for {{. This is implemented using a version of the tidyverse style guide that turns off the rule for curly-curly.

@lorenzwalthert

Copy link
Copy Markdown
Collaborator Author

The problem with this PR is that it does not allow {{ to be on a separate line in a function call:

# this is bad when the function call name + indention is so long that we simply want the 
# first argument on a new line.
styler::style_text(
  "call(
  {{x}}
)"
)
#> call({{ x }})

# or less common
styler::style_text(
  "call(1, 2, 3, 4,
  4, 5,
  {{x}}, 
  5
)"
)
#> call(
#>   1, 2, 3, 4,
#>   4, 5, {{ x }},
#>   5
#> )

Created on 2019-06-29 by the reprex package (v0.2.1)

E.g. call({{\nx }}\n) should be left as is. Because we can't look into the future 2 steps (token_after), we need to compute the token ad-hoc, check if it is {, and if yes, we know it is a curly-curly expression. Leaves the minor edge case of an expression starting with `{{` but not being a curly-curly expression (e.g. `call(\n{{1} + 2})`) treated inconsistently beause we assume here it is a curly curly expression (as we only check for `{{` in the beginning. Result, first `{` is moved to the new line.
… not a child of pd and rules setting line breaks before that token is not within the scope of this function (plus you get an error with .rm_break_idx + 1L.
@lorenzwalthert

Copy link
Copy Markdown
Collaborator Author

Problem from above resolved with ba2d45d:

styler::style_text(
  "call(
  {{x}}
)"
)
#> call(
#>   {{ x }}
#> )
# or less common
styler::style_text(
  "call(1, 2, 3, 4,
  4, 5,
  {{x}}, 
  5
)"
)
#> call(
#>   1, 2, 3, 4,
#>   4, 5,
#>   {{ x }},
#>   5
#> )

Created on 2019-06-30 by the reprex package (v0.2.1)

@lorenzwalthert
lorenzwalthert merged commit c3bb1ce into r-lib:master Jun 30, 2019
@lorenzwalthert
lorenzwalthert deleted the feature-curly-curly branch June 30, 2019 15:52
@lorenzwalthert
lorenzwalthert restored the feature-curly-curly branch August 5, 2019 21:58
@lorenzwalthert
lorenzwalthert deleted the feature-curly-curly branch December 16, 2021 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

styler fails to correctly style syntactic rlang sugar {{

1 participant