From the playground, but also seen on tree-sitter-bash 0.25.1 / tree-sitter 0.25.2
program [0, 0] - [4, 0]
test_command [0, 0] - [2, 3]
"[" [0, 0] - [0, 1]
redirected_statement [0, 2] - [2, 1]
body: command [0, 2] - [1, 4]
name: command_name [0, 2] - [0, 3]
number [0, 2] - [0, 3]
argument: word [0, 4] - [0, 7]
argument: number [0, 8] - [0, 9]
argument: word [0, 10] - [0, 11]
argument: word [1, 0] - [1, 4]
redirect: file_redirect [1, 5] - [2, 1]
">" [1, 5] - [1, 6]
destination: number [1, 6] - [1, 7]
destination: word [2, 0] - [2, 1]
"]" [2, 2] - [2, 3]
If two single-bracket test commands appear above and below a series of statements containing a redirection, both tests and all statements between will be interpreted as one large
redirected_statementinside a singletest_command. I believe this is a minimal example:which is (roughly) parsed as:
Full parse tree from playground
From the playground, but also seen on tree-sitter-bash 0.25.1 / tree-sitter 0.25.2
The problem still occurs when:
echoline (these will all be swallowed up by theredirected_statement)"strings",$variables)==,-eq,-ne,-lt,-gt,-ge,-le)!; adding terms with&&or||; encloding in the ternary operator, e.g.1 == 2 ? 3 : 4>,<,&>,>&',<&,>>`)echo), different destinations (tested descriptors0,1,2, and namesbar)The problem does not occur when the first test:
[ ],[ 0 ],[ -z "" ]), or their negation (e.g.[ ! 0 ], or[ ! -z "" ])-[a-z][a-z]) binary operator, except==,&&or||or when the
>redirection is replaced with a heredoc/herestring (<<<or<<)Hope that's useful, and thanks again!