Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this a bug or not? String concatenation of backtick command substitution generating extra argument splits #215

Open
unphased opened this issue Sep 14, 2023 · 0 comments

Comments

@unphased
Copy link

unphased commented Sep 14, 2023

This code:

echo 'TESTING!' 'abc'$(pwd)"def"
echo 'TESTING2!' 'abc'`pwd`"def"
echo 'TESTING3!' 'abc'"$(pwd)""def"
echo 'TESTING4!' 'abc'"`pwd`""def"

Parses out to (this is a copy of TSPlayground output):

command [96, 0] - [96, 32]
  name: command_name [96, 0] - [96, 4]
    word [96, 0] - [96, 4]
  argument: raw_string [96, 5] - [96, 15]
  argument: concatenation [96, 16] - [96, 32]
    raw_string [96, 16] - [96, 21]
    command_substitution [96, 21] - [96, 27]
      command [96, 23] - [96, 26]
        name: command_name [96, 23] - [96, 26]
          word [96, 23] - [96, 26]
    string [96, 27] - [96, 32]
      string_content [96, 28] - [96, 31]
command [97, 0] - [97, 32]
  name: command_name [97, 0] - [97, 4]
    word [97, 0] - [97, 4]
  argument: raw_string [97, 5] - [97, 16]
  argument: raw_string [97, 17] - [97, 22]
  argument: concatenation [97, 22] - [97, 32]
    command_substitution [97, 22] - [97, 27]
      command [97, 23] - [97, 26]
        name: command_name [97, 23] - [97, 26]
          word [97, 23] - [97, 26]
    string [97, 27] - [97, 32]
      string_content [97, 28] - [97, 31]
command [98, 0] - [98, 34]
  name: command_name [98, 0] - [98, 4]
    word [98, 0] - [98, 4]
  argument: raw_string [98, 5] - [98, 15]
  argument: concatenation [98, 16] - [98, 34]
    raw_string [98, 16] - [98, 21]
    string [98, 21] - [98, 29]
      command_substitution [98, 22] - [98, 28]
        command [98, 24] - [98, 27]
          name: command_name [98, 24] - [98, 27]
            word [98, 24] - [98, 27]
    string [98, 29] - [98, 34]
      string_content [98, 30] - [98, 33]
command [99, 0] - [99, 34]
  name: command_name [99, 0] - [99, 4]
    word [99, 0] - [99, 4]
  argument: raw_string [99, 5] - [99, 16]
  argument: concatenation [99, 17] - [99, 34]
    raw_string [99, 17] - [99, 22]
    string [99, 22] - [99, 29]
      command_substitution [99, 23] - [99, 28]
        command [99, 24] - [99, 27]
          name: command_name [99, 24] - [99, 27]
            word [99, 24] - [99, 27]
    string [99, 29] - [99, 34]
      string_content [99, 30] - [99, 33]

I think it's clear that the whole "abc$(pwd)def" string should be a SINGLE argument in all cases. It is not working properly to generate it as a single argument (as a "concatenation" node) in the second case where backticks are used (without double quotes) to generate the command substitution. Note it is the only one that treesitter is parsing out to three arguments instead of the expected two.


I use this bash script to confirm the argument parsing that bash performs:

#!/bin/bash
 
ITERATION=1
while (( "$#" )); do 
  echo '$'"${ITERATION}: ${1}"
  shift
  (( ITERATION ++ ))
done

When replacing the echos with argshow above the output is as expected

$1: TESTING!
$2: abc/Users/sludef
$1: TESTING2!
$2: abc/Users/sludef
$1: TESTING3!
$2: abc/Users/sludef
$1: TESTING4!
$2: abc/Users/sludef

I was considering doing something in my tool built on top of tree-sitter to auto-enumerate arguments and this is one wrinkle that would make it potentially incorrect. 😀

@unphased unphased changed the title Is this a bug or not? String concatenation Is this a bug or not? String concatenation of backtick command substitution generating spurious argument count Sep 14, 2023
@unphased unphased changed the title Is this a bug or not? String concatenation of backtick command substitution generating spurious argument count Is this a bug or not? String concatenation of backtick command substitution generating extra arguments Sep 14, 2023
@unphased unphased changed the title Is this a bug or not? String concatenation of backtick command substitution generating extra arguments Is this a bug or not? String concatenation of backtick command substitution generating extra argument splits Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant