Support when(...) clause in assert in facets.
This commit is contained in:
parent
9c5f427366
commit
a428423ff2
|
@ -144,8 +144,8 @@ var modifiedSourceActions = {
|
||||||
return '\n.addDoneBlock((function() ' + block.asES5 + '))';
|
return '\n.addDoneBlock((function() ' + block.asES5 + '))';
|
||||||
},
|
},
|
||||||
|
|
||||||
FacetSituation_assert: function(_assert, expr, _sc) {
|
FacetSituation_assert: function(_assert, expr, whenClause, _sc) {
|
||||||
return '\n.addAssertion(' + buildSubscription([expr], 'assert', 'pattern') + ')';
|
return '\n.addAssertion(' + buildSubscription([expr], 'assert', 'pattern', whenClause) + ')';
|
||||||
},
|
},
|
||||||
FacetSituation_event: function(_on, eventPattern, block) {
|
FacetSituation_event: function(_on, eventPattern, block) {
|
||||||
return buildOnEvent(false,
|
return buildOnEvent(false,
|
||||||
|
@ -172,6 +172,10 @@ var modifiedSourceActions = {
|
||||||
'.completeBuild(); }');
|
'.completeBuild(); }');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
AssertWhenClause: function(_when, _lparen, expr, _rparen) {
|
||||||
|
return expr.asES5;
|
||||||
|
},
|
||||||
|
|
||||||
FacetStateTransition_withContinuation: function(_case, eventPattern, block) {
|
FacetStateTransition_withContinuation: function(_case, eventPattern, block) {
|
||||||
return buildCaseEvent(eventPattern, block.asES5);
|
return buildCaseEvent(eventPattern, block.asES5);
|
||||||
},
|
},
|
||||||
|
@ -200,9 +204,13 @@ semantics.addAttribute('eventType', {
|
||||||
FacetTransitionEventPattern_risingEdge: function (_lp, expr, _rp) { return 'risingEdge'; }
|
FacetTransitionEventPattern_risingEdge: function (_lp, expr, _rp) { return 'risingEdge'; }
|
||||||
});
|
});
|
||||||
|
|
||||||
function buildSubscription(children, patchMethod, mode) {
|
function buildSubscription(children, patchMethod, mode, whenClause) {
|
||||||
var fragments = [];
|
var fragments = [];
|
||||||
|
var hasWhenClause = (whenClause && (whenClause.numChildren === 1));
|
||||||
fragments.push('(function() { var _ = Syndicate.__; return ');
|
fragments.push('(function() { var _ = Syndicate.__; return ');
|
||||||
|
if (hasWhenClause) {
|
||||||
|
fragments.push('(' + whenClause.asES5 + ') ? ');
|
||||||
|
}
|
||||||
if (patchMethod) {
|
if (patchMethod) {
|
||||||
fragments.push('Syndicate.Patch.' + patchMethod + '(');
|
fragments.push('Syndicate.Patch.' + patchMethod + '(');
|
||||||
} else {
|
} else {
|
||||||
|
@ -220,31 +228,34 @@ function buildSubscription(children, patchMethod, mode) {
|
||||||
} else {
|
} else {
|
||||||
fragments.push(' }');
|
fragments.push(' }');
|
||||||
}
|
}
|
||||||
|
if (hasWhenClause) {
|
||||||
|
fragments.push(' : Syndicate.Patch.emptyPatch');
|
||||||
|
}
|
||||||
fragments.push('; })');
|
fragments.push('; })');
|
||||||
return fragments.join('');
|
return fragments.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
semantics.addAttribute('subscription', {
|
semantics.addAttribute('subscription', {
|
||||||
_default: function(children) {
|
_default: function(children) {
|
||||||
return buildSubscription(children, 'sub', 'pattern');
|
return buildSubscription(children, 'sub', 'pattern', null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
semantics.addAttribute('instantiatedSubscription', {
|
semantics.addAttribute('instantiatedSubscription', {
|
||||||
_default: function(children) {
|
_default: function(children) {
|
||||||
return buildSubscription(children, 'sub', 'instantiated');
|
return buildSubscription(children, 'sub', 'instantiated', null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
semantics.addAttribute('instantiatedProjection', {
|
semantics.addAttribute('instantiatedProjection', {
|
||||||
_default: function(children) {
|
_default: function(children) {
|
||||||
return buildSubscription(children, null, 'instantiated');
|
return buildSubscription(children, null, 'instantiated', null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
semantics.addAttribute('projection', {
|
semantics.addAttribute('projection', {
|
||||||
_default: function(children) {
|
_default: function(children) {
|
||||||
return buildSubscription(children, null, 'projection');
|
return buildSubscription(children, null, 'projection', null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,11 @@ Syndicate <: ES5 {
|
||||||
FacetDoneBlock = done Block
|
FacetDoneBlock = done Block
|
||||||
|
|
||||||
FacetSituation
|
FacetSituation
|
||||||
= assert FacetPattern #(sc) -- assert
|
= assert FacetPattern AssertWhenClause? #(sc) -- assert
|
||||||
| on FacetEventPattern Block -- event
|
| on FacetEventPattern Block -- event
|
||||||
| during FacetPattern FacetBlock -- during
|
| during FacetPattern FacetBlock -- during
|
||||||
|
|
||||||
|
AssertWhenClause = when "(" Expression<withIn> ")"
|
||||||
|
|
||||||
FacetEventPattern
|
FacetEventPattern
|
||||||
= message FacetPattern -- messageEvent
|
= message FacetPattern -- messageEvent
|
||||||
|
@ -84,4 +86,5 @@ Syndicate <: ES5 {
|
||||||
state = "state" ~identifierPart
|
state = "state" ~identifierPart
|
||||||
type = "type" ~identifierPart
|
type = "type" ~identifierPart
|
||||||
until = "until" ~identifierPart
|
until = "until" ~identifierPart
|
||||||
|
when = "when" ~identifierPart
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue