Skip to content

Comments inside one-line backtick command expansions are not parsed properly -> # comment #116

Open

Description

@PowerUser64

When there is a comment inside `backticks`, the comment continues to the end of the line, rather than stopping at the closing backtick.

Example:

$ echo `echo hey # comment` there
hey there

Note the difference from the $() style of command substitution:

$ echo $(echo hey # comment) there
        )
hey

The first of these examples is the problematic one.

If you are wondering why anyone would do this, I have seen this technique used as a way of putting comments in tight places, like inside parts of pipelines.

$ printf 'hey %s' `# comment` |
  cat <<< 'there'
hey there

Activity

  1. changed the title [-]Comments inside one-line backtick command expansions are not parsed properly -> `\`# comment\``[/-] [+]Comments inside one-line backtick command expansions are not parsed properly -> `# comment`[/+] on Nov 30, 2021
  2. changed the title [-]Comments inside one-line backtick command expansions are not parsed properly -> `# comment`[/-] [+]Comments inside one-line backtick command expansions are not parsed properly -> \`# comment\`[/+] on Nov 30, 2021
  3. changed the title [-]Comments inside one-line backtick command expansions are not parsed properly -> \`# comment\`[/-] [+]Comments inside one-line backtick command expansions are not parsed properly -> `# comment`[/+] on Nov 30, 2021
  4. ahlinc commented on Aug 27, 2023

    @ahlinc
    Contributor

    Without above upstream feature this issue requires to handle comment nodes in external scanner what will make this parser very inefficient because external scanner would be triggered on every terminal symbol position.

    But looking on the current output:

    image

    I came up with an idea that maybe it's possible to handle only a part of comment after the # symbol in the external scanner, this would be pretty effective, but define node comment as the next so it wouldn't have any dangling nodes:

    comment: $ => seq(/#/, $._COMMENT_CONTENT),
  5. ahlinc commented on Aug 27, 2023

    @ahlinc
    Contributor

    The second case works fine:
    image


    The third case also has an issue:
    image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions