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

Function parseWord

src/utils/bash/bashParser.ts:2004–2157  ·  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

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

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
tryParseBraceLikeCatFunction · 0.85
parseBareWordFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected