styler (version 1.10.3)

compute_indent_indices: Compute the indices that need indention

Description

Based on token, find the rows in pd that need to be indented.

Usage

compute_indent_indices(pd, token_opening, token_closing = NULL)

Arguments

pd

A parse table.

token_opening

A character vector with tokens that could induce indention for subsequent tokens.

token_closing

A character vector with tokens that could terminate indention for previous tokens. If NULL (the default), indention should end with the last token in the parse table.

Handing of <code>[[</code>

Since text [[ has token "LBB" and text ]] is parsed as two independent ] (see 'Examples'), indention has to stop at the first ].

Details

Two cases are fundamentally different:

  • Indention based on operators (e.g '+'), where all subsequent tokens should be indented.

  • Indention based on braces (e.g. '('), where just the tokens between the opening and the closing brace have to be indented.

To cover the second case, we need token_closing because it cannot be taken for granted that token_closing is always the last token in pd. For example in if-else expressions, this is not the case and indenting everything between '(' and the penultimate token would result in the wrong formatting.

Examples

Run this code
styler:::parse_text("a[1]")
styler:::parse_text("a[[1\n]]")

Run the code above in your browser using DataLab