ecmarkup
Version:
Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.
73 lines (72 loc) • 1.66 kB
TypeScript
import type { parseFragment } from 'ecmarkdown';
declare type Unarray<T> = T extends Array<infer U> ? U : T;
declare type FragmentNode = Unarray<ReturnType<typeof parseFragment>>;
declare type ProsePart = FragmentNode | {
name: 'text';
contents: string;
location: {
start: {
offset: number;
};
};
};
declare type Prose = {
type: 'prose';
parts: ProsePart[];
};
declare type List = {
type: 'list';
elements: Seq[];
};
declare type Record = {
type: 'record';
members: {
name: string;
value: Seq;
}[];
};
declare type RecordSpec = {
type: 'record-spec';
members: {
name: string;
}[];
};
declare type Call = {
type: 'call';
callee: Prose;
arguments: Seq[];
};
declare type SDOCall = {
type: 'sdo-call';
callee: Prose;
parseNode: Seq;
arguments: Seq[];
};
declare type Paren = {
type: 'paren';
items: NonSeq[];
};
export declare type Seq = {
type: 'seq';
items: NonSeq[];
};
declare type NonSeq = Prose | List | Record | RecordSpec | Call | SDOCall | Paren;
export declare type Expr = NonSeq | Seq;
declare type Failure = {
type: 'failure';
message: string;
offset: number;
};
export declare function parse(src: FragmentNode[], opNames: Set<String>): Seq | Failure;
export declare type PathItem = {
parent: List | Record | Seq | Paren;
index: number;
} | {
parent: Call;
index: 'callee' | number;
} | {
parent: SDOCall;
index: 'callee' | number;
};
export declare function walk(f: (expr: Expr, path: PathItem[]) => void, current: Expr, path?: PathItem[]): void;
export {};