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

Function parseAndOr

source code/utils/bash/bashParser.ts:881–921  ·  view source on GitHub ↗

* Parse pipeline chains joined by && ||. Left-associative nesting. * tree-sitter quirk: trailing redirect on the last pipeline wraps the ENTIRE * list in a redirected_statement — `a > x && b > y` becomes * redirected_statement(list(redirected_statement(a,>x), &&, b), >y).

(P: ParseState)

Source from the content-addressed store, hash-verified

879 * redirected_statement(list(redirected_statement(a,>x), &&, b), >y).
880 */
881function parseAndOr(P: ParseState): TsNode | null {
882 let left = parsePipeline(P)
883 if (!left) return null
884 while (true) {
885 const save = saveLex(P.L)
886 const t = nextToken(P.L, 'cmd')
887 if (t.type === 'OP' && (t.value === '&&' || t.value === '||')) {
888 const op = leaf(P, t.value, t)
889 skipNewlines(P)
890 const right = parsePipeline(P)
891 if (!right) {
892 left = mk(P, 'list', left.startIndex, op.endIndex, [left, op])
893 break
894 }
895 // If right is a redirected_statement, hoist its redirects to wrap the list.
896 if (right.type === 'redirected_statement' && right.children.length >= 2) {
897 const inner = right.children[0]!
898 const redirs = right.children.slice(1)
899 const listNode = mk(P, 'list', left.startIndex, inner.endIndex, [
900 left,
901 op,
902 inner,
903 ])
904 const lastR = redirs[redirs.length - 1]!
905 left = mk(
906 P,
907 'redirected_statement',
908 listNode.startIndex,
909 lastR.endIndex,
910 [listNode, ...redirs],
911 )
912 } else {
913 left = mk(P, 'list', left.startIndex, right.endIndex, [left, op, right])
914 }
915 } else {
916 restoreLex(P.L, save)
917 break
918 }
919 }
920 return left
921}
922
923function skipNewlines(P: ParseState): void {
924 while (true) {

Callers 2

parseStatementsFunction · 0.85
parseBacktickFunction · 0.85

Calls 7

parsePipelineFunction · 0.85
saveLexFunction · 0.85
nextTokenFunction · 0.85
leafFunction · 0.85
skipNewlinesFunction · 0.85
mkFunction · 0.85
restoreLexFunction · 0.85

Tested by

no test coverage detected