11# ' The tidyverse style
2- # ' @param ... ...
3- # ' @export
4- tidyverse_style <- function (... ) {
5- get_transformers_nested(... )
6- }
7-
8- # ' Get the transformer functions for styling
9- # '
10- # ' @param flat Whether the transformer functions for flat or nested styling
11- # ' should be returned.
12- # ' @return A list of transformer functions that operate on flat parse tables.
13- # ' @param ... Parameters passed to
14- # ' * [get_transformers_flat()] if `flat = TRUE` or
15- # ' * [get_transformers_nested()] if `flat = FALSE`.
16- # ' @export
17- get_transformers <- function (flat = FALSE , ... ) {
18- if (flat ) {
19- get_transformers_flat(... )
20- } else {
21- get_transformers_nested(... )
22- }
23- }
24-
25- # ' Get the transformer functions for flat styling
26- # '
27- # ' @param strict A logical value indicating whether a set of strict
28- # ' or not so strict transformer functions should be returned.
29- # ' @param start_comments_with_one_space Whether or not comments should start
30- # ' with only one space (see [start_comments_with_space()]).
31- # ' @return A list of transformer functions that operate on flat parse
32- # ' tables.
33- # ' @export
34- # ' @family obtain transformers
35- # ' @importFrom purrr partial
36- get_transformers_flat <- function (strict = TRUE ,
37- start_comments_with_one_space = FALSE ) {
38- c(
39- fix_quotes ,
40- remove_space_before_closing_paren ,
41- if (strict ) remove_space_before_opening_paren ,
42- add_space_after_for_if_while ,
43- add_space_before_brace ,
44- if (strict ) set_space_around_op else add_space_around_op ,
45- if (strict ) set_space_after_comma else add_space_after_comma ,
46- remove_space_before_comma ,
47- remove_space_after_opening_paren ,
48- remove_space_after_excl ,
49- remove_space_before_dollar ,
50- partial(start_comments_with_space ,
51- force_one = start_comments_with_one_space ),
52- NULL )
53- }
54-
55- # ' Get the transformer functions for nested styling
56- # '
57- # ' Similar to [get_transformers_flat()], but additionally, returns some
58- # ' functions needed due the fact that styling is done in a nested way.
592# ' @param scope The extent of manipulation. Can range from "none" (least
603# ' invasive) to "token" (most invasive). See 'Details'. This argument is a
614# ' vector of length one.
625# ' @param indent_by How many spaces of indention should be inserted after
636# ' operators such as '('.
64- # ' @inheritParams get_transformers_flat
7+ # ' @param strict A logical value indicating whether a set of strict
8+ # ' or not so strict transformer functions should be returned.
9+ # ' @param start_comments_with_one_space Whether or not comments should start
10+ # ' with only one space (see [start_comments_with_space()]).
6511# ' @details The following options for `scope` are available.
6612# '
6713# ' * "none": Performs no transformation at all.
@@ -78,11 +24,10 @@ get_transformers_flat <- function(strict = TRUE,
7824# ' @family obtain transformers
7925# ' @importFrom purrr partial
8026# ' @export
81- get_transformers_nested <- function (
82- scope = " tokens" ,
83- strict = TRUE ,
84- indent_by = 2 ,
85- start_comments_with_one_space = FALSE ) {
27+ tidyverse_style <- function (scope = " tokens" ,
28+ strict = TRUE ,
29+ indent_by = 2 ,
30+ start_comments_with_one_space = FALSE ) {
8631
8732 scope <- character_to_ordered(
8833 scope ,
@@ -96,7 +41,21 @@ get_transformers_nested <- function(
9641 partial(indent_op , indent_by = indent_by ),
9742 partial(indent_eq_sub , indent_by = indent_by ),
9843 partial(indent_without_paren , indent_by = indent_by ),
99- get_transformers_flat(strict , start_comments_with_one_space ),
44+
45+ fix_quotes ,
46+ remove_space_before_closing_paren ,
47+ if (strict ) remove_space_before_opening_paren ,
48+ add_space_after_for_if_while ,
49+ add_space_before_brace ,
50+ if (strict ) set_space_around_op else add_space_around_op ,
51+ if (strict ) set_space_after_comma else add_space_after_comma ,
52+ remove_space_before_comma ,
53+ remove_space_after_opening_paren ,
54+ remove_space_after_excl ,
55+ remove_space_before_dollar ,
56+ partial(start_comments_with_space ,
57+ force_one = start_comments_with_one_space ),
58+
10059 remove_space_after_unary_pm_nested ,
10160 set_space_before_comments ,
10261 set_space_between_levels
@@ -139,6 +98,23 @@ get_transformers_nested <- function(
13998 )
14099}
141100
101+ # ' Create a style guide
102+ # '
103+ # ' This is a helper function to create a style guide, which is technically
104+ # ' speaking a named list of groups of transformer functions where each
105+ # ' transformer function corresponds to one styling rule. The output of this
106+ # ' function can be used as an argument for \code{style} in top level functions
107+ # ' like [style_text()] and friends.
108+ # ' @param filler A filler function that initializes various variables on each
109+ # ' level of nesting.
110+ # ' @param line_break A list of transformer functiosn that manipulate line_break
111+ # ' information.
112+ # ' @param space A list of transformer functions that manipulate spacing
113+ # ' information.
114+ # ' @param token A list of transformer functions that manipulate token text.
115+ # ' @param indention A list of transformer functions that manipulate indention.
116+ # ' @param use_raw_indention Boolean indicating wheter or not the raw indention
117+ # ' should be used.
142118# ' @export
143119create_style_guide <- function (filler ,
144120 line_break ,
0 commit comments