Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199/** Arithmetic and Bash test visitors for `unbash` shell command analysis. @module */
import type { ArithmeticExpression as UnbashArithmeticExpression, TestExpression as UnbashTestExpression,} from 'unbash';import type { ForeignBorrowed, } from '@monochromatic-dev/ownership-marker-foreign-borrowed/ts';import { EMPTY_VISIT_RESULT, type VisitResult,} from './internal-types.ts';import { visitExpansion, } from './nested.ts';import type { ShellCommandContext, } from './types.ts';import { wordWorkItems, } from './work-items.ts';
/** Build child work from arithmetic expression. @param expression - arithmetic expression to inspect @param context - execution context inherited by nested expansions @returns nested command expansion work @example ```ts visitArithmetic({ expression, context }); ``` */function visitArithmetic( { expression, context, }: { readonly expression: ForeignBorrowed<UnbashArithmeticExpression>; readonly context: ShellCommandContext; },): VisitResult { if (expression.type === 'ArithmeticCommandExpansion') { return visitExpansion({ expansion: expression, context, },); } if (expression.type === 'ArithmeticBinary') { return { ...EMPTY_VISIT_RESULT, workItems: [ { kind: 'arithmetic', expression: expression.left, context, }, { kind: 'arithmetic', expression: expression.right, context, }, ], }; } if (expression.type === 'ArithmeticUnary') { return { ...EMPTY_VISIT_RESULT, workItems: [{ kind: 'arithmetic', expression: expression.operand, context, },], }; } if (expression.type === 'ArithmeticTernary') { return { ...EMPTY_VISIT_RESULT, workItems: [ { kind: 'arithmetic', expression: expression.test, context, }, { kind: 'arithmetic', expression: expression.consequent, context, }, { kind: 'arithmetic', expression: expression.alternate, context, }, ], }; } if (expression.type === 'ArithmeticGroup') { return { ...EMPTY_VISIT_RESULT, workItems: [{ kind: 'arithmetic', expression: expression.expression, context, },], }; } return EMPTY_VISIT_RESULT;}
/** Build child work from Bash test expression. @param expression - Bash test expression to inspect @param context - execution context inherited by nested expansions @returns word or nested test work @example ```ts visitTest({ expression, context }); ``` */function visitTest( { expression, context, }: { readonly expression: ForeignBorrowed<UnbashTestExpression>; readonly context: ShellCommandContext; },): VisitResult { if (expression.type === 'TestUnary') { return { ...EMPTY_VISIT_RESULT, workItems: wordWorkItems({ word: expression.operand, context, },), }; } if (expression.type === 'TestBinary') { return { ...EMPTY_VISIT_RESULT, workItems: [ ...wordWorkItems({ word: expression.left, context, },), ...wordWorkItems({ word: expression.right, context, },), ], }; } if (expression.type === 'TestLogical') { return { ...EMPTY_VISIT_RESULT, workItems: [ { kind: 'test', expression: expression.left, context, }, { kind: 'test', expression: expression.right, context, }, ], }; } if (expression.type === 'TestNot') { return { ...EMPTY_VISIT_RESULT, workItems: [{ kind: 'test', expression: expression.operand, context, },], }; } return { ...EMPTY_VISIT_RESULT, workItems: [{ kind: 'test', expression: expression.expression, context, },], };}
export { visitArithmetic, visitTest,};