UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

80 lines (79 loc) 2.82 kB
import { IntervalSet, type Vocabulary } from "antlr4ng"; import type { CommonTree } from "../tree/CommonTree.js"; import type { ICodeBlockForOuterMostAlt } from "../types.js"; /** A generic constructor type. */ export type Constructor<T = unknown> = new (...args: unknown[]) => T; /** A line/column pair. */ export interface IPosition { line: number; column: number; } /** * Is id a valid token name? Does id start with an uppercase letter? * * @param id The string to check. * * @returns `true` if the string is a valid token name; otherwise, `false`. */ export declare const isTokenName: (id: string) => boolean; /** * Does the given object implement the `ICodeBlockForOuterMostAlt` interface? * * @param obj The object to check. * * @returns `true` if the object implements the interface; otherwise, `false`. */ export declare const isCodeBlockForOuterMostAlt: (obj: object) => obj is ICodeBlockForOuterMostAlt; /** * Format a map like Java does it. * * @param map The map to convert. * * @returns The string representation of the map. */ export declare const convertMapToString: (map: Map<unknown, unknown>) => string; /** * Format an array like Java does it. * * @param a The array to convert. * @param separator The separator to use between elements. * * @returns The string representation of the array. */ export declare const convertArrayToString: <T>(a: T[], separator?: string) => string; /** * Duplicates a tree. * * @param t The tree to duplicate. * @param parent The parent of the tree copy. * * @returns The duplicated tree. */ export declare const dupTree: <T extends CommonTree>(t: T, parent?: CommonTree) => T; /** * Given a token type, get a meaningful name for it such as the ID or string literal. If this is a lexer and the * ttype is in the char vocabulary, compute an ANTLR-valid (possibly escaped) char literal. * * @param ttype The type of the token to describe. * @param vocabulary A vocabulary object to use for the display name. * @param isLexer `true` if this is a lexer grammar; otherwise, `false`. * * @returns The display name for the token. */ export declare const getTokenDisplayName: (ttype: number, vocabulary: Vocabulary, isLexer: boolean) => string; /** * Formats a string using the provided arguments. This is a partial implementation of the `String.format` * method in Java. * * @param formatString The format string. * @param args The arguments to use for formatting. * * @returns The formatted string. */ export declare const format: (formatString: string, ...args: unknown[]) => string; /** * @returns whether interval (lookahead) sets are disjoint; no lookahead ⇒ not disjoint * * @param altLook The interval sets to check. */ export declare const disjoint: (altLook: Array<IntervalSet | undefined>) => boolean;