Skip to content

Tools to insert tokens + application on if-else clauses - #212

Merged
lorenzwalthert merged 7 commits into
r-lib:masterfrom
lorenzwalthert:insert_tokens
Sep 25, 2017
Merged

lorenzwalthert merged 7 commits into
r-lib:masterfrom
lorenzwalthert:insert_tokens

Conversation

@lorenzwalthert

@lorenzwalthert lorenzwalthert commented Sep 21, 2017 •

Copy link
Copy Markdown
Collaborator

This PR provides tools to insert tokens to a parse table. In particular, a mechanism to create valid pos_id attributes for the new token is implemented to make the method secure. The application of interest was to wrap if-else clauses in curly brackets if they span multiple lines, i.e. to turn

if (x)
  q
else
 c

Into

if (x) {
  q
} else {
 c
}

styler will do the above only if strict = TRUE and scope = "tokens".

Closes #201.

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks great!

Comment thread R/token-create.R
spaces = spaces,
multi_line = rep(FALSE, len_text),
indention_ref_id = indention_ref_ids,
line1 = rep(NA, len_text),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather omit NA columns, and let bind_rows() take care of it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can do that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our bind_rows() implementation does only support matching column names.

styler:::bind_rows(data.frame(a = 1, b = 3), data.frame(b = 3, c = 4))
#> Error in match.names(clabs, names(xi)): names do not match previous names

@lorenzwalthert lorenzwalthert Sep 22, 2017 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe just revert to the initial PR.

Comment thread R/token-create.R Outdated
)
}

#' Create a valid pos_ids if possible

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop "a"

Comment thread R/token-create.R
spaces = spaces,
multi_line = rep(FALSE, len_text),
indention_ref_id = indention_ref_ids,
line1 = rep(NA, len_text),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can do that.

Let them being created when the row of the parse table is bound with the main table.
lorenzwalthert added a commit to lorenzwalthert/styler that referenced this pull request Sep 22, 2017
This reverts commit 3071a03
because styler:::bind_rows() (unlike dplyr::bind_rows()) does
not allow to bind data_frames that don't have the same column
names.
@lorenzwalthert
lorenzwalthert merged commit e67a227 into r-lib:master Sep 25, 2017
@lorenzwalthert
lorenzwalthert deleted the insert_tokens branch September 25, 2017 18:52
lorenzwalthert added a commit to lorenzwalthert/styler that referenced this pull request Sep 28, 2017
lorenzwalthert added a commit to lorenzwalthert/styler that referenced this pull request Sep 28, 2017
lorenzwalthert added a commit to lorenzwalthert/styler that referenced this pull request Sep 28, 2017
jonmcalder pushed a commit to jonmcalder/styler that referenced this pull request Oct 9, 2017
krlmlr added a commit that referenced this pull request Oct 23, 2017
- Hotfix: utf8 should not be verbose (#245).
- Allow styling of Rmd files(#233).
- Remove duplicate @family (#244).
- Fixing token insertion (#242).
- Capitalize Addin titles (#241).
- Explicit `NULL` creation to make styler compatible with R3.2.0 (#237).
- Improve vignettes (#232).
- Allow exclusion of files with `style_pkg()` and `style_dir()`.
- Correct styling with long strings (#230).
- Add tools for re-indenting tokens (#217).
- Math token spacing (#221).
- Remove outdated line and col information (#218).
- Empty input for styling does not cause an error (#227, #228).
- Tools to insert tokens + application on `if`-`else` clauses (#212).
- Improve example in documentation (#222).
- Fix spacing around in (#214).
- Maintenance: renaming functions / files, extend helper, documentation, if_else etc. (#204).
- Disallow line break after ( for function calls (#210).
- Preserve space between `!` and bang (#209).
- Simplify RStudio Addin (#208, #211).
- Indention based on square brackets (#207).
- Add vignette on introducing styler (#203).
- Indent function declaration without curly braces correctly (#202).
- Fix indention in if-else statement (#200).
- Sorting key (#196).
- Use safe sequences (#197).
- Fix space between two commas (#195).
- Keep single-line pipes on one line (#74).
- Remove tidyr and dplyr dependency (#182, #183, @jimhester).
- Fix parsing inconsistency (#188).
- Substitute create filler (#190).
- Introducing class vertical (#189).
- Adapt line break rules (#172).
- Fix `R CMD check` (#185).
- Force argument evaluation for proper error handling (#179).
- Add nonstrict version of set_space_before_comment (#174).
- Add installation instructions to README (#175).
- Addin to style highlighted region (#143).
- Improve spelling (#168).
- Add coverage badge
- Change badge from WIP to active
- Add the number of files to message (#166).
- Improve documentation (#164).
- Add informative messages while styling files (#165).
- More examples in help file (#161).
- No line breaks after pipe if comment is next token (#160).
- Fixing spacing around `!` (non-bang-bang) (#157).
- Finalize function documentation (#154).
- Review vignette (#158).
- Update bang-bang rule (#156).
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.

2 participants