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

Newline isn't escaped when backslash is not preceded by whitespace #100

Closed
verhovsky opened this issue Sep 13, 2021 · 2 comments · Fixed by #102
Closed

Newline isn't escaped when backslash is not preceded by whitespace #100

verhovsky opened this issue Sep 13, 2021 · 2 comments · Fixed by #102

Comments

@verhovsky
Copy link
Collaborator

verhovsky commented Sep 13, 2021

echo a \
    b

parses correctly, however removing the space before the \

echo a\
    b

causes it to get parsed as a concatenation:

import Parser from 'web-tree-sitter';

await Parser.init();
const Bash = await Parser.Language.load('./tree-sitter-bash.wasm');
const parser = new Parser();
parser.setLanguage(Bash);

const result = parser.parse("echo a \\\n    b");
console.log(result.rootNode.toString())
console.log(result.rootNode.firstChild.children.map(x => x.text));

const badresult = parser.parse("echo a\\\n    b");
console.log(badresult.rootNode.toString())
console.log(badresult.rootNode.firstChild.children.map(x => x.text));

Output:

(program (command name: (command_name (word)) argument: (word) argument: (word)))
[ 'echo', 'a', 'b' ]
(program (command name: (command_name (word)) argument: (concatenation (word) (word))))
[ 'echo', 'a\\\n    b' ]

You can see that this doesn't happen on my GNU bash, version 5.1.8(1)-release (aarch64-apple-darwin20.4.0):

 $ echo a \
>   b
a b
$ echo a\
>   b
a b

there are multiple spaces before "b", but because bash parses them as two separate arguments, echo prints them separated by only 1 space, as expected.

@verhovsky verhovsky changed the title Newline when backslash is not preceded by whitespace Newline isn't escaped when backslash is not preceded by whitespace Sep 13, 2021
ahlinc added a commit to ahlinc/tree-sitter-bash that referenced this issue Sep 22, 2021
@verhovsky
Copy link
Collaborator Author

verhovsky commented Oct 14, 2021

@maxbrunsfeld

Screenshot 2023-05-30 at 11 44 05 AM

We just had a user open an issue about this.

@verhovsky
Copy link
Collaborator Author

@maxbrunsfeld if you find a chance to do it, can I get a release please?

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

Successfully merging a pull request may close this issue.

1 participant