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

Function parseBacktick

src/utils/bash/bashParser.ts:3097–3146  ·  view source on GitHub ↗
(P: ParseState)

Source from the content-addressed store, hash-verified

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

Callers 3

parseWordFunction · 0.85
parseDoubleQuotedFunction · 0.85
parseExpansionRestFunction · 0.85

Calls 10

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

Tested by

no test coverage detected