From ae5096fae2705f696dfb2df4dd30b6d965f5569b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 19 Nov 2018 22:20:26 +0000 Subject: [PATCH] Experimental approach to VisibilityRestriction --- packages/core/src/skeleton.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/core/src/skeleton.js b/packages/core/src/skeleton.js index b1a8199..9e07302 100644 --- a/packages/core/src/skeleton.js +++ b/packages/core/src/skeleton.js @@ -308,6 +308,40 @@ function analyzeAssertion(a) { return { skeleton, constPaths, constVals, capturePaths }; } +function VisibilityRestriction() {} + +function instantiateAssertion(a, vs) { + let remaining = vs; + function walk(a) { + if (Capture.isClassOf(a)) { + const v = remaining.first(); + remaining = remaining.shift(); + walk(a.get(0)); + return v; + } + + if (Discard.isClassOf(a)) { + return new VisibilityRestriction(); + // ^ Doesn't match ANYTHING ELSE, even other + // VisibilityRestriction instances. This does the equivalent of + // the Racket implementation's `visibility-restriction` stuff, + // to a degree. + } + + let cls = classOf(a); + if (cls !== null) { + if (typeof cls === 'number') { + return a.map(walk); + } else { + return new Record(a.label, a.fields.map(walk)); + } + } + + return a; + } + return walk(a); +} + /////////////////////////////////////////////////////////////////////////// module.exports.EVENT_ADDED = EVENT_ADDED; @@ -316,3 +350,4 @@ module.exports.EVENT_MESSAGE = EVENT_MESSAGE; module.exports.Index = Index; module.exports.analyzeAssertion = analyzeAssertion; +module.exports.instantiateAssertion = instantiateAssertion;