UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

108 lines (107 loc) 4.33 kB
import { QuintDeclaration, QuintDef, QuintEx, QuintModule } from '../ir/quintIr'; import { IdGenerator } from '../idGenerator'; import { LookupTable, UnusedDefinitions } from '../names/base'; import { NameResolver } from '../names/resolver'; import { QuintError } from '../quintError'; import { SourceLookupPath, SourceResolver } from './sourceResolver'; import { Loc } from '../ErrorMessage'; /** * A source map that is constructed by the parser phases. */ export type SourceMap = Map<bigint, Loc>; /** * The result of parsing, T is specialized to a phase, see below. */ export type ParseResult<T> = T; /** * Phase 1: Parsing a string of characters into intermediate representation. */ export interface ParserPhase1 { modules: QuintModule[]; sourceMap: SourceMap; errors: QuintError[]; } /** * Phase 2: Import resolution and detection of cyclic imports. */ export interface ParserPhase2 extends ParserPhase1 { } /** * Phase 3: Name resolution. */ export interface ParserPhase3 extends ParserPhase2 { table: LookupTable; unusedDefinitions: UnusedDefinitions; resolver: NameResolver; } /** * Phase 4: Topological sort of declarations and cycle detection. */ export interface ParserPhase4 extends ParserPhase3 { } /** * The result of parsing an expression or collection of declarations. */ export type ExpressionOrDeclarationParseResult = { kind: 'declaration'; decls: QuintDeclaration[]; } | { kind: 'expr'; expr: QuintEx; } | { kind: 'none'; } | { kind: 'error'; errors: QuintError[]; }; /** * Try parsing text as an expression or a top-level declaration. * * @param text input text * @param sourceLocation a textual description of the source * @returns the parsing result */ export declare function parseExpressionOrDeclaration(text: string, sourceLocation: string, idGenerator: IdGenerator, sourceMap: SourceMap): ExpressionOrDeclarationParseResult; /** * Phase 1 of the Quint parser. Read a string in the Quint syntax and produce the IR. * Note that the IR may be ill-typed and some names may be unresolved. * The main goal of this pass is to translate a sequence of characters into IR. */ export declare function parsePhase1fromText(idGen: IdGenerator, text: string, sourceLocation: string): ParseResult<ParserPhase1>; /** * Phase 2 of the Quint parser. Go over each declaration of the form * `import ... from '<path>'`, do the following: * * - parse the modules that are referenced by each path, * - add the parsed modules. * * Cyclic dependencies among different files are reported as errors. */ export declare function parsePhase2sourceResolution(idGen: IdGenerator, sourceResolver: SourceResolver, mainPath: SourceLookupPath, mainPhase1Result: ParserPhase1): ParseResult<ParserPhase2>; /** * Phase 3 of the Quint parser. Assuming that all external sources have been resolved, * resolve imports and names. Read the IR and check that all names are defined. * Note that the IR may be ill-typed. */ export declare function parsePhase3importAndNameResolution(phase2Data: ParserPhase2): ParseResult<ParserPhase3>; /** * Phase 4 of the Quint parser. Sort all declarations in the topologocal order, * that is, every name should be defined before it is used. */ export declare function parsePhase4toposort(phase3Data: ParserPhase3): ParseResult<ParserPhase4>; export declare function compactSourceMap(sourceMap: SourceMap): { sourceIndex: any; map: any; }; /** * Parses a Quint code string and returns a `ParseResult` containing the result of all three parsing phases. * * @param idGen An `IdGenerator` instance to generate unique IDs for parsed elements. * @param sourceLocation A string describing the source location of the code being parsed. * @param mainPath The main source lookup path for resolving imports. * @param code The Quint code string to parse. * @param sourceCode Optionally a map of previously parsed files, to be updated by this function * @returns A `ParseResult` containing the result of all three parsing phases. */ export declare function parse(idGen: IdGenerator, sourceLocation: string, mainPath: SourceLookupPath, code: string, sourceCode?: Map<string, string>): ParseResult<ParserPhase4>; export declare function parseDefOrThrow(text: string, idGen?: IdGenerator, sourceMap?: SourceMap): QuintDef;