import { nat } from "things"; import { Lexer } from "./lexer.js"; import { Span, Spanned } from "./span.js"; /** Some sort of normalized character representation. */ export type TextChar = string; export interface Text extends Iterable { count: nat; charAt(index: nat): TextChar; slice(startIndexInclusive: nat, endIndexExclusive?: nat): Text; toString(): string; } export declare const Text: import("things").Order & import("things").Hash; export interface TextLines { lineCount: nat; lineAt(line: nat): Text; valid(line: nat, column: nat): boolean; assert(line: nat, column: nat): void; absolute(line: nat, index: nat): [nat, nat]; } export declare function absoluteSpan(lines: TextLines, span: Span): Span; export declare function printTextLines(lines: TextLines, println?: (text: string) => void): void; export declare function textOf(text: string | Text): Text; export declare function textOfChars(chars: TextChar[]): Text; export declare function createTextLines(lines: string | Text[]): TextLines; export declare function copySliceOfTextLines(textlines: TextLines, startLine: nat, startColumn: nat, endLine: nat, endColumn: nat): TextLines; export declare function copySpannedTextLines(textlines: TextLines, span: Span): Spanned; export declare function textOfTextLines(textlines: TextLines, line_separator?: Text): Text; export declare function cutoffAfterIndentation(source: TextLines, line: nat, isIndented: (text: Text) => boolean): TextLines; export interface CutoutTextLines extends TextLines { shift(line: nat, column: nat): [nat, nat]; } /** Represents a (possibly modified) window into an existing TextLines. */ export declare class TextLinesWindow implements TextLines, CutoutTextLines { source: TextLines; /** The first line in the window corresponds to the startLine in the source. */ startLine: nat; /** The text lines of the window. */ lines: Text[]; /** The offsets at which window text lines start in the source window. */ columns: nat[]; /** Same as lines.length */ lineCount: nat; constructor(source: TextLines, startLine: number, lines: Text[], columns: nat[]); log(print?: (text: string) => void): void; lineAt(line: nat): Text; valid(line: nat, column: nat): boolean; assert(line: nat, column: nat): void; shift(line: nat, column: nat): [nat, nat]; absolute(line: nat, column: nat): [nat, nat]; } export declare class EmptyTextLines implements TextLines, CutoutTextLines { source: TextLines; /** The position in the source to which (0, 0) corresponds, which is the only valid position. */ startLine: nat; startColumn: nat; constructor(source: TextLines, line: nat, column: nat); get lineCount(): nat; lineAt(line: nat): Text; valid(line: nat, column: nat): boolean; assert(line: nat, column: nat): void; absolute(line: nat, column: nat): [nat, nat]; shift(line: nat, column: nat): [nat, nat]; } /** * Cuts a window out of an existing TextLines. * * The window starts at the given line and column after skipFirst, and ends * before the first subsequent line where skipRemaining fails. */ export declare function cutoutTextLines(source: TextLines, line: nat, column: nat, skipFirst: Lexer, skipRemaining: Lexer): CutoutTextLines; export declare function trimText(text: Text): Text; export declare function trimTextLines(textlines: TextLines): TextLines; export declare class TextLinesUntil implements TextLines { source: TextLines; endLine: number; lastLine: Text; /** Same as lines.length */ lineCount: number; constructor(source: TextLines, endLine: number, endColumn: number); log(print?: (text: string) => void): void; lineAt(line: number): Text; absolute(line: number, offset: number): [number, number]; valid(line: nat, column: nat): boolean; assert(line: nat, column: nat): void; } export declare function textlinesUntil(lines: TextLines, endLine: number, endColumn: number): TextLines;