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

Function nextToken

source code/utils/bash/bashParser.ts:304–593  ·  view source on GitHub ↗

* Scan next token. Context-sensitive: `cmd` mode treats [ as operator (test * command start), `arg` mode treats [ as word char (glob/subscript).

(L: Lexer, ctx: 'cmd' | 'arg' = 'arg')

Source from the content-addressed store, hash-verified

302 * command start), `arg` mode treats [ as word char (glob/subscript).
303 */
304function nextToken(L: Lexer, ctx: 'cmd' | 'arg' = 'arg'): Token {
305 skipBlanks(L)
306 const start = L.b
307 if (L.i >= L.len) return { type: 'EOF', value: '', start, end: start }
308
309 const c = L.src[L.i]!
310 const c1 = peek(L, 1)
311 const c2 = peek(L, 2)
312
313 if (c === '\n') {
314 advance(L)
315 return { type: 'NEWLINE', value: '\n', start, end: L.b }
316 }
317
318 if (c === '#') {
319 const si = L.i
320 while (L.i < L.len && L.src[L.i] !== '\n') advance(L)
321 return {
322 type: 'COMMENT',
323 value: L.src.slice(si, L.i),
324 start,
325 end: L.b,
326 }
327 }
328
329 // Multi-char operators (longest match first)
330 if (c === '&' && c1 === '&') {
331 advance(L)
332 advance(L)
333 return { type: 'OP', value: '&&', start, end: L.b }
334 }
335 if (c === '|' && c1 === '|') {
336 advance(L)
337 advance(L)
338 return { type: 'OP', value: '||', start, end: L.b }
339 }
340 if (c === '|' && c1 === '&') {
341 advance(L)
342 advance(L)
343 return { type: 'OP', value: '|&', start, end: L.b }
344 }
345 if (c === ';' && c1 === ';' && c2 === '&') {
346 advance(L)
347 advance(L)
348 advance(L)
349 return { type: 'OP', value: ';;&', start, end: L.b }
350 }
351 if (c === ';' && c1 === ';') {
352 advance(L)
353 advance(L)
354 return { type: 'OP', value: ';;', start, end: L.b }
355 }
356 if (c === ';' && c1 === '&') {
357 advance(L)
358 advance(L)
359 return { type: 'OP', value: ';&', start, end: L.b }
360 }
361 if (c === '>' && c1 === '>') {

Callers 15

parseProgramFunction · 0.85
parseStatementsFunction · 0.85
parseAndOrFunction · 0.85
skipNewlinesFunction · 0.85
parsePipelineFunction · 0.85
parseCommandFunction · 0.85
parseSimpleCommandFunction · 0.85
tryParseAssignmentFunction · 0.85
tryParseRedirectFunction · 0.85
parseWordFunction · 0.85
parseBacktickFunction · 0.85
parseIfFunction · 0.85

Calls 6

skipBlanksFunction · 0.85
advanceFunction · 0.85
isDigitFunction · 0.85
isWordStartFunction · 0.85
isWordCharFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected