import type { DiagnosticCode, DiagnosticValues } from '../catalogue/index.js'; import type { DiagnosticSink } from '../diagnostics/index.js'; import type { SourceFile } from '../source/index.js'; import type { Span } from '../span/index.js'; import type { Token, TokenKind } from '../tokens/index.js'; /** * What a diagnostic calls a token when it has to quote one. * * A layout token carries no text, and a message that quoted one would quote * nothing at all, so each is named by what a reader would call it. */ export declare function describeToken(token: Token): string; export declare class Cursor { #private; readonly file: SourceFile; constructor(file: SourceFile, tokens: readonly Token[], sink: DiagnosticSink); /** An index into the stream, which a loop compares to prove it made progress. */ get position(): number; get token(): Token; get kind(): TokenKind; peek(ahead?: number): Token; at(kind: TokenKind): boolean; atStatementEnd(): boolean; advance(): Token; take(kind: TokenKind): Token | undefined; /** The last token consumed, for a node that has to end where one ended. */ previous(): Token; /** * The token before this one, when it is one a reader wrote. * * OS1022 names the token the statement ran out after, which is the one to the * left of the hole. At the start of a line there is no such token, and the * caller names the one it is looking at instead. */ previousMeaningful(): Token | undefined; /** * What the reader wrote across a span. * * A diagnostic that has to quote a piece of a program quotes the source * rather than rebuilding it from the tree. `a.b` put back together out of a * member node is a reconstruction, and one that differs from the page by so * much as a space sends the reader looking for something they did not write. */ textOf(span: Span): string; /** An empty span where something should have been written and was not. */ holeSpan(): Span; report(code: Code, span: Span, values: DiagnosticValues[Code]): void; /** * Whether this statement has already been reported on. * * One mistake is one diagnostic. A statement that has been reported on has * nothing more to say about its own leftovers, so the second message about * the same mistake is suppressed rather than the reader being left to work * out which of the two to believe. */ get reportedHere(): boolean; /** * A token where the grammar had one exact thing in mind, OS1018. * * The catalogue has no code for "a closing bracket belongs here", so the one * it does have is used for all of them: OS1018 states what is true, that the * token was not expected where it sits, and its fix names the two things that * are usually wrong, a missing operator or a line that lost its newline. */ unexpected(token: Token): void; /** * Whether one more level of expression nesting is within the ceiling. * * Refusing abandons the statement rather than only this level, because a * parser that unwound from here would report the brackets it never reached * the closers of, one per level, all of them about the expression that was * already too deep. */ deeper(span: Span): boolean; shallower(): void; /** * The same ceiling for blocks, counted across statements rather than within * one, because a block's depth is the file's shape and not a line's. * * A refusal here costs the block and not the statement: the caller skips the * whole of it, so there is nothing left inside to report on twice. */ openBlock(span: Span): boolean; closeBlock(): void; beginStatement(): void; /** * The first statement in the file, which is the line OS1021 names when a * version declaration turns up below it. */ noteStatement(line: number): void; get firstStatementLine(): number | undefined; /** Where the most recent `if` sat, which is what OS1016 pairs an `else` against. */ noteIf(column: number): void; get nearestIfColumn(): number; /** * Whether a loop body is being read, which is the whole of OS1009. * * It is a count on the cursor rather than an argument threaded through every * rule, because the one question `break` asks is whether any loop is open, * and a function body cannot be inside one: functions are top level only. */ enterLoop(): void; leaveLoop(): void; get insideLoop(): boolean; /** To the end of this line, taking the newline, and no further. */ skipToEndOfLine(): void; /** * The whole statement, including a block written under it. * * This is the boundary to recover at when the line itself was not understood. * A header the parser could not read still has its body indented beneath it, * and reading that body as though it stood at the outer level would report * every line of it. */ skipStatement(): void; /** A block, and the blocks inside it, when no statement can hold it. */ skipBlockBody(): void; } //# sourceMappingURL=cursor.d.ts.map