Skip to content

parse difference for heredoc with multiple consecutive line continuations #3837

@froydnj

Description

@froydnj

I think this is like #2842, but with more line continuations:

description = <<~EOS
  This line\
  \
  Another line.

  Extra rationale.
EOS

bin/prism ripper gives:

Ripper:
[:program,
 [:stmts_add,
  [:stmts_new],
  [:assign,
   [:var_field, [:@ident, "description", [1, 0]]],
   [:string_literal,
    [:string_add,
     [:string_add,
      [:string_add, [:string_add, [:string_add, [:string_content], [:@tstring_content, "This line\\\n", [2, 2]]], [:@tstring_content, "  \\\n", [3, 0]]], [:@tstring_content, "Another line.\n", [4, 2]]],
      [:@tstring_content, "\n", [5, 0]]],
     [:@tstring_content, "Extra rationale.\n", [6, 2]]]]]]]
Prism:
[:program,
 [:stmts_add,
  [:stmts_new],
  [:assign,
   [:var_field, [:@ident, "description", [1, 0]]],
   [:string_literal,
    [:string_add,
     [:string_add, [:string_add, [:string_add, [:string_content], [:@tstring_content, "  This line\\\n", [2, 0]]], [:@tstring_content, "Another line.\n", [4, 2]]], [:@tstring_content, "\n", [5, 0]]],
     [:@tstring_content, "Extra rationale.\n", [6, 2]]]]]]]
Output is not identical

The second line continuation is nowhere to be found in the prism output. I'm not sure how deeply you care about this, given that the ultimate output is unchanged, but it was a little surprising that the parse tree didn't really correspond to the source for this bit.

Found while debugging fables-tables/rubyfmt#772. (cc @reese)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions