@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
128 lines • 4.92 kB
TypeScript
import type { Heredoc, ShellNode } from '../shell/types.ts';
interface Exports {
readonly memory: WebAssembly.Memory;
mirage_rs_args(len: number): number;
mirage_rs_shell_parse(len: number, aliasesLen: number, extglob: number): number;
mirage_rs_shell_table(): number;
mirage_rs_shell_error_at(): number;
mirage_rs_shell_status(): number;
mirage_rs_shell_message(): number;
mirage_rs_shell_message_len(): number;
mirage_rs_shell_names(): number;
mirage_rs_shell_names_len(): number;
mirage_rs_shell_extras(): number;
mirage_rs_shell_extras_len(): number;
mirage_rs_shell_text(): number;
mirage_rs_shell_text_len(): number;
}
/** A shell program as mirage's own parser reads it. Mirrors Python's ShellTree. */
export declare class ShellTree {
/** The line as typed. */
readonly original: string;
readonly table: Uint32Array;
/**
* What bash reports of the line when it refuses it: where in the line as
* typed, in UTF-16 units, the diagnostic lines as mirage prints them, and
* the status.
*/
readonly error: {
readonly index: number;
readonly message: string;
readonly status: number;
} | null;
private readonly extras;
/** Unique per tree, so node ids differ across trees. */
readonly serial: number;
constructor(
/** The line as typed. */
original: string, table: Uint32Array,
/**
* What bash reports of the line when it refuses it: where in the line as
* typed, in UTF-16 units, the diagnostic lines as mirage prints them, and
* the status.
*/
error: {
readonly index: number;
readonly message: string;
readonly status: number;
} | null, extras: ReturnType<typeof readExtras>);
get rootNode(): ShellTreeNode;
get source(): string;
get offsets(): Uint32Array;
get heredocs(): readonly Heredoc[];
get warnings(): string;
inlined(index: number): string | undefined;
/**
* The line as typed under nodes `start` to `end`, less the line continuations
* the parser dropped: those no unit of the nodes came from, outside the
* heredocs it folded. Mirrors the parser's `Tree::typed`.
*/
typed(start: number, end: number): string;
}
/**
* One node of a ShellTree: the kinds, fields and spans tree-sitter-bash
* gives, offsets and columns in UTF-16 units as a string index counts them.
*/
export declare class ShellTreeNode implements ShellNode {
readonly tree: ShellTree;
readonly index: number;
constructor(tree: ShellTree, index: number);
private word;
private at;
get id(): number;
get type(): string;
get isNamed(): boolean;
get startIndex(): number;
get endIndex(): number;
get startPosition(): {
row: number;
column: number;
};
get endPosition(): {
row: number;
column: number;
};
get text(): string;
get childCount(): number;
get children(): ShellTreeNode[];
get namedChildren(): ShellTreeNode[];
get parent(): ShellTreeNode | null;
private sibling;
get nextSibling(): ShellTreeNode | null;
get previousSibling(): ShellTreeNode | null;
child(index: number): ShellTreeNode | null;
/** The field a child has in this node. */
fieldNameForChild(index: number): string | null;
childForFieldName(name: string): ShellTreeNode | null;
/** The heredoc a `file_redirect` was folded from. */
get heredoc(): Heredoc | undefined;
/** The node's text in the line as typed, the heredoc bodies it holds included. */
get sourceText(): string;
/** The node's text with the heredoc bodies the line reads after a substitution in it moved inside it. */
get inlined(): string | undefined;
/** Where each UTF-16 unit of the tree's source came from in the line as typed, then its end. */
get offsets(): Uint32Array;
/** What bash warns of while it reads the tree's heredocs. */
get warnings(): string;
/** The tree's refusal, as `ShellTree.error` gives it. */
get error(): ShellTree['error'];
}
/**
* Parse a shell program with mirage's own bash parser: tree-sitter-bash's
* node kinds, fields and spans, bash's reading where that grammar misreads
* bash. `aliases` are the names the shell expands as aliases: one is a
* command where a command starts, never a reserved word. Mirrors Python's
* parse_shell.
*/
export declare function parseShell(source: string, aliases?: Iterable<string>, extglob?: boolean): ShellTree;
/** The parse's extras, laid out as `mirage_rs_shell_extras` describes them. */
/** What a parse says of the line beyond its nodes. */
export declare function readExtras(wasm: Exports): {
source: string;
offsets: Uint32Array<ArrayBuffer>;
heredocs: Heredoc[];
inlined: Map<number, string>;
warnings: string;
};
export {};
//# sourceMappingURL=shell.d.ts.map