Skip to content

Commit 60806e5

Browse files
use *nest* terminology
1 parent 58276a9 commit 60806e5

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

vignettes/customizing_styler.Rmd

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ There are three major steps that styler performs in order to style code:
2121
this a nested parse table. You can learn more about how that is done
2222
exactly in the vignettes "Data Structures" and "Manipulating the nested
2323
parse table".
24-
2. Apply transformer functions at each level of the nested parse table. In
25-
particular, we create two columns `lag_newlines` and `spaces`, which contain
24+
2. Apply transformer functions at each level of the nested parse table. We
25+
use a visitor approach, i.e. a function that takes functions as arguments and
26+
applies them to every level of nesting. You can find out more about it on
27+
the help file for `visit`. Note that the function is not exported by styler.
28+
The visitor will take care of applying the functions on every
29+
level of nesting - and we can supply transformer functions that operate on
30+
one level of nesting. In the sequel, we use the term *nest* to refer to
31+
such a parse table at one level of nesting. A *nest* always represents a
32+
complete expression. Before we apply the transformers, we have to initialize
33+
two columns `lag_newlines` and `spaces`, which contain
2634
the number of line breaks before the token and the number of spaces
2735
after the token. These will be the columns that most of our transformer
28-
functions will modify. To go through the whole nested structure and apply
29-
the transformer functions repeatedly on every level of nesting, we use
30-
a visitor approach, i.e. a function that takes functions as arguments and
31-
applies them to every level of nesting.
36+
functions will modify.
3237
3. Serialize the nested parse table, that is, extract the terminal tokens from
3338
the nested parse table and add spaces and line breaks between them as
3439
specified in the nested parse table.
@@ -57,10 +62,10 @@ tidyverse_style()$space$remove_space_after_opening_paren
5762
```
5863

5964
As the name says, this function removes spaces after the opening parenthesis. But
60-
how? Its input is a flat parse table. Since the visitor functions `pre_visit()`
61-
and `post_visit()` will go through all levels of nesting, we don't need to care
62-
about that - we just need a function that can be applied to a flat parse table,
63-
i.e at one level of nesting.
65+
how?
66+
Its input is a *nest*. Since the visitor will go through all levels of nesting,
67+
we just need a function that can be applied to a *nest*, that is, to a parse
68+
table at one level of nesting.
6469
We can compute the nested parse table and look at one of the levels of nesting
6570
that is interesting for us (more on the data structure in the vignettes
6671
"Data structures" and "Manipulating the parse table"):

0 commit comments

Comments
 (0)