Skip to content

Token dependent indention - #106

Closed
lorenzwalthert wants to merge 27 commits into
r-lib:masterfrom
lorenzwalthert:token_dependent_indention
Closed

lorenzwalthert wants to merge 27 commits into
r-lib:masterfrom
lorenzwalthert:token_dependent_indention

Conversation

@lorenzwalthert

@lorenzwalthert lorenzwalthert commented Jul 31, 2017 •

Copy link
Copy Markdown
Collaborator

This PR consists of two parts:

Step 1: Allow for token-dependent indention
This implements #94 (and hence #66) rudimentary. By flattening out the nested parse table completely and computing the absolute position a token will take when serialised, we can use a look-up approach to set the indention of any token dependent on the indention of another token. There is room for improvement since set_token_dependent_indention() is really just work in progress and can be improved.

Step 2: Allow for styling without touching indention
Since step 1 implies to merge the spacing and indention information in enrich_terminals()into the column spaces, we are also able to discard the indention computed and use what we called raw indention, that is, take the indention from the input and don't modify it. The only thing for it to work is to not overwrite the spacing information if there is a line break after a token, which is checked via newlines. Since we modify lag_newlines before (in R/rules-line_breaks.R) and not newlines, this attribute needs to be updated after line breaks are set (closes #104). Hence, step 2 closes #105 and lays the foundations for #85.

@codecov

codecov Bot commented Jul 31, 2017 •

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@e0b2029). Click here to learn what that means.
The diff coverage is 98.65%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #106   +/-   ##
=========================================
  Coverage          ?   87.93%           
=========================================
  Files             ?       18           
  Lines             ?      721           
  Branches          ?        0           
=========================================
  Hits              ?      634           
  Misses            ?       87           
  Partials          ?        0
Impacted Files Coverage Δ
R/get_transformers.R 96.61% <100%> (ø)
R/modify_pd.R 90.9% <100%> (ø)
R/serialize.R 41.3% <100%> (ø)
R/unindent.R 98.24% <100%> (ø)
R/visit.R 100% <100%> (ø)
R/transform.R 88.88% <100%> (ø)
R/rules-spacing.R 93.87% <80%> (ø)
R/serialized_tests.R 88.76% <85.71%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0b2029...e6244f5. Read the comment docs.

@lorenzwalthert
lorenzwalthert force-pushed the token_dependent_indention branch from 15225be to 7cb0f54 Compare August 1, 2017 10:21
@lorenzwalthert

Copy link
Copy Markdown
Collaborator Author

I think this is quite a bit to review. Maybe we should even split it up. I believe that the code is not too bad, apart from everything in R/indent-token-dependent. I think I still have not found a good way of indenting token-dependent. It's all based on indices and maybe there are simpler ways to solve it.
Since for the tidyverse style guide, we only have token-dependent indention, we would not to have to bother about everything that is not a function declaration, but I found it better to solve the function calls also, i.e.

call(1, 
     3)

And then add a rule that turns that into

call(
  1, 
  3)

Or even

call(
  1, 
  3
)

@krlmlr

krlmlr commented Aug 3, 2017

Copy link
Copy Markdown
Member

If you can split it into smaller pieces, please do by all means -- these will be much easier to review.

@lorenzwalthert

Copy link
Copy Markdown
Collaborator Author

Ok, will do so. Will require some time though.

@lorenzwalthert

Copy link
Copy Markdown
Collaborator Author

This PR was split up in the above referenced pull requests and can hence be closed.

@lorenzwalthert
lorenzwalthert deleted the token_dependent_indention branch September 17, 2017 21:03
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.

Allow styling without modifying indention Decide on the usage of the newlines attribute

2 participants