find_pos_id_to_keep: Find the pos ids to keep

View source: R/nest.R

find_pos_id_to_keepR Documentation

Find the pos ids to keep

Description

To make a parse table shallow, we must know which ids to keep. split(cumsum(pd_parent_first$parent == 0L)) above puts comments with negative parents in the same block as proceeding expressions (but also with positive). find_pos_id_to_keep() must hence always keep negative comments. We did not use split(cumsum(pd_parent_first$parent < 1L)) because then every top-level comment is an expression on its own and processing takes much longer for typical roxygen annotated code.

Usage

find_pos_id_to_keep(pd)

Arguments

pd

A temporary top-level nest where the first expression is always a top-level expression, potentially cached.

Details

Note that top-level comments above code have negative parents (the negative value of the parent of the code expression that follows after, another comment might be in the way though), all comments that are not top level have positive ids. All comments for which no code follows afterwards have parent 0.

Examples

styler:::get_parse_data(c("#", "1"))
styler:::get_parse_data(c("c(#", "1)"))
styler:::get_parse_data(c("", "c(#", "1)", "#"))

krlmlr/styler documentation built on Dec. 12, 2024, 8:36 a.m.