@eagleoutice/flowr 2.2.15 → 2.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +210 -6
- package/benchmark/slicer.d.ts +3 -1
- package/benchmark/slicer.js +8 -5
- package/benchmark/summarizer/first-phase/process.d.ts +2 -1
- package/benchmark/summarizer/first-phase/process.js +2 -2
- package/cli/benchmark-app.d.ts +1 -0
- package/cli/benchmark-app.js +4 -1
- package/cli/benchmark-helper-app.d.ts +1 -0
- package/cli/benchmark-helper-app.js +7 -8
- package/cli/common/options.js +2 -0
- package/cli/export-quads-app.js +2 -1
- package/cli/flowr.js +58 -57
- package/cli/repl/commands/repl-cfg.js +13 -13
- package/cli/repl/commands/repl-commands.js +2 -2
- package/cli/repl/commands/repl-dataflow.js +10 -10
- package/cli/repl/commands/repl-execute.d.ts +2 -3
- package/cli/repl/commands/repl-execute.js +4 -4
- package/cli/repl/commands/repl-lineage.js +4 -4
- package/cli/repl/commands/repl-main.d.ts +12 -1
- package/cli/repl/commands/repl-normalize.js +6 -6
- package/cli/repl/commands/repl-parse.js +2 -2
- package/cli/repl/commands/repl-query.js +9 -9
- package/cli/repl/commands/repl-version.js +1 -1
- package/cli/repl/core.d.ts +5 -2
- package/cli/repl/core.js +10 -8
- package/cli/repl/server/connection.d.ts +3 -1
- package/cli/repl/server/connection.js +7 -5
- package/cli/repl/server/server.d.ts +3 -2
- package/cli/repl/server/server.js +4 -2
- package/cli/script-core/statistics-core.d.ts +2 -1
- package/cli/script-core/statistics-core.js +2 -2
- package/cli/script-core/statistics-helper-core.d.ts +2 -1
- package/cli/script-core/statistics-helper-core.js +5 -4
- package/cli/slicer-app.js +4 -2
- package/cli/statistics-app.js +2 -1
- package/cli/statistics-helper-app.js +2 -1
- package/config.d.ts +12 -10
- package/config.js +26 -42
- package/control-flow/cfg-dead-code.js +45 -2
- package/control-flow/cfg-simplification.d.ts +2 -0
- package/control-flow/control-flow-graph.d.ts +1 -0
- package/control-flow/control-flow-graph.js +4 -0
- package/control-flow/dfg-cfg-guided-visitor.d.ts +5 -3
- package/control-flow/dfg-cfg-guided-visitor.js +15 -4
- package/control-flow/extract-cfg.d.ts +4 -2
- package/control-flow/extract-cfg.js +4 -3
- package/control-flow/semantic-cfg-guided-visitor.d.ts +19 -1
- package/control-flow/semantic-cfg-guided-visitor.js +23 -3
- package/core/pipeline-executor.d.ts +4 -1
- package/core/pipeline-executor.js +6 -5
- package/core/steps/all/core/10-normalize.d.ts +2 -0
- package/core/steps/all/core/10-normalize.js +1 -1
- package/core/steps/all/core/11-normalize-tree-sitter.d.ts +2 -1
- package/core/steps/all/core/11-normalize-tree-sitter.js +2 -2
- package/core/steps/all/core/20-dataflow.d.ts +2 -1
- package/core/steps/all/core/20-dataflow.js +2 -2
- package/core/steps/all/static-slicing/00-slice.d.ts +2 -1
- package/core/steps/all/static-slicing/00-slice.js +2 -2
- package/core/steps/pipeline/default-pipelines.d.ts +32 -31
- package/core/steps/pipeline/default-pipelines.js +8 -8
- package/core/steps/pipeline-step.d.ts +2 -1
- package/dataflow/environments/built-in-config.d.ts +3 -3
- package/dataflow/environments/built-in.d.ts +7 -1
- package/dataflow/environments/built-in.js +2 -2
- package/dataflow/environments/default-builtin-config.js +4 -2
- package/dataflow/environments/define.d.ts +2 -1
- package/dataflow/environments/define.js +4 -5
- package/dataflow/environments/remove.d.ts +6 -0
- package/dataflow/environments/remove.js +29 -0
- package/dataflow/eval/resolve/alias-tracking.d.ts +7 -2
- package/dataflow/eval/resolve/alias-tracking.js +9 -6
- package/dataflow/eval/resolve/resolve-argument.d.ts +8 -0
- package/dataflow/eval/resolve/resolve-argument.js +118 -0
- package/dataflow/eval/resolve/resolve.d.ts +18 -15
- package/dataflow/eval/resolve/resolve.js +20 -18
- package/dataflow/eval/values/string/string-constants.d.ts +1 -1
- package/dataflow/eval/values/string/string-constants.js +7 -2
- package/dataflow/extractor.d.ts +2 -1
- package/dataflow/extractor.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +5 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +11 -11
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +10 -11
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +7 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-list.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +5 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +15 -15
- package/dataflow/internal/process/functions/call/built-in/built-in-vector.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +1 -1
- package/dataflow/internal/process/functions/call/common.js +1 -1
- package/dataflow/internal/process/functions/process-parameter.js +1 -1
- package/dataflow/origin/dfg-get-symbol-refs.d.ts +21 -0
- package/dataflow/origin/dfg-get-symbol-refs.js +50 -0
- package/dataflow/processor.d.ts +5 -0
- package/documentation/doc-util/doc-cfg.js +4 -3
- package/documentation/doc-util/doc-code.d.ts +1 -1
- package/documentation/doc-util/doc-dfg.js +3 -2
- package/documentation/doc-util/doc-functions.d.ts +24 -0
- package/documentation/doc-util/doc-functions.js +65 -0
- package/documentation/doc-util/doc-normalized-ast.js +3 -2
- package/documentation/doc-util/doc-print.d.ts +5 -0
- package/documentation/doc-util/doc-print.js +36 -0
- package/documentation/doc-util/doc-query.js +3 -2
- package/documentation/doc-util/doc-repl.js +2 -1
- package/documentation/doc-util/doc-search.js +3 -2
- package/documentation/doc-util/doc-types.d.ts +28 -6
- package/documentation/doc-util/doc-types.js +89 -45
- package/documentation/print-cfg-wiki.js +6 -7
- package/documentation/print-core-wiki.js +5 -5
- package/documentation/print-dataflow-graph-wiki.js +10 -10
- package/documentation/print-engines-wiki.js +1 -2
- package/documentation/print-faq-wiki.js +8 -2
- package/documentation/print-interface-wiki.js +1 -2
- package/documentation/print-linter-issue.d.ts +1 -0
- package/documentation/print-linter-issue.js +71 -0
- package/documentation/print-linter-wiki.js +219 -34
- package/documentation/print-linting-and-testing-wiki.js +2 -4
- package/documentation/print-normalized-ast-wiki.js +3 -3
- package/documentation/print-query-wiki.js +1 -2
- package/documentation/print-readme.js +24 -1
- package/documentation/print-search-wiki.js +1 -2
- package/linter/linter-executor.d.ts +3 -1
- package/linter/linter-executor.js +3 -2
- package/linter/linter-format.d.ts +67 -7
- package/linter/linter-format.js +12 -1
- package/linter/linter-rules.d.ts +155 -16
- package/linter/linter-rules.js +12 -4
- package/linter/linter-tags.d.ts +80 -0
- package/linter/linter-tags.js +85 -0
- package/linter/rules/absolute-path.d.ts +71 -0
- package/linter/rules/absolute-path.js +177 -0
- package/linter/rules/deprecated-functions.d.ts +43 -0
- package/linter/rules/deprecated-functions.js +58 -0
- package/linter/rules/{2-file-path-validity.d.ts → file-path-validity.d.ts} +16 -6
- package/linter/rules/{2-file-path-validity.js → file-path-validity.js} +21 -13
- package/linter/rules/naming-convention.d.ts +71 -0
- package/linter/rules/naming-convention.js +164 -0
- package/linter/rules/seeded-randomness.d.ts +65 -0
- package/linter/rules/seeded-randomness.js +122 -0
- package/linter/rules/unused-definition.d.ts +41 -0
- package/linter/rules/unused-definition.js +105 -0
- package/package.json +4 -1
- package/queries/base-query-format.d.ts +2 -0
- package/queries/catalog/call-context-query/call-context-query-executor.d.ts +1 -1
- package/queries/catalog/call-context-query/call-context-query-executor.js +2 -2
- package/queries/catalog/cluster-query/cluster-query-format.d.ts +1 -1
- package/queries/catalog/config-query/config-query-executor.d.ts +1 -1
- package/queries/catalog/config-query/config-query-executor.js +2 -3
- package/queries/catalog/control-flow-query/control-flow-query-executor.d.ts +1 -1
- package/queries/catalog/control-flow-query/control-flow-query-executor.js +2 -2
- package/queries/catalog/control-flow-query/control-flow-query-format.d.ts +1 -1
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +1 -1
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +1 -1
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +4 -116
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -1
- package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -1
- package/queries/catalog/id-map-query/id-map-query-format.d.ts +1 -1
- package/queries/catalog/lineage-query/lineage-query-format.d.ts +1 -1
- package/queries/catalog/linter-query/linter-query-executor.d.ts +1 -1
- package/queries/catalog/linter-query/linter-query-executor.js +2 -2
- package/queries/catalog/linter-query/linter-query-format.d.ts +1 -1
- package/queries/catalog/linter-query/linter-query-format.js +16 -12
- package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +1 -1
- package/queries/catalog/origin-query/origin-query-format.d.ts +1 -1
- package/queries/catalog/project-query/project-query-format.d.ts +1 -1
- package/queries/catalog/resolve-value-query/resolve-value-query-executor.d.ts +1 -1
- package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +2 -2
- package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -1
- package/queries/catalog/search-query/search-query-executor.d.ts +1 -1
- package/queries/catalog/search-query/search-query-executor.js +2 -2
- package/queries/catalog/search-query/search-query-format.d.ts +1 -1
- package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +1 -1
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +2 -2
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +1 -1
- package/queries/query.d.ts +15 -15
- package/r-bridge/lang-4.x/ast/parser/json/parser.d.ts +2 -1
- package/r-bridge/lang-4.x/ast/parser/json/parser.js +4 -2
- package/r-bridge/lang-4.x/convert-values.js +2 -1
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +3 -1
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +4 -4
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.d.ts +1 -1
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +7 -5
- package/r-bridge/shell.d.ts +3 -2
- package/r-bridge/shell.js +4 -5
- package/search/flowr-search-builder.d.ts +6 -2
- package/search/flowr-search-builder.js +7 -0
- package/search/flowr-search-filters.d.ts +32 -8
- package/search/flowr-search-filters.js +42 -15
- package/search/flowr-search.d.ts +4 -0
- package/search/search-executor/search-enrichers.d.ts +7 -3
- package/search/search-executor/search-enrichers.js +29 -20
- package/search/search-executor/search-generators.js +1 -1
- package/search/search-executor/search-transformer.d.ts +2 -0
- package/search/search-executor/search-transformer.js +10 -1
- package/slicing/static/static-slicer.d.ts +1 -1
- package/slicing/static/static-slicer.js +2 -3
- package/statistics/statistics.d.ts +3 -1
- package/statistics/statistics.js +5 -4
- package/util/containers.d.ts +12 -9
- package/util/containers.js +12 -9
- package/util/objects.d.ts +5 -4
- package/util/range.d.ts +5 -1
- package/util/range.js +11 -3
- package/util/text/strings.d.ts +6 -0
- package/util/text/strings.js +35 -0
- package/util/version.js +1 -1
- package/linter/rules/1-deprecated-functions.d.ts +0 -34
- package/linter/rules/1-deprecated-functions.js +0 -54
package/cli/flowr.js
CHANGED
|
@@ -52,45 +52,51 @@ if (options['no-ansi']) {
|
|
|
52
52
|
log_1.log.info('disabling ansi colors');
|
|
53
53
|
(0, ansi_1.setFormatter)(ansi_1.voidFormatter);
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
function createConfig() {
|
|
56
|
+
let config;
|
|
57
|
+
if (options['config-json']) {
|
|
58
|
+
const passedConfig = (0, config_1.parseConfig)(options['config-json']);
|
|
59
|
+
if (passedConfig) {
|
|
60
|
+
log_1.log.info(`Using passed config ${JSON.stringify(passedConfig)}`);
|
|
61
|
+
config = passedConfig;
|
|
62
|
+
}
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
if (config == undefined) {
|
|
65
|
+
if (options['config-file']) {
|
|
66
|
+
// validate it exists
|
|
67
|
+
if (!fs_1.default.existsSync(path_1.default.resolve(options['config-file']))) {
|
|
68
|
+
log_1.log.error(`Config file '${options['config-file']}' does not exist`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
70
71
|
}
|
|
72
|
+
config = (0, config_1.getConfig)(options['config-file'] ?? flowr_main_options_1.defaultConfigFile);
|
|
71
73
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!options['engine.r-shell.disabled']) {
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
if (!options['engine.tree-sitter.disabled']) {
|
|
79
|
-
|
|
74
|
+
// for all options that we manually supply that have a config equivalent, set them in the config
|
|
75
|
+
config = (0, config_1.amendConfig)(config, c => {
|
|
76
|
+
c.engines ??= [];
|
|
77
|
+
if (!options['engine.r-shell.disabled']) {
|
|
78
|
+
c.engines.push({ type: 'r-shell', rPath: options['r-path'] || options['engine.r-shell.r-path'] });
|
|
79
|
+
}
|
|
80
|
+
if (!options['engine.tree-sitter.disabled']) {
|
|
81
|
+
c.engines.push({
|
|
80
82
|
type: 'tree-sitter',
|
|
81
83
|
wasmPath: options['engine.tree-sitter.wasm-path'],
|
|
82
84
|
treeSitterWasmPath: options['engine.tree-sitter.tree-sitter-wasm-path'],
|
|
83
85
|
lax: options['engine.tree-sitter.lax']
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (options['default-engine']) {
|
|
87
|
-
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (options['default-engine']) {
|
|
89
|
+
c.defaultEngine = options['default-engine'];
|
|
90
|
+
}
|
|
91
|
+
return c;
|
|
92
|
+
});
|
|
93
|
+
return config;
|
|
88
94
|
}
|
|
89
|
-
async function retrieveEngineInstances() {
|
|
95
|
+
async function retrieveEngineInstances(config) {
|
|
90
96
|
const engines = {};
|
|
91
|
-
if ((0, config_1.getEngineConfig)('r-shell')) {
|
|
97
|
+
if ((0, config_1.getEngineConfig)(config, 'r-shell')) {
|
|
92
98
|
// we keep an active shell session to allow other parse investigations :)
|
|
93
|
-
engines['r-shell'] = new shell_1.RShell({
|
|
99
|
+
engines['r-shell'] = new shell_1.RShell((0, config_1.getEngineConfig)(config, 'r-shell'), {
|
|
94
100
|
revive: 2 /* RShellReviveOptions.Always */,
|
|
95
101
|
onRevive: (code, signal) => {
|
|
96
102
|
const signalText = signal == null ? '' : ` and signal ${signal}`;
|
|
@@ -99,11 +105,11 @@ async function retrieveEngineInstances() {
|
|
|
99
105
|
}
|
|
100
106
|
});
|
|
101
107
|
}
|
|
102
|
-
if ((0, config_1.getEngineConfig)('tree-sitter')) {
|
|
103
|
-
await tree_sitter_executor_1.TreeSitterExecutor.initTreeSitter();
|
|
108
|
+
if ((0, config_1.getEngineConfig)(config, 'tree-sitter')) {
|
|
109
|
+
await tree_sitter_executor_1.TreeSitterExecutor.initTreeSitter((0, config_1.getEngineConfig)(config, 'tree-sitter'));
|
|
104
110
|
engines['tree-sitter'] = new tree_sitter_executor_1.TreeSitterExecutor();
|
|
105
111
|
}
|
|
106
|
-
let defaultEngine =
|
|
112
|
+
let defaultEngine = config.defaultEngine;
|
|
107
113
|
if (!defaultEngine || !engines[defaultEngine]) {
|
|
108
114
|
// if a default engine isn't specified, we just take the first one we have
|
|
109
115
|
defaultEngine = Object.keys(engines)[0];
|
|
@@ -111,7 +117,19 @@ async function retrieveEngineInstances() {
|
|
|
111
117
|
log_1.log.info(`Using engines ${Object.keys(engines).join(', ')} with default ${defaultEngine}`);
|
|
112
118
|
return { engines, default: defaultEngine };
|
|
113
119
|
}
|
|
120
|
+
function hookSignalHandlers(engines) {
|
|
121
|
+
const end = () => {
|
|
122
|
+
if (options.execute === undefined) {
|
|
123
|
+
console.log(`\n${(0, ansi_1.italic)('Exiting...')}`);
|
|
124
|
+
}
|
|
125
|
+
Object.values(engines.engines).forEach(e => e?.close());
|
|
126
|
+
process.exit(0);
|
|
127
|
+
};
|
|
128
|
+
process.on('SIGINT', end);
|
|
129
|
+
process.on('SIGTERM', end);
|
|
130
|
+
}
|
|
114
131
|
async function mainRepl() {
|
|
132
|
+
const config = createConfig();
|
|
115
133
|
if (options.script) {
|
|
116
134
|
const target = scripts_info_1.scripts[options.script].target;
|
|
117
135
|
(0, assert_1.guard)(target !== undefined, `Unknown script ${options.script}, pick one of ${(0, flowr_main_options_1.getScriptsText)()}.`);
|
|
@@ -124,7 +142,7 @@ async function mainRepl() {
|
|
|
124
142
|
console.log((0, command_line_usage_1.default)(exports.optionHelp));
|
|
125
143
|
process.exit(0);
|
|
126
144
|
}
|
|
127
|
-
const engines = await retrieveEngineInstances();
|
|
145
|
+
const engines = await retrieveEngineInstances(config);
|
|
128
146
|
const defaultEngine = engines.engines[engines.default];
|
|
129
147
|
if (options.version) {
|
|
130
148
|
for (const engine of Object.values(engines.engines)) {
|
|
@@ -133,39 +151,22 @@ async function mainRepl() {
|
|
|
133
151
|
}
|
|
134
152
|
process.exit(0);
|
|
135
153
|
}
|
|
136
|
-
|
|
137
|
-
if (options.execute === undefined) {
|
|
138
|
-
console.log(`\n${(0, ansi_1.italic)('Exiting...')}`);
|
|
139
|
-
}
|
|
140
|
-
Object.values(engines.engines).forEach(e => e?.close());
|
|
141
|
-
process.exit(0);
|
|
142
|
-
};
|
|
143
|
-
// hook some handlers
|
|
144
|
-
process.on('SIGINT', end);
|
|
145
|
-
process.on('SIGTERM', end);
|
|
154
|
+
hookSignalHandlers(engines);
|
|
146
155
|
const allowRSessionAccess = options['r-session-access'] ?? false;
|
|
147
156
|
if (options.execute) {
|
|
148
|
-
await (0, core_1.replProcessAnswer)(repl_main_1.standardReplOutput, options.execute, defaultEngine, allowRSessionAccess);
|
|
157
|
+
await (0, core_1.replProcessAnswer)(config, repl_main_1.standardReplOutput, options.execute, defaultEngine, allowRSessionAccess);
|
|
149
158
|
}
|
|
150
159
|
else {
|
|
151
160
|
await (0, print_version_1.printVersionRepl)(defaultEngine);
|
|
152
|
-
await (0, core_1.repl)({ parser: defaultEngine, allowRSessionAccess });
|
|
161
|
+
await (0, core_1.repl)(config, { parser: defaultEngine, allowRSessionAccess });
|
|
153
162
|
}
|
|
154
163
|
process.exit(0);
|
|
155
164
|
}
|
|
156
165
|
async function mainServer(backend = new net_1.NetServer()) {
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
Object.values(engines.engines).forEach(e => e?.close());
|
|
163
|
-
process.exit(0);
|
|
164
|
-
};
|
|
165
|
-
// hook some handlers
|
|
166
|
-
process.on('SIGINT', end);
|
|
167
|
-
process.on('SIGTERM', end);
|
|
168
|
-
await new server_1.FlowRServer(engines.engines, engines.default, options['r-session-access'], backend).start(options.port);
|
|
166
|
+
const config = createConfig();
|
|
167
|
+
const engines = await retrieveEngineInstances(config);
|
|
168
|
+
hookSignalHandlers(engines);
|
|
169
|
+
await new server_1.FlowRServer(engines.engines, engines.default, options['r-session-access'], config, backend).start(options.port);
|
|
169
170
|
}
|
|
170
171
|
if (options.server) {
|
|
171
172
|
void mainServer(options.ws ? new net_1.WebSocketServerWrapper() : new net_1.NetServer());
|
|
@@ -40,10 +40,10 @@ const retriever_1 = require("../../../r-bridge/retriever");
|
|
|
40
40
|
const cfg_1 = require("../../../util/mermaid/cfg");
|
|
41
41
|
const ansi_1 = require("../../../util/text/ansi");
|
|
42
42
|
const cfg_simplification_1 = require("../../../control-flow/cfg-simplification");
|
|
43
|
-
async function controlflow(parser, remainingLine) {
|
|
43
|
+
async function controlflow(parser, remainingLine, config) {
|
|
44
44
|
return await (0, default_pipelines_1.createDataflowPipeline)(parser, {
|
|
45
45
|
request: (0, retriever_1.requestFromInput)(remainingLine.trim())
|
|
46
|
-
}).allRemainingSteps();
|
|
46
|
+
}, config).allRemainingSteps();
|
|
47
47
|
}
|
|
48
48
|
function handleString(code) {
|
|
49
49
|
return code.startsWith('"') ? JSON.parse(code) : code;
|
|
@@ -51,9 +51,9 @@ function handleString(code) {
|
|
|
51
51
|
function formatInfo(out, type) {
|
|
52
52
|
return out.formatter.format(`Copied ${type} to clipboard.`, { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground, style: 3 /* FontStyles.Italic */ });
|
|
53
53
|
}
|
|
54
|
-
async function produceAndPrintCfg(shell, remainingLine, output, simplifications, cfgConverter) {
|
|
55
|
-
const result = await controlflow(shell, handleString(remainingLine));
|
|
56
|
-
const cfg = (0, extract_cfg_1.extractCfg)(result.normalize, result.dataflow.graph, [...cfg_simplification_1.DefaultCfgSimplificationOrder, ...simplifications]);
|
|
54
|
+
async function produceAndPrintCfg(shell, remainingLine, output, simplifications, cfgConverter, config) {
|
|
55
|
+
const result = await controlflow(shell, handleString(remainingLine), config);
|
|
56
|
+
const cfg = (0, extract_cfg_1.extractCfg)(result.normalize, config, result.dataflow.graph, [...cfg_simplification_1.DefaultCfgSimplificationOrder, ...simplifications]);
|
|
57
57
|
const mermaid = cfgConverter(cfg, result.normalize);
|
|
58
58
|
output.stdout(mermaid);
|
|
59
59
|
try {
|
|
@@ -69,8 +69,8 @@ exports.controlflowCommand = {
|
|
|
69
69
|
usageExample: ':controlflow',
|
|
70
70
|
aliases: ['cfg', 'cf'],
|
|
71
71
|
script: false,
|
|
72
|
-
fn: async (output,
|
|
73
|
-
await produceAndPrintCfg(
|
|
72
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
73
|
+
await produceAndPrintCfg(parser, remainingLine, output, [], cfg_1.cfgToMermaid, config);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
exports.controlflowStarCommand = {
|
|
@@ -78,8 +78,8 @@ exports.controlflowStarCommand = {
|
|
|
78
78
|
usageExample: ':controlflow*',
|
|
79
79
|
aliases: ['cfg*', 'cf*'],
|
|
80
80
|
script: false,
|
|
81
|
-
fn: async (output,
|
|
82
|
-
await produceAndPrintCfg(
|
|
81
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
82
|
+
await produceAndPrintCfg(parser, remainingLine, output, [], cfg_1.cfgToMermaidUrl, config);
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
exports.controlflowBbCommand = {
|
|
@@ -87,8 +87,8 @@ exports.controlflowBbCommand = {
|
|
|
87
87
|
usageExample: ':controlflowbb',
|
|
88
88
|
aliases: ['cfgb', 'cfb'],
|
|
89
89
|
script: false,
|
|
90
|
-
fn: async (output,
|
|
91
|
-
await produceAndPrintCfg(
|
|
90
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
91
|
+
await produceAndPrintCfg(parser, remainingLine, output, ['to-basic-blocks'], cfg_1.cfgToMermaid, config);
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
exports.controlflowBbStarCommand = {
|
|
@@ -96,8 +96,8 @@ exports.controlflowBbStarCommand = {
|
|
|
96
96
|
usageExample: ':controlflowbb*',
|
|
97
97
|
aliases: ['cfgb*', 'cfb*'],
|
|
98
98
|
script: false,
|
|
99
|
-
fn: async (output,
|
|
100
|
-
await produceAndPrintCfg(
|
|
99
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
100
|
+
await produceAndPrintCfg(parser, remainingLine, output, ['to-basic-blocks'], cfg_1.cfgToMermaidUrl, config);
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
//# sourceMappingURL=repl-cfg.js.map
|
|
@@ -50,7 +50,7 @@ exports.helpCommand = {
|
|
|
50
50
|
script: false,
|
|
51
51
|
usageExample: ':help',
|
|
52
52
|
aliases: ['h', '?'],
|
|
53
|
-
fn: output => {
|
|
53
|
+
fn: ({ output }) => {
|
|
54
54
|
initCommandMapping();
|
|
55
55
|
output.stdout(`
|
|
56
56
|
If enabled ('--r-session-access' and if using the 'r-shell' engine), you can just enter R expressions which get evaluated right away:
|
|
@@ -113,7 +113,7 @@ function getReplCommands() {
|
|
|
113
113
|
aliases: [],
|
|
114
114
|
script: true,
|
|
115
115
|
usageExample: `:${script} --help`,
|
|
116
|
-
fn: async (output,
|
|
116
|
+
fn: async ({ output, remainingLine }) => {
|
|
117
117
|
// check if the target *module* exists in the current directory, else try two dirs up, otherwise, fail with a message
|
|
118
118
|
let path = `${__dirname}/${target}`;
|
|
119
119
|
if (!hasModule(path)) {
|
|
@@ -41,10 +41,10 @@ const ansi_1 = require("../../../util/text/ansi");
|
|
|
41
41
|
/**
|
|
42
42
|
* Obtain the dataflow graph using a known parser (such as the {@link RShell} or {@link TreeSitterExecutor}).
|
|
43
43
|
*/
|
|
44
|
-
async function replGetDataflow(parser, code) {
|
|
44
|
+
async function replGetDataflow(config, parser, code) {
|
|
45
45
|
return await (0, default_pipelines_1.createDataflowPipeline)(parser, {
|
|
46
46
|
request: (0, retriever_1.requestFromInput)(code.trim())
|
|
47
|
-
}).allRemainingSteps();
|
|
47
|
+
}, config).allRemainingSteps();
|
|
48
48
|
}
|
|
49
49
|
function handleString(code) {
|
|
50
50
|
return code.startsWith('"') ? JSON.parse(code) : code;
|
|
@@ -57,8 +57,8 @@ exports.dataflowCommand = {
|
|
|
57
57
|
usageExample: ':dataflow',
|
|
58
58
|
aliases: ['d', 'df'],
|
|
59
59
|
script: false,
|
|
60
|
-
fn: async (output,
|
|
61
|
-
const result = await replGetDataflow(
|
|
60
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
61
|
+
const result = await replGetDataflow(config, parser, handleString(remainingLine));
|
|
62
62
|
const mermaid = (0, dfg_1.graphToMermaid)({ graph: result.dataflow.graph, includeEnvironments: false }).string;
|
|
63
63
|
output.stdout(mermaid);
|
|
64
64
|
try {
|
|
@@ -74,8 +74,8 @@ exports.dataflowStarCommand = {
|
|
|
74
74
|
usageExample: ':dataflow*',
|
|
75
75
|
aliases: ['d*', 'df*'],
|
|
76
76
|
script: false,
|
|
77
|
-
fn: async (output,
|
|
78
|
-
const result = await replGetDataflow(
|
|
77
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
78
|
+
const result = await replGetDataflow(config, parser, handleString(remainingLine));
|
|
79
79
|
const mermaid = (0, dfg_1.graphToMermaidUrl)(result.dataflow.graph, false);
|
|
80
80
|
output.stdout(mermaid);
|
|
81
81
|
try {
|
|
@@ -91,8 +91,8 @@ exports.dataflowSimplifiedCommand = {
|
|
|
91
91
|
usageExample: ':dataflowsimple',
|
|
92
92
|
aliases: ['ds', 'dfs'],
|
|
93
93
|
script: false,
|
|
94
|
-
fn: async (output,
|
|
95
|
-
const result = await replGetDataflow(
|
|
94
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
95
|
+
const result = await replGetDataflow(config, parser, handleString(remainingLine));
|
|
96
96
|
const mermaid = (0, dfg_1.graphToMermaid)({ graph: result.dataflow.graph, includeEnvironments: false, simplified: true }).string;
|
|
97
97
|
output.stdout(mermaid);
|
|
98
98
|
try {
|
|
@@ -108,8 +108,8 @@ exports.dataflowSimpleStarCommand = {
|
|
|
108
108
|
usageExample: ':dataflowsimple*',
|
|
109
109
|
aliases: ['ds*', 'dfs*'],
|
|
110
110
|
script: false,
|
|
111
|
-
fn: async (output,
|
|
112
|
-
const result = await replGetDataflow(
|
|
111
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
112
|
+
const result = await replGetDataflow(config, parser, handleString(remainingLine));
|
|
113
113
|
const mermaid = (0, dfg_1.graphToMermaidUrl)(result.dataflow.graph, false, undefined, true);
|
|
114
114
|
output.stdout(mermaid);
|
|
115
115
|
try {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ReplCommand,
|
|
2
|
-
|
|
3
|
-
export declare function tryExecuteRShellCommand(output: ReplOutput, parser: KnownParser, statement: string, allowRSessionAccess: boolean): Promise<void>;
|
|
1
|
+
import type { ReplCommand, ReplCommandInformation } from './repl-main';
|
|
2
|
+
export declare function tryExecuteRShellCommand({ output, parser, allowRSessionAccess, remainingLine }: ReplCommandInformation): Promise<void>;
|
|
4
3
|
export declare const executeCommand: ReplCommand;
|
|
@@ -4,16 +4,16 @@ exports.executeCommand = void 0;
|
|
|
4
4
|
exports.tryExecuteRShellCommand = tryExecuteRShellCommand;
|
|
5
5
|
const ansi_1 = require("../../../util/text/ansi");
|
|
6
6
|
const shell_1 = require("../../../r-bridge/shell");
|
|
7
|
-
async function tryExecuteRShellCommand(output, parser,
|
|
7
|
+
async function tryExecuteRShellCommand({ output, parser, allowRSessionAccess, remainingLine }) {
|
|
8
8
|
if (!allowRSessionAccess) {
|
|
9
9
|
output.stderr(`${output.formatter.format('You are not allowed to execute arbitrary R code.', { style: 1 /* FontStyles.Bold */, color: 1 /* Colors.Red */, effect: ansi_1.ColorEffect.Foreground })}
|
|
10
|
-
If you want to do so, please restart flowR with the ${output.formatter.format('--r-session-access', { style: 1 /* FontStyles.Bold */ })} flag${parser.name !== 'r-shell' ? '. Additionally, please enable the r-shell engine, e.g., with ' + output.formatter.format('--default-engine r-shell', { style: 1 /* FontStyles.Bold */ }) : ''}. Please be careful of the security implications of this action.`);
|
|
10
|
+
If you want to do so, please restart flowR with the ${output.formatter.format('--r-session-access', { style: 1 /* FontStyles.Bold */ })} flag${parser.name !== 'r-shell' ? '. Additionally, please enable the r-shell engine, e.g., with ' + output.formatter.format('--default-engine r-shell', { style: 1 /* FontStyles.Bold */ }) : ''}. Please be careful of the security implications of this action. When running flowR with npm, you have to use an extra ${output.formatter.format('--', { style: 1 /* FontStyles.Bold */ })} to separate flowR from npm arguments.`);
|
|
11
11
|
}
|
|
12
12
|
else if (parser instanceof shell_1.RShell) {
|
|
13
|
-
await executeRShellCommand(output, parser,
|
|
13
|
+
await executeRShellCommand(output, parser, remainingLine);
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
output.stderr(`Executing arbitrary R code is only possible when using the r-shell engine as the default engine. Enable it using the configuration file or the ${output.formatter.format('--default-engine r-shell', { style: 1 /* FontStyles.Bold */ })} command line option.`);
|
|
16
|
+
output.stderr(`Executing arbitrary R code is only possible when using the r-shell engine as the default engine. Enable it using the configuration file or the ${output.formatter.format('--default-engine r-shell', { style: 1 /* FontStyles.Bold */ })} command line option. When running flowR with npm, you have to use an extra ${output.formatter.format('--', { style: 1 /* FontStyles.Bold */ })} to separate flowR from npm arguments.`);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
async function executeRShellCommand(output, shell, statement) {
|
|
@@ -10,10 +10,10 @@ const assert_1 = require("../../../util/assert");
|
|
|
10
10
|
function splitAt(str, idx) {
|
|
11
11
|
return [str.slice(0, idx), str.slice(idx)];
|
|
12
12
|
}
|
|
13
|
-
async function getDfg(parser, remainingLine) {
|
|
13
|
+
async function getDfg(config, parser, remainingLine) {
|
|
14
14
|
return await (0, default_pipelines_1.createDataflowPipeline)(parser, {
|
|
15
15
|
request: (0, retriever_1.requestFromInput)(remainingLine.trim())
|
|
16
|
-
}).allRemainingSteps();
|
|
16
|
+
}, config).allRemainingSteps();
|
|
17
17
|
}
|
|
18
18
|
function filterRelevantEdges(edge) {
|
|
19
19
|
return (0, edge_1.edgeIncludesType)(edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Returns | edge_1.EdgeType.Reads, edge.types);
|
|
@@ -56,9 +56,9 @@ exports.lineageCommand = {
|
|
|
56
56
|
usageExample: ':lineage',
|
|
57
57
|
aliases: ['lin'],
|
|
58
58
|
script: false,
|
|
59
|
-
fn: async (output,
|
|
59
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
60
60
|
const [criterion, rest] = splitAt(remainingLine, remainingLine.indexOf(' '));
|
|
61
|
-
const { dataflow: dfg } = await getDfg(
|
|
61
|
+
const { dataflow: dfg } = await getDfg(config, parser, rest);
|
|
62
62
|
const lineageIds = getLineage(criterion, dfg.graph);
|
|
63
63
|
output.stdout([...lineageIds].join('\n'));
|
|
64
64
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OutputFormatter } from '../../../util/text/ansi';
|
|
2
2
|
import type { KnownParser } from '../../../r-bridge/parser';
|
|
3
|
+
import type { FlowrConfigOptions } from '../../../config';
|
|
3
4
|
/**
|
|
4
5
|
* Defines the main interface for output of the repl.
|
|
5
6
|
* This allows us to redirect it (e.g., in the case of a server connection or tests).
|
|
@@ -18,6 +19,16 @@ export interface ReplOutput {
|
|
|
18
19
|
* @see ReplOutput
|
|
19
20
|
*/
|
|
20
21
|
export declare const standardReplOutput: ReplOutput;
|
|
22
|
+
/**
|
|
23
|
+
* Information passed to each repl command function
|
|
24
|
+
*/
|
|
25
|
+
export interface ReplCommandInformation {
|
|
26
|
+
output: ReplOutput;
|
|
27
|
+
parser: KnownParser;
|
|
28
|
+
remainingLine: string;
|
|
29
|
+
allowRSessionAccess: boolean;
|
|
30
|
+
config: FlowrConfigOptions;
|
|
31
|
+
}
|
|
21
32
|
/**
|
|
22
33
|
* Content of a single command in the repl.
|
|
23
34
|
* The command may execute an external script or simply call *flowR* functions.
|
|
@@ -35,5 +46,5 @@ export interface ReplCommand {
|
|
|
35
46
|
* Function to execute when the command is invoked, it must not write to the command line but instead use the output handler.
|
|
36
47
|
* Furthermore, it has to obey the formatter defined in the {@link ReplOutput}.
|
|
37
48
|
*/
|
|
38
|
-
fn: (
|
|
49
|
+
fn: (info: ReplCommandInformation) => Promise<void> | void;
|
|
39
50
|
}
|
|
@@ -38,10 +38,10 @@ const default_pipelines_1 = require("../../../core/steps/pipeline/default-pipeli
|
|
|
38
38
|
const retriever_1 = require("../../../r-bridge/retriever");
|
|
39
39
|
const ast_1 = require("../../../util/mermaid/ast");
|
|
40
40
|
const ansi_1 = require("../../../util/text/ansi");
|
|
41
|
-
async function normalize(parser, remainingLine) {
|
|
41
|
+
async function normalize(parser, remainingLine, config) {
|
|
42
42
|
return await (0, default_pipelines_1.createNormalizePipeline)(parser, {
|
|
43
43
|
request: (0, retriever_1.requestFromInput)(remainingLine.trim())
|
|
44
|
-
}).allRemainingSteps();
|
|
44
|
+
}, config).allRemainingSteps();
|
|
45
45
|
}
|
|
46
46
|
function handleString(code) {
|
|
47
47
|
return code.startsWith('"') ? JSON.parse(code) : code;
|
|
@@ -54,8 +54,8 @@ exports.normalizeCommand = {
|
|
|
54
54
|
usageExample: ':normalize',
|
|
55
55
|
aliases: ['n'],
|
|
56
56
|
script: false,
|
|
57
|
-
fn: async (output,
|
|
58
|
-
const result = await normalize(
|
|
57
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
58
|
+
const result = await normalize(parser, handleString(remainingLine), config);
|
|
59
59
|
const mermaid = (0, ast_1.normalizedAstToMermaid)(result.normalize.ast);
|
|
60
60
|
output.stdout(mermaid);
|
|
61
61
|
try {
|
|
@@ -71,8 +71,8 @@ exports.normalizeStarCommand = {
|
|
|
71
71
|
usageExample: ':normalize*',
|
|
72
72
|
aliases: ['n*'],
|
|
73
73
|
script: false,
|
|
74
|
-
fn: async (output,
|
|
75
|
-
const result = await normalize(
|
|
74
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
75
|
+
const result = await normalize(parser, handleString(remainingLine), config);
|
|
76
76
|
const mermaid = (0, ast_1.normalizedAstToMermaidUrl)(result.normalize.ast);
|
|
77
77
|
output.stdout(mermaid);
|
|
78
78
|
try {
|
|
@@ -130,10 +130,10 @@ exports.parseCommand = {
|
|
|
130
130
|
usageExample: ':parse',
|
|
131
131
|
aliases: ['p'],
|
|
132
132
|
script: false,
|
|
133
|
-
fn: async (output, parser, remainingLine) => {
|
|
133
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
134
134
|
const result = await (0, default_pipelines_1.createParsePipeline)(parser, {
|
|
135
135
|
request: (0, retriever_1.requestFromInput)((0, retriever_1.removeRQuotes)(remainingLine.trim()))
|
|
136
|
-
}).allRemainingSteps();
|
|
136
|
+
}, config).allRemainingSteps();
|
|
137
137
|
if (parser.name === 'r-shell') {
|
|
138
138
|
const object = (0, format_1.convertPreparedParsedData)((0, format_1.prepareParsedData)(result.parse.parsed));
|
|
139
139
|
output.stdout(depthListToTextTree(toDepthMap(object), output.formatter));
|
|
@@ -9,10 +9,10 @@ const schema_1 = require("../../../util/schema");
|
|
|
9
9
|
const query_1 = require("../../../queries/query");
|
|
10
10
|
const json_1 = require("../../../util/json");
|
|
11
11
|
const query_print_1 = require("../../../queries/query-print");
|
|
12
|
-
async function getDataflow(parser, remainingLine) {
|
|
12
|
+
async function getDataflow(config, parser, remainingLine) {
|
|
13
13
|
return await (0, default_pipelines_1.createDataflowPipeline)(parser, {
|
|
14
14
|
request: (0, retriever_1.requestFromInput)(remainingLine.trim())
|
|
15
|
-
}).allRemainingSteps();
|
|
15
|
+
}, config).allRemainingSteps();
|
|
16
16
|
}
|
|
17
17
|
function printHelp(output) {
|
|
18
18
|
output.stderr(`Format: ${(0, ansi_1.italic)(':query "<query>" <code>', output.formatter)}`);
|
|
@@ -24,7 +24,7 @@ function printHelp(output) {
|
|
|
24
24
|
output.stdout('Similarly, \'@<type>\' is interpreted as a query of the given type.');
|
|
25
25
|
output.stdout(`With this, ${(0, ansi_1.italic)(':query @config', output.formatter)} prints the result of the config query.`);
|
|
26
26
|
}
|
|
27
|
-
async function processQueryArgs(line, parser, output) {
|
|
27
|
+
async function processQueryArgs(line, parser, output, config) {
|
|
28
28
|
const args = (0, args_1.splitAtEscapeSensitive)(line);
|
|
29
29
|
const query = args.shift();
|
|
30
30
|
if (!query) {
|
|
@@ -57,9 +57,9 @@ async function processQueryArgs(line, parser, output) {
|
|
|
57
57
|
else {
|
|
58
58
|
parsedQuery = [{ type: 'call-context', callName: query }];
|
|
59
59
|
}
|
|
60
|
-
const processed = await getDataflow(parser, args.join(' '));
|
|
60
|
+
const processed = await getDataflow(config, parser, args.join(' '));
|
|
61
61
|
return {
|
|
62
|
-
query: (0, query_1.executeQueries)({ dataflow: processed.dataflow, ast: processed.normalize }, parsedQuery),
|
|
62
|
+
query: (0, query_1.executeQueries)({ dataflow: processed.dataflow, ast: processed.normalize, config: config }, parsedQuery),
|
|
63
63
|
processed
|
|
64
64
|
};
|
|
65
65
|
}
|
|
@@ -68,9 +68,9 @@ exports.queryCommand = {
|
|
|
68
68
|
usageExample: ':query "<query>" <code>',
|
|
69
69
|
aliases: [],
|
|
70
70
|
script: false,
|
|
71
|
-
fn: async (output, parser, remainingLine) => {
|
|
71
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
72
72
|
const totalStart = Date.now();
|
|
73
|
-
const results = await processQueryArgs(remainingLine, parser, output);
|
|
73
|
+
const results = await processQueryArgs(remainingLine, parser, output, config);
|
|
74
74
|
const totalEnd = Date.now();
|
|
75
75
|
if (results) {
|
|
76
76
|
output.stdout((0, query_print_1.asciiSummaryOfQueryResult)(ansi_1.ansiFormatter, totalEnd - totalStart, results.query, results.processed));
|
|
@@ -82,8 +82,8 @@ exports.queryStarCommand = {
|
|
|
82
82
|
usageExample: ':query* <query> <code>',
|
|
83
83
|
aliases: [],
|
|
84
84
|
script: false,
|
|
85
|
-
fn: async (output,
|
|
86
|
-
const results = await processQueryArgs(remainingLine,
|
|
85
|
+
fn: async ({ output, parser, remainingLine, config }) => {
|
|
86
|
+
const results = await processQueryArgs(remainingLine, parser, output, config);
|
|
87
87
|
if (results) {
|
|
88
88
|
output.stdout(JSON.stringify(results.query, json_1.jsonReplacer));
|
|
89
89
|
}
|
|
@@ -24,6 +24,6 @@ exports.versionCommand = {
|
|
|
24
24
|
aliases: [],
|
|
25
25
|
usageExample: ':version',
|
|
26
26
|
script: false,
|
|
27
|
-
fn: (output, parser) => printVersionInformation(output, parser)
|
|
27
|
+
fn: ({ output, parser }) => printVersionInformation(output, parser)
|
|
28
28
|
};
|
|
29
29
|
//# sourceMappingURL=repl-version.js.map
|
package/cli/repl/core.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as readline from 'readline';
|
|
|
2
2
|
import type { ReplOutput } from './commands/repl-main';
|
|
3
3
|
import type { MergeableRecord } from '../../util/objects';
|
|
4
4
|
import type { KnownParser } from '../../r-bridge/parser';
|
|
5
|
+
import type { FlowrConfigOptions } from '../../config';
|
|
5
6
|
/**
|
|
6
7
|
* Used by the repl to provide automatic completions for a given (partial) input line
|
|
7
8
|
*/
|
|
@@ -10,12 +11,13 @@ export declare function makeDefaultReplReadline(): readline.ReadLineOptions;
|
|
|
10
11
|
/**
|
|
11
12
|
* This function interprets the given `expr` as a REPL command (see {@link repl} for more on the semantics).
|
|
12
13
|
*
|
|
14
|
+
* @param config - flowr Config
|
|
13
15
|
* @param output - Defines two methods that every function in the repl uses to output its data.
|
|
14
16
|
* @param expr - The expression to process.
|
|
15
17
|
* @param parser - The {@link RShell} or {@link TreeSitterExecutor} to use (see {@link repl}).
|
|
16
18
|
* @param allowRSessionAccess - If true, allows the execution of arbitrary R code.
|
|
17
19
|
*/
|
|
18
|
-
export declare function replProcessAnswer(output: ReplOutput, expr: string, parser: KnownParser, allowRSessionAccess: boolean): Promise<void>;
|
|
20
|
+
export declare function replProcessAnswer(config: FlowrConfigOptions, output: ReplOutput, expr: string, parser: KnownParser, allowRSessionAccess: boolean): Promise<void>;
|
|
19
21
|
/**
|
|
20
22
|
* Options for the {@link repl} function.
|
|
21
23
|
*/
|
|
@@ -43,9 +45,10 @@ export interface FlowrReplOptions extends MergeableRecord {
|
|
|
43
45
|
* - Starting with anything else, indicating default R code to be directly executed. If you kill the underlying shell, that is on you! </li>
|
|
44
46
|
*
|
|
45
47
|
* @param options - The options for the repl. See {@link FlowrReplOptions} for more information.
|
|
48
|
+
* @param config - The flowr config
|
|
46
49
|
*
|
|
47
50
|
* For the execution, this function makes use of {@link replProcessAnswer}.
|
|
48
51
|
*
|
|
49
52
|
*/
|
|
50
|
-
export declare function repl({ parser, rl, output, historyFile, allowRSessionAccess }: FlowrReplOptions): Promise<void>;
|
|
53
|
+
export declare function repl(config: FlowrConfigOptions, { parser, rl, output, historyFile, allowRSessionAccess }: FlowrReplOptions): Promise<void>;
|
|
51
54
|
export declare function loadReplHistory(historyFile: string): string[] | undefined;
|
package/cli/repl/core.js
CHANGED
|
@@ -59,6 +59,7 @@ const retriever_1 = require("../../r-bridge/retriever");
|
|
|
59
59
|
const repl_main_1 = require("./commands/repl-main");
|
|
60
60
|
const shell_1 = require("../../r-bridge/shell");
|
|
61
61
|
const log_1 = require("../../util/log");
|
|
62
|
+
const config_1 = require("../../config");
|
|
62
63
|
let _replCompleterKeywords = undefined;
|
|
63
64
|
function replCompleterKeywords() {
|
|
64
65
|
if (_replCompleterKeywords === undefined) {
|
|
@@ -109,15 +110,14 @@ function makeDefaultReplReadline() {
|
|
|
109
110
|
completer: replCompleter
|
|
110
111
|
};
|
|
111
112
|
}
|
|
112
|
-
|
|
113
|
-
async function replProcessStatement(output, statement, parser, allowRSessionAccess) {
|
|
113
|
+
async function replProcessStatement(output, statement, parser, allowRSessionAccess, config) {
|
|
114
114
|
if (statement.startsWith(':')) {
|
|
115
115
|
const command = statement.slice(1).split(' ')[0].toLowerCase();
|
|
116
116
|
const processor = (0, repl_commands_1.getCommand)(command);
|
|
117
117
|
const bold = (s) => output.formatter.format(s, { style: 1 /* FontStyles.Bold */ });
|
|
118
118
|
if (processor) {
|
|
119
119
|
try {
|
|
120
|
-
await processor.fn(output, parser, statement.slice(command.length + 2).trim(), allowRSessionAccess);
|
|
120
|
+
await processor.fn({ output, parser, remainingLine: statement.slice(command.length + 2).trim(), allowRSessionAccess, config });
|
|
121
121
|
}
|
|
122
122
|
catch (e) {
|
|
123
123
|
output.stdout(`${bold(`Failed to execute command ${command}`)}: ${e?.message}. Using the ${bold('--verbose')} flag on startup may provide additional information.\n`);
|
|
@@ -131,21 +131,22 @@ async function replProcessStatement(output, statement, parser, allowRSessionAcce
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
|
-
await (0, repl_execute_1.tryExecuteRShellCommand)(output, parser, statement, allowRSessionAccess);
|
|
134
|
+
await (0, repl_execute_1.tryExecuteRShellCommand)({ output, parser, remainingLine: statement, allowRSessionAccess, config });
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* This function interprets the given `expr` as a REPL command (see {@link repl} for more on the semantics).
|
|
139
139
|
*
|
|
140
|
+
* @param config - flowr Config
|
|
140
141
|
* @param output - Defines two methods that every function in the repl uses to output its data.
|
|
141
142
|
* @param expr - The expression to process.
|
|
142
143
|
* @param parser - The {@link RShell} or {@link TreeSitterExecutor} to use (see {@link repl}).
|
|
143
144
|
* @param allowRSessionAccess - If true, allows the execution of arbitrary R code.
|
|
144
145
|
*/
|
|
145
|
-
async function replProcessAnswer(output, expr, parser, allowRSessionAccess) {
|
|
146
|
+
async function replProcessAnswer(config, output, expr, parser, allowRSessionAccess) {
|
|
146
147
|
const statements = (0, args_1.splitAtEscapeSensitive)(expr, false, ';');
|
|
147
148
|
for (const statement of statements) {
|
|
148
|
-
await replProcessStatement(output, statement, parser, allowRSessionAccess);
|
|
149
|
+
await replProcessStatement(output, statement, parser, allowRSessionAccess, config);
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
/**
|
|
@@ -156,11 +157,12 @@ async function replProcessAnswer(output, expr, parser, allowRSessionAccess) {
|
|
|
156
157
|
* - Starting with anything else, indicating default R code to be directly executed. If you kill the underlying shell, that is on you! </li>
|
|
157
158
|
*
|
|
158
159
|
* @param options - The options for the repl. See {@link FlowrReplOptions} for more information.
|
|
160
|
+
* @param config - The flowr config
|
|
159
161
|
*
|
|
160
162
|
* For the execution, this function makes use of {@link replProcessAnswer}.
|
|
161
163
|
*
|
|
162
164
|
*/
|
|
163
|
-
async function repl({ parser = new shell_1.RShell({ revive: 2 /* RShellReviveOptions.Always */ }), rl = readline.createInterface(makeDefaultReplReadline()), output = repl_main_1.standardReplOutput, historyFile = defaultHistoryFile, allowRSessionAccess = false }) {
|
|
165
|
+
async function repl(config, { parser = new shell_1.RShell((0, config_1.getEngineConfig)(config, 'r-shell'), { revive: 2 /* RShellReviveOptions.Always */ }), rl = readline.createInterface(makeDefaultReplReadline()), output = repl_main_1.standardReplOutput, historyFile = defaultHistoryFile, allowRSessionAccess = false }) {
|
|
164
166
|
if (historyFile) {
|
|
165
167
|
rl.on('history', h => fs_1.default.writeFileSync(historyFile, h.join('\n'), { encoding: 'utf-8' }));
|
|
166
168
|
}
|
|
@@ -169,7 +171,7 @@ async function repl({ parser = new shell_1.RShell({ revive: 2 /* RShellReviveOpt
|
|
|
169
171
|
await new Promise((resolve, reject) => {
|
|
170
172
|
rl.question((0, prompt_1.prompt)(), answer => {
|
|
171
173
|
rl.pause();
|
|
172
|
-
replProcessAnswer(output, answer, parser, allowRSessionAccess).then(() => {
|
|
174
|
+
replProcessAnswer(config, output, answer, parser, allowRSessionAccess).then(() => {
|
|
173
175
|
rl.resume();
|
|
174
176
|
resolve();
|
|
175
177
|
}).catch(reject);
|