MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseBacktick

Function parseBacktick

source code/utils/bash/bashParser.ts:3103–3152  ·  view source on GitHub ↗
(P: ParseState)

Source from the content-addressed store, hash-verified

3101}
3102
3103function parseBacktick(P: ParseState): TsNode | null {
3104 const start = P.L.b
3105 advance(P.L)
3106 const open = mk(P, '`', start, P.L.b, [])
3107 P.inBacktick++
3108 // Parse statements inline — stop at closing backtick
3109 const body: TsNode[] = []
3110 while (true) {
3111 skipBlanks(P.L)
3112 if (peek(P.L) === '`' || peek(P.L) === '') break
3113 const save = saveLex(P.L)
3114 const t = nextToken(P.L, 'cmd')
3115 if (t.type === 'EOF' || t.type === 'BACKTICK') {
3116 restoreLex(P.L, save)
3117 break
3118 }
3119 if (t.type === 'NEWLINE') continue
3120 restoreLex(P.L, save)
3121 const stmt = parseAndOr(P)
3122 if (!stmt) break
3123 body.push(stmt)
3124 skipBlanks(P.L)
3125 if (peek(P.L) === '`') break
3126 const save2 = saveLex(P.L)
3127 const sep = nextToken(P.L, 'cmd')
3128 if (sep.type === 'OP' && (sep.value === ';' || sep.value === '&')) {
3129 body.push(leaf(P, sep.value, sep))
3130 } else if (sep.type !== 'NEWLINE') {
3131 restoreLex(P.L, save2)
3132 }
3133 }
3134 P.inBacktick--
3135 let close: TsNode
3136 if (peek(P.L) === '`') {
3137 const cStart = P.L.b
3138 advance(P.L)
3139 close = mk(P, '`', cStart, P.L.b, [])
3140 } else {
3141 close = mk(P, '`', P.L.b, P.L.b, [])
3142 }
3143 // Empty backticks (whitespace/newline only) are elided entirely by
3144 // tree-sitter — used as a line-continuation hack: "foo"`<newline>`"bar"
3145 // → (concatenation (string) (string)) with no command_substitution.
3146 if (body.length === 0) return null
3147 return mk(P, 'command_substitution', start, close.endIndex, [
3148 open,
3149 ...body,
3150 close,
3151 ])
3152}
3153
3154function parseIf(P: ParseState, ifTok: Token): TsNode {
3155 const ifKw = leaf(P, 'if', ifTok)

Callers 3

parseWordFunction · 0.85
parseDoubleQuotedFunction · 0.85
parseExpansionRestFunction · 0.85

Calls 9

advanceFunction · 0.85
mkFunction · 0.85
skipBlanksFunction · 0.85
saveLexFunction · 0.85
nextTokenFunction · 0.85
restoreLexFunction · 0.85
parseAndOrFunction · 0.85
leafFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected