Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 140 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"@j-ulrich/release-it-regex-bumper": "^5.3.0",
"@types/command-line-args": "^5.2.3",
"@types/command-line-usage": "^5.0.4",
"@types/commonmark": "^0.27.10",
"@types/n-readlines": "^1.0.6",
"@types/n3": "^1.26.0",
"@types/object-hash": "^3.0.6",
Expand Down Expand Up @@ -212,6 +213,8 @@
"clipboardy": "^4.0.0",
"command-line-args": "^6.0.1",
"command-line-usage": "^7.0.3",
"commonmark": "^0.31.2",
"gray-matter": "^4.0.3",
"joi": "^18.0.1",
"lz-string": "^1.5.0",
"n-readlines": "^1.0.1",
Expand Down
4 changes: 1 addition & 3 deletions src/benchmark/slicer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import type { IStoppableStopwatch } from './stopwatch';
import { Measurements } from './stopwatch';
import fs from 'fs';
import seedrandom from 'seedrandom';
import { log, LogLevel } from '../util/log';
import type { MergeableRecord } from '../util/objects';
Expand All @@ -29,8 +28,6 @@ import type { NormalizedAst, ParentInformation } from '../r-bridge/lang-4.x/ast/
import type { SlicingCriteria } from '../slicing/criterion/parse';
import type { DEFAULT_SLICING_PIPELINE, TREE_SITTER_SLICING_PIPELINE } from '../core/steps/pipeline/default-pipelines';
import { createSlicePipeline } from '../core/steps/pipeline/default-pipelines';


import type { RParseRequestFromFile, RParseRequestFromText } from '../r-bridge/retriever';
import { retrieveNumberOfRTokensOfLastParse } from '../r-bridge/retriever';
import type { PipelineStepNames, PipelineStepOutputWithName } from '../core/steps/pipeline/pipeline';
Expand Down Expand Up @@ -69,6 +66,7 @@ import {
IntervalTop
} from '../abstract-interpretation/data-frame/domain';
import { inferDataFrameShapes } from '../abstract-interpretation/data-frame/shape-inference';
import fs from 'fs';

/**
* The logger to be used for benchmarking as a global object.
Expand Down
9 changes: 7 additions & 2 deletions src/cli/slicer-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { stats2string } from '../benchmark/stats/print';
import { makeMagicCommentHandler } from '../reconstruct/auto-select/magic-comments';
import { doNotAutoSelect } from '../reconstruct/auto-select/auto-select-defaults';
import { getConfig, getEngineConfig } from '../config';
import { requestFromFile } from '../util/formats/adapter';

export interface SlicerCliOptions {
verbose: boolean
Expand Down Expand Up @@ -50,7 +51,7 @@ async function getSlice() {
await slicer.init(
options['input-is-text']
? { request: 'text', content: options.input.replaceAll('\\n', '\n') }
: { request: 'file', content: options.input },
: requestFromFile(options.input),
config,
options['no-magic-comments'] ? doNotAutoSelect : makeMagicCommentHandler(doNotAutoSelect)
);
Expand Down Expand Up @@ -99,7 +100,11 @@ async function getSlice() {
console.log(JSON.stringify(output, jsonReplacer));
} else {
if(doSlicing && options.diff) {
const originalCode = options['input-is-text'] ? options.input : fs.readFileSync(options.input).toString();
let originalCode = options.input;
if(!options['input-is-text']) {
const request = requestFromFile(options.input);
originalCode = request.request === 'text' ? request.content : fs.readFileSync(request.content).toString();
}
console.log(sliceDiffAnsi((slice as SliceResult).result, normalize, new Set(mappedSlices.map(({ id }) => id)), originalCode));
}
if(options.stats) {
Expand Down
2 changes: 1 addition & 1 deletion src/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Parser from 'web-tree-sitter';

import type { RParseRequest } from '../../retriever';
import fs from 'fs';
import type { SyncParser } from '../../parser';
import type { TreeSitterEngineConfig } from '../../../config';
import { log } from '../../../util/log';
import fs from 'fs';

export const DEFAULT_TREE_SITTER_R_WASM_PATH = './node_modules/@eagleoutice/tree-sitter-r/tree-sitter-r.wasm';
export const DEFAULT_TREE_SITTER_WASM_PATH = './node_modules/web-tree-sitter/tree-sitter.wasm';
Expand Down
35 changes: 29 additions & 6 deletions src/r-bridge/retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@ import { deterministicCountingIdGenerator } from './lang-4.x/ast/model/processin
import { RawRType } from './lang-4.x/ast/model/type';
import fs from 'fs';
import path from 'path';
import type { SupportedFormats } from '../util/formats/adapter-format';
import { requestFromFile } from '../util/formats/adapter';

export const fileProtocol = 'file://';

export interface RParseRequestFromFile {
export interface PraseRequestAdditionalInfoBase {
type: SupportedFormats
}

export interface RParseRequestFromFile<AdditionalInfo extends PraseRequestAdditionalInfoBase = PraseRequestAdditionalInfoBase> {
readonly request: 'file';
/**
* The path to the file (an absolute path is probably best here).
* See {@link RParseRequests} for multiple files.
*/
readonly content: string;

/**
* Aditional info from different file formates like .Rmd
*/
readonly info?: AdditionalInfo;

}

export interface RParseRequestFromText {
export interface RParseRequestFromText<AdditionalInfo extends PraseRequestAdditionalInfoBase = PraseRequestAdditionalInfoBase> {
readonly request: 'text'
/**
* Source code to parse (not a file path).
Expand All @@ -32,6 +44,11 @@ export interface RParseRequestFromText {
* or concatenate their contents to pass them with this request.
*/
readonly content: string

/**
* Aditional info from different file formates like .Rmd
*/
readonly info?: AdditionalInfo;
}

/**
Expand Down Expand Up @@ -66,10 +83,15 @@ export function requestFromInput(input: `${typeof fileProtocol}${string}` | stri
}
const content = input as string;
const file = content.startsWith(fileProtocol);
return {
request: file ? 'file' : 'text',
content: file ? content.slice(7) : content
};

if(file) {
return requestFromFile(content.slice(7));
} else {
return {
request: 'text',
content: content
};
}
}


Expand Down Expand Up @@ -135,6 +157,7 @@ export function retrieveParseDataFromRCode(request: RParseRequest, shell: RShell
if(isEmptyRequest(request)) {
return Promise.resolve('');
}

const suffix = request.request === 'file' ? ', encoding="utf-8"' : '';
/* call the function with the request */
const command =`flowr_get_ast(${request.request}=${JSON.stringify(
Expand Down
9 changes: 9 additions & 0 deletions src/util/formats/adapter-format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { RParseRequest } from '../../r-bridge/retriever';

export interface FileAdapter {
convertRequest(request: RParseRequest): RParseRequest
}

export type SupportedFormats = 'R' | 'Rmd';

export type SupportedDocumentTypes = '.r' | '.rmd';
Loading