Skip to content

Allowing line break transformers to depend on multi-line attribute #357

Closed

Description

@lorenzwalthert

Line break rules may depend on the structure of the parse table. So we may want to keep curly-brace-expressions as one-liner if the input was one line:

if (x) { x + (1+1) }

Note that this is not easily possible. The multi-line attribute is not up-to-date for the line break transformers, hence we cannot rely on it. Further, we cannot rely on line1 and line2, because this attribute was removed for safety beforehand (as it's also not up to date). We can try to "pre-reconstruct" the multi-line attribute by looking into the children, but that's brittle. One way out would be to split the line break transformers into two groups. One not depending on an up-to-date multi-line attribute and one dependent on it.
We could first apply the first transformer group, then update the multi-line attribute and then apply all transformers, updating the multi-line attribute between every transformer (which seems expensive).

Activity

  1. changed the title [-]Allowing line break transformers depending on multiline attribute[/-] [+]Allowing line break transformers to depend on multiline attribute[/+] on Feb 24, 2018
  2. changed the title [-]Allowing line break transformers to depend on multiline attribute[/-] [+]Allowing line break transformers to depend on multi-line attribute[/+] on Feb 24, 2018
  3. lorenzwalthert commented on Feb 26, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Reference: #342.

  4. lorenzwalthert commented on Feb 26, 2018

    @lorenzwalthert
    CollaboratorAuthor

    This requires style guides to have a new structure:

    create_style_guide(
        # transformer functions
        initialize                      = default_style_guide_attributes,
        line_break                      = line_break_manipulators,
        line_break_requiring_multi_line = new_transformers,  # new category
        space                           = space_manipulators,
        token                           = token_manipulators,
        indention                       = indention_modifier,
        # transformer options
        use_raw_indention               = use_raw_indention,
        reindention                     = reindention
      )
  5. lorenzwalthert commented on Feb 26, 2018

    @lorenzwalthert
    CollaboratorAuthor

    @krlmlr what do you think? This is needed to solve #353 (comment) and #342 properly, which I wanted to be part of milestone styler 1.0.1 but it seems time consuming. I think especially #342 should be solved as part of styler 0.1.0, especially the case we can solve with an improper approach (i.e. without solving #357) and using a one-level deep multi-line attribute via lag_newlines.

  6. krlmlr commented on Feb 26, 2018

    @krlmlr
    Member

    I don't mind postponing #353, let's add a test for the behavior in #342 instead ;-)

  7. lorenzwalthert commented on Feb 28, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Blocks #351.

  8. lorenzwalthert commented on Feb 28, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Blocks #342.

  9. lorenzwalthert commented on Mar 13, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Blocks #371.

  10. lorenzwalthert commented on Mar 14, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Blocks #363.

  11. krlmlr commented on Mar 21, 2018

    @krlmlr
    Member

    Does the increasing number of "blocks" increase the priority of this issue?

  12. lorenzwalthert commented on Mar 23, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Not if a review of the issues yields that half of them are not blocked anymore 😊

  13. lorenzwalthert commented on Oct 14, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Blocks #428 (if we agree on @krlmlr's viewpoint 😄).

  14. lorenzwalthert commented on Oct 14, 2018

    @lorenzwalthert
    CollaboratorAuthor

    It seems as a reasonable approach would indeed entail to add a new class of line-break transformers that require an up-to-date multi-line attribute as outlined above. This is potentially computatiaionally expensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions