@eagleoutice/flowr 2.1.11 → 2.2.0

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.
Files changed (137) hide show
  1. package/benchmark/slicer.d.ts +5 -12
  2. package/benchmark/slicer.js +46 -28
  3. package/cli/benchmark-app.d.ts +2 -0
  4. package/cli/benchmark-app.js +2 -1
  5. package/cli/benchmark-helper-app.d.ts +2 -0
  6. package/cli/benchmark-helper-app.js +2 -2
  7. package/cli/common/options.js +3 -1
  8. package/cli/flowr-main-options.js +36 -2
  9. package/cli/flowr.d.ts +6 -0
  10. package/cli/flowr.js +51 -24
  11. package/cli/repl/commands/repl-cfg.js +2 -4
  12. package/cli/repl/commands/repl-dataflow.js +2 -4
  13. package/cli/repl/commands/repl-execute.d.ts +2 -2
  14. package/cli/repl/commands/repl-execute.js +15 -5
  15. package/cli/repl/commands/repl-lineage.js +2 -4
  16. package/cli/repl/commands/repl-main.d.ts +2 -2
  17. package/cli/repl/commands/repl-normalize.js +2 -4
  18. package/cli/repl/commands/repl-parse.js +2 -4
  19. package/cli/repl/commands/repl-query.js +7 -9
  20. package/cli/repl/commands/repl-version.d.ts +5 -4
  21. package/cli/repl/commands/repl-version.js +10 -9
  22. package/cli/repl/core.d.ts +5 -5
  23. package/cli/repl/core.js +8 -12
  24. package/cli/repl/print-version.d.ts +2 -2
  25. package/cli/repl/print-version.js +3 -3
  26. package/cli/repl/server/connection.d.ts +3 -3
  27. package/cli/repl/server/connection.js +6 -8
  28. package/cli/repl/server/messages/message-hello.js +2 -1
  29. package/cli/repl/server/server.d.ts +4 -3
  30. package/cli/repl/server/server.js +7 -5
  31. package/cli/slicer-app.js +1 -1
  32. package/config.d.ts +36 -4
  33. package/config.js +30 -1
  34. package/core/pipeline-executor.d.ts +1 -1
  35. package/core/pipeline-executor.js +1 -1
  36. package/core/steps/all/core/00-parse.d.ts +4 -18
  37. package/core/steps/all/core/00-parse.js +2 -11
  38. package/core/steps/all/core/01-parse-tree-sitter.d.ts +23 -0
  39. package/core/steps/all/core/01-parse-tree-sitter.js +19 -0
  40. package/core/steps/all/core/10-normalize.d.ts +3 -2
  41. package/core/steps/all/core/10-normalize.js +1 -0
  42. package/core/steps/all/core/11-normalize-tree-sitter.d.ts +25 -0
  43. package/core/steps/all/core/11-normalize-tree-sitter.js +27 -0
  44. package/core/steps/all/core/20-dataflow.d.ts +2 -0
  45. package/core/steps/all/core/20-dataflow.js +1 -1
  46. package/core/steps/pipeline/default-pipelines.d.ts +374 -23
  47. package/core/steps/pipeline/default-pipelines.js +48 -4
  48. package/dataflow/extractor.d.ts +2 -1
  49. package/dataflow/extractor.js +2 -1
  50. package/dataflow/graph/vertex.d.ts +4 -0
  51. package/dataflow/graph/vertex.js +3 -1
  52. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +6 -5
  53. package/dataflow/processor.d.ts +2 -0
  54. package/documentation/doc-util/doc-auto-gen.js +2 -1
  55. package/documentation/doc-util/doc-cfg.js +1 -1
  56. package/documentation/doc-util/doc-dfg.js +3 -3
  57. package/documentation/doc-util/doc-files.d.ts +1 -0
  58. package/documentation/doc-util/doc-files.js +4 -0
  59. package/documentation/doc-util/doc-normalized-ast.js +2 -3
  60. package/documentation/doc-util/doc-query.js +2 -2
  61. package/documentation/doc-util/doc-search.d.ts +25 -0
  62. package/documentation/doc-util/doc-search.js +121 -0
  63. package/documentation/doc-util/doc-types.d.ts +10 -2
  64. package/documentation/doc-util/doc-types.js +81 -3
  65. package/documentation/print-dataflow-graph-wiki.js +16 -16
  66. package/documentation/print-engines-wiki.d.ts +1 -0
  67. package/documentation/print-engines-wiki.js +82 -0
  68. package/documentation/print-interface-wiki.js +30 -20
  69. package/documentation/print-normalized-ast-wiki.js +5 -5
  70. package/documentation/print-query-wiki.js +22 -0
  71. package/documentation/print-search-wiki.d.ts +1 -0
  72. package/documentation/print-search-wiki.js +74 -0
  73. package/package.json +10 -5
  74. package/queries/base-query-format.d.ts +2 -2
  75. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +1 -1
  76. package/queries/catalog/call-context-query/call-context-query-executor.js +1 -1
  77. package/queries/catalog/cluster-query/cluster-query-executor.d.ts +1 -1
  78. package/queries/catalog/cluster-query/cluster-query-executor.js +1 -1
  79. package/queries/catalog/cluster-query/cluster-query-format.d.ts +5 -4
  80. package/queries/catalog/dataflow-query/dataflow-query-executor.d.ts +1 -1
  81. package/queries/catalog/dataflow-query/dataflow-query-executor.js +1 -1
  82. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +5 -4
  83. package/queries/catalog/dependencies-query/dependencies-query-executor.js +2 -2
  84. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +5 -4
  85. package/queries/catalog/id-map-query/id-map-query-format.d.ts +5 -4
  86. package/queries/catalog/lineage-query/lineage-query-executor.d.ts +1 -1
  87. package/queries/catalog/lineage-query/lineage-query-executor.js +1 -1
  88. package/queries/catalog/lineage-query/lineage-query-format.d.ts +5 -4
  89. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +5 -4
  90. package/queries/catalog/search-query/search-query-executor.d.ts +3 -0
  91. package/queries/catalog/search-query/search-query-executor.js +27 -0
  92. package/queries/catalog/search-query/search-query-format.d.ts +73 -0
  93. package/queries/catalog/search-query/search-query-format.js +29 -0
  94. package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +1 -1
  95. package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
  96. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +5 -4
  97. package/queries/query.d.ts +95 -29
  98. package/queries/query.js +3 -1
  99. package/r-bridge/lang-4.x/ast/model/type.d.ts +4 -0
  100. package/r-bridge/lang-4.x/ast/model/type.js +3 -1
  101. package/r-bridge/lang-4.x/ast/parser/json/parser.d.ts +4 -2
  102. package/r-bridge/lang-4.x/ast/parser/json/parser.js +5 -0
  103. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +18 -0
  104. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +57 -0
  105. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.d.ts +3 -0
  106. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +541 -0
  107. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-types.d.ts +35 -0
  108. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-types.js +40 -0
  109. package/r-bridge/parser.d.ts +32 -0
  110. package/r-bridge/parser.js +14 -0
  111. package/r-bridge/shell-executor.d.ts +37 -1
  112. package/r-bridge/shell-executor.js +39 -0
  113. package/r-bridge/shell.d.ts +12 -6
  114. package/r-bridge/shell.js +15 -6
  115. package/search/flowr-search-builder.d.ts +193 -0
  116. package/search/flowr-search-builder.js +192 -0
  117. package/search/flowr-search-executor.d.ts +9 -0
  118. package/search/flowr-search-executor.js +16 -0
  119. package/search/flowr-search-filters.d.ts +74 -0
  120. package/search/flowr-search-filters.js +136 -0
  121. package/search/flowr-search-printer.d.ts +10 -0
  122. package/search/flowr-search-printer.js +85 -0
  123. package/search/flowr-search-traverse.d.ts +7 -0
  124. package/search/flowr-search-traverse.js +12 -0
  125. package/search/flowr-search.d.ts +58 -0
  126. package/search/flowr-search.js +29 -0
  127. package/search/search-executor/search-generators.d.ts +37 -0
  128. package/search/search-executor/search-generators.js +64 -0
  129. package/search/search-executor/search-transformer.d.ts +57 -0
  130. package/search/search-executor/search-transformer.js +99 -0
  131. package/search/search-optimizer/search-optimizer.d.ts +9 -0
  132. package/search/search-optimizer/search-optimizer.js +89 -0
  133. package/statistics/statistics.js +1 -1
  134. package/util/arrays.d.ts +13 -0
  135. package/util/assert.d.ts +1 -1
  136. package/util/mermaid/mermaid.js +17 -0
  137. package/util/version.js +1 -1
@@ -0,0 +1,74 @@
1
+ import { RType } from '../r-bridge/lang-4.x/ast/model/type';
2
+ import type { VertexType } from '../dataflow/graph/vertex';
3
+ import type { NormalizedAst, ParentInformation } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
4
+ import type { DataflowInformation } from '../dataflow/info';
5
+ import type { RNode } from '../r-bridge/lang-4.x/ast/model/model';
6
+ export type FlowrFilterName = keyof typeof FlowrFilters;
7
+ export declare enum FlowrFilter {
8
+ DropEmptyArguments = "drop-empty-arguments"
9
+ }
10
+ export declare const ValidFlowrFilters: Set<string>;
11
+ export declare const ValidFlowrFiltersReverse: {
12
+ [k: string]: string;
13
+ };
14
+ export declare const FlowrFilters: {
15
+ readonly "drop-empty-arguments": (n: RNode<ParentInformation>) => boolean;
16
+ };
17
+ type ValidFilterTypes = FlowrFilterName | RType | VertexType;
18
+ /**
19
+ * By default, we provide filter for every {@link RType} and {@link VertexType}.
20
+ */
21
+ export type FlowrFilterExpression = FlowrFilterCombinator | ValidFilterTypes;
22
+ interface BooleanBinaryNode<Composite> {
23
+ readonly type: 'and' | 'or' | 'xor';
24
+ readonly left: Composite;
25
+ readonly right: Composite;
26
+ }
27
+ interface BooleanUnaryNode<Composite> {
28
+ readonly type: 'not';
29
+ readonly operand: Composite;
30
+ }
31
+ type LeafRType = {
32
+ readonly type: 'r-type';
33
+ readonly value: RType;
34
+ };
35
+ type LeafVertexType = {
36
+ readonly type: 'vertex-type';
37
+ readonly value: VertexType;
38
+ };
39
+ type LeafSpecial = {
40
+ readonly type: 'special';
41
+ readonly value: string;
42
+ };
43
+ type Leaf = LeafRType | LeafVertexType | LeafSpecial;
44
+ type BooleanNode = BooleanBinaryNode<BooleanNode> | BooleanUnaryNode<BooleanNode> | Leaf;
45
+ type BooleanNodeOrCombinator = BooleanNode | FlowrFilterCombinator;
46
+ /**
47
+ * @see {@link FlowrFilterCombinator.is}
48
+ * @see {@link evalFilter}
49
+ * @see {@link binaryTreeToString}
50
+ */
51
+ export declare class FlowrFilterCombinator {
52
+ private tree;
53
+ protected constructor(init: BooleanNodeOrCombinator);
54
+ static is(value: BooleanNodeOrCombinator | ValidFilterTypes): FlowrFilterCombinator;
55
+ and(right: BooleanNodeOrCombinator | ValidFilterTypes): this;
56
+ or(right: BooleanNodeOrCombinator | ValidFilterTypes): this;
57
+ xor(right: BooleanNodeOrCombinator | ValidFilterTypes): this;
58
+ private binaryRight;
59
+ not(): this;
60
+ private unary;
61
+ private unpack;
62
+ get(): BooleanNode;
63
+ }
64
+ export declare function binaryTreeToString(tree: BooleanNode): string;
65
+ export declare function isBinaryTree(tree: unknown): tree is {
66
+ tree: BooleanNode;
67
+ };
68
+ interface FilterData {
69
+ readonly node: RNode<ParentInformation>;
70
+ readonly normalize: NormalizedAst;
71
+ readonly dataflow: DataflowInformation;
72
+ }
73
+ export declare function evalFilter(filter: FlowrFilterExpression, data: FilterData): boolean;
74
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowrFilterCombinator = exports.FlowrFilters = exports.ValidFlowrFiltersReverse = exports.ValidFlowrFilters = exports.FlowrFilter = void 0;
4
+ exports.binaryTreeToString = binaryTreeToString;
5
+ exports.isBinaryTree = isBinaryTree;
6
+ exports.evalFilter = evalFilter;
7
+ const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
8
+ const vertex_1 = require("../dataflow/graph/vertex");
9
+ var FlowrFilter;
10
+ (function (FlowrFilter) {
11
+ FlowrFilter["DropEmptyArguments"] = "drop-empty-arguments";
12
+ })(FlowrFilter || (exports.FlowrFilter = FlowrFilter = {}));
13
+ exports.ValidFlowrFilters = new Set(Object.values(FlowrFilter));
14
+ exports.ValidFlowrFiltersReverse = Object.fromEntries(Object.entries(FlowrFilter).map(([k, v]) => [v, k]));
15
+ exports.FlowrFilters = {
16
+ [FlowrFilter.DropEmptyArguments]: (n) => {
17
+ return n.type !== type_1.RType.Argument || n.name !== undefined;
18
+ }
19
+ };
20
+ /**
21
+ * @see {@link FlowrFilterCombinator.is}
22
+ * @see {@link evalFilter}
23
+ * @see {@link binaryTreeToString}
24
+ */
25
+ class FlowrFilterCombinator {
26
+ tree;
27
+ constructor(init) {
28
+ this.tree = this.unpack(init);
29
+ }
30
+ static is(value) {
31
+ if (typeof value === 'object') {
32
+ return new this(value);
33
+ }
34
+ else if (type_1.ValidRTypes.has(value)) {
35
+ return new this({ type: 'r-type', value: value });
36
+ }
37
+ else if (vertex_1.ValidVertexTypes.has(value)) {
38
+ return new this({ type: 'vertex-type', value: value });
39
+ }
40
+ else if (exports.ValidFlowrFilters.has(value)) {
41
+ return new this({ type: 'special', value: value });
42
+ }
43
+ else {
44
+ throw new Error(`Invalid filter value: ${value}`);
45
+ }
46
+ }
47
+ and(right) {
48
+ return this.binaryRight('and', right);
49
+ }
50
+ or(right) {
51
+ return this.binaryRight('or', right);
52
+ }
53
+ xor(right) {
54
+ return this.binaryRight('xor', right);
55
+ }
56
+ binaryRight(op, right) {
57
+ this.tree = {
58
+ type: op,
59
+ left: this.tree,
60
+ right: this.unpack(FlowrFilterCombinator.is(right))
61
+ };
62
+ return this;
63
+ }
64
+ not() {
65
+ return this.unary('not');
66
+ }
67
+ unary(op) {
68
+ this.tree = {
69
+ type: op,
70
+ operand: this.tree
71
+ };
72
+ return this;
73
+ }
74
+ unpack(val) {
75
+ return val instanceof FlowrFilterCombinator ? val.tree : val;
76
+ }
77
+ get() {
78
+ return this.tree;
79
+ }
80
+ }
81
+ exports.FlowrFilterCombinator = FlowrFilterCombinator;
82
+ function binaryTreeToString(tree) {
83
+ const res = treeToStringImpl(tree, 0);
84
+ // drop outer parens
85
+ if (res.startsWith('(') && res.endsWith(')')) {
86
+ return res.slice(1, -1);
87
+ }
88
+ else {
89
+ return res;
90
+ }
91
+ }
92
+ const typeToSymbol = {
93
+ 'and': '∧',
94
+ 'or': '∨',
95
+ 'xor': '⊕',
96
+ 'not': '¬'
97
+ };
98
+ function treeToStringImpl(tree, depth) {
99
+ if (tree.type === 'r-type' || tree.type === 'vertex-type' || tree.type === 'special') {
100
+ return tree.value;
101
+ }
102
+ if (tree.type === 'not') {
103
+ return `${typeToSymbol[tree.type]}${treeToStringImpl(tree.operand, depth)}`;
104
+ }
105
+ const left = treeToStringImpl(tree.left, depth + 1);
106
+ const right = treeToStringImpl(tree.right, depth + 1);
107
+ return `(${left} ${typeToSymbol[tree.type]} ${right})`;
108
+ }
109
+ function isBinaryTree(tree) {
110
+ return typeof tree === 'object' && tree !== null && 'tree' in tree;
111
+ }
112
+ const evalVisit = {
113
+ and: ({ left, right }, data) => evalTree(left, data) && evalTree(right, data),
114
+ or: ({ left, right }, data) => evalTree(left, data) || evalTree(right, data),
115
+ xor: ({ left, right }, data) => evalTree(left, data) !== evalTree(right, data),
116
+ not: ({ operand }, data) => !evalTree(operand, data),
117
+ 'r-type': ({ value }, { node }) => node.type === value,
118
+ 'vertex-type': ({ value }, { dataflow: { graph }, node }) => graph.getVertex(node.info.id)?.tag === value,
119
+ 'special': ({ value }, { node }) => {
120
+ const getHandler = exports.FlowrFilters[value];
121
+ if (getHandler) {
122
+ return getHandler(node);
123
+ }
124
+ throw new Error(`Special filter not implemented: ${value}`);
125
+ }
126
+ };
127
+ function evalTree(tree, data) {
128
+ /* we ensure that the types fit */
129
+ return evalVisit[tree.type](tree, data);
130
+ }
131
+ function evalFilter(filter, data) {
132
+ /* common lift, this can be improved easily :D */
133
+ const tree = FlowrFilterCombinator.is(filter);
134
+ return evalTree(tree.get(), data);
135
+ }
136
+ //# sourceMappingURL=flowr-search-filters.js.map
@@ -0,0 +1,10 @@
1
+ import type { FlowrSearchLike } from './flowr-search-builder';
2
+ export interface FlowrSearchMermaidBuilderOptions {
3
+ header?: string;
4
+ }
5
+ /**
6
+ * Converts a {@link FlowrSearchLike} object to a mermaid flowchart.
7
+ */
8
+ export declare function flowrSearchToMermaid(search: FlowrSearchLike, conf?: FlowrSearchMermaidBuilderOptions): string;
9
+ export declare function flowrSearchToAscii(search: FlowrSearchLike): string;
10
+ export declare function flowrSearchToCode(search: FlowrSearchLike): string;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flowrSearchToMermaid = flowrSearchToMermaid;
4
+ exports.flowrSearchToAscii = flowrSearchToAscii;
5
+ exports.flowrSearchToCode = flowrSearchToCode;
6
+ const flowr_search_traverse_1 = require("./flowr-search-traverse");
7
+ const mermaid_1 = require("../util/mermaid/mermaid");
8
+ const flowr_search_filters_1 = require("./flowr-search-filters");
9
+ const vertex_1 = require("../dataflow/graph/vertex");
10
+ const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
11
+ /**
12
+ * Converts a {@link FlowrSearchLike} object to a mermaid flowchart.
13
+ */
14
+ function flowrSearchToMermaid(search, conf) {
15
+ const out = [conf?.header ?? 'flowchart LR'];
16
+ let count = 0;
17
+ out.push((0, flowr_search_traverse_1.traverseFlowrSearchBuilderType)(search, ({ type, name, args }) => `${count}("<b>${name}</b>(${argsToMermaidString(args)})<br/>_${type}_")`, (acc, { name, args, type }) => `${acc} --> ${++count}["<b>${name}</b>(${argsToMermaidString(args)})<br/>_${type}_"]`));
18
+ return out.join('\n');
19
+ }
20
+ function argsToMermaidString(args) {
21
+ if (args === undefined) {
22
+ return '';
23
+ }
24
+ return Object.entries(args).map(([key, value]) => `${key}: ${(0, flowr_search_filters_1.isBinaryTree)(value) ? '_' + (0, mermaid_1.escapeMarkdown)((0, flowr_search_filters_1.binaryTreeToString)(value.tree)) + '_'
25
+ : (0, mermaid_1.escapeMarkdown)(JSON.stringify(value))}`)
26
+ .join(', ');
27
+ }
28
+ function argsToAsciiString(args) {
29
+ if (args === undefined) {
30
+ return '';
31
+ }
32
+ else if (Object.keys(args).length === 1) {
33
+ const key = Object.keys(args)[0];
34
+ const value = args[key];
35
+ return `${key}: ${(0, flowr_search_filters_1.isBinaryTree)(value) ? '_' + (0, flowr_search_filters_1.binaryTreeToString)(value.tree) + '_' : JSON.stringify(value)}`;
36
+ }
37
+ return Object.entries(args).map(([key, value]) => `${key}: ${(0, flowr_search_filters_1.isBinaryTree)(value) ? '_' + (0, flowr_search_filters_1.binaryTreeToString)(value.tree) + '_' : JSON.stringify(value)}`)
38
+ .join(', ');
39
+ }
40
+ function flowrSearchToAscii(search) {
41
+ return (0, flowr_search_traverse_1.traverseFlowrSearchBuilderType)(search, ({ name, args }) => `${name}(${argsToAsciiString(args)})`, (acc, { name, args }) => `${acc} --> ${name}(${argsToAsciiString(args)})`);
42
+ }
43
+ function argsToCodeString(args) {
44
+ if (args === undefined) {
45
+ return '';
46
+ }
47
+ return Object.entries(args).map(([, value]) => `${JSON.stringify(value)}`)
48
+ .join(', ');
49
+ }
50
+ function flowrSearchToCode(search) {
51
+ return (0, flowr_search_traverse_1.traverseFlowrSearchBuilderType)(search, (node) => `Q.${flowrGeneratorToCode(node)}`, (acc, node) => `${acc}.${flowrTransformerToCode(node)}`);
52
+ }
53
+ function flowrTransformerToCode(node) {
54
+ if (node.name === 'filter') {
55
+ const a = node.args.filter;
56
+ if (vertex_1.ValidVertexTypes.has(String(a))) {
57
+ return `${node.name}(VertexType.${vertex_1.ValidVertexTypeReverse[String(a)]})`;
58
+ }
59
+ else if (type_1.ValidRTypes.has(String(a))) {
60
+ return `${node.name}(RType.${type_1.ValidRTypesReverse[String(a)]})`;
61
+ }
62
+ else if (flowr_search_filters_1.ValidFlowrFilters.has(String(a))) {
63
+ return `${node.name}(FlowrFilter.${flowr_search_filters_1.ValidFlowrFiltersReverse[String(a)]})`;
64
+ }
65
+ }
66
+ return `${node.name}(${argsToCodeString(node.args)})`;
67
+ }
68
+ function flowrGeneratorToCode(node) {
69
+ if (node.name !== 'get') {
70
+ return `${node.name}(${argsToCodeString(node.args)})`;
71
+ }
72
+ const a = node.args.filter;
73
+ if (Object.keys(a).length === 1) {
74
+ if (a.name) {
75
+ return `var(${JSON.stringify(a.name)})`;
76
+ }
77
+ }
78
+ else if (Object.keys(a).length === 2) {
79
+ if (a.name && a.line) {
80
+ return `varInLine(${JSON.stringify(a.name)}, ${JSON.stringify(a.line)})`;
81
+ }
82
+ }
83
+ return `${node.name}(${argsToCodeString(node.args)})`;
84
+ }
85
+ //# sourceMappingURL=flowr-search-printer.js.map
@@ -0,0 +1,7 @@
1
+ import type { FlowrSearchLike } from './flowr-search-builder';
2
+ import type { FlowrSearchGeneratorNode } from './search-executor/search-generators';
3
+ import type { FlowrSearchTransformerNode } from './search-executor/search-transformer';
4
+ /**
5
+ * Allows you to traverse a {@link FlowrSearchLike} object.
6
+ */
7
+ export declare function traverseFlowrSearchBuilderType<Accumulate, GeneratorVisit extends (generator: FlowrSearchGeneratorNode) => Accumulate, TransformerVisit extends (acc: Accumulate, transformer: FlowrSearchTransformerNode) => Accumulate>(search: FlowrSearchLike, gen: GeneratorVisit, trans: TransformerVisit): Accumulate;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.traverseFlowrSearchBuilderType = traverseFlowrSearchBuilderType;
4
+ const flowr_search_builder_1 = require("./flowr-search-builder");
5
+ /**
6
+ * Allows you to traverse a {@link FlowrSearchLike} object.
7
+ */
8
+ function traverseFlowrSearchBuilderType(search, gen, trans) {
9
+ const s = (0, flowr_search_builder_1.getFlowrSearch)(search);
10
+ return s.search.reduce(trans, gen(s.generator));
11
+ }
12
+ //# sourceMappingURL=flowr-search-traverse.js.map
@@ -0,0 +1,58 @@
1
+ import type { NoInfo, RNode } from '../r-bridge/lang-4.x/ast/model/model';
2
+ import type { Pipeline, PipelineOutput, PipelineStepOutputWithName } from '../core/steps/pipeline/pipeline';
3
+ import type { NormalizedAst } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
4
+ import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
5
+ import type { DataflowInformation } from '../dataflow/info';
6
+ /**
7
+ * Yes, for now we do technically not need a wrapper around the RNode, but this allows us to attach caches etc.
8
+ * just for the respective search.
9
+ */
10
+ export interface FlowrSearchElement<Info> {
11
+ readonly node: RNode<Info>;
12
+ }
13
+ export interface FlowrSearchNodeBase<Type extends string, Name extends string, Args extends Record<string, unknown> | undefined> {
14
+ readonly type: Type;
15
+ readonly name: Name;
16
+ readonly args: Args;
17
+ }
18
+ export type FlowrSearchGeneratorNodeBase<Name extends string, Args extends Record<string, unknown> | undefined> = FlowrSearchNodeBase<'generator', Name, Args>;
19
+ export type FlowrSearchTransformerNodeBase<Name extends string, Args extends Record<string, unknown> | undefined> = FlowrSearchNodeBase<'transformer', Name, Args>;
20
+ export interface FlowrSearchGetFilter extends Record<string, unknown> {
21
+ /**
22
+ * The node must be in the given line.
23
+ */
24
+ readonly line?: number;
25
+ /**
26
+ * The node must be in the given column.
27
+ */
28
+ readonly column?: number;
29
+ /**
30
+ * The node must have the given name.
31
+ * To treat this name as a regular expression, set {@link FlowrSearchGetFilter#nameIsRegex} to true.
32
+ */
33
+ readonly name?: string;
34
+ /**
35
+ * Only useful in combination with `name`. If true, the name is treated as a regular expression.
36
+ */
37
+ readonly nameIsRegex?: boolean;
38
+ /**
39
+ * The node must have the given id.
40
+ */
41
+ readonly id?: NodeId;
42
+ }
43
+ type MinimumInputForFlowrSearch<P extends Pipeline> = PipelineStepOutputWithName<P, 'normalize'> extends NormalizedAst ? (PipelineStepOutputWithName<P, 'dataflow'> extends DataflowInformation ? PipelineOutput<P> & {
44
+ normalize: NormalizedAst;
45
+ dataflow: DataflowInformation;
46
+ } : never) : never;
47
+ /** we allow any pipeline, which provides us with a 'normalize' and 'dataflow' step */
48
+ export type FlowrSearchInput<P extends Pipeline> = MinimumInputForFlowrSearch<P>;
49
+ /** Intentionally, we abstract away from an array to avoid the use of conventional typescript operations */
50
+ export declare class FlowrSearchElements<Info = NoInfo, Elements extends FlowrSearchElement<Info>[] = FlowrSearchElement<Info>[]> {
51
+ private elements;
52
+ constructor(elements?: Elements);
53
+ add(element: FlowrSearchElement<Info>): this;
54
+ addAll(elements: FlowrSearchElement<Info>[]): this;
55
+ getElements(): readonly FlowrSearchElement<Info>[];
56
+ mutate<OutElements extends Elements>(mutator: (elements: Elements) => OutElements): this;
57
+ }
58
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowrSearchElements = void 0;
4
+ /** Intentionally, we abstract away from an array to avoid the use of conventional typescript operations */
5
+ class FlowrSearchElements {
6
+ elements = [];
7
+ constructor(elements) {
8
+ if (elements) {
9
+ this.elements = elements;
10
+ }
11
+ }
12
+ add(element) {
13
+ this.elements.push(element);
14
+ return this;
15
+ }
16
+ addAll(elements) {
17
+ this.elements.push(...elements);
18
+ return this;
19
+ }
20
+ getElements() {
21
+ return this.elements;
22
+ }
23
+ mutate(mutator) {
24
+ this.elements = mutator(this.elements);
25
+ return this;
26
+ }
27
+ }
28
+ exports.FlowrSearchElements = FlowrSearchElements;
29
+ //# sourceMappingURL=flowr-search.js.map
@@ -0,0 +1,37 @@
1
+ import type { FlowrSearchElement, FlowrSearchGeneratorNodeBase, FlowrSearchGetFilter, FlowrSearchInput } from '../flowr-search';
2
+ import { FlowrSearchElements } from '../flowr-search';
3
+ import type { Pipeline } from '../../core/steps/pipeline/pipeline';
4
+ import type { TailTypesOrUndefined } from '../../util/arrays';
5
+ import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
6
+ import type { SlicingCriteria } from '../../slicing/criterion/parse';
7
+ /**
8
+ * This is a union of all possible generator node types
9
+ */
10
+ export type FlowrSearchGeneratorNode = {
11
+ [K in GeneratorNames]: FlowrSearchGeneratorNodeBase<K, TailTypesOrUndefined<Parameters<typeof generators[K]>>>;
12
+ }[GeneratorNames];
13
+ export type GeneratorNames = keyof typeof generators;
14
+ export type GetGenerator<Name extends GeneratorNames> = FlowrSearchGeneratorNode & {
15
+ name: Name;
16
+ };
17
+ /**
18
+ * All supported generators!
19
+ */
20
+ export declare const generators: {
21
+ readonly all: typeof generateAll;
22
+ readonly get: typeof generateGet;
23
+ readonly criterion: typeof generateCriterion;
24
+ readonly from: typeof generateFrom;
25
+ };
26
+ declare function generateAll(data: FlowrSearchInput<Pipeline>): FlowrSearchElements<ParentInformation>;
27
+ declare function generateGet(data: FlowrSearchInput<Pipeline>, { filter: { line, column, id, name, nameIsRegex } }: {
28
+ filter: FlowrSearchGetFilter;
29
+ }): FlowrSearchElements<ParentInformation>;
30
+ declare function generateFrom(data: FlowrSearchInput<Pipeline>, args: {
31
+ from: FlowrSearchElement<ParentInformation> | FlowrSearchElement<ParentInformation>[];
32
+ }): FlowrSearchElements<ParentInformation>;
33
+ declare function generateCriterion(data: FlowrSearchInput<Pipeline>, args: {
34
+ criterion: SlicingCriteria;
35
+ }): FlowrSearchElements<ParentInformation>;
36
+ export declare function getGenerator<Name extends GeneratorNames>(name: Name): typeof generators[Name];
37
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generators = void 0;
4
+ exports.getGenerator = getGenerator;
5
+ const flowr_search_1 = require("../flowr-search");
6
+ const parse_1 = require("../../slicing/criterion/parse");
7
+ const assert_1 = require("../../util/assert");
8
+ /**
9
+ * All supported generators!
10
+ */
11
+ exports.generators = {
12
+ all: generateAll,
13
+ get: generateGet,
14
+ criterion: generateCriterion,
15
+ from: generateFrom
16
+ };
17
+ function generateAll(data) {
18
+ return new flowr_search_1.FlowrSearchElements(getAllNodes(data)
19
+ .map(node => ({ node })));
20
+ }
21
+ function getAllNodes(data) {
22
+ return [...new Map([...data.normalize.idMap.values()].map(n => [n.info.id, n]))
23
+ .values()];
24
+ }
25
+ function generateGet(data, { filter: { line, column, id, name, nameIsRegex } }) {
26
+ let potentials = (id ?
27
+ [data.normalize.idMap.get(id)].filter(assert_1.isNotUndefined) :
28
+ getAllNodes(data));
29
+ if (line && line < 0) {
30
+ const maxLines = data.normalize.ast.info.fullRange?.[2] ??
31
+ (id ? getAllNodes(data) : potentials).reduce((maxLine, { location }) => location && location[2] > maxLine ? location[2] : maxLine, 0);
32
+ line = maxLines + line + 1;
33
+ }
34
+ if (line && column) {
35
+ potentials = potentials.filter(({ location }) => location?.[0] === line && location?.[1] === column);
36
+ }
37
+ else if (line) {
38
+ potentials = potentials.filter(({ location }) => location?.[0] === line);
39
+ }
40
+ else if (column) {
41
+ potentials = potentials.filter(({ location }) => location?.[1] === column);
42
+ }
43
+ if (nameIsRegex && name) {
44
+ const nameFilter = new RegExp(name);
45
+ potentials = potentials.filter(({ lexeme }) => lexeme && nameFilter.test(lexeme));
46
+ }
47
+ else if (name) {
48
+ potentials = potentials.filter(({ lexeme }) => lexeme === name);
49
+ }
50
+ return new flowr_search_1.FlowrSearchElements(potentials.map(node => ({ node })));
51
+ }
52
+ function generateFrom(data, args) {
53
+ return new flowr_search_1.FlowrSearchElements(Array.isArray(args.from) ? args.from : [args.from]);
54
+ }
55
+ function generateCriterion(data, args) {
56
+ return new flowr_search_1.FlowrSearchElements(args.criterion.map(c => ({ node: data.normalize.idMap.get((0, parse_1.slicingCriterionToId)(c, data.normalize.idMap)) })));
57
+ }
58
+ function getGenerator(name) {
59
+ if (!exports.generators[name]) {
60
+ throw new Error(`Unknown generator: ${name}`);
61
+ }
62
+ return exports.generators[name];
63
+ }
64
+ //# sourceMappingURL=search-generators.js.map
@@ -0,0 +1,57 @@
1
+ import type { FlowrSearchElement, FlowrSearchElements, FlowrSearchInput, FlowrSearchTransformerNodeBase } from '../flowr-search';
2
+ import type { Pipeline } from '../../core/steps/pipeline/pipeline';
3
+ import type { LastOfArray, Tail2TypesOrUndefined, TailOfArray } from '../../util/arrays';
4
+ import type { FlowrFilterExpression } from '../flowr-search-filters';
5
+ import type { FlowrSearchGeneratorNode } from './search-generators';
6
+ import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
7
+ /**
8
+ * This is a union of all possible transformer node types
9
+ */
10
+ export type FlowrSearchTransformerNode = {
11
+ [K in TransformerNames]: FlowrSearchTransformerNodeBase<K, Tail2TypesOrUndefined<Parameters<typeof transformers[K]>>>;
12
+ }[TransformerNames];
13
+ export type TransformerNames = keyof typeof transformers;
14
+ export type GetTransformer<Name extends TransformerNames> = FlowrSearchTransformerNode & {
15
+ name: Name;
16
+ };
17
+ export type GetOutputOfTransformer<Name extends TransformerNames> = ReturnType<typeof transformers[Name]>;
18
+ /**
19
+ * All supported generators!
20
+ */
21
+ export declare const transformers: {
22
+ readonly first: typeof getFirst;
23
+ readonly last: typeof getLast;
24
+ readonly index: typeof getIndex;
25
+ readonly tail: typeof getTail;
26
+ readonly take: typeof getTake;
27
+ readonly skip: typeof getSkip;
28
+ readonly filter: typeof getFilter;
29
+ readonly merge: typeof getMerge;
30
+ readonly select: typeof getSelect;
31
+ };
32
+ export declare function getTransformer<Name extends TransformerNames>(name: Name): typeof transformers[Name];
33
+ /** If we already have no more elements, cascade will not add any but keep the empty elements, otherwise it will now be NewElements */
34
+ type CascadeEmpty<Elements extends FlowrSearchElement<ParentInformation>[], NewElements extends FlowrSearchElement<ParentInformation>[]> = Elements extends [] ? FlowrSearchElements<ParentInformation, []> : FlowrSearchElements<ParentInformation, NewElements>;
35
+ declare function getFirst<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE): CascadeEmpty<Elements, [Elements[0]]>;
36
+ declare function getLast<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE): CascadeEmpty<Elements, [LastOfArray<Elements>]>;
37
+ declare function getIndex<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE, { index }: {
38
+ index: number;
39
+ }): CascadeEmpty<Elements, [Elements[number]]>;
40
+ declare function getSelect<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE, { select }: {
41
+ select: number[];
42
+ }): CascadeEmpty<Elements, Elements>;
43
+ declare function getTail<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE): CascadeEmpty<Elements, TailOfArray<Elements>>;
44
+ declare function getTake<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE, { count }: {
45
+ count: number;
46
+ }): CascadeEmpty<Elements, TailOfArray<Elements>>;
47
+ declare function getSkip<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE, { count }: {
48
+ count: number;
49
+ }): CascadeEmpty<Elements, TailOfArray<Elements>>;
50
+ declare function getFilter<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE, { filter }: {
51
+ filter: FlowrFilterExpression;
52
+ }): CascadeEmpty<Elements, Elements | []>;
53
+ declare function getMerge<Elements extends FlowrSearchElement<ParentInformation>[], FSE extends FlowrSearchElements<ParentInformation, Elements>>(data: FlowrSearchInput<Pipeline>, elements: FSE, other: {
54
+ search: unknown[];
55
+ generator: FlowrSearchGeneratorNode;
56
+ }): FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>;
57
+ export {};