@eagleoutice/flowr 2.17.12 → 2.17.13

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 (29) hide show
  1. package/config.d.ts +1 -0
  2. package/config.js +4 -2
  3. package/dataflow/environments/default-builtin-config/base-functions.d.ts +1 -1
  4. package/dataflow/environments/default-builtin-config/base-functions.js +2 -0
  5. package/dataflow/environments/default-builtin-config/guards.js +3 -1
  6. package/dataflow/environments/default-builtin-config/index.d.ts +1 -1
  7. package/dataflow/extractor.js +58 -0
  8. package/dataflow/fn/guards/built-in-guards.js +4 -4
  9. package/dataflow/fn/guards/call-contracts.js +8 -8
  10. package/dataflow/fn/guards/condition-grouping.js +4 -3
  11. package/dataflow/fn/guards/function-guards.js +103 -97
  12. package/dataflow/fn/guards/group-method-guards.js +10 -8
  13. package/dataflow/fn/guards/guard-claims.js +152 -128
  14. package/dataflow/fn/guards/guard-knowledge.js +19 -18
  15. package/dataflow/fn/guards/guard-term-syntax.js +13 -12
  16. package/dataflow/fn/guards/guard-term.d.ts +71 -0
  17. package/dataflow/fn/guards/guard-term.js +183 -75
  18. package/dataflow/graph/graph.d.ts +9 -0
  19. package/dataflow/graph/graph.js +19 -0
  20. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +6 -2
  21. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +9 -2
  22. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +1 -1
  23. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +1 -1
  24. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +19 -9
  25. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +35 -3
  26. package/documentation/wiki-interface.js +1 -0
  27. package/package.json +1 -1
  28. package/util/flowr-version.d.ts +1 -1
  29. package/util/flowr-version.js +2 -2
@@ -81,11 +81,11 @@ function onlyComputesBy(facts) {
81
81
  const is = (fn, of) => guard_term_1.GuardTerm.known(fn, of);
82
82
  /** The name of a function as a string in R, for `exists`. */
83
83
  function exists(of) {
84
- return { kind: 'call', fn: 'exists', known: true, args: [{ value: of }, { name: 'mode', value: guard_term_1.GuardTerm.string('function') }] };
84
+ return { kind: 'call', fn: guard_term_1.GuardFn.Exists, known: true, args: [{ value: of }, { name: 'mode', value: guard_term_1.GuardTerm.string('function') }] };
85
85
  }
86
86
  /** Whether the term spells out a name at run time, like `paste0("f_", x)`. */
87
87
  function composesName(term) {
88
- return guard_term_1.GuardTerm.isCall(term) && term.known === true && (term.fn === 'paste0' || term.fn === 'paste' || term.fn === 'sprintf');
88
+ return guard_term_1.GuardTerm.isCall(term) && term.known === true && (term.fn === guard_term_1.GuardFn.Paste0 || term.fn === guard_term_1.GuardFn.Paste || term.fn === guard_term_1.GuardFn.Sprintf);
89
89
  }
90
90
  /**
91
91
  * What it takes for `of` to be called, or to be handed to something calling it.
@@ -103,8 +103,8 @@ function callable(of, resolves, byName = true) {
103
103
  return guard_term_1.GuardTerm.True;
104
104
  }
105
105
  const own = exists(guard_term_1.GuardTerm.string(String(of.name)));
106
- return byName ? guard_term_1.GuardTerm.any(is('is.function', of), guard_term_1.GuardTerm.all(is('is.character', of), exists(of)), is('is.symbol', of), own)
107
- : guard_term_1.GuardTerm.any(is('is.function', of), own);
106
+ return byName ? guard_term_1.GuardTerm.any(is(guard_term_1.GuardFn.IsFunction, of), guard_term_1.GuardTerm.all(is(guard_term_1.GuardFn.IsCharacter, of), exists(of)), is('is.symbol', of), own)
107
+ : guard_term_1.GuardTerm.any(is(guard_term_1.GuardFn.IsFunction, of), own);
108
108
  }
109
109
  /** `reader(of)`, for a reader written `pkg::name` a call of the function of that package. */
110
110
  function readerOf(reader, of) {
@@ -125,14 +125,14 @@ function recyclingConditions(recycling, values, to, resolves) {
125
125
  const { rule, skips } = recycling;
126
126
  const size = (of) => readerOf(recycling.size, of);
127
127
  const skipped = (of) => skips === undefined ? guard_term_1.GuardTerm.False : conditionOn(skips, of, resolves, () => undefined);
128
- const eq = (a, b) => guard_term_1.GuardTerm.known('==', a, b);
128
+ const eq = (a, b) => guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Equal, a, b);
129
129
  const one = (of) => eq(size(of), number(1));
130
130
  if (rule === 'single') {
131
131
  return values.map(v => guard_term_1.GuardTerm.any(skipped(v), one(v)));
132
132
  }
133
133
  else if (rule === 'one' && to !== undefined) {
134
134
  /* R takes the first element of the size it is told, and recycles to no size for `NULL` */
135
- const [target, unsized] = to.kind === 'constant' ? [to, guard_term_1.GuardTerm.False] : [guard_term_1.GuardTerm.known('[', to, number(1)), guard_term_1.GuardTerm.known('is.null', to)];
135
+ const [target, unsized] = to.kind === 'constant' ? [to, guard_term_1.GuardTerm.False] : [guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Index, to, number(1)), guard_term_1.GuardTerm.known(guard_term_1.GuardFn.IsNull, to)];
136
136
  return values.map(v => guard_term_1.GuardTerm.any(skipped(v), unsized, eq(size(v), target), one(v)));
137
137
  }
138
138
  else if (rule === 'one') {
@@ -143,14 +143,14 @@ function recyclingConditions(recycling, values, to, resolves) {
143
143
  }
144
144
  /* `divides`: a value of a size flowR cannot read leaves the largest size open */
145
145
  const open = values.map(skipped);
146
- const positive = (of) => guard_term_1.GuardTerm.known('>', size(of), number(0));
147
- const divides = (a, b) => eq(guard_term_1.GuardTerm.known('%%', b, a), number(0));
146
+ const positive = (of) => guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Greater, size(of), number(0));
147
+ const divides = (a, b) => eq(guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Modulo, b, a), number(0));
148
148
  if (values.length === 2) {
149
149
  const [a, b] = values;
150
- return [guard_term_1.GuardTerm.any(...open, eq(size(a), size(b)), guard_term_1.GuardTerm.all(positive(a), positive(b), guard_term_1.GuardTerm.any(divides(size(a), size(b)), divides(size(b), size(a)))))];
150
+ return [guard_term_1.GuardTerm.anyOf(open.concat(eq(size(a), size(b)), guard_term_1.GuardTerm.all(positive(a), positive(b), guard_term_1.GuardTerm.any(divides(size(a), size(b)), divides(size(b), size(a))))))];
151
151
  }
152
- const largest = guard_term_1.GuardTerm.known('max', ...values.map(size));
153
- return values.map(v => guard_term_1.GuardTerm.any(...open, eq(size(v), largest), guard_term_1.GuardTerm.all(positive(v), divides(size(v), largest))));
152
+ const largest = guard_term_1.GuardTerm.knownOf('max', values.map(size));
153
+ return values.map(v => guard_term_1.GuardTerm.anyOf(open.concat(eq(size(v), largest), guard_term_1.GuardTerm.all(positive(v), divides(size(v), largest)))));
154
154
  }
155
155
  /**
156
156
  * The condition in terms of the value `of`, with `resolves` telling whether a function of the name is around, see {@link callable}, and `formals` the values of the other formals.
@@ -163,16 +163,16 @@ function conditionOn(condition, of, resolves, formals, positive = true) {
163
163
  }
164
164
  else if ('not' in condition) {
165
165
  const inner = conditionOn(condition.not, of, resolves, formals, !positive);
166
- return guard_term_1.GuardTerm.isTrue(inner) ? guard_term_1.GuardTerm.False : guard_term_1.GuardTerm.isFalse(inner) ? guard_term_1.GuardTerm.True : guard_term_1.GuardTerm.known('!', inner);
166
+ return guard_term_1.GuardTerm.isTrue(inner) ? guard_term_1.GuardTerm.False : guard_term_1.GuardTerm.isFalse(inner) ? guard_term_1.GuardTerm.True : guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Not, inner);
167
167
  }
168
168
  else if ('any' in condition) {
169
- return guard_term_1.GuardTerm.any(...condition.any.map(c => conditionOn(c, of, resolves, formals, positive)));
169
+ return guard_term_1.GuardTerm.anyOf(condition.any.map(c => conditionOn(c, of, resolves, formals, positive)));
170
170
  }
171
171
  else if ('all' in condition) {
172
- return guard_term_1.GuardTerm.all(...condition.all.map(c => conditionOn(c, of, resolves, formals, positive)));
172
+ return guard_term_1.GuardTerm.allOf(condition.all.map(c => conditionOn(c, of, resolves, formals, positive)));
173
173
  }
174
174
  else if ('length' in condition) {
175
- return guard_term_1.GuardTerm.known(condition.length, is('length', of), { kind: 'constant', lexeme: String(condition.to), value: condition.to });
175
+ return guard_term_1.GuardTerm.known(condition.length, is(guard_term_1.GuardFn.Length, of), { kind: 'constant', lexeme: String(condition.to), value: condition.to });
176
176
  }
177
177
  else if ('on' in condition) {
178
178
  const other = formals(condition.on);
@@ -205,7 +205,8 @@ function passes(failure, of, resolves, other, formals = () => undefined) {
205
205
  return guard_term_1.GuardTerm.True;
206
206
  }
207
207
  const unchecked = when === undefined || looked === undefined ? guard_term_1.GuardTerm.False : conditionOn({ not: when.holds }, looked, resolves, formals);
208
- return guard_term_1.GuardTerm.any(unchecked, condition, ...(failure.dispatches ? [is('is.object', of), ...(other === undefined || other.kind === 'constant' ? [] : [is('is.object', other)])] : []));
208
+ const classed = failure.dispatches ? [of].concat(other === undefined || other.kind === 'constant' ? [] : [other]) : [];
209
+ return guard_term_1.GuardTerm.anyOf([unchecked, condition].concat(classed.map(c => is(guard_term_1.GuardFn.IsObject, c))));
209
210
  }
210
211
  /** What R says on the failure for the value `of`. */
211
212
  function messageFor({ message }, of) {
@@ -213,13 +214,13 @@ function messageFor({ message }, of) {
213
214
  }
214
215
  /** `succeeds(call)`, see {@link GuardTerm}. */
215
216
  function succeeds(call) {
216
- return guard_term_1.GuardTerm.known('succeeds', call);
217
+ return guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Succeeds, call);
217
218
  }
218
219
  /** Whether `get(x)` for the name `x` is the same as `exists(x)`, to state it as such: only as long as it looks in the same place. */
219
220
  function getAsExists(call) {
220
221
  const others = call.args.slice(1);
221
222
  if (others.length === 0 || (others.length === 1 && others[0].name === 'mode')) {
222
- return { ...call, fn: 'exists' };
223
+ return { ...call, fn: guard_term_1.GuardFn.Exists };
223
224
  }
224
225
  return succeeds(call);
225
226
  }
@@ -5,8 +5,9 @@ const r_base_packages_1 = require("../../../util/r-base-packages");
5
5
  const guard_term_1 = require("./guard-term");
6
6
  const args_1 = require("../../../util/text/args");
7
7
  const string_constants_1 = require("../../eval/values/string/string-constants");
8
+ const objects_1 = require("../../../util/objects");
8
9
  /** What flowR writes into terms beyond plain R, see {@link GuardTerm}. */
9
- const OwnNotation = new Set(['succeeds', '...names']);
10
+ const OwnNotation = new Set([guard_term_1.GuardFn.Succeeds, guard_term_1.GuardFn.DotsNames]);
10
11
  const SignPrecedence = guard_term_1.AtomPrecedence - 1;
11
12
  const SpecialPrecedence = 7;
12
13
  const Name = /^(?:[A-Za-z]|\.(?![0-9]))[A-Za-z0-9._]*|^\./;
@@ -77,20 +78,20 @@ class TermParser {
77
78
  call(fn, args, pkg, syntax = true) {
78
79
  const bare = pkg === undefined || (0, r_base_packages_1.baseRExportOwner)(fn) === pkg;
79
80
  const known = bare && (syntax || OwnNotation.has(fn) || this.facts(fn) !== undefined || (0, r_base_packages_1.baseRExportOwner)(fn) !== undefined);
80
- return { kind: 'call', fn, args, ...(pkg === undefined || bare ? {} : { pkg }), ...(known ? { known: true } : {}) };
81
+ return (0, objects_1.compactRecord)({ kind: 'call', fn, args, pkg: bare ? undefined : pkg, known: known || undefined });
81
82
  }
82
83
  expression(min) {
83
84
  let left;
84
85
  const first = this.peek();
85
- if (first?.kind === 'op' && first.text === '!') {
86
+ if (first?.kind === 'op' && first.text === guard_term_1.GuardFn.Not) {
86
87
  this.at++;
87
88
  const operand = this.expression(guard_term_1.NegationPrecedence);
88
- left = operand === undefined ? undefined : this.call('!', [{ value: operand }]);
89
+ left = operand === undefined ? undefined : this.call(guard_term_1.GuardFn.Not, [{ value: operand }]);
89
90
  }
90
- else if (first?.kind === 'op' && (first.text === '-' || first.text === '+')) {
91
+ else if (first?.kind === 'op' && (first.text === guard_term_1.GuardFn.Minus || first.text === guard_term_1.GuardFn.Plus)) {
91
92
  this.at++;
92
93
  const operand = this.expression(SignPrecedence);
93
- left = operand?.kind === 'constant' && typeof operand.value === 'number' && first.text === '-'
94
+ left = operand?.kind === 'constant' && typeof operand.value === 'number' && first.text === guard_term_1.GuardFn.Minus
94
95
  ? { kind: 'constant', lexeme: `-${operand.lexeme}`, value: -operand.value }
95
96
  : operand === undefined ? undefined : this.call(first.text, [{ value: operand }]);
96
97
  }
@@ -134,18 +135,18 @@ class TermParser {
134
135
  if (term === undefined) {
135
136
  return undefined;
136
137
  }
137
- else if (this.take('$') ?? this.take('@')) {
138
+ else if (this.take(guard_term_1.GuardFn.Dollar) ?? this.take(guard_term_1.GuardFn.At)) {
138
139
  const op = this.tokens[this.at - 1].text;
139
140
  const field = this.take();
140
141
  term = field?.kind === 'name' || field?.kind === 'string' ? this.call(op, [{ value: term }, { value: { kind: 'constant', lexeme: field.text } }]) : undefined;
141
142
  }
142
- else if (this.take('[[') !== undefined) {
143
+ else if (this.take(guard_term_1.GuardFn.Element) !== undefined) {
143
144
  const args = this.args(']');
144
- term = args === undefined || this.take(']') === undefined ? undefined : this.call('[[', [{ value: term }, ...args]);
145
+ term = args === undefined || this.take(']') === undefined ? undefined : this.call(guard_term_1.GuardFn.Element, [{ value: term }, ...args]);
145
146
  }
146
- else if (this.take('[') !== undefined) {
147
+ else if (this.take(guard_term_1.GuardFn.Index) !== undefined) {
147
148
  const args = this.args(']');
148
- term = args === undefined ? undefined : this.call('[', [{ value: term }, ...args]);
149
+ term = args === undefined ? undefined : this.call(guard_term_1.GuardFn.Index, [{ value: term }, ...args]);
149
150
  }
150
151
  else {
151
152
  return term;
@@ -162,7 +163,7 @@ class TermParser {
162
163
  }
163
164
  else if (token.kind === 'number') {
164
165
  const value = numberOf(token.text);
165
- return { kind: 'constant', lexeme: token.text, ...(value === undefined ? {} : { value }) };
166
+ return (0, objects_1.compactRecord)({ kind: 'constant', lexeme: token.text, value });
166
167
  }
167
168
  else if (token.kind === 'op') {
168
169
  if (token.text !== '(') {
@@ -1,6 +1,68 @@
1
1
  import { Identifier, type BrandedIdentifier, type BrandedNamespace } from '../../environments/identifier';
2
2
  import { type GuardFactsLookup } from '../../environments/guard-facts';
3
3
  import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
+ /** The operators and functions of R the guards speak of by name, with flowR's own `succeeds` and `...names` (see {@link GuardTerm}). */
5
+ export declare enum GuardFn {
6
+ And = "&&",
7
+ Or = "||",
8
+ Not = "!",
9
+ ElementAnd = "&",
10
+ ElementOr = "|",
11
+ Equal = "==",
12
+ NotEqual = "!=",
13
+ Less = "<",
14
+ LessEqual = "<=",
15
+ Greater = ">",
16
+ GreaterEqual = ">=",
17
+ Plus = "+",
18
+ Minus = "-",
19
+ Times = "*",
20
+ Divide = "/",
21
+ Power = "^",
22
+ Modulo = "%%",
23
+ IntegerDivide = "%/%",
24
+ In = "%in%",
25
+ MatrixProduct = "%*%",
26
+ Colon = ":",
27
+ Dollar = "$",
28
+ At = "@",
29
+ Index = "[",
30
+ Element = "[[",
31
+ Succeeds = "succeeds",
32
+ DotsNames = "...names",
33
+ Missing = "missing",
34
+ All = "all",
35
+ Any = "any",
36
+ Combine = "c",
37
+ Length = "length",
38
+ IsTrue = "isTRUE",
39
+ IsFalse = "isFALSE",
40
+ IsNull = "is.null",
41
+ IsNa = "is.na",
42
+ IsObject = "is.object",
43
+ IsCharacter = "is.character",
44
+ IsFunction = "is.function",
45
+ AsLogical = "as.logical",
46
+ Unclass = "unclass",
47
+ OldClass = "oldClass",
48
+ Class = "class",
49
+ Inherits = "inherits",
50
+ Identical = "identical",
51
+ Exists = "exists",
52
+ Get = "get",
53
+ MatchArg = "match.arg",
54
+ Paste = "paste",
55
+ Paste0 = "paste0",
56
+ Sprintf = "sprintf",
57
+ If = "if",
58
+ For = "for",
59
+ While = "while",
60
+ Switch = "switch",
61
+ Return = "return",
62
+ OnExit = "on.exit",
63
+ UseMethod = "UseMethod",
64
+ NextMethod = "NextMethod"
65
+ }
4
66
  /** A formal parameter of the function a term speaks about. */
5
67
  export interface GuardFormal {
6
68
  readonly kind: 'formal';
@@ -42,11 +104,15 @@ export interface GuardCall {
42
104
  export type GuardTerm = GuardFormal | GuardConstant | GuardFree | GuardCall;
43
105
  /** A call of what R ships with, its arguments unnamed. */
44
106
  declare function known(this: void, fn: BrandedIdentifier, ...args: readonly GuardTerm[]): GuardCall;
107
+ /** {@link known} with the arguments as one list. */
108
+ declare function knownOf(this: void, fn: BrandedIdentifier, args: readonly GuardTerm[]): GuardCall;
45
109
  declare function isCall(this: void, term: GuardTerm | undefined, fn?: BrandedIdentifier): term is GuardCall;
46
110
  /** The name of the function without the namespace it was written with. */
47
111
  declare function bareName(this: void, fn: BrandedIdentifier): BrandedIdentifier;
48
112
  /** All of the terms; dropping unknowable ones turns into {@link True}, which leaves what is left necessary. */
49
113
  declare function all(this: void, ...terms: readonly GuardTerm[]): GuardTerm;
114
+ /** {@link all} with the terms as one list. */
115
+ declare function allOf(this: void, terms: readonly GuardTerm[]): GuardTerm;
50
116
  /**
51
117
  * The conjuncts with what follows from them by what they are written as: of `p` and `p || q` the former says it all,
52
118
  * and `a || p` with `!a || p` leaves `p`, `merge` telling what the item for that is.
@@ -54,6 +120,8 @@ declare function all(this: void, ...terms: readonly GuardTerm[]): GuardTerm;
54
120
  declare function resolved<T>(this: void, items: readonly T[], termOf: (item: T) => GuardTerm, merge: (a: T, b: T, term: GuardTerm) => T): T[];
55
121
  /** Any of the terms. */
56
122
  declare function any(this: void, ...terms: readonly GuardTerm[]): GuardTerm;
123
+ /** {@link any} with the terms as one list. */
124
+ declare function anyOf(this: void, terms: readonly GuardTerm[]): GuardTerm;
57
125
  /** Whether R goes by the first element of a longer `operand` of `fn`, as before R 4.2 for `if` and before R 4.3 for `&&`, instead of failing on it. */
58
126
  declare function firstOnly(this: void, facts: GuardFactsLookup, fn: BrandedIdentifier, operand: BrandedIdentifier): boolean;
59
127
  /**
@@ -103,9 +171,12 @@ export declare const GuardTerm: {
103
171
  readonly True: GuardConstant;
104
172
  readonly False: GuardConstant;
105
173
  readonly known: typeof known;
174
+ readonly knownOf: typeof knownOf;
106
175
  readonly isCall: typeof isCall;
107
176
  readonly all: typeof all;
177
+ readonly allOf: typeof allOf;
108
178
  readonly any: typeof any;
179
+ readonly anyOf: typeof anyOf;
109
180
  readonly truth: typeof truth;
110
181
  readonly firstOnly: typeof firstOnly;
111
182
  readonly render: typeof render;