diff --git a/generated_template.d.ts b/generated_template.d.ts index f49d9f8..bbde75d 100755 --- a/generated_template.d.ts +++ b/generated_template.d.ts @@ -8,10 +8,23 @@ export interface Location { offset: number; } +type AnyObject = { + readonly [K: string]: unknown; +} + +export interface Source extends AnyObject { + /** + * This function is used when trace is set to true to do ??? + * TODO: Better documentation. I don't know what's going on here entirely to be honest. + */ + offset?: (location: Location) => Location +} + + /** The `start` and `end` position's of an object within the source. */ export interface LocationRange { /** Any object that was supplied to the `parse()` call as the `grammarSource` option. */ - source: any; + source: Source; /** Position at the beginning of the expression. */ start: Location; /** Position after the end of the expression. */ @@ -23,7 +36,7 @@ export interface LiteralExpectation { text: string; ignoreCase: boolean; } -export interface ClassParts extends Array {} +export interface ClassParts extends Array {} export interface ClassExpectation { type: "class"; parts: ClassParts; @@ -47,7 +60,7 @@ export type Expectation = | LiteralExpectation | OtherExpectation; -declare class _PeggySyntaxError extends Error { +export declare class SyntaxError extends Error { /** * Constructs the human-readable message from the machine representation. * @@ -55,21 +68,21 @@ declare class _PeggySyntaxError extends Error { * @param found Any text that will appear as found in the input instead of * expected */ - static buildMessage(expected: Expectation[], found: string | null): string; - message: string; - expected: Expectation[]; - found: string | null; - location: LocationRange; - name: string; + static buildMessage(expected: Expectation[], found: string | null | undefined): string; + readonly message: string; + readonly expected: Expectation[]; + readonly found: string | null | undefined; + readonly location: LocationRange; + readonly name: string; constructor( message: string, expected: Expectation[], - found: string | null, + found: string | null | undefined, location: LocationRange ); format( sources: { - source?: any; + source?: Source | undefined; text: string; }[] ): string; @@ -82,7 +95,8 @@ export interface ParserTracer { export type ParserTracerEvent = | { type: "rule.enter"; rule: string; location: LocationRange } | { type: "rule.fail"; rule: string; location: LocationRange } - | { type: "rule.match"; rule: string; result: any; location: LocationRange }; + // `unknown` may be more appropriate but I looked at callsites and it seems like it's always a string or number + | { type: "rule.match"; rule: string; result: string | number; location: LocationRange }; export type StartRules = $$$StartRules$$$; export interface ParseOptions { @@ -91,24 +105,22 @@ export interface ParseOptions { * the parser. For example, this can be path to the parsed file or even the * File object. */ - grammarSource?: any; - startRule?: T; - tracer?: ParserTracer; + grammarSource?: Source | undefined; + startRule?: T | undefined; + tracer?: ParserTracer | undefined; // Internal use only: - peg$library?: boolean; + peg$library?: boolean | undefined; // Internal use only: - peg$currPos?: number; + peg$currPos?: number | undefined; // Internal use only: - peg$silentFails?: number; + peg$silentFails?: number | undefined; // Internal use only: - peg$maxFailExpected?: Expectation[]; + peg$maxFailExpected?: Expectation[] | undefined; // Extra application-specific properties - [key: string]: any; + [key: string]: unknown; } export declare const parse: typeof ParseFunction; -export declare const SyntaxError: typeof _PeggySyntaxError; -export type SyntaxError = _PeggySyntaxError; // Overload of ParseFunction for each allowedStartRule