Skip to main content

bash_test_connective

Function bash_test_connective 

Source
pub fn bash_test_connective(
    op: &Node<'_>,
    parent: &Node<'_>,
    code: &[u8],
) -> Option<Bash>
Expand description

The && / || a [ … ] connective stands for: Some(AMPAMP) for -a and Some(PIPEPIPE) for -o, when op, a child of parent, is one.

tree-sitter-bash gives every -x operator the one kind test_operator, so the text decides. Only a binary position joins two tests: the unary -a FILE (a file-exists test) has a unary_expression parent and is a comparison like -f FILE. Every expression kind is matched by name, not by kind_id, because the grammar aliases binary_expression five times (grammar-dispatch §1).

The test builtin spelling (test "$a" = 1 -a "$b" = 2) is out of reach: the grammar parses its arguments as plain words, so neither its comparisons nor its connectives exist as nodes, and it scores as one command.