MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / parseTestBinary

Function parseTestBinary

src/utils/bash/bashParser.ts:3817–3929  ·  view source on GitHub ↗
(P: ParseState, closer: string)

Source from the content-addressed store, hash-verified

3815}
3816
3817function parseTestBinary(P: ParseState, closer: string): TsNode | null {
3818 skipBlanks(P.L)
3819 // `!` in test context binds tighter than =~/==.
3820 // `[[ ! "x" =~ y ]]` → (binary_expression (unary_expression (string)) (regex))
3821 // `[[ ! -f x ]]` → (unary_expression ! (unary_expression (test_operator) (word)))
3822 const left = parseTestNegatablePrimary(P, closer)
3823 if (!left) return null
3824 skipBlanks(P.L)
3825 // Binary comparison: == != =~ -eq -lt etc.
3826 const c = peek(P.L)
3827 const c1 = peek(P.L, 1)
3828 let op: TsNode | null = null
3829 const os = P.L.b
3830 if (c === '=' && c1 === '=') {
3831 advance(P.L)
3832 advance(P.L)
3833 op = mk(P, '==', os, P.L.b, [])
3834 } else if (c === '!' && c1 === '=') {
3835 advance(P.L)
3836 advance(P.L)
3837 op = mk(P, '!=', os, P.L.b, [])
3838 } else if (c === '=' && c1 === '~') {
3839 advance(P.L)
3840 advance(P.L)
3841 op = mk(P, '=~', os, P.L.b, [])
3842 } else if (c === '=' && c1 !== '=') {
3843 advance(P.L)
3844 op = mk(P, '=', os, P.L.b, [])
3845 } else if (c === '<' && c1 !== '<') {
3846 advance(P.L)
3847 op = mk(P, '<', os, P.L.b, [])
3848 } else if (c === '>' && c1 !== '>') {
3849 advance(P.L)
3850 op = mk(P, '>', os, P.L.b, [])
3851 } else if (c === '-' && isIdentStart(c1)) {
3852 advance(P.L)
3853 while (isIdentChar(peek(P.L))) advance(P.L)
3854 op = mk(P, 'test_operator', os, P.L.b, [])
3855 }
3856 if (!op) return left
3857 skipBlanks(P.L)
3858 // In [[ ]], RHS of ==/!=/=/=~ gets special pattern parsing: paren counting
3859 // so @(a|b|c) doesn't break on |, and segments become extglob_pattern/regex.
3860 if (closer === ']]') {
3861 const opText = op.type
3862 if (opText === '=~') {
3863 skipBlanks(P.L)
3864 // If the ENTIRE RHS is a quoted string, emit string/raw_string not
3865 // regex: `[[ "$x" =~ "$y" ]]` → (binary_expression (string) (string)).
3866 // If there's content after the quote (`' boop '(.*)$`), the whole RHS
3867 // stays a single (regex). Peek past the quote to check.
3868 const rc = peek(P.L)
3869 let rhs: TsNode | null = null
3870 if (rc === '"' || rc === "'") {
3871 const save = saveLex(P.L)
3872 const quoted =
3873 rc === '"'
3874 ? parseDoubleQuoted(P)

Callers 1

parseTestUnaryFunction · 0.85

Calls 15

skipBlanksFunction · 0.85
advanceFunction · 0.85
isIdentStartFunction · 0.85
isIdentCharFunction · 0.85
saveLexFunction · 0.85
parseDoubleQuotedFunction · 0.85
leafFunction · 0.85
nextTokenFunction · 0.85
restoreLexFunction · 0.85
parseTestRegexRhsFunction · 0.85
parseTestExtglobRhsFunction · 0.85

Tested by

no test coverage detected