-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt to R devel parser #441
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2df14ec
trigger parsing failure on r devel
lorenzwalthert feb71f6
revert dummy implementation
lorenzwalthert b92e54c
implement on a nest level
lorenzwalthert 7a387a0
tree creator from parse data
lorenzwalthert 4788f2e
Using environments to manage parser versions
lorenzwalthert 25b0e28
close connection after it was used
lorenzwalthert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#' Work with parser versions | ||
#' | ||
#' The structure of the parse data affects many operations in styler. There was | ||
#' unexpected behaviour of the parser that styler was initially designed to work | ||
#' around. Examples are [#187](https://github.com/r-lib/styler/issues/187), | ||
#' [#216](https://github.com/r-lib/styler/issues/216), | ||
#' [#100](https://github.com/r-lib/styler/issues/100) and others. With | ||
#' [#419](https://github.com/r-lib/styler/issues/419), the structrure of the parse | ||
#' data changes and we need to dispatch for older versions. As it is inconvenient | ||
#' to pass a parser version down in the call stack in various places, the | ||
#' environment `env_current` is used to store the current version *globally* | ||
#' but internally. | ||
#' | ||
#' We version the parser as follows: | ||
#' | ||
#' * version 1: Before fix mentioned in #419. | ||
#' * version 2: After #419. | ||
#' | ||
#'The following utilities are available: | ||
#' | ||
#' * `parser_version_set()` sets the parser version in the environment | ||
#' `env_current`. | ||
#' * `parser_version_get()` retrieves the parser version from the | ||
#' environment `env_current`. | ||
#' * `parser_version_find()` determines the version of the parser from parse | ||
#' data. This does not necessarily mean that the version found is the | ||
#' actual version, but it *behaves* like it. For example, code that does not | ||
#' contain `EQ_ASSIGN` is parsed the same way with version 1 and 2. If the | ||
#' behaviour is identical, the version is set to 1. | ||
#' @param version The version of the parser to be used. | ||
#' @param pd A parse table such as the output from | ||
#' `utils::getParseData(parse(text = text))`. | ||
#' @keywords internal | ||
parser_version_set <- function(version) { | ||
env_current$parser_version <- version | ||
} | ||
|
||
#' @rdname parser_version_set | ||
parser_version_get <- function() { | ||
env_current$parser_version | ||
} | ||
|
||
#' @rdname parser_version_set | ||
parser_version_find <- function(pd) { | ||
ifelse(any(pd$token == "equal_assign"), 2, 1) | ||
} | ||
|
||
|
||
|
||
env_current <- rlang::new_environment(parent = rlang::empty_env()) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we leave
"EQ_ASSIGN"
here unconditionally?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. A few changes in #441 did not have any known effects on the styling, it's just about making the AST look the same. But probably it would break something because there was some reason why it was not included in the list I guess.