* Can the current position start a redirect destination literal? * Returns false at redirect ops, terminators, or file-descriptor-prefixed ops * so file_redirect's repeat1($._literal) stops at the right boundary.
(P: ParseState)
| 1586 | * so file_redirect's repeat1($._literal) stops at the right boundary. |
| 1587 | */ |
| 1588 | function isRedirectLiteralStart(P: ParseState): boolean { |
| 1589 | const c = peek(P.L) |
| 1590 | if (c === '' || c === '\n') return false |
| 1591 | // Shell terminators and operators |
| 1592 | if (c === '|' || c === '&' || c === ';' || c === '(' || c === ')') |
| 1593 | return false |
| 1594 | // Redirect operators (< > with any suffix; <( >( handled by caller) |
| 1595 | if (c === '<' || c === '>') { |
| 1596 | // <( >( are process substitutions — those ARE literals |
| 1597 | return peek(P.L, 1) === '(' |
| 1598 | } |
| 1599 | // N< N> file descriptor prefix — starts a new redirect, not a literal |
| 1600 | if (isDigit(c)) { |
| 1601 | let j = P.L.i |
| 1602 | while (j < P.L.len && isDigit(P.L.src[j]!)) j++ |
| 1603 | const after = j < P.L.len ? P.L.src[j]! : '' |
| 1604 | if (after === '>' || after === '<') return false |
| 1605 | } |
| 1606 | // `}` only terminates if we're in a context where it's a closer — but |
| 1607 | // file_redirect sees `}` as word char (e.g., `>$HOME}` is valid path char). |
| 1608 | // Actually `}` at top level terminates compound_statement — need to stop. |
| 1609 | if (c === '}') return false |
| 1610 | // Test command closer — when parseSimpleCommand is called from `[` context, |
| 1611 | // `]` must terminate so parseCommand can return and `[` handler consume it. |
| 1612 | if (P.stopToken === ']' && c === ']') return false |
| 1613 | return true |
| 1614 | } |
| 1615 | |
| 1616 | /** |
| 1617 | * Parse a redirect operator + destination(s). |
no test coverage detected