UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

62 lines (61 loc) 3.23 kB
import { type RShell } from './shell'; import type { AsyncOrSync } from 'ts-essentials'; import { RShellExecutor } from './shell-executor'; import type { NormalizedAst } from './lang-4.x/ast/model/processing/decorate'; export declare const fileProtocol = "file://"; export interface RParseRequestFromFile { readonly request: 'file'; /** * The path to the file (an absolute path is probably best here). * See {@link RParseRequests} for multiple files. */ readonly content: string; } export interface RParseRequestFromText { readonly request: 'text'; /** * Source code to parse (not a file path). * If you want to parse multiple files as one, either use {@link RParseRequests}, * a higher request as a {@link FileAnalysisRequestMessage}, * or concatenate their contents to pass them with this request. */ readonly content: string; } /** * A provider for an {@link RParseRequests} that can be used, for example, to override source file parsing behavior in tests */ export interface RParseRequestProvider { /** returns the path if it exists, otherwise undefined */ exists(path: string, ignoreCase: boolean): string | undefined; createRequest(path: string): RParseRequest; } export type RParseRequest = RParseRequestFromFile | RParseRequestFromText; /** * Several requests that can be passed along to {@link retrieveParseDataFromRCode}. */ export type RParseRequests = RParseRequest | ReadonlyArray<RParseRequest>; export declare function requestFromInput(input: `${typeof fileProtocol}${string}`): RParseRequestFromFile; export declare function requestFromInput(input: `${typeof fileProtocol}${string}`[]): RParseRequestFromFile[]; export declare function requestFromInput(input: string): RParseRequestFromText; export declare function requestFromInput(input: readonly string[] | string): RParseRequests; export declare function requestProviderFromFile(): RParseRequestProvider; export declare function requestProviderFromText(text: Readonly<{ [path: string]: string; }>): RParseRequestProvider; export declare function isEmptyRequest(request: RParseRequest): boolean; export declare function retrieveParseDataFromRCode(request: RParseRequest, shell: RShell): Promise<string>; export declare function retrieveParseDataFromRCode(request: RParseRequest, shell: RShellExecutor): string; export declare function retrieveParseDataFromRCode(request: RParseRequest, shell: RShell | RShellExecutor): AsyncOrSync<string>; /** * Uses {@link retrieveParseDataFromRCode} and returns the nicely formatted object-AST. * If successful, allows further querying the last result with {@link retrieveNumberOfRTokensOfLastParse}. */ export declare function retrieveNormalizedAstFromRCode(request: RParseRequest, shell: RShell): Promise<NormalizedAst>; /** * If the string has (R-)quotes around it, they will be removed; otherwise the string is returned unchanged. */ export declare function removeRQuotes(str: string): string; /** * Needs to be called *after* {@link retrieveParseDataFromRCode} (or {@link retrieveNormalizedAstFromRCode}) */ export declare function retrieveNumberOfRTokensOfLastParse(shell: RShell, ignoreComments?: boolean): Promise<number>;