@eagleoutice/flowr 2.13.3 → 2.13.5
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 +32 -32
- package/abstract-interpretation/absint-visitor.js +2 -2
- package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
- package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +1 -1
- package/abstract-interpretation/unsupported-functions.js +1 -1
- package/cli/repl/core.js +10 -2
- package/config.d.ts +4 -1
- package/config.js +10 -1
- package/control-flow/cfg-dead-code.js +91 -15
- package/control-flow/extract-cfg.js +93 -8
- package/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/dataflow/environments/built-in-config.d.ts +6 -3
- package/dataflow/environments/built-in-eval-name.d.ts +20 -0
- package/dataflow/environments/built-in-eval-name.js +25 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +4 -0
- package/dataflow/environments/built-in-props.d.ts +175 -0
- package/dataflow/environments/built-in-props.js +207 -0
- package/dataflow/environments/built-in.d.ts +28 -20
- package/dataflow/environments/built-in.js +39 -8
- package/dataflow/environments/default-builtin-config.d.ts +1094 -86
- package/dataflow/environments/default-builtin-config.js +496 -212
- package/dataflow/environments/identifier.d.ts +25 -1
- package/dataflow/environments/identifier.js +24 -2
- package/dataflow/environments/query-fn-props.d.ts +102 -0
- package/dataflow/environments/query-fn-props.js +188 -0
- package/dataflow/eval/resolve/alias-tracking.d.ts +2 -0
- package/dataflow/eval/resolve/alias-tracking.js +12 -2
- package/dataflow/eval/resolve/match-arguments.d.ts +15 -0
- package/dataflow/eval/resolve/match-arguments.js +77 -0
- package/dataflow/eval/resolve/resolve-numbers.d.ts +202 -0
- package/dataflow/eval/resolve/resolve-numbers.js +163 -0
- package/dataflow/eval/resolve/resolve-operators.d.ts +60 -0
- package/dataflow/eval/resolve/resolve-operators.js +115 -0
- package/dataflow/eval/resolve/resolve-strings.d.ts +98 -0
- package/dataflow/eval/resolve/resolve-strings.js +116 -0
- package/dataflow/eval/resolve/resolve.d.ts +5 -23
- package/dataflow/eval/resolve/resolve.js +56 -87
- package/dataflow/fn/higher-order-function.js +3 -3
- package/dataflow/fn/recursive-function.js +1 -1
- package/dataflow/graph/df-helper.js +1 -1
- package/dataflow/graph/vertex.d.ts +32 -25
- package/dataflow/graph/vertex.js +40 -36
- package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +30 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +62 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +5 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +46 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -1
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +2 -1
- package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
- package/dataflow/internal/process/functions/process-parameter.js +2 -1
- package/documentation/data/faq/faqs.js +11 -0
- package/documentation/doc-util/doc-types.js +1 -1
- package/documentation/wiki-analyzer.js +75 -0
- package/documentation/wiki-core.js +65 -16
- package/documentation/wiki-interface.js +3 -0
- package/linter/linter-rules.d.ts +10 -11
- package/linter/rules/absolute-path.js +1 -1
- package/linter/rules/deprecated-functions.js +5 -3
- package/linter/rules/function-finder-util.d.ts +2 -2
- package/linter/rules/function-finder-util.js +11 -4
- package/linter/rules/network-functions.d.ts +25 -5
- package/linter/rules/network-functions.js +51 -11
- package/linter/rules/no-leaked-credentials.js +1 -1
- package/linter/rules/problematic-inputs.d.ts +1 -1
- package/linter/rules/problematic-inputs.js +7 -1
- package/linter/rules/seeded-randomness.d.ts +5 -8
- package/linter/rules/seeded-randomness.js +17 -9
- package/linter/rules/undefined-symbol.js +1 -1
- package/linter/rules/unused-definition.js +15 -10
- package/linter/rules/useless-loop.js +1 -1
- package/package.json +3 -2
- package/project/cache/flowr-analyzer-cache.d.ts +4 -3
- package/project/cache/flowr-analyzer-cache.js +32 -13
- package/project/cache/flowr-cache.d.ts +39 -12
- package/project/cache/flowr-cache.js +5 -3
- package/project/context/flowr-analyzer-context.d.ts +8 -1
- package/project/context/flowr-analyzer-context.js +11 -1
- package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -2
- package/project/context/flowr-analyzer-dependencies-context.js +15 -1
- package/project/context/flowr-analyzer-files-context.d.ts +8 -4
- package/project/context/flowr-analyzer-files-context.js +20 -1
- package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +33 -0
- package/project/context/flowr-analyzer-incremental-analysis-context.js +63 -0
- package/project/context/flowr-analyzer-meta-context.d.ts +3 -1
- package/project/context/flowr-analyzer-meta-context.js +14 -0
- package/project/context/flowr-file.d.ts +25 -3
- package/project/context/flowr-file.js +24 -2
- package/project/dependency-version-space.d.ts +37 -0
- package/project/dependency-version-space.js +118 -26
- package/project/flowr-analyzer.d.ts +6 -0
- package/project/flowr-analyzer.js +6 -2
- package/project/incremental/incremental-parse/edit-computation.d.ts +7 -0
- package/project/incremental/incremental-parse/edit-computation.js +61 -0
- package/project/incremental/incremental-parse/incremental-parse.d.ts +12 -0
- package/project/incremental/incremental-parse/incremental-parse.js +37 -0
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +57 -0
- package/project/plugins/file-plugins/files/flowr-manifest-files.js +121 -0
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -2
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +2 -2
- package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +33 -0
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +53 -0
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +27 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +47 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +7 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -3
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +10 -4
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +17 -4
- package/project/plugins/plugin-registry.d.ts +4 -4
- package/project/plugins/plugin-registry.js +7 -4
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
- package/project/sigdb/reader.d.ts +7 -0
- package/project/sigdb/reader.js +12 -0
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
- package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
- package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +10 -0
- package/queries/catalog/dependencies-query/function-info/derived-functions.js +41 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +14 -13
- package/queries/catalog/dependencies-query/function-info/write-functions.js +28 -36
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +33 -3
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +31 -0
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +9 -2
- package/queries/catalog/input-sources-query/input-source-functions.d.ts +9 -10
- package/queries/catalog/input-sources-query/input-source-functions.js +23 -394
- package/queries/catalog/input-sources-query/input-sources-query-executor.js +11 -6
- package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +7 -0
- package/queries/catalog/input-sources-query/input-sources-query-format.js +28 -10
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +14 -1
- package/queries/catalog/input-sources-query/simple-input-classifier.js +24 -0
- package/queries/catalog/signature-query/signature-query-executor.d.ts +2 -1
- package/queries/catalog/signature-query/signature-query-executor.js +79 -3
- package/queries/catalog/signature-query/signature-query-format.d.ts +27 -0
- package/queries/catalog/signature-query/signature-query-render.js +21 -3
- package/r-bridge/data/data.d.ts +2 -2
- package/r-bridge/data/data.js +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +6 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +21 -2
- package/r-bridge/parser.d.ts +11 -1
- package/r-bridge/parser.js +7 -4
- package/r-bridge/shell-executor.d.ts +1 -0
- package/r-bridge/shell-executor.js +1 -0
- package/r-bridge/shell.d.ts +1 -0
- package/r-bridge/shell.js +1 -0
- package/reconstruct/inline/source-inline-map.js +1 -1
- package/search/flowr-search-filters.d.ts +1 -6
- package/search/flowr-search-filters.js +1 -8
- package/search/search-executor/search-enrichers.d.ts +2 -0
- package/search/search-executor/search-enrichers.js +29 -12
- package/util/mermaid/dfg.js +1 -1
- package/util/version.js +1 -1
- package/project/plugins/file-plugins/files/flowr-rproject-file.d.ts +0 -31
- package/project/plugins/file-plugins/files/flowr-rproject-file.js +0 -66
- package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.d.ts +0 -22
- package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.js +0 -36
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.d.ts +0 -13
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.js +0 -32
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { BuiltInEvalHandlerArgs } from '../../environments/built-in';
|
|
2
|
+
import { type Value } from '../values/r-value';
|
|
3
|
+
/** R breaks a tie to the even neighbor, unlike `Math.round`, which always goes up */
|
|
4
|
+
declare function roundHalfEven(x: number, digits?: number): number;
|
|
5
|
+
/** R rounds `%%` and `%/%` towards `-Inf`, unlike the JS `%` */
|
|
6
|
+
declare function mod(a: number, b: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* One entry of the {@link NumericFns} registry: the parameters R declares, in order, and how to fold them.
|
|
9
|
+
*
|
|
10
|
+
* A call supplies its arguments positionally or under these names, and `fold` receives them in declaration
|
|
11
|
+
* order, so a parameter R gives a default is simply an optional parameter of `fold`. Whatever `fold` cannot
|
|
12
|
+
* answer (a missing operand it needs, a domain error) it returns `undefined` for, which keeps the call `Top`.
|
|
13
|
+
*/
|
|
14
|
+
export interface NumericFn {
|
|
15
|
+
/** the parameter names, in the order R declares them; an argument matching none of them stops the fold */
|
|
16
|
+
readonly params: readonly string[];
|
|
17
|
+
/** the fold over the supplied operands, in declaration order */
|
|
18
|
+
readonly fold: (...args: number[]) => number | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Every numeric built-in the value solver folds, operators included: `-` is an entry like `sqrt` is, and both
|
|
22
|
+
* are reached through {@link resolveAsNumeric}. Teaching flowR one more is a line here plus the matching
|
|
23
|
+
* `evalHandler` in the built-in configuration -- a test checks that the two agree.
|
|
24
|
+
*
|
|
25
|
+
* An operator gets its operands under the names R gives them (`e1`, `e2`), and the ones that also exist as a
|
|
26
|
+
* unary form declare `e2` as optional. Anything the fold hands back that is not a finite number stays `Top`,
|
|
27
|
+
* so `sqrt(-1)` or `1/0` need no special case here.
|
|
28
|
+
*/
|
|
29
|
+
export declare const NumericFns: {
|
|
30
|
+
readonly '+': {
|
|
31
|
+
readonly params: readonly ["e1", "e2"];
|
|
32
|
+
readonly fold: (a: number, b?: number) => number;
|
|
33
|
+
};
|
|
34
|
+
readonly '-': {
|
|
35
|
+
readonly params: readonly ["e1", "e2"];
|
|
36
|
+
readonly fold: (a: number, b?: number) => number;
|
|
37
|
+
};
|
|
38
|
+
readonly '*': {
|
|
39
|
+
readonly params: readonly ["e1", "e2"];
|
|
40
|
+
readonly fold: (a: number, b: number) => number;
|
|
41
|
+
};
|
|
42
|
+
readonly '/': {
|
|
43
|
+
readonly params: readonly ["e1", "e2"];
|
|
44
|
+
readonly fold: (a: number, b: number) => number;
|
|
45
|
+
};
|
|
46
|
+
readonly '^': {
|
|
47
|
+
readonly params: readonly ["e1", "e2"];
|
|
48
|
+
readonly fold: (a: number, b: number) => number;
|
|
49
|
+
};
|
|
50
|
+
readonly '**': {
|
|
51
|
+
readonly params: readonly ["e1", "e2"];
|
|
52
|
+
readonly fold: (a: number, b: number) => number;
|
|
53
|
+
};
|
|
54
|
+
readonly '%%': {
|
|
55
|
+
readonly params: readonly ["e1", "e2"];
|
|
56
|
+
readonly fold: typeof mod;
|
|
57
|
+
};
|
|
58
|
+
readonly '%/%': {
|
|
59
|
+
readonly params: readonly ["e1", "e2"];
|
|
60
|
+
readonly fold: (a: number, b: number) => number;
|
|
61
|
+
};
|
|
62
|
+
readonly abs: {
|
|
63
|
+
readonly params: readonly ["x"];
|
|
64
|
+
readonly fold: (x: number) => number;
|
|
65
|
+
};
|
|
66
|
+
readonly sqrt: {
|
|
67
|
+
readonly params: readonly ["x"];
|
|
68
|
+
readonly fold: (x: number) => number;
|
|
69
|
+
};
|
|
70
|
+
readonly floor: {
|
|
71
|
+
readonly params: readonly ["x"];
|
|
72
|
+
readonly fold: (x: number) => number;
|
|
73
|
+
};
|
|
74
|
+
readonly ceiling: {
|
|
75
|
+
readonly params: readonly ["x"];
|
|
76
|
+
readonly fold: (x: number) => number;
|
|
77
|
+
};
|
|
78
|
+
readonly trunc: {
|
|
79
|
+
readonly params: readonly ["x"];
|
|
80
|
+
readonly fold: (x: number) => number;
|
|
81
|
+
};
|
|
82
|
+
readonly sign: {
|
|
83
|
+
readonly params: readonly ["x"];
|
|
84
|
+
readonly fold: (x: number) => number;
|
|
85
|
+
};
|
|
86
|
+
readonly round: {
|
|
87
|
+
readonly params: readonly ["x", "digits"];
|
|
88
|
+
readonly fold: typeof roundHalfEven;
|
|
89
|
+
};
|
|
90
|
+
readonly signif: {
|
|
91
|
+
readonly params: readonly ["x", "digits"];
|
|
92
|
+
readonly fold: (x: number, digits?: number) => number | undefined;
|
|
93
|
+
};
|
|
94
|
+
readonly exp: {
|
|
95
|
+
readonly params: readonly ["x"];
|
|
96
|
+
readonly fold: (x: number) => number;
|
|
97
|
+
};
|
|
98
|
+
readonly expm1: {
|
|
99
|
+
readonly params: readonly ["x"];
|
|
100
|
+
readonly fold: (x: number) => number;
|
|
101
|
+
};
|
|
102
|
+
readonly log: {
|
|
103
|
+
readonly params: readonly ["x", "base"];
|
|
104
|
+
readonly fold: (x: number, base?: number) => number;
|
|
105
|
+
};
|
|
106
|
+
readonly log2: {
|
|
107
|
+
readonly params: readonly ["x"];
|
|
108
|
+
readonly fold: (x: number) => number;
|
|
109
|
+
};
|
|
110
|
+
readonly log10: {
|
|
111
|
+
readonly params: readonly ["x"];
|
|
112
|
+
readonly fold: (x: number) => number;
|
|
113
|
+
};
|
|
114
|
+
readonly log1p: {
|
|
115
|
+
readonly params: readonly ["x"];
|
|
116
|
+
readonly fold: (x: number) => number;
|
|
117
|
+
};
|
|
118
|
+
readonly sin: {
|
|
119
|
+
readonly params: readonly ["x"];
|
|
120
|
+
readonly fold: (x: number) => number;
|
|
121
|
+
};
|
|
122
|
+
readonly cos: {
|
|
123
|
+
readonly params: readonly ["x"];
|
|
124
|
+
readonly fold: (x: number) => number;
|
|
125
|
+
};
|
|
126
|
+
readonly tan: {
|
|
127
|
+
readonly params: readonly ["x"];
|
|
128
|
+
readonly fold: (x: number) => number;
|
|
129
|
+
};
|
|
130
|
+
readonly asin: {
|
|
131
|
+
readonly params: readonly ["x"];
|
|
132
|
+
readonly fold: (x: number) => number;
|
|
133
|
+
};
|
|
134
|
+
readonly acos: {
|
|
135
|
+
readonly params: readonly ["x"];
|
|
136
|
+
readonly fold: (x: number) => number;
|
|
137
|
+
};
|
|
138
|
+
readonly atan: {
|
|
139
|
+
readonly params: readonly ["x"];
|
|
140
|
+
readonly fold: (x: number) => number;
|
|
141
|
+
};
|
|
142
|
+
readonly atan2: {
|
|
143
|
+
readonly params: readonly ["y", "x"];
|
|
144
|
+
readonly fold: (y: number, x: number) => number;
|
|
145
|
+
};
|
|
146
|
+
readonly sinh: {
|
|
147
|
+
readonly params: readonly ["x"];
|
|
148
|
+
readonly fold: (x: number) => number;
|
|
149
|
+
};
|
|
150
|
+
readonly cosh: {
|
|
151
|
+
readonly params: readonly ["x"];
|
|
152
|
+
readonly fold: (x: number) => number;
|
|
153
|
+
};
|
|
154
|
+
readonly tanh: {
|
|
155
|
+
readonly params: readonly ["x"];
|
|
156
|
+
readonly fold: (x: number) => number;
|
|
157
|
+
};
|
|
158
|
+
readonly asinh: {
|
|
159
|
+
readonly params: readonly ["x"];
|
|
160
|
+
readonly fold: (x: number) => number;
|
|
161
|
+
};
|
|
162
|
+
readonly acosh: {
|
|
163
|
+
readonly params: readonly ["x"];
|
|
164
|
+
readonly fold: (x: number) => number;
|
|
165
|
+
};
|
|
166
|
+
readonly atanh: {
|
|
167
|
+
readonly params: readonly ["x"];
|
|
168
|
+
readonly fold: (x: number) => number;
|
|
169
|
+
};
|
|
170
|
+
readonly bitwAnd: {
|
|
171
|
+
readonly params: readonly ["a", "b"];
|
|
172
|
+
readonly fold: (a: number, b: number) => number;
|
|
173
|
+
};
|
|
174
|
+
readonly bitwOr: {
|
|
175
|
+
readonly params: readonly ["a", "b"];
|
|
176
|
+
readonly fold: (a: number, b: number) => number;
|
|
177
|
+
};
|
|
178
|
+
readonly bitwXor: {
|
|
179
|
+
readonly params: readonly ["a", "b"];
|
|
180
|
+
readonly fold: (a: number, b: number) => number;
|
|
181
|
+
};
|
|
182
|
+
readonly bitwNot: {
|
|
183
|
+
readonly params: readonly ["a"];
|
|
184
|
+
readonly fold: (a: number) => number;
|
|
185
|
+
};
|
|
186
|
+
readonly bitwShiftL: {
|
|
187
|
+
readonly params: readonly ["a", "n"];
|
|
188
|
+
readonly fold: (a: number, n: number) => number;
|
|
189
|
+
};
|
|
190
|
+
readonly bitwShiftR: {
|
|
191
|
+
readonly params: readonly ["a", "n"];
|
|
192
|
+
readonly fold: (a: number, n: number) => number;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Resolves any call of a {@link NumericFns} entry to a {@link Value}: the operators in prefix or infix form,
|
|
197
|
+
* the unary `+`/`-`, and the named functions with their arguments in any order R accepts. An operand may be a
|
|
198
|
+
* number, a logical (counting as its `0`/`1`), or a vector of numbers, which folds elementwise. Anything that
|
|
199
|
+
* does not resolve, a result that is not finite, and a vector length mismatch all stay `Top`.
|
|
200
|
+
*/
|
|
201
|
+
export declare function resolveAsNumeric(args: BuiltInEvalHandlerArgs): Value;
|
|
202
|
+
export {};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumericFns = void 0;
|
|
4
|
+
exports.resolveAsNumeric = resolveAsNumeric;
|
|
5
|
+
const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
|
|
6
|
+
const identifier_1 = require("../../environments/identifier");
|
|
7
|
+
const r_value_1 = require("../../../util/r-value");
|
|
8
|
+
const r_value_2 = require("../values/r-value");
|
|
9
|
+
const interval_constants_1 = require("../values/intervals/interval-constants");
|
|
10
|
+
const vector_constants_1 = require("../values/vectors/vector-constants");
|
|
11
|
+
const alias_tracking_1 = require("./alias-tracking");
|
|
12
|
+
const match_arguments_1 = require("./match-arguments");
|
|
13
|
+
/** R breaks a tie to the even neighbor, unlike `Math.round`, which always goes up */
|
|
14
|
+
function roundHalfEven(x, digits = 0) {
|
|
15
|
+
const scale = 10 ** digits;
|
|
16
|
+
const scaled = x * scale;
|
|
17
|
+
const below = Math.floor(scaled);
|
|
18
|
+
const rounded = scaled - below !== 0.5 ? Math.round(scaled) : below % 2 === 0 ? below : below + 1;
|
|
19
|
+
return rounded / scale;
|
|
20
|
+
}
|
|
21
|
+
/** R rounds `%%` and `%/%` towards `-Inf`, unlike the JS `%` */
|
|
22
|
+
function mod(a, b) {
|
|
23
|
+
return a - Math.floor(a / b) * b;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Every numeric built-in the value solver folds, operators included: `-` is an entry like `sqrt` is, and both
|
|
27
|
+
* are reached through {@link resolveAsNumeric}. Teaching flowR one more is a line here plus the matching
|
|
28
|
+
* `evalHandler` in the built-in configuration -- a test checks that the two agree.
|
|
29
|
+
*
|
|
30
|
+
* An operator gets its operands under the names R gives them (`e1`, `e2`), and the ones that also exist as a
|
|
31
|
+
* unary form declare `e2` as optional. Anything the fold hands back that is not a finite number stays `Top`,
|
|
32
|
+
* so `sqrt(-1)` or `1/0` need no special case here.
|
|
33
|
+
*/
|
|
34
|
+
exports.NumericFns = {
|
|
35
|
+
/* the arithmetic operators; `+` and `-` fold their unary form as well, which is why `e2` may be missing */
|
|
36
|
+
'+': { params: ['e1', 'e2'], fold: (a, b) => b === undefined ? a : a + b },
|
|
37
|
+
'-': { params: ['e1', 'e2'], fold: (a, b) => b === undefined ? -a : a - b },
|
|
38
|
+
'*': { params: ['e1', 'e2'], fold: (a, b) => a * b },
|
|
39
|
+
'/': { params: ['e1', 'e2'], fold: (a, b) => a / b },
|
|
40
|
+
'^': { params: ['e1', 'e2'], fold: (a, b) => a ** b },
|
|
41
|
+
'**': { params: ['e1', 'e2'], fold: (a, b) => a ** b },
|
|
42
|
+
'%%': { params: ['e1', 'e2'], fold: mod },
|
|
43
|
+
'%/%': { params: ['e1', 'e2'], fold: (a, b) => Math.floor(a / b) },
|
|
44
|
+
/* rounding, each under the parameter names R documents */
|
|
45
|
+
abs: { params: ['x'], fold: Math.abs },
|
|
46
|
+
sqrt: { params: ['x'], fold: Math.sqrt },
|
|
47
|
+
floor: { params: ['x'], fold: Math.floor },
|
|
48
|
+
ceiling: { params: ['x'], fold: Math.ceil },
|
|
49
|
+
trunc: { params: ['x'], fold: Math.trunc },
|
|
50
|
+
sign: { params: ['x'], fold: Math.sign },
|
|
51
|
+
round: { params: ['x', 'digits'], fold: roundHalfEven },
|
|
52
|
+
signif: { params: ['x', 'digits'], fold: (x, digits = 6) => digits >= 1 && digits <= 21 ? Number(x.toPrecision(digits)) : undefined },
|
|
53
|
+
/* exponentials and logarithms; `log` takes its base as a second argument, the rest are fixed */
|
|
54
|
+
exp: { params: ['x'], fold: Math.exp },
|
|
55
|
+
expm1: { params: ['x'], fold: Math.expm1 },
|
|
56
|
+
log: { params: ['x', 'base'], fold: (x, base) => base === undefined ? Math.log(x) : Math.log(x) / Math.log(base) },
|
|
57
|
+
log2: { params: ['x'], fold: Math.log2 },
|
|
58
|
+
log10: { params: ['x'], fold: Math.log10 },
|
|
59
|
+
log1p: { params: ['x'], fold: Math.log1p },
|
|
60
|
+
/* trigonometry and its hyperbolic counterparts */
|
|
61
|
+
sin: { params: ['x'], fold: Math.sin },
|
|
62
|
+
cos: { params: ['x'], fold: Math.cos },
|
|
63
|
+
tan: { params: ['x'], fold: Math.tan },
|
|
64
|
+
asin: { params: ['x'], fold: Math.asin },
|
|
65
|
+
acos: { params: ['x'], fold: Math.acos },
|
|
66
|
+
atan: { params: ['x'], fold: Math.atan },
|
|
67
|
+
atan2: { params: ['y', 'x'], fold: Math.atan2 },
|
|
68
|
+
sinh: { params: ['x'], fold: Math.sinh },
|
|
69
|
+
cosh: { params: ['x'], fold: Math.cosh },
|
|
70
|
+
tanh: { params: ['x'], fold: Math.tanh },
|
|
71
|
+
asinh: { params: ['x'], fold: Math.asinh },
|
|
72
|
+
acosh: { params: ['x'], fold: Math.acosh },
|
|
73
|
+
atanh: { params: ['x'], fold: Math.atanh },
|
|
74
|
+
/* bit twiddling, which R defines on 32-bit integers just as JS does */
|
|
75
|
+
bitwAnd: { params: ['a', 'b'], fold: (a, b) => a & b },
|
|
76
|
+
bitwOr: { params: ['a', 'b'], fold: (a, b) => a | b },
|
|
77
|
+
bitwXor: { params: ['a', 'b'], fold: (a, b) => a ^ b },
|
|
78
|
+
bitwNot: { params: ['a'], fold: (a) => ~a },
|
|
79
|
+
bitwShiftL: { params: ['a', 'n'], fold: (a, n) => a << n },
|
|
80
|
+
bitwShiftR: { params: ['a', 'n'], fold: (a, n) => a >>> n }
|
|
81
|
+
};
|
|
82
|
+
/** the number an operand folds to, with a logical counting as its `0`/`1` just like R would coerce it */
|
|
83
|
+
function numeric(node, args) {
|
|
84
|
+
const value = (0, r_value_1.unliftRValue)((0, alias_tracking_1.resolveIdToValue)(node, args));
|
|
85
|
+
if (typeof value === 'boolean') {
|
|
86
|
+
return Number(value);
|
|
87
|
+
}
|
|
88
|
+
else if ((0, r_value_1.isRNumberValue)(value)) {
|
|
89
|
+
return value.complexNumber ? undefined : value.num;
|
|
90
|
+
}
|
|
91
|
+
/* a vector folds elementwise, so it only counts when every element is a plain number */
|
|
92
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const nums = value.map(e => (0, r_value_1.isRNumberValue)(e) && !e.complexNumber ? e.num : undefined);
|
|
96
|
+
return nums.every(n => n !== undefined) ? nums : undefined;
|
|
97
|
+
}
|
|
98
|
+
/** the name a node calls, whether it is written as an operator or as a plain call of the quoted operator */
|
|
99
|
+
function calledName(node) {
|
|
100
|
+
switch (node.type) {
|
|
101
|
+
case type_1.RType.UnaryOp:
|
|
102
|
+
case type_1.RType.BinaryOp:
|
|
103
|
+
return node.operator;
|
|
104
|
+
case type_1.RType.FunctionCall:
|
|
105
|
+
return node.named ? identifier_1.Identifier.getName(node.functionName.content) : undefined;
|
|
106
|
+
default:
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** apply `fold` to the operands, mapping over the one vector among them (R recycles, we only fold equal lengths) */
|
|
111
|
+
function apply(fold, operands) {
|
|
112
|
+
const lengths = operands.filter(o => Array.isArray(o)).map(o => o.length);
|
|
113
|
+
if (lengths.length === 0) {
|
|
114
|
+
return fold(...operands);
|
|
115
|
+
}
|
|
116
|
+
else if (lengths.some(l => l !== lengths[0])) {
|
|
117
|
+
return undefined; // R would recycle the shorter one, which is too easy to get wrong to guess at
|
|
118
|
+
}
|
|
119
|
+
const out = [];
|
|
120
|
+
for (let i = 0; i < lengths[0]; i++) {
|
|
121
|
+
const value = fold(...operands.map(o => Array.isArray(o) ? o[i] : o));
|
|
122
|
+
if (value === undefined || !Number.isFinite(value)) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
out.push(value);
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Resolves any call of a {@link NumericFns} entry to a {@link Value}: the operators in prefix or infix form,
|
|
131
|
+
* the unary `+`/`-`, and the named functions with their arguments in any order R accepts. An operand may be a
|
|
132
|
+
* number, a logical (counting as its `0`/`1`), or a vector of numbers, which folds elementwise. Anything that
|
|
133
|
+
* does not resolve, a result that is not finite, and a vector length mismatch all stay `Top`.
|
|
134
|
+
*/
|
|
135
|
+
function resolveAsNumeric(args) {
|
|
136
|
+
const name = calledName(args.node);
|
|
137
|
+
const fn = name === undefined ? undefined : exports.NumericFns[name];
|
|
138
|
+
if (fn === undefined) {
|
|
139
|
+
return r_value_2.Top;
|
|
140
|
+
}
|
|
141
|
+
const nodes = (0, match_arguments_1.matchCallArguments)(args.node, fn.params);
|
|
142
|
+
if (nodes === undefined || nodes[0] === undefined) {
|
|
143
|
+
return r_value_2.Top;
|
|
144
|
+
}
|
|
145
|
+
const operands = [];
|
|
146
|
+
for (const node of nodes) {
|
|
147
|
+
if (node === undefined) {
|
|
148
|
+
break; // the parameters R gives a default are the trailing ones, so the fold sees a shorter prefix
|
|
149
|
+
}
|
|
150
|
+
const value = numeric(node, args);
|
|
151
|
+
if (value === undefined) {
|
|
152
|
+
return r_value_2.Top;
|
|
153
|
+
}
|
|
154
|
+
operands.push(value);
|
|
155
|
+
}
|
|
156
|
+
const folded = apply(fn.fold, operands);
|
|
157
|
+
if (typeof folded === 'number') {
|
|
158
|
+
return Number.isFinite(folded) ? (0, interval_constants_1.intervalFrom)(folded, folded) : r_value_2.Top;
|
|
159
|
+
}
|
|
160
|
+
/* a number is an exact interval everywhere else in the solver, so the elements are lifted the same way */
|
|
161
|
+
return folded === undefined ? r_value_2.Top : (0, vector_constants_1.vectorFrom)(folded.map(n => (0, interval_constants_1.intervalFrom)(n, n)));
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=resolve-numbers.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { BuiltInEvalHandlerArgs } from '../../environments/built-in';
|
|
2
|
+
import { type Value } from '../values/r-value';
|
|
3
|
+
/** `strings` marks the operators that also fold for two strings; the ordering ones do not, as R compares them by locale collation */
|
|
4
|
+
export declare const ComparisonOps: {
|
|
5
|
+
readonly '==': {
|
|
6
|
+
readonly apply: (a: number | string, b: number | string) => boolean;
|
|
7
|
+
readonly strings: true;
|
|
8
|
+
};
|
|
9
|
+
readonly '!=': {
|
|
10
|
+
readonly apply: (a: number | string, b: number | string) => boolean;
|
|
11
|
+
readonly strings: true;
|
|
12
|
+
};
|
|
13
|
+
readonly '<': {
|
|
14
|
+
readonly apply: (a: number | string, b: number | string) => boolean;
|
|
15
|
+
readonly strings: false;
|
|
16
|
+
};
|
|
17
|
+
readonly '>': {
|
|
18
|
+
readonly apply: (a: number | string, b: number | string) => boolean;
|
|
19
|
+
readonly strings: false;
|
|
20
|
+
};
|
|
21
|
+
readonly '<=': {
|
|
22
|
+
readonly apply: (a: number | string, b: number | string) => boolean;
|
|
23
|
+
readonly strings: false;
|
|
24
|
+
};
|
|
25
|
+
readonly '>=': {
|
|
26
|
+
readonly apply: (a: number | string, b: number | string) => boolean;
|
|
27
|
+
readonly strings: false;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Resolves a comparison operator on two scalars of the same kind to a {@link Value} logical, with a logical counting as
|
|
32
|
+
* its `0`/`1`. Operands of different kinds stay Top, as R would coerce them to a common type first.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveAsComparison(args: BuiltInEvalHandlerArgs): Value;
|
|
35
|
+
/** `decidedBy` is the lhs that fixes the result of the short-circuiting `&&`/`||` on its own; `&`/`|` vectorize, so they need both sides */
|
|
36
|
+
export declare const LogicalOps: {
|
|
37
|
+
readonly '&&': {
|
|
38
|
+
readonly apply: (a: boolean, b: boolean) => boolean;
|
|
39
|
+
readonly decidedBy: false;
|
|
40
|
+
};
|
|
41
|
+
readonly '||': {
|
|
42
|
+
readonly apply: (a: boolean, b: boolean) => boolean;
|
|
43
|
+
readonly decidedBy: true;
|
|
44
|
+
};
|
|
45
|
+
readonly '&': {
|
|
46
|
+
readonly apply: (a: boolean, b: boolean) => boolean;
|
|
47
|
+
readonly decidedBy: undefined;
|
|
48
|
+
};
|
|
49
|
+
readonly '|': {
|
|
50
|
+
readonly apply: (a: boolean, b: boolean) => boolean;
|
|
51
|
+
readonly decidedBy: undefined;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Resolves the unary `!` and the binary {@link LogicalOps} on scalar logicals to a {@link Value} logical.
|
|
56
|
+
* `NA` and any operand that does not fold keep the result Top, unless the lhs alone already decides it.
|
|
57
|
+
*/
|
|
58
|
+
export declare function resolveAsLogical(args: BuiltInEvalHandlerArgs): Value;
|
|
59
|
+
/** Resolves `(x)` to the {@link Value} of `x`, so that a parenthesized sub-expression folds like the expression itself. */
|
|
60
|
+
export declare function resolveAsGroup(args: BuiltInEvalHandlerArgs): Value;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogicalOps = exports.ComparisonOps = void 0;
|
|
4
|
+
exports.resolveAsComparison = resolveAsComparison;
|
|
5
|
+
exports.resolveAsLogical = resolveAsLogical;
|
|
6
|
+
exports.resolveAsGroup = resolveAsGroup;
|
|
7
|
+
const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
8
|
+
const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
|
|
9
|
+
const identifier_1 = require("../../environments/identifier");
|
|
10
|
+
const r_value_1 = require("../../../util/r-value");
|
|
11
|
+
const logical_constants_1 = require("../values/logical/logical-constants");
|
|
12
|
+
const r_value_2 = require("../values/r-value");
|
|
13
|
+
const general_1 = require("../values/general");
|
|
14
|
+
const alias_tracking_1 = require("./alias-tracking");
|
|
15
|
+
/** the scalar an operand folds to, with a logical counting as its `0`/`1` just like R would coerce it */
|
|
16
|
+
function operand(node, args) {
|
|
17
|
+
const value = (0, r_value_1.unliftRValue)((0, alias_tracking_1.resolveIdToValue)(node, args));
|
|
18
|
+
if (typeof value === 'boolean') {
|
|
19
|
+
return Number(value);
|
|
20
|
+
}
|
|
21
|
+
else if ((0, r_value_1.isRNumberValue)(value)) {
|
|
22
|
+
return value.complexNumber ? undefined : value.num;
|
|
23
|
+
}
|
|
24
|
+
return typeof value === 'object' && value !== null && 'str' in value ? value.str : undefined;
|
|
25
|
+
}
|
|
26
|
+
/** as a condition, R takes any non-zero number for `TRUE`; `NA`, strings and everything else do not fold */
|
|
27
|
+
function asLogical(node, args) {
|
|
28
|
+
const value = operand(node, args);
|
|
29
|
+
return typeof value === 'number' && !Number.isNaN(value) ? value !== 0 : undefined;
|
|
30
|
+
}
|
|
31
|
+
/** the operands of a binary operator and its entry in `ops`, with R presenting the `%.%` ones as an infix call */
|
|
32
|
+
function binary(node, ops) {
|
|
33
|
+
let name, lhs, rhs;
|
|
34
|
+
if (node.type === type_1.RType.BinaryOp) {
|
|
35
|
+
[name, lhs, rhs] = [node.operator, node.lhs, node.rhs];
|
|
36
|
+
}
|
|
37
|
+
else if (node.type === type_1.RType.FunctionCall && node.named && node.arguments.length === 2) {
|
|
38
|
+
const [l, r] = node.arguments;
|
|
39
|
+
name = identifier_1.Identifier.getName(node.functionName.content);
|
|
40
|
+
/* a named argument may swap the operands, as in `` `-`(e2 = 1, e1 = 5) ``, so we only take positional ones */
|
|
41
|
+
[lhs, rhs] = [l === r_function_call_1.EmptyArgument || l.name ? undefined : l.value, r === r_function_call_1.EmptyArgument || r.name ? undefined : r.value];
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const op = ops[name];
|
|
47
|
+
return op === undefined || lhs === undefined || rhs === undefined ? undefined : { op, lhs, rhs };
|
|
48
|
+
}
|
|
49
|
+
function logicalValue(value) {
|
|
50
|
+
return value ? logical_constants_1.ValueLogicalTrue : logical_constants_1.ValueLogicalFalse;
|
|
51
|
+
}
|
|
52
|
+
/** `strings` marks the operators that also fold for two strings; the ordering ones do not, as R compares them by locale collation */
|
|
53
|
+
exports.ComparisonOps = {
|
|
54
|
+
'==': { apply: (a, b) => a === b, strings: true },
|
|
55
|
+
'!=': { apply: (a, b) => a !== b, strings: true },
|
|
56
|
+
'<': { apply: (a, b) => a < b, strings: false },
|
|
57
|
+
'>': { apply: (a, b) => a > b, strings: false },
|
|
58
|
+
'<=': { apply: (a, b) => a <= b, strings: false },
|
|
59
|
+
'>=': { apply: (a, b) => a >= b, strings: false }
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Resolves a comparison operator on two scalars of the same kind to a {@link Value} logical, with a logical counting as
|
|
63
|
+
* its `0`/`1`. Operands of different kinds stay Top, as R would coerce them to a common type first.
|
|
64
|
+
*/
|
|
65
|
+
function resolveAsComparison(args) {
|
|
66
|
+
const bin = binary(args.node, exports.ComparisonOps);
|
|
67
|
+
if (bin === undefined) {
|
|
68
|
+
return r_value_2.Top;
|
|
69
|
+
}
|
|
70
|
+
const lhs = operand(bin.lhs, args);
|
|
71
|
+
const rhs = operand(bin.rhs, args);
|
|
72
|
+
if (lhs === undefined || rhs === undefined || typeof lhs !== typeof rhs || (typeof lhs === 'string' && !bin.op.strings)) {
|
|
73
|
+
return r_value_2.Top;
|
|
74
|
+
}
|
|
75
|
+
return logicalValue(bin.op.apply(lhs, rhs));
|
|
76
|
+
}
|
|
77
|
+
/** `decidedBy` is the lhs that fixes the result of the short-circuiting `&&`/`||` on its own; `&`/`|` vectorize, so they need both sides */
|
|
78
|
+
exports.LogicalOps = {
|
|
79
|
+
'&&': { apply: (a, b) => a && b, decidedBy: false },
|
|
80
|
+
'||': { apply: (a, b) => a || b, decidedBy: true },
|
|
81
|
+
'&': { apply: (a, b) => a && b, decidedBy: undefined },
|
|
82
|
+
'|': { apply: (a, b) => a || b, decidedBy: undefined }
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Resolves the unary `!` and the binary {@link LogicalOps} on scalar logicals to a {@link Value} logical.
|
|
86
|
+
* `NA` and any operand that does not fold keep the result Top, unless the lhs alone already decides it.
|
|
87
|
+
*/
|
|
88
|
+
function resolveAsLogical(args) {
|
|
89
|
+
const node = args.node;
|
|
90
|
+
if (node.type === type_1.RType.UnaryOp) {
|
|
91
|
+
const value = node.operator === '!' ? asLogical(node.operand, args) : undefined;
|
|
92
|
+
return value === undefined ? r_value_2.Top : logicalValue(!value);
|
|
93
|
+
}
|
|
94
|
+
const bin = binary(node, exports.LogicalOps);
|
|
95
|
+
const lhs = bin === undefined ? undefined : asLogical(bin.lhs, args);
|
|
96
|
+
if (bin === undefined || lhs === undefined) {
|
|
97
|
+
return r_value_2.Top;
|
|
98
|
+
}
|
|
99
|
+
else if (lhs === bin.op.decidedBy) {
|
|
100
|
+
return logicalValue(lhs);
|
|
101
|
+
}
|
|
102
|
+
const rhs = asLogical(bin.rhs, args);
|
|
103
|
+
return rhs === undefined ? r_value_2.Top : logicalValue(bin.op.apply(lhs, rhs));
|
|
104
|
+
}
|
|
105
|
+
/** Resolves `(x)` to the {@link Value} of `x`, so that a parenthesized sub-expression folds like the expression itself. */
|
|
106
|
+
function resolveAsGroup(args) {
|
|
107
|
+
const node = args.node;
|
|
108
|
+
if (node.type !== type_1.RType.ExpressionList || node.children.length !== 1) {
|
|
109
|
+
return r_value_2.Top;
|
|
110
|
+
}
|
|
111
|
+
/* unwrap the set again, as the caller of a handler wraps the returned value in one */
|
|
112
|
+
const values = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(node.children[0], args));
|
|
113
|
+
return values?.elements.length === 1 ? values.elements[0] : r_value_2.Top;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=resolve-operators.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { RNamedFunctionCall } from '../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
2
|
+
import type { RNode } from '../../../r-bridge/lang-4.x/ast/model/model';
|
|
3
|
+
import type { BuiltInEvalHandlerArgs } from '../../environments/built-in';
|
|
4
|
+
import { type Value } from '../values/r-value';
|
|
5
|
+
/** everything after the last separator, with trailing separators dropped first (`a/b/` is `b`, `/` is the empty string) */
|
|
6
|
+
declare function basename(path: string): string;
|
|
7
|
+
/** everything before the last separator, `.` if there is none and `/` if only the root remains */
|
|
8
|
+
declare function dirname(path: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* One entry of the {@link StringFns} registry: the parameters R declares, in order, and how to fold them.
|
|
11
|
+
*
|
|
12
|
+
* `fold` receives them in that order, so a parameter R gives a default is an optional parameter of `fold`,
|
|
13
|
+
* and a `...` parameter arrives as the array of everything it collected. Whatever `fold` cannot answer it
|
|
14
|
+
* returns `undefined` for, which keeps the call `Top`.
|
|
15
|
+
*/
|
|
16
|
+
export interface StringFn {
|
|
17
|
+
/** the parameter names, in the order R declares them; `...` collects the arguments naming no other parameter */
|
|
18
|
+
readonly params: readonly string[];
|
|
19
|
+
/** what a parameter R gives a default stands for, so `paste(a, b)` folds like `paste(a, b, sep = ' ')` */
|
|
20
|
+
readonly defaults?: Readonly<Record<string, string>>;
|
|
21
|
+
/** parameters a call may supply that change nothing for the single strings we fold, like `paste`'s `collapse` */
|
|
22
|
+
readonly ignored?: readonly string[];
|
|
23
|
+
/** the fold over the supplied arguments, in declaration order */
|
|
24
|
+
readonly fold: (...args: any[]) => string | number | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Every string built-in the value solver folds, the joining ones included: `paste` is an entry like `toupper`
|
|
28
|
+
* is, and both are reached through {@link resolveAsStringFn}. Teaching flowR one more is a line here plus the
|
|
29
|
+
* matching `evalHandler` in the built-in configuration -- a test checks that the two agree.
|
|
30
|
+
*
|
|
31
|
+
* An entry with a `...` parameter joins what it collected, which is why its separator is just another
|
|
32
|
+
* parameter with a default. The rest take a fixed number of arguments under the names R documents.
|
|
33
|
+
*/
|
|
34
|
+
export declare const StringFns: {
|
|
35
|
+
readonly paste: {
|
|
36
|
+
readonly params: readonly ["...", "sep"];
|
|
37
|
+
readonly defaults: {
|
|
38
|
+
readonly sep: " ";
|
|
39
|
+
};
|
|
40
|
+
readonly ignored: readonly ["collapse"];
|
|
41
|
+
readonly fold: (parts: string[], sep: string) => string;
|
|
42
|
+
};
|
|
43
|
+
readonly paste0: {
|
|
44
|
+
readonly params: readonly ["...", "sep"];
|
|
45
|
+
readonly defaults: {
|
|
46
|
+
readonly sep: "";
|
|
47
|
+
};
|
|
48
|
+
readonly ignored: readonly ["collapse"];
|
|
49
|
+
readonly fold: (parts: string[], sep: string) => string;
|
|
50
|
+
};
|
|
51
|
+
readonly 'file.path': {
|
|
52
|
+
readonly params: readonly ["...", "fsep"];
|
|
53
|
+
readonly defaults: {
|
|
54
|
+
readonly fsep: "/";
|
|
55
|
+
};
|
|
56
|
+
readonly fold: (parts: string[], fsep: string) => string;
|
|
57
|
+
};
|
|
58
|
+
readonly basename: {
|
|
59
|
+
readonly params: readonly ["path"];
|
|
60
|
+
readonly fold: typeof basename;
|
|
61
|
+
};
|
|
62
|
+
readonly dirname: {
|
|
63
|
+
readonly params: readonly ["path"];
|
|
64
|
+
readonly fold: typeof dirname;
|
|
65
|
+
};
|
|
66
|
+
readonly toupper: {
|
|
67
|
+
readonly params: readonly ["x"];
|
|
68
|
+
readonly fold: (s: string) => string;
|
|
69
|
+
};
|
|
70
|
+
readonly tolower: {
|
|
71
|
+
readonly params: readonly ["x"];
|
|
72
|
+
readonly fold: (s: string) => string;
|
|
73
|
+
};
|
|
74
|
+
readonly trimws: {
|
|
75
|
+
readonly params: readonly ["x"];
|
|
76
|
+
readonly fold: (s: string) => string;
|
|
77
|
+
};
|
|
78
|
+
/** R counts characters, so we count code points rather than UTF-16 units */
|
|
79
|
+
readonly nchar: {
|
|
80
|
+
readonly params: readonly ["x"];
|
|
81
|
+
readonly fold: (s: string) => number;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/** the entries that join what they are handed, the ones a name at construction time may be built from */
|
|
85
|
+
export declare const PasteLikeCalls: ReadonlySet<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Folds a named {@link StringFns} call to its result, resolving each argument with `resolveArg`. `undefined`
|
|
88
|
+
* when the name is not one of them, an argument does not resolve, or the call does not match what the entry
|
|
89
|
+
* declares. Shared by the value solver ({@link resolveAsStringFn}) and construction-time name resolution.
|
|
90
|
+
*/
|
|
91
|
+
export declare function foldStringCall<Info>(node: RNamedFunctionCall<Info>, resolveArg: (arg: RNode<Info>) => string | undefined): string | number | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Resolves any call of a {@link StringFns} entry to a {@link Value}, with its arguments in any order R accepts:
|
|
94
|
+
* a join like `paste0("cfg_", k)` when every part resolves to a single string constant, and a transformation
|
|
95
|
+
* like `basename(p)` when its argument does. Anything that does not resolve stays `Top`.
|
|
96
|
+
*/
|
|
97
|
+
export declare function resolveAsStringFn(args: BuiltInEvalHandlerArgs): Value;
|
|
98
|
+
export {};
|