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

Function parseAndOr

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

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

Tested by

no test coverage detected