/** * Reading a script in the source dialect into logical lines of tokens. * * The source dialect is line oriented and indentation delimited, like * OpenScript, and it differs in the two places a reader has to know about. A * statement continues onto the next line when a bracket is still open, when * the line ends on an operator that cannot end one, or when the next line is * indented by an amount that is not a whole number of blocks: the dialect's * blocks are four columns deep, and a continuation is told apart from a block * by being indented off that grid. A tab in leading whitespace counts as one * block. * * This reader is deliberately separate from OpenScript's lexer. The two * languages share a shape and differ in almost every token rule that matters to * a diagnostic: the source dialect has `:=`, `=>` and single quoted strings as * ordinary tokens and no `none`, and running its text through OpenScript's * lexer would report every one of those as a mistake in a file nobody wrote in * OpenScript. * * Nothing here refuses anything. A character the dialect does not have becomes * a `bad` token, and the parser decides what the statement holding it is. */ import type { SourceFile } from '../source/index.js'; export type TokenKind = 'name' | 'number' | 'string' | 'color' | 'op' | 'bad'; export interface Token { readonly kind: TokenKind; /** The characters as written. */ readonly text: string; /** A string literal's decoded value; for every other kind, the text. */ readonly value: string; readonly offset: number; readonly length: number; } /** A `//` comment, with the text after the two slashes. */ export interface Remark { readonly text: string; readonly offset: number; readonly line: number; } /** One statement's worth of tokens, which may have spanned several lines. */ export interface Logical { /** Leading columns of the first line, a tab counted as one block. */ readonly indent: number; readonly tokens: readonly Token[]; /** Comments written after code on any of the statement's lines. */ readonly remarks: readonly Remark[]; readonly firstLine: number; readonly lastLine: number; } export type Item = { readonly kind: 'code'; readonly logical: Logical; } | { readonly kind: 'remark'; readonly remark: Remark; readonly indent: number; } | { readonly kind: 'blank'; readonly line: number; }; /** * The whole file as items: statements, comment lines and blank lines, in order. * * A comment line or a blank line inside an open statement belongs to that * statement and ends nothing, the same rule OpenScript gives them. */ export declare function readItems(file: SourceFile): readonly Item[]; //# sourceMappingURL=lexer.d.ts.map