Jean-Yves Didier

misspell with catastrophic consequences

......@@ -1631,234 +1631,6 @@ ARCS.EventLogicParser = (function() {
};
})();
/*
* The purpose of this class is to build a transition system in order to fully
* ascertain some "event" logic
*/
ARCS.TransitionSystem = function(a, b, c) {
this.initial = "" ;
this.final = "";
var transitions = {};
if ( a !== undefined) {
if ( (b === undefined || c === undefined)) {
this.initial = "a$";
this.final = "z$";
transitions[this.initial] = {};
transitions[this.initial][a] = this.final;
} else {
this.initial = a;
this.final = c;
transitions[this.initial] = {};
transitions[this.initial][b] = this.final;
}
}
this.visitTransitions = function( closure ) {
var p,t;
for (p in transitions) {
if (transitions.hasOwnProperty(p)) {
for (t in transitions[p]) {
if (transitions[p].hasOwnProperty(t)) {
closure(p,t,transitions[p][t]);
}
}
}
}
}
this.clone = function(pf) {
// checked
var prefix = pf || "";
var res = new ARCS.TransitionSystem();
res.initial = prefix + this.initial;
res.final = prefix + this.final;
this.visitTransitions( function(s, t, e) {
res.addTransition(prefix + s, t, prefix + e);
});
return res;
};
this.fuse = function(ts, i, f) {
// checked
var res = ts.clone();
this.visitTransitions( function(s, t, e) {
res.addTransition(s, t, e);
});
if (i === undefined) {
res.initial = this.initial;
} else {
res.initial = i;
}
if (f === undefined) {
res.final = this.final;
} else {
res.final = f;
}
return res;
};
this.hasState = function(s) {
if (this.initial === s || this.final === s || transitions.hasOwnProperty(s)) {
return true;
}
try {
this.visitTransitions( function (s1, t, e) {
if ( e === s) throw '!';
});
} catch ( e ) {
if (e === '!')
return true;
}
return false;
};
this.renameState = function (currentName, newName) {
if (this.hasState(newName)) {
// this is bad !
console.error("This transition system is corrupt !");
}
if (this.initial === currentName) {
this.initial = newName;
}
if (this.final === currentName) {
this.final = newName;
}
if (transitions.hasOwnProperty(currentName)) {
transitions[newName] = transitions[currentName];
delete transitions[currentName];
}
this.visitTransitions( function (s, t, e) {
if ( e === currentName ) {
transitions[s][t] = newName;
}
});
};
this.dump = function () {
console.log('@ = ' + this.initial + ', + = ' + this.final);
this.visitTransitions( function(s, t, e) {
console.log(' ' + s + '\t---\t'+ t +'\t-->\t' + e);
});
};
this.getStates = function() {
// check
var states = [];
// then we start looking for states
this.visitTransitions(function (s, t, e) {
if (states.indexOf(s) < 0) {
states.push(s);
}
if (states.indexOf(e) < 0) {
states.push(e);
}
});
return states;
}
this.addTransition = function( start, token, end) {
if ( ! transitions.hasOwnProperty(start)) {
transitions[start] = {};
}
transitions[start][token] = end;
};
// let's make a AND operation
this.and = function(ts) {
//check
// letters will create disambiguation
var i;
// first, let's create two identical trees
var leftTS1 = this.clone('i');
var leftTS2 = this.clone('j');
var rightTS;
// then, we fuse the trees together.
var res = leftTS1.fuse(leftTS2, leftTS1.initial, leftTS2.final);
var tmpFuse;
var states = this.getStates();
for( i = 0; i < states.length; i++) {
rightTS = ts.clone('k'+i);
rightTS.renameState(rightTS.initial, 'i'+ states[i]);
rightTS.renameState(rightTS.final, 'j'+ states[i]);
tmpFuse = res.fuse(rightTS);
res = tmpFuse;
}
return res;
};
// let's make a OR operation
this.or = function(ts) {
// checked
var leftTS = this.clone('s');
var rightTS = ts.clone('t');
rightTS.renameState(rightTS.initial, leftTS.initial);
rightTS.renameState(rightTS.final, leftTS.final);
return leftTS.fuse(rightTS);
};
};
// tree is the one obtained by parsing expressions
ARCS.TransitionSystem.build = function( tree, d) {
var depth = d || 1;
var counter = 1;
var i;
var res;
var tmpTS;
var rightTS;
if (typeof tree === "string") {
return new ARCS.TransitionSystem(tree).clone('w0d' + depth);
}
// TODO: depth is not handled in subexpression prefixes.
// This may results in name clashes for intermediate transformations (or not)
res = ARCS.TransitionSystem.build(tree[0], depth + 1);
for (i=1; i < tree.length; i++) {
if (tree[i].hasOwnProperty('and')) {
rightTS = ARCS.TransitionSystem.build(tree[i]['and'], depth + 1).clone('w' + counter++);
tmpTS = res.and(rightTS);
} else {
if (tree[i].hasOwnProperty('or')) {
rightTS = ARCS.TransitionSystem.build(tree[i]['or'], depth + 1).clone('w' + counter++);
tmpTS = res.or(rightTS);
} else {
console.warn('[ARCS] Illegal tree');
}
}
res = tmpTS;
}
return res;
};
// this class creates a promise that can be deferred as long as necessary.
// calls to accept or reject will solve the promise.
......@@ -1919,11 +1691,11 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
for (i=1; i < tree.length; i++) {
if (tree[i].hasOwnProperty('and')) {
rightTN = ARCS.TransitionSystem.build(tree[i]['and'], tokenEvents);
rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents);
tmpTN = res.and(rightTN);
} else {
if (tree[i].hasOwnProperty('or')) {
rightTN = ARCS.TransitionSystem.build(tree[i]['or'], tokenEvents);
rightTN = ARCS.TransitionNetwork.build(tree[i]['or'], tokenEvents);
tmpTN = res.or(rightTN);
} else {
console.warn('[ARCS] Illegal tree');
......
This diff is collapsed. Click to expand it.
......@@ -38,11 +38,11 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
for (i=1; i < tree.length; i++) {
if (tree[i].hasOwnProperty('and')) {
rightTN = ARCS.TransitionSystem.build(tree[i]['and'], tokenEvents);
rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents);
tmpTN = res.and(rightTN);
} else {
if (tree[i].hasOwnProperty('or')) {
rightTN = ARCS.TransitionSystem.build(tree[i]['or'], tokenEvents);
rightTN = ARCS.TransitionNetwork.build(tree[i]['or'], tokenEvents);
tmpTN = res.or(rightTN);
} else {
console.warn('[ARCS] Illegal tree');
......