/** * @fileoverview Language-agnostic scanner primitives for source-stripping * lexers — the lower half of the strip toolkit. * * Every `packages/languages/lang-*` strip.ts composes these primitives into a * language-specific `scan`, which `makeStripper` (in `strip-utils.ts`) turns * into the `{ stripStrings, stripComments }` pair. Each scanner recognizes one * lexical shape (regular string, line/block comment, char literal) and emits * the half-open `Region`s to replace; `applyRegions` overlays them with spaces * while preserving line/column offsets. * * Split out of `strip-utils.ts` so neither file exceeds the file-length limit; * `strip-utils.ts` re-exports everything here, so consumers still import these * from `@opensip-tools/core` (or `strip-utils.js`) unchanged. */ /** Half-open region `[start, end)` for region-overlay strippers. */ export interface Region { readonly start: number; readonly end: number; } /** Result of `scanRegularString`. */ export interface RegStrResult { /** Index of the closing `"` (or EOF / newline position for unterminated). */ readonly contentEnd: number; /** Index after the closing quote — where the outer scanner resumes. */ readonly next: number; } /** Options for `scanRegularString`. */ export interface ScanRegularStringOptions { /** * When `true`, `\n` is treated as part of the body — the scanner * traverses newlines and only stops at the closing quote or EOF. * Used by Rust regular strings (which can span multiple lines). * Defaults to `false` (matches Java/Go/C++ semantics). */ readonly allowMultiline?: boolean; } /** * Scan a regular double-quoted string starting at `openQuotePos` * (which must reference the opening `"`). Returns the position of the * closing quote and the resume index. Honors backslash escapes (`\"`, * `\\`, `\n`, etc. by simply advancing 2). By default, stops at * unescaped newlines (Java/Go/C++ semantics); pass * `{ allowMultiline: true }` for Rust-style strings that may span * lines. * * If the string is unterminated (no closing quote before newline or * EOF), returns the unterminated position rather than throwing — * callers decide how to handle that case. */ export declare function scanRegularString(src: string, openQuotePos: number, options?: ScanRegularStringOptions): RegStrResult; /** Result of `scanLineComment` and `scanBlockCommentNonNesting`. */ export interface ScanCommentResult { /** * Index just past the end of the comment region (i.e. the position * where the outer scanner resumes). For line comments without line * continuation this is the position of the terminating newline (or * EOF); for block comments this is the position immediately after * the closing delimiter. */ readonly end: number; } /** Options for `scanLineComment`. */ export interface ScanLineCommentOptions { /** * When `true`, a `\` (backslash immediately before a * newline) is a phase-2 line splice — the comment continues onto * the next physical line. Used by C/C++. Defaults to `false` * (matches Java/Go semantics). */ readonly allowLineContinuation?: boolean; } /** * Scan a `//` line comment starting at `start` (which must reference * the first `/` of the opener). Returns the index of the next `\n` * (or EOF) — i.e. where the outer scanner resumes. The returned index * does not include the `\n` itself. * * Pass `{ allowLineContinuation: true }` for C/C++-style line splices: * a `\` continues the comment onto the next physical line * (per C/C++ phase-2 translation). Defaults to `false`; Java and Go * comments have no such behavior. * * Used by lang-cpp (with `allowLineContinuation: true`), lang-java, * lang-go, lang-rust. */ export declare function scanLineComment(src: string, start: number, options?: ScanLineCommentOptions): ScanCommentResult; /** * Scan a non-nesting block comment starting at `start` (which must * reference the opening slash). Returns the index just past the * closing delimiter — i.e. where the outer scanner resumes. If the * comment is unterminated, returns the EOF position. * * Used by lang-cpp, lang-java, lang-go. */ export declare function scanBlockCommentNonNesting(src: string, start: number): ScanCommentResult; /** Result of `scanBlockCommentNesting`. */ export interface ScanNestingBlockCommentResult { /** Index just past the closing delimiter (or EOF if unterminated). */ readonly end: number; /** * Final depth at scan completion. `0` indicates a balanced (well- * terminated) comment. A positive value indicates an unterminated * comment — `depth` openers were unmatched at EOF. */ readonly depth: number; } /** * Scan a Rust-style nested block comment starting at `start` (which * must reference the opening slash). Each nested opener increments * the depth counter; each closer decrements it. The scan returns when * the depth hits zero (balanced) or when EOF is reached (unterminated * — `depth > 0`). * * Used by lang-rust. */ export declare function scanBlockCommentNesting(src: string, start: number): ScanNestingBlockCommentResult; /** Result of `scanCharLiteral`. */ export interface ScanCharLiteralResult { /** * Index just past the char literal — i.e. where the outer scanner * resumes. If the close-quote is found within the bound, this is * one past the closing apostrophe. If the literal is unterminated * (overflow or newline), this is one past the opening apostrophe * (the apostrophe is treated as code rather than committing the run * as a literal — see lang-java F2 / lang-cpp F5b). */ readonly end: number; } /** Options for `scanCharLiteral`. */ export interface ScanCharLiteralOptions { /** * Maximum number of source positions to scan from the opening * quote, inclusive of the close. Defaults to `8` — matches the * lang-java / lang-rust heuristic. lang-cpp overrides this to `12` * to accommodate unicode escapes such as `'\u{1F600}'` (10 chars * including quotes); other C-family adopters should override * similarly when their language permits longer escape sequences. * The scan-cap is permissive: on overflow it recovers by treating * the apostrophe as code. */ readonly maxScan?: number; } /** * Scan a char literal starting at `start` (which must reference the * opening apostrophe). Returns the index just past the literal — or, * if the literal does not close within the scan bound, the index * immediately after the opening apostrophe (the apostrophe is treated * as code rather than committing the consumed run). * * Branch ordering is load-bearing: the escape-sequence advance MUST * run before the close-quote check so escaped-apostrophe char * literals do not terminate at the second apostrophe. See lang-java * F6. * * Used by lang-cpp, lang-java (with prefix-stripping at the call * site), lang-rust (with the lifetime-vs-literal heuristic at the * call site). */ export declare function scanCharLiteral(src: string, start: number, options?: ScanCharLiteralOptions): ScanCharLiteralResult; /** * Replace each region with spaces, preserving newlines and overall * length. Indexes into `src` and out remain identical, so any * line/column derived from the original string is still valid. * * The `Region[]` is treated as readonly; callers may pass either * regions from a comment scan or regions from a string scan (or both). */ export declare function applyRegions(src: string, regions: readonly Region[]): string; //# sourceMappingURL=strip-scanners.d.ts.map