@enspirit/elo 0.9.3 → 0.9.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 +27 -9
- package/dist/src/ast.d.ts +29 -6
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast.js +14 -3
- package/dist/src/ast.js.map +1 -1
- package/dist/src/bindings/javascript.d.ts.map +1 -1
- package/dist/src/bindings/javascript.js +11 -0
- package/dist/src/bindings/javascript.js.map +1 -1
- package/dist/src/bindings/ruby.d.ts.map +1 -1
- package/dist/src/bindings/ruby.js +31 -2
- package/dist/src/bindings/ruby.js.map +1 -1
- package/dist/src/bindings/sql.d.ts.map +1 -1
- package/dist/src/bindings/sql.js +35 -0
- package/dist/src/bindings/sql.js.map +1 -1
- package/dist/src/compilers/javascript.d.ts +2 -0
- package/dist/src/compilers/javascript.d.ts.map +1 -1
- package/dist/src/compilers/javascript.js +39 -10
- package/dist/src/compilers/javascript.js.map +1 -1
- package/dist/src/compilers/ruby.d.ts +2 -0
- package/dist/src/compilers/ruby.d.ts.map +1 -1
- package/dist/src/compilers/ruby.js +37 -10
- package/dist/src/compilers/ruby.js.map +1 -1
- package/dist/src/compilers/sql.js +2 -0
- package/dist/src/compilers/sql.js.map +1 -1
- package/dist/src/csv.d.ts +39 -0
- package/dist/src/csv.d.ts.map +1 -0
- package/dist/src/csv.js +177 -0
- package/dist/src/csv.js.map +1 -0
- package/dist/src/elo.js +64 -13
- package/dist/src/elo.js.map +1 -1
- package/dist/src/eloc.js +10 -4
- package/dist/src/eloc.js.map +1 -1
- package/dist/src/formats.d.ts +94 -0
- package/dist/src/formats.d.ts.map +1 -0
- package/dist/src/formats.js +92 -0
- package/dist/src/formats.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/ir.d.ts +23 -4
- package/dist/src/ir.d.ts.map +1 -1
- package/dist/src/ir.js +12 -2
- package/dist/src/ir.js.map +1 -1
- package/dist/src/parser.d.ts +41 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/parser.js +212 -7
- package/dist/src/parser.js.map +1 -1
- package/dist/src/runtime.d.ts.map +1 -1
- package/dist/src/runtime.js +47 -0
- package/dist/src/runtime.js.map +1 -1
- package/dist/src/serialize.d.ts +24 -0
- package/dist/src/serialize.d.ts.map +1 -0
- package/dist/src/serialize.js +138 -0
- package/dist/src/serialize.js.map +1 -0
- package/dist/src/transform.d.ts.map +1 -1
- package/dist/src/transform.js +40 -5
- package/dist/src/transform.js.map +1 -1
- package/package.json +1 -1
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC1F,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC1F,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AACxC,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,UAAU,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACV,MAAM,WAAW,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.getPrelude = exports.JS_HELPERS = exports.compileToSQL = exports.compileToJavaScriptWithMeta = exports.compileToJavaScript = exports.compileToRuby = exports.compile = void 0;
|
|
20
|
+
exports.getFormat = exports.defaultFormats = exports.eloAdapter = exports.csvAdapter = exports.jsonAdapter = exports.toCSV = exports.parseCSV = exports.toEloCode = exports.getPrelude = exports.JS_HELPERS = exports.compileToSQL = exports.compileToJavaScriptWithMeta = exports.compileToJavaScript = exports.compileToRuby = exports.compile = void 0;
|
|
21
21
|
__exportStar(require("./ast"), exports);
|
|
22
22
|
__exportStar(require("./parser"), exports);
|
|
23
23
|
var compile_1 = require("./compile");
|
|
@@ -33,4 +33,15 @@ var runtime_1 = require("./runtime");
|
|
|
33
33
|
Object.defineProperty(exports, "JS_HELPERS", { enumerable: true, get: function () { return runtime_1.JS_HELPERS; } });
|
|
34
34
|
var preludes_1 = require("./preludes");
|
|
35
35
|
Object.defineProperty(exports, "getPrelude", { enumerable: true, get: function () { return preludes_1.getPrelude; } });
|
|
36
|
+
var serialize_1 = require("./serialize");
|
|
37
|
+
Object.defineProperty(exports, "toEloCode", { enumerable: true, get: function () { return serialize_1.toEloCode; } });
|
|
38
|
+
var csv_1 = require("./csv");
|
|
39
|
+
Object.defineProperty(exports, "parseCSV", { enumerable: true, get: function () { return csv_1.parseCSV; } });
|
|
40
|
+
Object.defineProperty(exports, "toCSV", { enumerable: true, get: function () { return csv_1.toCSV; } });
|
|
41
|
+
var formats_1 = require("./formats");
|
|
42
|
+
Object.defineProperty(exports, "jsonAdapter", { enumerable: true, get: function () { return formats_1.jsonAdapter; } });
|
|
43
|
+
Object.defineProperty(exports, "csvAdapter", { enumerable: true, get: function () { return formats_1.csvAdapter; } });
|
|
44
|
+
Object.defineProperty(exports, "eloAdapter", { enumerable: true, get: function () { return formats_1.eloAdapter; } });
|
|
45
|
+
Object.defineProperty(exports, "defaultFormats", { enumerable: true, get: function () { return formats_1.defaultFormats; } });
|
|
46
|
+
Object.defineProperty(exports, "getFormat", { enumerable: true, get: function () { return formats_1.getFormat; } });
|
|
36
47
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,wCAAsB;AACtB,2CAAyB;AACzB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,yCAAiD;AAAxC,qGAAA,aAAa,OAAA;AAEtB,qDAA0F;AAAjF,iHAAA,mBAAmB,OAAA;AAAE,yHAAA,2BAA2B,OAAA;AAEzD,uCAA+C;AAAtC,mGAAA,YAAY,OAAA;AAErB,qCAAuC;AAA9B,qGAAA,UAAU,OAAA;AACnB,uCAAwC;AAA/B,sGAAA,UAAU,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,wCAAsB;AACtB,2CAAyB;AACzB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,yCAAiD;AAAxC,qGAAA,aAAa,OAAA;AAEtB,qDAA0F;AAAjF,iHAAA,mBAAmB,OAAA;AAAE,yHAAA,2BAA2B,OAAA;AAEzD,uCAA+C;AAAtC,mGAAA,YAAY,OAAA;AAErB,qCAAuC;AAA9B,qGAAA,UAAU,OAAA;AACnB,uCAAwC;AAA/B,sGAAA,UAAU,OAAA;AAEnB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,6BAAwC;AAA/B,+FAAA,QAAQ,OAAA;AAAE,4FAAA,KAAK,OAAA;AAExB,qCAMmB;AALjB,sGAAA,WAAW,OAAA;AACX,qGAAA,UAAU,OAAA;AACV,qGAAA,UAAU,OAAA;AACV,yGAAA,cAAc,OAAA;AACd,oGAAA,SAAS,OAAA"}
|
package/dist/src/ir.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { EloType } from './types';
|
|
|
12
12
|
/**
|
|
13
13
|
* IR expression types
|
|
14
14
|
*/
|
|
15
|
-
export type IRExpr = IRIntLiteral | IRFloatLiteral | IRBoolLiteral | IRNullLiteral | IRStringLiteral | IRDateLiteral | IRDateTimeLiteral | IRDurationLiteral | IRObjectLiteral | IRArrayLiteral | IRVariable | IRCall | IRApply | IRLet | IRMemberAccess | IRIf | IRLambda | IRAlternative | IRDataPath | IRTypeDef;
|
|
15
|
+
export type IRExpr = IRIntLiteral | IRFloatLiteral | IRBoolLiteral | IRNullLiteral | IRStringLiteral | IRDateLiteral | IRDateTimeLiteral | IRDurationLiteral | IRObjectLiteral | IRArrayLiteral | IRVariable | IRCall | IRApply | IRLet | IRMemberAccess | IRIf | IRLambda | IRAlternative | IRDataPath | IRTypeDef | IRGuard;
|
|
16
16
|
/**
|
|
17
17
|
* Integer literal
|
|
18
18
|
*/
|
|
@@ -214,13 +214,20 @@ export interface IRTypeSchema {
|
|
|
214
214
|
extras?: 'closed' | 'ignored' | IRTypeExpr;
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
|
-
*
|
|
217
|
+
* A single constraint with optional label (IR version)
|
|
218
|
+
*/
|
|
219
|
+
export interface IRConstraint {
|
|
220
|
+
label?: string;
|
|
221
|
+
condition: IRExpr;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Subtype constraint: Int(i | i > 0) or Int(i | positive: i > 0, even: i % 2 == 0)
|
|
218
225
|
*/
|
|
219
226
|
export interface IRSubtypeConstraint {
|
|
220
227
|
kind: 'subtype_constraint';
|
|
221
228
|
baseType: IRTypeExpr;
|
|
222
229
|
variable: string;
|
|
223
|
-
|
|
230
|
+
constraints: IRConstraint[];
|
|
224
231
|
}
|
|
225
232
|
/**
|
|
226
233
|
* Array type: [Int]
|
|
@@ -254,6 +261,17 @@ export interface IRTypeDef {
|
|
|
254
261
|
typeExpr: IRTypeExpr;
|
|
255
262
|
body: IRExpr;
|
|
256
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Guard expression: guard [label:] condition in body
|
|
266
|
+
* Throws at runtime if condition is false, unless guards are stripped.
|
|
267
|
+
* guardType distinguishes preconditions (guard) from postconditions (check).
|
|
268
|
+
*/
|
|
269
|
+
export interface IRGuard {
|
|
270
|
+
type: 'guard';
|
|
271
|
+
constraints: IRConstraint[];
|
|
272
|
+
body: IRExpr;
|
|
273
|
+
guardType: 'guard' | 'check';
|
|
274
|
+
}
|
|
257
275
|
/**
|
|
258
276
|
* Factory functions for creating IR nodes
|
|
259
277
|
*/
|
|
@@ -278,10 +296,11 @@ export declare function irAlternative(alternatives: IRExpr[], resultType: EloTyp
|
|
|
278
296
|
export declare function irDataPath(segments: (string | number)[]): IRDataPath;
|
|
279
297
|
export declare function irTypeRef(name: string): IRTypeRef;
|
|
280
298
|
export declare function irTypeSchema(properties: IRTypeSchemaProperty[], extras?: 'closed' | 'ignored' | IRTypeExpr): IRTypeSchema;
|
|
281
|
-
export declare function irSubtypeConstraint(baseType: IRTypeExpr, variable: string,
|
|
299
|
+
export declare function irSubtypeConstraint(baseType: IRTypeExpr, variable: string, constraints: IRConstraint[]): IRSubtypeConstraint;
|
|
282
300
|
export declare function irArrayType(elementType: IRTypeExpr): IRArrayType;
|
|
283
301
|
export declare function irUnionType(types: IRTypeExpr[]): IRUnionType;
|
|
284
302
|
export declare function irTypeDef(name: string, typeExpr: IRTypeExpr, body: IRExpr): IRTypeDef;
|
|
303
|
+
export declare function irGuard(constraints: IRConstraint[], body: IRExpr, guardType?: 'guard' | 'check'): IRGuard;
|
|
285
304
|
/**
|
|
286
305
|
* Infer the type of an IR expression
|
|
287
306
|
*/
|
package/dist/src/ir.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../../src/ir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAS,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,MAAM,GACd,YAAY,GACZ,cAAc,GACd,aAAa,GACb,aAAa,GACb,eAAe,GACf,aAAa,GACb,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,cAAc,GACd,UAAU,GACV,MAAM,GACN,OAAO,GACP,KAAK,GACL,cAAc,GACd,IAAI,GACJ,QAAQ,GACR,aAAa,GACb,UAAU,GACV,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../../src/ir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAS,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,MAAM,GACd,YAAY,GACZ,cAAc,GACd,aAAa,GACb,aAAa,GACb,eAAe,GACf,aAAa,GACb,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,cAAc,GACd,UAAU,GACV,MAAM,GACN,OAAO,GACP,KAAK,GACL,cAAc,GACd,IAAI,GACJ,QAAQ,GACR,aAAa,GACb,UAAU,GACV,SAAS,GACT,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,cAAc,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,M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UnionType;
|
|
37
37
|
exports.irTypeDef = irTypeDef;
|
|
38
|
+
exports.irGuard = irGuard;
|
|
38
39
|
exports.inferType = inferType;
|
|
39
40
|
exports.usesInput = usesInput;
|
|
40
41
|
const types_1 = require("./types");
|
|
@@ -104,8 +105,8 @@ function irTypeRef(name) {
|
|
|
104
105
|
function irTypeSchema(properties, extras) {
|
|
105
106
|
return { kind: 'type_schema', properties, extras };
|
|
106
107
|
}
|
|
107
|
-
function irSubtypeConstraint(baseType, variable,
|
|
108
|
-
return { kind: 'subtype_constraint', baseType, variable,
|
|
108
|
+
function irSubtypeConstraint(baseType, variable, constraints) {
|
|
109
|
+
return { kind: 'subtype_constraint', baseType, variable, constraints };
|
|
109
110
|
}
|
|
110
111
|
function irArrayType(elementType) {
|
|
111
112
|
return { kind: 'array_type', elementType };
|
|
@@ -116,6 +117,9 @@ function irUnionType(types) {
|
|
|
116
117
|
function irTypeDef(name, typeExpr, body) {
|
|
117
118
|
return { type: 'typedef', name, typeExpr, body };
|
|
118
119
|
}
|
|
120
|
+
function irGuard(constraints, body, guardType = 'guard') {
|
|
121
|
+
return { type: 'guard', constraints, body, guardType };
|
|
122
|
+
}
|
|
119
123
|
/**
|
|
120
124
|
* Infer the type of an IR expression
|
|
121
125
|
*/
|
|
@@ -161,6 +165,8 @@ function inferType(ir) {
|
|
|
161
165
|
return types_1.Types.fn; // DataPath is a function that takes data and returns a value
|
|
162
166
|
case 'typedef':
|
|
163
167
|
return inferType(ir.body);
|
|
168
|
+
case 'guard':
|
|
169
|
+
return inferType(ir.body);
|
|
164
170
|
}
|
|
165
171
|
}
|
|
166
172
|
/**
|
|
@@ -219,6 +225,10 @@ function usesInput(ir, boundVars = new Set()) {
|
|
|
219
225
|
newBound.add(ir.name);
|
|
220
226
|
return usesInput(ir.body, newBound);
|
|
221
227
|
}
|
|
228
|
+
case 'guard':
|
|
229
|
+
// Check constraints and body for input usage
|
|
230
|
+
return ir.constraints.some(c => usesInput(c.condition, boundVars)) ||
|
|
231
|
+
usesInput(ir.body, boundVars);
|
|
222
232
|
}
|
|
223
233
|
}
|
|
224
234
|
//# sourceMappingURL=ir.js.map
|
package/dist/src/ir.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ir.js","sourceRoot":"","sources":["../../src/ir.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;
|
|
1
|
+
{"version":3,"file":"ir.js","sourceRoot":"","sources":["../../src/ir.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAqUH,sBAEC;AAED,0BAEC;AAED,wBAEC;AAED,wBAEC;AAED,4BAEC;AAED,wBAEC;AAED,gCAEC;AAED,gCAEC;AAED,4BAEC;AAED,0BAEC;AAED,gCAEC;AAED,wBAEC;AAED,0BAEC;AAED,sBAEC;AAED,wCAEC;AAED,oBAEC;AAED,4BAEC;AAED,sCAEC;AAED,gCAEC;AAED,8BAEC;AAED,oCAEC;AAED,kDAEC;AAED,kCAEC;AAED,kCAEC;AAED,8BAEC;AAED,0BAEC;AAKD,8BA+CC;AAOD,8BAqEC;AAziBD,mCAAyC;AA+TzC;;GAEG;AAEH,SAAgB,KAAK,CAAC,KAAa;IACjC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC;AAED,SAAgB,OAAO,CAAC,KAAa;IACnC,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;AAC1C,CAAC;AAED,SAAgB,MAAM,CAAC,KAAc;IACnC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;AACzC,CAAC;AAED,SAAgB,MAAM;IACpB,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;AAClC,CAAC;AAED,SAAgB,QAAQ,CAAC,KAAa;IACpC,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;AAC3C,CAAC;AAED,SAAgB,MAAM,CAAC,KAAa;IAClC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C,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7C,OAAO,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC;QAED,KAAK,aAAa;YAChB,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;QAEhE,KAAK,UAAU;YACb,OAAO,KAAK,CAAC,CAAE,wDAAwD;QAEzE,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,gEAAgE;YAChE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;YACpC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC;QAED,KAAK,OAAO;YACV,6CAA6C;YAC7C,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBAC3D,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzC,CAAC;AACH,CAAC"}
|
package/dist/src/parser.d.ts
CHANGED
|
@@ -72,10 +72,23 @@ export declare class Parser {
|
|
|
72
72
|
*/
|
|
73
73
|
private typeExprPrimary;
|
|
74
74
|
/**
|
|
75
|
-
* Parse a subtype constraint: Int(i | i > 0)
|
|
75
|
+
* Parse a subtype constraint: Int(i | i > 0) or Int(i | positive: i > 0, even: i % 2 == 0)
|
|
76
76
|
* Called after the base type has been parsed, when we see '('
|
|
77
|
+
* Supports:
|
|
78
|
+
* - Single constraint: Int(i | i > 0)
|
|
79
|
+
* - Labeled constraint: Int(i | positive: i > 0)
|
|
80
|
+
* - Multiple constraints: Int(i | positive: i > 0, even: i % 2 == 0)
|
|
81
|
+
* - String labels: Int(i | 'must be positive': i > 0)
|
|
77
82
|
*/
|
|
78
83
|
private subtypeConstraintExpr;
|
|
84
|
+
/**
|
|
85
|
+
* Parse a single constraint with optional label
|
|
86
|
+
* Formats:
|
|
87
|
+
* - condition (no label)
|
|
88
|
+
* - identifier: condition
|
|
89
|
+
* - 'string message': condition
|
|
90
|
+
*/
|
|
91
|
+
private parseConstraint;
|
|
79
92
|
/**
|
|
80
93
|
* Parse a type schema: { name: String, age: Int, nickname :? String, ... } or { name: String, ...: Int }
|
|
81
94
|
* extras:
|
|
@@ -85,6 +98,29 @@ export declare class Parser {
|
|
|
85
98
|
*/
|
|
86
99
|
private typeSchemaExpr;
|
|
87
100
|
private ifExprParse;
|
|
101
|
+
/**
|
|
102
|
+
* Try to parse pipe-style guard: guard(x | condition, ...)
|
|
103
|
+
* Returns a lambda that checks constraints and returns the input value.
|
|
104
|
+
* Returns null if not a pipe-style guard (e.g., regular function call).
|
|
105
|
+
* Called from lowercase identifier parsing (when guard/check used as function name).
|
|
106
|
+
*/
|
|
107
|
+
private tryParsePipeGuard;
|
|
108
|
+
/**
|
|
109
|
+
* Try to parse pipe-style guard body after LPAREN has been seen.
|
|
110
|
+
* Called from GUARD/CHECK keyword parsing.
|
|
111
|
+
* Returns null if not a valid pipe-style guard pattern.
|
|
112
|
+
*/
|
|
113
|
+
private tryParsePipeGuardBody;
|
|
114
|
+
/**
|
|
115
|
+
* Parse the body of a pipe-style guard after LPAREN has been consumed.
|
|
116
|
+
* Returns null if not a valid pattern, restoring the saved state.
|
|
117
|
+
*/
|
|
118
|
+
private parsePipeGuardBody;
|
|
119
|
+
/**
|
|
120
|
+
* Parse guard/check expression: guard [label:] condition[, ...] in body
|
|
121
|
+
* Supports the guard...let...check...in sugar pattern
|
|
122
|
+
*/
|
|
123
|
+
private guardExprParse;
|
|
88
124
|
/**
|
|
89
125
|
* Parse lambda expression: fn( ~> body ) or fn( x ~> body ) or fn( x, y ~> body )
|
|
90
126
|
*/
|
|
@@ -128,6 +164,10 @@ export declare class Parser {
|
|
|
128
164
|
*/
|
|
129
165
|
private parsePathSegment;
|
|
130
166
|
private expr;
|
|
167
|
+
/**
|
|
168
|
+
* Parse guard/check: detect if it's pipe-style guard(x | cond) or block-style guard cond in body
|
|
169
|
+
*/
|
|
170
|
+
private guardOrPipeGuard;
|
|
131
171
|
parse(): Expr;
|
|
132
172
|
}
|
|
133
173
|
/**
|
package/dist/src/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAwY,MAAM,OAAO,CAAC;AA+fna,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAID,qBAAa,MAAM;IACjB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,QAAQ,CAAS;gBAEb,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB;IAMtD,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,GAAG;IAUX,OAAO,CAAC,OAAO;IA2Kf,OAAO,CAAC,OAAO;IA8Bf,OAAO,CAAC,KAAK;IAmBb,OAAO,CAAC,KAAK;IAYb,OAAO,CAAC,MAAM;IAqBd,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,QAAQ;IAkBhB,OAAO,CAAC,UAAU;IA4ClB,OAAO,CAAC,QAAQ;IAkBhB,OAAO,CAAC,WAAW;IAWnB;;;OAGG;IACH,OAAO,CAAC,W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@@ -274,6 +274,12 @@ class Lexer {
|
|
|
274
274
|
if (id === 'fn') {
|
|
275
275
|
return { type: 'FN', value: id, position: pos, line, column: col };
|
|
276
276
|
}
|
|
277
|
+
if (id === 'guard') {
|
|
278
|
+
return { type: 'GUARD', value: id, position: pos, line, column: col };
|
|
279
|
+
}
|
|
280
|
+
if (id === 'check') {
|
|
281
|
+
return { type: 'CHECK', value: id, position: pos, line, column: col };
|
|
282
|
+
}
|
|
277
283
|
// Uppercase identifiers: types, selectors, temporal keywords
|
|
278
284
|
if (/^[A-Z]/.test(id)) {
|
|
279
285
|
return { type: 'UPPER_IDENTIFIER', value: id, position: pos, line, column: col };
|
|
@@ -483,6 +489,13 @@ class Parser {
|
|
|
483
489
|
}
|
|
484
490
|
// Check if this is a function call
|
|
485
491
|
if (this.currentToken.type === 'LPAREN') {
|
|
492
|
+
// Special handling for guard/check pipe-style: guard(x | condition)
|
|
493
|
+
if (name === 'guard' || name === 'check') {
|
|
494
|
+
const pipeGuard = this.tryParsePipeGuard(name);
|
|
495
|
+
if (pipeGuard) {
|
|
496
|
+
return pipeGuard;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
486
499
|
this.eat('LPAREN');
|
|
487
500
|
const args = [];
|
|
488
501
|
// Parse arguments
|
|
@@ -515,6 +528,15 @@ class Parser {
|
|
|
515
528
|
if (token.type === 'IF') {
|
|
516
529
|
return this.ifExprParse();
|
|
517
530
|
}
|
|
531
|
+
// Handle guard expressions: guard [label:] condition in body
|
|
532
|
+
// Note: pipe-style guard(x | condition) is handled in expr() via guardOrPipeGuard
|
|
533
|
+
if (token.type === 'GUARD') {
|
|
534
|
+
return this.guardExprParse('guard');
|
|
535
|
+
}
|
|
536
|
+
// Handle check expressions (synonym for guard, for postconditions)
|
|
537
|
+
if (token.type === 'CHECK') {
|
|
538
|
+
return this.guardExprParse('check');
|
|
539
|
+
}
|
|
518
540
|
// Handle lambda expressions: fn( x | body ) or fn( x, y | body )
|
|
519
541
|
if (token.type === 'FN') {
|
|
520
542
|
return this.lambdaParse();
|
|
@@ -720,13 +742,25 @@ class Parser {
|
|
|
720
742
|
let node = this.logical_or();
|
|
721
743
|
while (this.currentToken.type === 'PIPE_OP') {
|
|
722
744
|
this.eat('PIPE_OP');
|
|
723
|
-
// Right side must be an identifier (function name)
|
|
745
|
+
// Right side must be an identifier (function name), uppercase (type name), or guard/check
|
|
724
746
|
const tok = this.currentToken;
|
|
725
|
-
if (tok.type !== 'IDENTIFIER' && tok.type !== 'UPPER_IDENTIFIER'
|
|
747
|
+
if (tok.type !== 'IDENTIFIER' && tok.type !== 'UPPER_IDENTIFIER' &&
|
|
748
|
+
tok.type !== 'GUARD' && tok.type !== 'CHECK') {
|
|
726
749
|
throw new Error(`Expected function name after |> at ${this.formatLocation(tok)}`);
|
|
727
750
|
}
|
|
728
751
|
const funcName = tok.value;
|
|
752
|
+
const isGuardOrCheck = tok.type === 'GUARD' || tok.type === 'CHECK';
|
|
729
753
|
this.eat(tok.type);
|
|
754
|
+
// For guard/check with pipe-style syntax, parse specially
|
|
755
|
+
if (isGuardOrCheck && this.currentToken.type === 'LPAREN') {
|
|
756
|
+
const guardType = funcName;
|
|
757
|
+
const pipeGuard = this.tryParsePipeGuardBody(guardType);
|
|
758
|
+
if (pipeGuard) {
|
|
759
|
+
// Apply the lambda to the piped value: node |> guard(x | cond) -> pipeGuard(node)
|
|
760
|
+
node = (0, ast_1.apply)(pipeGuard, [node]);
|
|
761
|
+
continue;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
730
764
|
const args = [node]; // Left side becomes first argument
|
|
731
765
|
// Parentheses are optional - if present, parse additional arguments
|
|
732
766
|
const tok2 = this.currentToken;
|
|
@@ -834,6 +868,15 @@ class Parser {
|
|
|
834
868
|
const value = this.logical_or();
|
|
835
869
|
bindings.push({ name, value });
|
|
836
870
|
}
|
|
871
|
+
// Check for let...guard or let...check sugar: let x = ... guard/check condition in body
|
|
872
|
+
if (this.currentToken.type === 'GUARD') {
|
|
873
|
+
const inner = this.guardExprParse('guard');
|
|
874
|
+
return (0, ast_1.letExpr)(bindings, inner);
|
|
875
|
+
}
|
|
876
|
+
if (this.currentToken.type === 'CHECK') {
|
|
877
|
+
const inner = this.guardExprParse('check');
|
|
878
|
+
return (0, ast_1.letExpr)(bindings, inner);
|
|
879
|
+
}
|
|
837
880
|
this.eat('IN');
|
|
838
881
|
const body = this.expr(); // Body can be any expression including nested let
|
|
839
882
|
return (0, ast_1.letExpr)(bindings, body);
|
|
@@ -945,8 +988,13 @@ class Parser {
|
|
|
945
988
|
return baseType;
|
|
946
989
|
}
|
|
947
990
|
/**
|
|
948
|
-
* Parse a subtype constraint: Int(i | i > 0)
|
|
991
|
+
* Parse a subtype constraint: Int(i | i > 0) or Int(i | positive: i > 0, even: i % 2 == 0)
|
|
949
992
|
* Called after the base type has been parsed, when we see '('
|
|
993
|
+
* Supports:
|
|
994
|
+
* - Single constraint: Int(i | i > 0)
|
|
995
|
+
* - Labeled constraint: Int(i | positive: i > 0)
|
|
996
|
+
* - Multiple constraints: Int(i | positive: i > 0, even: i % 2 == 0)
|
|
997
|
+
* - String labels: Int(i | 'must be positive': i > 0)
|
|
950
998
|
*/
|
|
951
999
|
subtypeConstraintExpr(baseType) {
|
|
952
1000
|
this.eat('LPAREN');
|
|
@@ -955,10 +1003,61 @@ class Parser {
|
|
|
955
1003
|
this.eat('IDENTIFIER');
|
|
956
1004
|
// Expect '|' separator
|
|
957
1005
|
this.eat('PIPE');
|
|
958
|
-
// Parse
|
|
959
|
-
const
|
|
1006
|
+
// Parse constraints (one or more, comma-separated)
|
|
1007
|
+
const constraints = [];
|
|
1008
|
+
constraints.push(this.parseConstraint());
|
|
1009
|
+
while (this.currentToken.type === 'COMMA') {
|
|
1010
|
+
this.eat('COMMA');
|
|
1011
|
+
constraints.push(this.parseConstraint());
|
|
1012
|
+
}
|
|
960
1013
|
this.eat('RPAREN');
|
|
961
|
-
return (0, ast_1.subtypeConstraint)(baseType, varName,
|
|
1014
|
+
return (0, ast_1.subtypeConstraint)(baseType, varName, constraints);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Parse a single constraint with optional label
|
|
1018
|
+
* Formats:
|
|
1019
|
+
* - condition (no label)
|
|
1020
|
+
* - identifier: condition
|
|
1021
|
+
* - 'string message': condition
|
|
1022
|
+
*/
|
|
1023
|
+
parseConstraint() {
|
|
1024
|
+
// Check for label (identifier or string followed by colon)
|
|
1025
|
+
let label;
|
|
1026
|
+
if (this.currentToken.type === 'IDENTIFIER') {
|
|
1027
|
+
// Could be a label or the start of the condition
|
|
1028
|
+
// Look ahead: if next is COLON, it's a label
|
|
1029
|
+
const savedState = this.saveState();
|
|
1030
|
+
const potentialLabel = this.currentToken.value;
|
|
1031
|
+
this.eat('IDENTIFIER');
|
|
1032
|
+
if (this.currentToken.type === 'COLON') {
|
|
1033
|
+
// It's a label
|
|
1034
|
+
this.eat('COLON');
|
|
1035
|
+
label = potentialLabel;
|
|
1036
|
+
}
|
|
1037
|
+
else {
|
|
1038
|
+
// Not a label, restore and parse as expression
|
|
1039
|
+
this.restoreState(savedState);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
else if (this.currentToken.type === 'STRING') {
|
|
1043
|
+
// String label
|
|
1044
|
+
const savedState = this.saveState();
|
|
1045
|
+
const potentialLabel = this.currentToken.value;
|
|
1046
|
+
this.eat('STRING');
|
|
1047
|
+
if (this.currentToken.type === 'COLON') {
|
|
1048
|
+
// It's a label
|
|
1049
|
+
this.eat('COLON');
|
|
1050
|
+
label = potentialLabel;
|
|
1051
|
+
}
|
|
1052
|
+
else {
|
|
1053
|
+
// Not a label, restore and parse as expression
|
|
1054
|
+
this.restoreState(savedState);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
// Parse the constraint condition
|
|
1058
|
+
// Use logical_or to avoid consuming COMMA and RPAREN which delimit constraints
|
|
1059
|
+
const condition = this.logical_or();
|
|
1060
|
+
return { label, condition };
|
|
962
1061
|
}
|
|
963
1062
|
/**
|
|
964
1063
|
* Parse a type schema: { name: String, age: Int, nickname :? String, ... } or { name: String, ...: Int }
|
|
@@ -1041,6 +1140,88 @@ class Parser {
|
|
|
1041
1140
|
const elseBranch = this.expr();
|
|
1042
1141
|
return (0, ast_1.ifExpr)(condition, thenBranch, elseBranch);
|
|
1043
1142
|
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Try to parse pipe-style guard: guard(x | condition, ...)
|
|
1145
|
+
* Returns a lambda that checks constraints and returns the input value.
|
|
1146
|
+
* Returns null if not a pipe-style guard (e.g., regular function call).
|
|
1147
|
+
* Called from lowercase identifier parsing (when guard/check used as function name).
|
|
1148
|
+
*/
|
|
1149
|
+
tryParsePipeGuard(guardType) {
|
|
1150
|
+
const savedState = this.saveState();
|
|
1151
|
+
this.eat('LPAREN');
|
|
1152
|
+
return this.parsePipeGuardBody(guardType, savedState);
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* Try to parse pipe-style guard body after LPAREN has been seen.
|
|
1156
|
+
* Called from GUARD/CHECK keyword parsing.
|
|
1157
|
+
* Returns null if not a valid pipe-style guard pattern.
|
|
1158
|
+
*/
|
|
1159
|
+
tryParsePipeGuardBody(guardType) {
|
|
1160
|
+
const savedState = this.saveState();
|
|
1161
|
+
this.eat('LPAREN');
|
|
1162
|
+
return this.parsePipeGuardBody(guardType, savedState);
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Parse the body of a pipe-style guard after LPAREN has been consumed.
|
|
1166
|
+
* Returns null if not a valid pattern, restoring the saved state.
|
|
1167
|
+
*/
|
|
1168
|
+
parsePipeGuardBody(guardType, savedState) {
|
|
1169
|
+
// Check for IDENTIFIER PIPE pattern
|
|
1170
|
+
if (this.currentToken.type !== 'IDENTIFIER') {
|
|
1171
|
+
this.restoreState(savedState);
|
|
1172
|
+
return null;
|
|
1173
|
+
}
|
|
1174
|
+
const varName = this.currentToken.value;
|
|
1175
|
+
this.eat('IDENTIFIER');
|
|
1176
|
+
if (this.currentToken.type !== 'PIPE') {
|
|
1177
|
+
this.restoreState(savedState);
|
|
1178
|
+
return null;
|
|
1179
|
+
}
|
|
1180
|
+
this.eat('PIPE');
|
|
1181
|
+
// Parse constraints (one or more, comma-separated) - reuse constraint parsing
|
|
1182
|
+
const constraints = [];
|
|
1183
|
+
constraints.push(this.parseConstraint());
|
|
1184
|
+
while (this.currentToken.type === 'COMMA') {
|
|
1185
|
+
this.eat('COMMA');
|
|
1186
|
+
constraints.push(this.parseConstraint());
|
|
1187
|
+
}
|
|
1188
|
+
this.eat('RPAREN');
|
|
1189
|
+
// Create a lambda: fn(x ~> guard constraints in x)
|
|
1190
|
+
// The guard body is just the variable itself (returns input if guard passes)
|
|
1191
|
+
const varRef = (0, ast_1.variable)(varName);
|
|
1192
|
+
const guardBody = (0, ast_1.guardExpr)(constraints, varRef, guardType);
|
|
1193
|
+
return (0, ast_1.lambda)([varName], guardBody);
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Parse guard/check expression: guard [label:] condition[, ...] in body
|
|
1197
|
+
* Supports the guard...let...check...in sugar pattern
|
|
1198
|
+
*/
|
|
1199
|
+
guardExprParse(guardType) {
|
|
1200
|
+
this.eat(guardType === 'guard' ? 'GUARD' : 'CHECK');
|
|
1201
|
+
// Parse constraints (one or more, comma-separated)
|
|
1202
|
+
const constraints = [];
|
|
1203
|
+
constraints.push(this.parseConstraint());
|
|
1204
|
+
while (this.currentToken.type === 'COMMA') {
|
|
1205
|
+
this.eat('COMMA');
|
|
1206
|
+
constraints.push(this.parseConstraint());
|
|
1207
|
+
}
|
|
1208
|
+
// Check for guard...check sugar
|
|
1209
|
+
// guard cond check cond in body
|
|
1210
|
+
const tok = this.currentToken;
|
|
1211
|
+
if (tok.type === 'GUARD' && guardType === 'guard') {
|
|
1212
|
+
// guard...guard sugar (nested guards)
|
|
1213
|
+
const inner = this.guardExprParse('guard');
|
|
1214
|
+
return (0, ast_1.guardExpr)(constraints, inner, guardType);
|
|
1215
|
+
}
|
|
1216
|
+
else if (tok.type === 'CHECK') {
|
|
1217
|
+
// guard...check sugar: guard cond check cond in body
|
|
1218
|
+
const inner = this.guardExprParse('check');
|
|
1219
|
+
return (0, ast_1.guardExpr)(constraints, inner, guardType);
|
|
1220
|
+
}
|
|
1221
|
+
this.eat('IN');
|
|
1222
|
+
const body = this.expr();
|
|
1223
|
+
return (0, ast_1.guardExpr)(constraints, body, guardType);
|
|
1224
|
+
}
|
|
1044
1225
|
/**
|
|
1045
1226
|
* Parse lambda expression: fn( ~> body ) or fn( x ~> body ) or fn( x, y ~> body )
|
|
1046
1227
|
*/
|
|
@@ -1236,19 +1417,43 @@ class Parser {
|
|
|
1236
1417
|
this.depth++;
|
|
1237
1418
|
this.checkDepth();
|
|
1238
1419
|
try {
|
|
1239
|
-
// Let
|
|
1420
|
+
// Let, if, guard, check expressions have lowest precedence
|
|
1240
1421
|
if (this.currentToken.type === 'LET') {
|
|
1241
1422
|
return this.letExpr();
|
|
1242
1423
|
}
|
|
1243
1424
|
if (this.currentToken.type === 'IF') {
|
|
1244
1425
|
return this.ifExprParse();
|
|
1245
1426
|
}
|
|
1427
|
+
// Handle guard/check: either block-style or pipe-style
|
|
1428
|
+
if (this.currentToken.type === 'GUARD') {
|
|
1429
|
+
return this.guardOrPipeGuard('guard');
|
|
1430
|
+
}
|
|
1431
|
+
if (this.currentToken.type === 'CHECK') {
|
|
1432
|
+
return this.guardOrPipeGuard('check');
|
|
1433
|
+
}
|
|
1246
1434
|
return this.pipe();
|
|
1247
1435
|
}
|
|
1248
1436
|
finally {
|
|
1249
1437
|
this.depth--;
|
|
1250
1438
|
}
|
|
1251
1439
|
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Parse guard/check: detect if it's pipe-style guard(x | cond) or block-style guard cond in body
|
|
1442
|
+
*/
|
|
1443
|
+
guardOrPipeGuard(guardType) {
|
|
1444
|
+
const savedState = this.saveState();
|
|
1445
|
+
this.eat(guardType === 'guard' ? 'GUARD' : 'CHECK');
|
|
1446
|
+
// Check for pipe-style: guard(x | condition)
|
|
1447
|
+
if (this.currentToken.type === 'LPAREN') {
|
|
1448
|
+
const pipeGuard = this.tryParsePipeGuardBody(guardType);
|
|
1449
|
+
if (pipeGuard) {
|
|
1450
|
+
return pipeGuard;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
// Not pipe-style, restore and parse as block-style
|
|
1454
|
+
this.restoreState(savedState);
|
|
1455
|
+
return this.guardExprParse(guardType);
|
|
1456
|
+
}
|
|
1252
1457
|
parse() {
|
|
1253
1458
|
const result = this.expr();
|
|
1254
1459
|
this.eat('EOF');
|