Remove __ and _$ in favour of plain structs Discard() and Capture(_), respectively
This commit is contained in:
parent
324eaa9978
commit
ff7d235120
|
@ -35,8 +35,10 @@ Seal.prototype.toJSON = function () {
|
|||
return { '@seal': 0 };
|
||||
};
|
||||
|
||||
module.exports.Observe = Struct.makeConstructor('Observe', ['specification']);
|
||||
module.exports.Discard = Struct.makeConstructor('discard', []);
|
||||
module.exports.Capture = Struct.makeConstructor('capture', ['specification']);
|
||||
module.exports.Observe = Struct.makeConstructor('observe', ['specification']);
|
||||
module.exports.Seal = Seal;
|
||||
module.exports.Inbound = Struct.makeConstructor('Inbound', ['assertion']);
|
||||
module.exports.Outbound = Struct.makeConstructor('Outbound', ['assertion']);
|
||||
module.exports.Instance = Struct.makeConstructor('Instance', ['uniqueId']);
|
||||
module.exports.Inbound = Struct.makeConstructor('inbound', ['assertion']);
|
||||
module.exports.Outbound = Struct.makeConstructor('outbound', ['assertion']);
|
||||
module.exports.Instance = Struct.makeConstructor('instance', ['uniqueId']);
|
||||
|
|
|
@ -25,9 +25,6 @@ const Bag = require('./bag.js');
|
|||
const Assertions = require('./assertions.js');
|
||||
const Dataflow = require('./dataflow.js');
|
||||
|
||||
const __ = Struct.__;
|
||||
const _$ = Struct._$;
|
||||
|
||||
const PRIORITY = Object.freeze({
|
||||
QUERY_HIGH: 0,
|
||||
QUERY: 1,
|
||||
|
|
|
@ -32,8 +32,6 @@ module.exports.Bag = require("./bag.js");
|
|||
module.exports.Struct = Struct;
|
||||
module.exports.Skeleton = Skeleton;
|
||||
module.exports.RandomID = RandomID;
|
||||
module.exports.__ = Struct.__;
|
||||
module.exports._$ = Skeleton._$;
|
||||
|
||||
module.exports._Dataspace = Dataspace;
|
||||
module.exports.Dataspace = Dataspace.Dataspace;
|
||||
|
@ -41,6 +39,8 @@ module.exports.currentFacet = Dataspace.Dataspace.currentFacet;
|
|||
module.exports.Ground = Ground;
|
||||
|
||||
module.exports._Assertions = Assertions;
|
||||
module.exports.Discard = Assertions.Discard;
|
||||
module.exports.Capture = Assertions.Capture;
|
||||
module.exports.Observe = Assertions.Observe;
|
||||
module.exports.Seal = Assertions.Seal;
|
||||
module.exports.Inbound = Assertions.Inbound;
|
||||
|
|
|
@ -21,9 +21,7 @@ const Immutable = require("immutable");
|
|||
const Struct = require('./struct.js');
|
||||
const $Special = require('./special.js');
|
||||
const Bag = require('./bag.js');
|
||||
const Assertions = require('./assertions.js');
|
||||
|
||||
const __ = Struct.__;
|
||||
const { Capture, Discard } = require('./assertions.js');
|
||||
|
||||
const EVENT_ADDED = +1;
|
||||
const EVENT_REMOVED = -1;
|
||||
|
@ -275,24 +273,6 @@ Index.prototype.sendMessage = function(v) {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// The name argument should be a string or null; it defaults to null.
|
||||
// The pattern argument defaults to wildcard, __.
|
||||
function Capture(name, pattern) {
|
||||
this.name = name;
|
||||
this.pattern = (pattern === void 0 ? __ : pattern);
|
||||
}
|
||||
|
||||
// Abbreviation: _$(...) <==> new Capture(...)
|
||||
function _$(name, pattern) {
|
||||
return new Capture(name, pattern);
|
||||
}
|
||||
|
||||
function isCapture(x) { return x instanceof Capture || x === _$; }
|
||||
function captureName(x) { return x instanceof Capture ? x.name : null; }
|
||||
function capturePattern(x) { return x instanceof Capture ? x.pattern : __; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function analyzeAssertion(a) {
|
||||
let constPaths = Immutable.List();
|
||||
let constVals = Immutable.List();
|
||||
|
@ -308,10 +288,10 @@ function analyzeAssertion(a) {
|
|||
}
|
||||
return result;
|
||||
} else {
|
||||
if (isCapture(a)) {
|
||||
if (Capture.isClassOf(a)) {
|
||||
capturePaths = capturePaths.push(path);
|
||||
return walk(path, capturePattern(a));
|
||||
} else if (a === __) {
|
||||
return walk(path, a.get(0));
|
||||
} else if (Discard.isClassOf(a)) {
|
||||
return null;
|
||||
} else {
|
||||
constPaths = constPaths.push(path);
|
||||
|
@ -333,10 +313,4 @@ module.exports.EVENT_REMOVED = EVENT_REMOVED;
|
|||
module.exports.EVENT_MESSAGE = EVENT_MESSAGE;
|
||||
module.exports.Index = Index;
|
||||
|
||||
module.exports.Capture = Capture;
|
||||
module.exports._$ = _$;
|
||||
module.exports.isCapture = isCapture;
|
||||
module.exports.captureName = captureName;
|
||||
module.exports.capturePattern = capturePattern;
|
||||
|
||||
module.exports.analyzeAssertion = analyzeAssertion;
|
||||
|
|
|
@ -22,20 +22,15 @@
|
|||
const Immutable = require("immutable");
|
||||
const $Special = require('./special.js');
|
||||
|
||||
/* Defined here rather than elsewhere because we need it in makeConstructor. */
|
||||
const __ = new $Special("wildcard"); /* wildcard marker */
|
||||
|
||||
function StructureType(label, arity) {
|
||||
this.label = label;
|
||||
this.arity = arity;
|
||||
// this.pattern = this.instantiate(Immutable.Repeat(__, arity).toArray());
|
||||
|
||||
var self = this;
|
||||
this.ctor = function () {
|
||||
return self.instantiate(Array.prototype.slice.call(arguments));
|
||||
};
|
||||
this.ctor.meta = this;
|
||||
// this.ctor.pattern = this.pattern;
|
||||
this.ctor.isClassOf = function (v) { return self.isClassOf(v); };
|
||||
}
|
||||
|
||||
|
@ -165,7 +160,6 @@ function isStructure(v) {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
module.exports.__ = __;
|
||||
module.exports.StructureType = StructureType;
|
||||
module.exports.makeConstructor = makeConstructor;
|
||||
module.exports.Structure = Structure;
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
import { genUuid, Seal, Observe, Dataspace, Skeleton, currentFacet } from "@syndicate-lang/core";
|
||||
const { isCapture, captureName } = Skeleton;
|
||||
import { genUuid, Seal, Capture, Observe, Dataspace, currentFacet } from "@syndicate-lang/core";
|
||||
import { parse as parseUrl } from "url";
|
||||
|
||||
const http = require('http');
|
||||
|
@ -60,7 +59,7 @@ function _server(host, port, httpsOptions) {
|
|||
const wsHandlerMap = {};
|
||||
|
||||
function encodePath(path) {
|
||||
return JSON.stringify(path.toJS().map((s) => isCapture(s) ? null : s));
|
||||
return JSON.stringify(path.toJS().map((s) => Capture.isClassOf(s) ? null : s));
|
||||
}
|
||||
|
||||
during Observe(Request(_, server, $method, $pathPattern, _, _)) {
|
||||
|
|
|
@ -61,7 +61,7 @@ function hasCapturesOrDiscards(nodePath) {
|
|||
return result;
|
||||
}
|
||||
|
||||
const _discardAst = template.expression(`SYNDICATE.__`, { placeholderPattern: /^[A-Z]+$/ });
|
||||
const _discardAst = template.expression(`SYNDICATE.Discard()`);
|
||||
function discardAst(state) {
|
||||
return _discardAst({ SYNDICATE: state.SyndicateID });
|
||||
}
|
||||
|
@ -71,10 +71,9 @@ function listAst(state, vs) {
|
|||
return _listAst({ IMMUTABLE: state.ImmutableID, VS: vs });
|
||||
}
|
||||
|
||||
function captureWrap(state, idNode, ast) {
|
||||
return template.expression(`SYNDICATE._$(NAME, PATTERN)`, { placeholderPattern: /^[A-Z]+$/ })({
|
||||
function captureWrap(state, ast) {
|
||||
return template.expression(`SYNDICATE.Capture(PATTERN)`)({
|
||||
SYNDICATE: state.SyndicateID,
|
||||
NAME: t.stringLiteral(idNode.name.slice(1)),
|
||||
PATTERN: ast
|
||||
});
|
||||
}
|
||||
|
@ -114,7 +113,7 @@ function compilePattern(state, patternPath) {
|
|||
// It's a capture with a nested subpattern.
|
||||
pushCapture(pattern.callee);
|
||||
let [s, a] = walk(patternPath.get('arguments.0'));
|
||||
return [s, captureWrap(state, pattern.callee, a)];
|
||||
return [s, captureWrap(state, a)];
|
||||
} else {
|
||||
// It's a regular call. If there are nested captures or
|
||||
// discards, this indicates the programmer believes it to be
|
||||
|
@ -146,7 +145,7 @@ function compilePattern(state, patternPath) {
|
|||
return [t.nullLiteral(), discardAst(state)];
|
||||
} else if (isCaptureIdentifier(pattern)) {
|
||||
pushCapture(pattern);
|
||||
return [t.nullLiteral(), captureWrap(state, pattern, discardAst(state))];
|
||||
return [t.nullLiteral(), captureWrap(state, discardAst(state))];
|
||||
} else {
|
||||
pushConstant(pattern);
|
||||
return [t.nullLiteral(), pattern];
|
||||
|
|
Loading…
Reference in New Issue