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

Function parseWord

source code/utils/bash/bashParser.ts:2010–2163  ·  view source on GitHub ↗

* Parse a word-position element: bare word, string, expansion, or concatenation * thereof. Returns a single node; if multiple adjacent fragments, wraps in * concatenation.

(P: ParseState, _ctx: 'cmd' | 'arg')

Source from the content-addressed store, hash-verified

2008 * concatenation.
2009 */
2010function parseWord(P: ParseState, _ctx: 'cmd' | 'arg'): TsNode | null {
2011 skipBlanks(P.L)
2012 const parts: TsNode[] = []
2013 while (P.L.i < P.L.len) {
2014 const c = peek(P.L)
2015 if (
2016 c === ' ' ||
2017 c === '\t' ||
2018 c === '\n' ||
2019 c === '\r' ||
2020 c === '' ||
2021 c === '|' ||
2022 c === '&' ||
2023 c === ';' ||
2024 c === '(' ||
2025 c === ')'
2026 ) {
2027 break
2028 }
2029 // < > are redirect operators unless <( >( (process substitution)
2030 if (c === '<' || c === '>') {
2031 if (peek(P.L, 1) === '(') {
2032 const ps = parseProcessSub(P)
2033 if (ps) parts.push(ps)
2034 continue
2035 }
2036 break
2037 }
2038 if (c === '"') {
2039 parts.push(parseDoubleQuoted(P))
2040 continue
2041 }
2042 if (c === "'") {
2043 const tok = nextToken(P.L, 'arg')
2044 parts.push(leaf(P, 'raw_string', tok))
2045 continue
2046 }
2047 if (c === '$') {
2048 const c1 = peek(P.L, 1)
2049 if (c1 === "'") {
2050 const tok = nextToken(P.L, 'arg')
2051 parts.push(leaf(P, 'ansi_c_string', tok))
2052 continue
2053 }
2054 if (c1 === '"') {
2055 // Translated string: emit $ leaf + string node
2056 const dTok: Token = {
2057 type: 'DOLLAR',
2058 value: '$',
2059 start: P.L.b,
2060 end: P.L.b + 1,
2061 }
2062 advance(P.L)
2063 parts.push(leaf(P, '$', dTok))
2064 parts.push(parseDoubleQuoted(P))
2065 continue
2066 }
2067 if (c1 === '`') {

Callers 9

parseSimpleCommandFunction · 0.85
tryParseAssignmentFunction · 0.85
tryParseRedirectFunction · 0.85
parseForFunction · 0.85
parseCaseFunction · 0.85
parseCasePatternFunction · 0.85
parseDeclarationFunction · 0.85
parseUnsetFunction · 0.85
parseTestPrimaryFunction · 0.85

Calls 13

skipBlanksFunction · 0.85
parseProcessSubFunction · 0.85
parseDoubleQuotedFunction · 0.85
nextTokenFunction · 0.85
leafFunction · 0.85
advanceFunction · 0.85
parseDollarLikeFunction · 0.85
parseBacktickFunction · 0.85
tryParseBraceExprFunction · 0.85
mkFunction · 0.85
tryParseBraceLikeCatFunction · 0.85
parseBareWordFunction · 0.85

Tested by

no test coverage detected