simple-graph-query 3.3.0 → 3.3.2

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.
@@ -2,6 +2,8 @@ import { AbstractParseTreeVisitor } from "antlr4ts/tree/AbstractParseTreeVisitor
2
2
  import { ForgeVisitor } from "./forge-antlr/ForgeVisitor";
3
3
  import { ExprContext, Expr1Context, Expr1_5Context, Expr2Context, Expr3Context, Expr4Context, Expr5Context, Expr6Context, Expr7Context, Expr8Context, Expr9Context, Expr10Context, Expr11Context, Expr12Context, Expr13Context, Expr14Context, Expr15Context, Expr17Context, Expr18Context, ExprListContext, NameContext, PredDeclContext, BlockContext, QualNameContext, QuantDeclListContext, NameListContext, QuantDeclContext, CompareOpContext } from "./forge-antlr/ForgeParser";
4
4
  import { IDataInstance } from "./types";
5
+ import { ParseTree } from "antlr4ts/tree/ParseTree";
6
+ import { RuleNode } from "antlr4ts/tree/RuleNode";
5
7
  export type SingleValue = string | number | boolean;
6
8
  export type Tuple = SingleValue[];
7
9
  export type EvalResult = SingleValue | Tuple[];
@@ -51,13 +53,19 @@ export declare function unquoteStringLiteral(text: string): string;
51
53
  * This visitor walks the parse tree and prints the type of operation encountered.
52
54
  */
53
55
  export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalResult> implements ForgeVisitor<EvalResult> {
56
+ private precedenceTargets;
54
57
  private environmentStack;
55
58
  private freeVariableFinder;
56
59
  private freeVariables;
57
60
  private cachedResults;
58
61
  private instanceData;
62
+ private labelLookups;
63
+ private labelsById?;
59
64
  private relationCache;
60
- private relationIndexCache;
65
+ private globalNameCache;
66
+ private unresolvedNames;
67
+ private closedResults;
68
+ private unresolvedReportCount;
61
69
  private diagnostics;
62
70
  constructor(datum: IDataInstance);
63
71
  /** Diagnostics recorded since the last `resetDiagnostics()`. */
@@ -79,6 +87,7 @@ export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalRes
79
87
  private buildRelationCache;
80
88
  private updateFreeVariables;
81
89
  private constructFreeVariableKey;
90
+ evaluate(tree: ParseTree): EvalResult;
82
91
  private getLabelForValue;
83
92
  private getLabelAsString;
84
93
  private getLabelAsBoolean;
@@ -90,6 +99,20 @@ export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalRes
90
99
  private dotJoin;
91
100
  private cacheResult;
92
101
  private getIden;
102
+ /**
103
+ * Evaluate a node, reusing the value of closed operator nodes.
104
+ *
105
+ * `visitExpr` caches per free-variable binding, but only for nodes of the
106
+ * `expr` rule. A closed subexpression that is not itself an `expr` -- the
107
+ * `^edge` in `{x: Node | some x.^edge}` -- was therefore recomputed for every
108
+ * binding of the enclosing quantifier. Such a node has no free variables, so
109
+ * its value depends only on the instance and can be computed once.
110
+ *
111
+ * Only nodes with more than one child are considered: the single-child nodes
112
+ * that make up the precedence chain do no work of their own.
113
+ */
114
+ visit(tree: ParseTree): EvalResult;
115
+ visitChildren(node: RuleNode): EvalResult;
93
116
  protected aggregateResult(aggregate: EvalResult, nextResult: EvalResult): EvalResult;
94
117
  protected defaultResult(): EvalResult;
95
118
  visitPredDecl(ctx: PredDeclContext): EvalResult;
@@ -39,5 +39,14 @@ export declare class ForgeExprFreeVariableFinder extends AbstractParseTreeVisito
39
39
  visitExpr17(ctx: Expr17Context): FreeVariables;
40
40
  visitExpr18(ctx: Expr18Context): FreeVariables;
41
41
  visitExprList(ctx: ExprListContext): FreeVariables;
42
+ /**
43
+ * Whether `identifier`, used at `ctx`, is in the scope of a quantifier or
44
+ * comprehension that binds it.
45
+ *
46
+ * A binder's variables are in scope in its body but not in its own
47
+ * declaration list: the domains are evaluated before anything is bound, so
48
+ * in `{Node: Node | ...}` the domain `Node` is still the type.
49
+ */
50
+ private isBoundByEnclosingBinder;
42
51
  visitName(ctx: NameContext): FreeVariables;
43
52
  }
@@ -1,26 +1,15 @@
1
1
  import { ExprContext } from "./forge-antlr/ForgeParser";
2
- import { Tuple } from "./ForgeExprEvaluator";
2
+ import type { Tuple } from "./ForgeExprEvaluator";
3
3
  /**
4
4
  * Analyzes set comprehension constraints to detect simple numeric comparison patterns
5
5
  * that can be optimized by generating only valid combinations instead of filtering.
6
6
  */
7
7
  export interface NumericConstraintPattern {
8
- type: 'less_than' | 'greater_than' | 'less_equal' | 'greater_equal' | 'not_equal' | 'none';
8
+ type: 'equal' | 'less_than' | 'greater_than' | 'less_equal' | 'greater_equal' | 'not_equal' | 'none';
9
9
  leftVar: string;
10
10
  rightVar: string;
11
11
  }
12
- /**
13
- * Detects if a constraint expression is a simple numeric comparison between two variables.
14
- * Currently detects patterns like: a < b, a > b, a <= b, a >= b, a != b
15
- *
16
- * Note: Uses string matching on expression text which is simple but may miss expressions
17
- * with extra whitespace or parentheses. This is intentionally conservative - we prefer
18
- * to fall back to the standard approach rather than risk incorrect optimization.
19
- *
20
- * @param constraintExpr The constraint expression to analyze
21
- * @param varNames The variable names in scope
22
- * @returns Pattern info if detected, null otherwise
23
- */
12
+ /** Match the entire predicate before authorizing the evaluator to skip its body. */
24
13
  export declare function detectNumericComparisonPattern(constraintExpr: ExprContext, varNames: string[]): NumericConstraintPattern | null;
25
14
  /**
26
15
  * Checks if all values in the sets are numbers (or tuples containing single numbers).
@@ -36,4 +25,4 @@ export declare function areAllNumericSets(sets: Tuple[][]): boolean;
36
25
  * @param pattern The detected numeric comparison pattern
37
26
  * @returns Only the tuples that satisfy the constraint
38
27
  */
39
- export declare function generateOptimizedNumericCombinations(varNames: string[], quantifiedSets: Tuple[][], pattern: NumericConstraintPattern): Tuple[];
28
+ export declare function generateOptimizedNumericCombinations(varNames: string[], quantifiedSets: Tuple[][], pattern: NumericConstraintPattern): Generator<Tuple>;
@@ -0,0 +1,2 @@
1
+ /** Enumerate in nested-loop order. Each yielded binding can be retained by its caller. */
2
+ export declare function cartesianProduct<T>(domains: T[][]): Generator<T[]>;