@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
76 lines (75 loc) • 3.68 kB
TypeScript
import * as readline from 'readline';
import { type ReplOutput } from './commands/repl-main';
import type { MergeableRecord } from '../../util/objects';
import type { FlowrConfig } from '../../config';
import type { FlowrAnalyzer } from '../../project/flowr-analyzer';
/**
* Completion suggestions for a specific REPL command
*/
export interface CommandCompletions {
/** The possible completions for the current argument */
readonly completions: string[];
/**
* The current argument fragment being completed, if any.
* This is relevant if an argument is composed of multiple parts (e.g. comma-separated lists).
*/
readonly argumentPart?: string;
}
/**
* Used by the repl to provide automatic completions for a given (partial) input line
*/
export declare function replCompleter(line: string, config: FlowrConfig): [string[], string];
/**
* Produces default readline options for the flowR REPL
*/
export declare function makeDefaultReplReadline(config: FlowrConfig): readline.ReadLineOptions;
/**
* Handles a string input for the REPL, returning the parsed string and any remaining input.
*/
export declare function handleString(code: string): {
rCode: string | undefined;
remaining: never[];
};
/**
* This function interprets the given `expr` as a REPL command (see {@link repl} for more on the semantics).
* @param analyzer - The flowR analyzer to use.
* @param output - Defines two methods that every function in the repl uses to output its data.
* @param expr - The expression to process.
* @param allowRSessionAccess - If true, allows the execution of arbitrary R code.
*/
export declare function replProcessAnswer(analyzer: FlowrAnalyzer, output: ReplOutput, expr: string, allowRSessionAccess: boolean): Promise<void>;
/**
* Options for the {@link repl} function.
*/
export interface FlowrReplOptions extends MergeableRecord {
/**
* The flowR analyzer to use.
*/
readonly analyzer: FlowrAnalyzer;
/**
* A potentially customized readline interface to be used for the repl to *read* from the user, we write the output with the {@link ReplOutput | `output` } interface.
* If you want to provide a custom one but use the same `completer`, refer to {@link replCompleter}.
*/
readonly rl?: readline.Interface;
/** Defines two methods that every function in the repl uses to output its data. */
readonly output?: ReplOutput;
/** The file to use for persisting the repl's history. Passing undefined causes history not to be saved. */
readonly historyFile?: string;
/** If true, allows the execution of arbitrary R code. This is a security risk, as it allows the execution of arbitrary R code. */
readonly allowRSessionAccess?: boolean;
}
/**
* Provides a never-ending repl (read-evaluate-print loop) processor that can be used to interact with a {@link RShell} as well as all flowR scripts.
*
* The repl allows for two kinds of inputs:
* - Starting with a colon `:`, indicating a command (probe `:help`, and refer to {@link commands}) </li>
* - Starting with anything else, indicating default R code to be directly executed. If you kill the underlying shell, that is on you! </li>
* @param options - The options for the repl. See {@link FlowrReplOptions} for more information.
*
* For the execution, this function makes use of {@link replProcessAnswer}.
*/
export declare function repl({ analyzer, rl, output, historyFile, allowRSessionAccess }: FlowrReplOptions): Promise<void>;
/**
* Loads the REPL history from the given file.
*/
export declare function loadReplHistory(historyFile: string): string[] | undefined;