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