@tabnas/expr 0.5.18 → 0.5.20

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/dist/expr.d.ts CHANGED
@@ -16,12 +16,15 @@ type OpDef = {
16
16
  required?: boolean;
17
17
  allow?: string[];
18
18
  };
19
+ key?: boolean;
20
+ dynamic?: boolean;
19
21
  };
20
22
  type ExprOptions = {
21
23
  op?: {
22
24
  [name: string]: OpDef;
23
25
  };
24
- evaluate?: typeof evaluation;
26
+ evaluate?: Evaluate;
27
+ fold?: FoldOptions;
25
28
  };
26
29
  type Op = {
27
30
  name: string;
@@ -48,22 +51,103 @@ type Op = {
48
51
  required: boolean;
49
52
  allow?: string[];
50
53
  };
54
+ key: boolean;
55
+ dynamic: boolean;
51
56
  token: Token;
52
57
  OP_MARK: typeof OP_MARK;
53
58
  };
54
- type Evaluate = (rule: Rule, ctx: Context, op: Op, ...terms: any) => any;
59
+ type KeyMap = Map<string, Op>;
60
+ type Evaluate = (rule: Rule, ctx: Context, op: Op, terms: any[]) => any;
61
+ type Path = (string | number)[];
62
+ type FoldHit = {
63
+ found: boolean;
64
+ cycle: boolean;
65
+ value?: any;
66
+ };
67
+ type Site = {
68
+ readonly root: any;
69
+ readonly doc: string;
70
+ readonly path: Path;
71
+ readonly node: any;
72
+ readonly k: Record<string, any>;
73
+ readonly token?: Token;
74
+ at: (path: Path, doc?: string) => FoldHit;
75
+ locate: (path: Path, doc?: string) => {
76
+ found: boolean;
77
+ value?: any;
78
+ };
79
+ plain: () => any;
80
+ };
81
+ type FoldEvaluate = (site: Site, op: Op, terms: any[]) => any;
82
+ type Inherit = (site: Site, node: any, k: Record<string, any>) => Record<string, any>;
83
+ type Recognise = (site: Site, op: Op) => boolean;
84
+ type Positions = (node: object) => Token | undefined;
85
+ type FoldEntry = {
86
+ doc: string;
87
+ at: string;
88
+ targetDoc: string;
89
+ target: string;
90
+ };
91
+ type FoldReport = {
92
+ cycles: FoldEntry[];
93
+ unresolved: FoldEntry[];
94
+ dynamic: {
95
+ doc: string;
96
+ at: string;
97
+ src: string;
98
+ }[];
99
+ };
100
+ type FoldOptions = {
101
+ op?: {
102
+ [name: string]: OpDef;
103
+ };
104
+ evaluate: FoldEvaluate;
105
+ inherit?: Inherit;
106
+ recognise?: Recognise;
107
+ k?: Record<string, any>;
108
+ doc?: string;
109
+ load?: (doc: string, site: Site) => any;
110
+ cycle?: 'verbatim' | 'error';
111
+ tokens?: boolean;
112
+ positions?: boolean | Positions;
113
+ maxDepth?: number;
114
+ report?: (report: FoldReport) => void;
115
+ };
55
116
  declare const OP_MARK: {};
56
117
  declare let Expr: Plugin;
118
+ declare function isOp(node: any): any;
119
+ declare function makeKeyMap(optop: {
120
+ [name: string]: OpDef;
121
+ }): KeyMap;
122
+ declare function keyOpOf(keys: KeyMap, node: any): Op | undefined;
123
+ declare class FoldError extends Error {
124
+ code: string;
125
+ doc?: string;
126
+ at?: string;
127
+ targetDoc?: string;
128
+ target?: string;
129
+ constructor(code: string, message: string, fields?: {
130
+ doc?: string;
131
+ at?: string;
132
+ targetDoc?: string;
133
+ target?: string;
134
+ });
135
+ }
136
+ declare function recordPositions(tn: Tabnas): Positions;
137
+ declare function fold(root: any, opts: FoldOptions): any;
57
138
  declare function prattify(expr: any, op?: Op, whence?: string): any[];
58
- declare function evaluation(rule: Rule, ctx: Context, expr: any, evaluate: Evaluate): any;
139
+ declare function evaluation(rule: Rule, ctx: Context, expr: any, evaluate: Evaluate, opts?: {
140
+ objects?: boolean;
141
+ }): any;
59
142
  declare function simplify(value: any): any;
60
143
  declare function parseSimplified(tn: Tabnas, src: string, meta?: any): any;
144
+ declare function opify<T extends object>(op: T): T;
61
145
  declare const testing: {
62
146
  prattify: typeof prattify;
63
- opify: (x: any) => any;
147
+ opify: typeof opify;
64
148
  };
65
- declare const VERSION = "0.5.18";
66
- export { VERSION, Expr, evaluation, simplify, parseSimplified, testing };
67
- export type { ExprOptions, OpDef, Op, Evaluate };
149
+ declare const VERSION = "0.5.20";
150
+ export { VERSION, Expr, evaluation, simplify, parseSimplified, fold, recordPositions, FoldError, opify, isOp, keyOpOf, makeKeyMap, testing, };
151
+ export type { ExprOptions, OpDef, Op, Evaluate, FoldOptions, FoldEvaluate, FoldHit, FoldEntry, Inherit, Recognise, Positions, Site, FoldReport, Path, KeyMap, };
68
152
  export { translate } from './translate';
69
153
  export type { TranslationPart, TranslationParts } from './translate';