Skip to content

Commit cea2c1b

Browse files
author
Steve Ives
committed
Added support for REPLICATION_REMAINING_EXCLUSIVE_MAX_n and REPLICATION_REMAINING_INCLUSIVE_MAX_n.
1 parent b78738a commit cea2c1b

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

CodeGenEngine/TokenExpanders/TokenExpander.dbl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ namespace CodeGen.Engine
119119
& || tkn.Value.StartsWith("REMAINING_INCLUSIVE_MAX_")) then
120120
mreturn expandLoopUtilRemainingMax(tkn, template, loops)
121121

122+
else if (tkn.Value.StartsWith("REPLICATION_REMAINING_EXCLUSIVE_MAX_")
123+
& || tkn.Value.StartsWith("REPLICATION_REMAINING_INCLUSIVE_MAX_")) then
124+
mreturn replicationExpandLoopUtilRemainingMax(tkn, template, loops)
125+
122126
else
123127
throw new ApplicationException(noExpanderMessage())
124128
end

CodeGenEngine/TokenExpanders/TokenExpanderLoopUtility.dbl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import System.Collections.Generic
4545
import System.Linq
4646
import System.Text
4747
import System.Threading.Tasks
48+
import CodeGen.RepositoryAPI
4849

4950
.array 0
5051

@@ -342,6 +343,65 @@ namespace CodeGen.Engine
342343

343344
endmethod
344345

346+
private static method replicationExpandLoopUtilRemainingMax, string
347+
tkn, @Token
348+
template, @FileNode
349+
loops, @IEnumerable<LoopNode>
350+
endparams
351+
proc
352+
;This method will be called to expand the following tokens:
353+
;
354+
;<REPLICATION_REMAINING_EXCLUSIVE_MAX_value>
355+
;<REPLICATION_REMAINING_INCLUSIVE_MAX_value>
356+
;
357+
;Where value is a numeric literal
358+
;
359+
;The bahavior is identical to that of expandLoopUtilRemainingMax (above)
360+
;except that the loops MaxIndex is reduced by the number of fields being
361+
;excluded via the special token REPLICATOR_EXCLUDE in field user text or
362+
;long descripotions.
363+
364+
lambda isLoopNode(node) (node .is. LoopNode)
365+
data loop, @LoopNode, loops.Last(isLoopNode)
366+
367+
data tokenText = tkn.Value
368+
data maxValue = 0
369+
data remainingValue = 0
370+
371+
;;Figure out how many fields have been excluded
372+
373+
data fld, @RpsField
374+
data excludedFieldCount = 0
375+
376+
foreach fld in template.Context.CurrentStructure.Fields
377+
begin
378+
if (fld.UserText.Contains("REPLICATOR_EXCLUDE") || fld.LongDescription.Contains("REPLICATOR_EXCLUDE"))
379+
begin
380+
excludedFieldCount += 1
381+
end
382+
end
383+
384+
if (tokenText.StartsWith("REPLICATION_REMAINING_EXCLUSIVE_MAX_")) then
385+
begin
386+
tokenText = tokenText.Replace("REPLICATION_REMAINING_EXCLUSIVE_MAX_","")
387+
remainingValue = loop.MaxIndex - excludedFieldCount - loop.CurrentIndex
388+
end
389+
else if (tokenText.StartsWith("REPLICATION_REMAINING_INCLUSIVE_MAX_"))
390+
begin
391+
tokenText = tokenText.Replace("REPLICATION_REMAINING_INCLUSIVE_MAX_","")
392+
remainingValue = loop.MaxIndex - excludedFieldCount - loop.CurrentIndex + 1
393+
end
394+
395+
if (int.TryParse(tokenText,maxValue))
396+
begin
397+
lambda doExpand(loop) String.Format("{0}", (remainingValue < maxValue) ? remainingValue : maxValue )
398+
mreturn ExpandLoopUtilityToken(tkn, template, loops, doExpand)
399+
end
400+
401+
throw new ApplicationException("Invalid loop utility token " + tkn.Value)
402+
403+
endmethod
404+
345405
private static method expandLoopUtilTotalItems, string
346406
tkn, @Token
347407
template, @FileNode

CodeGenEngine/Tokenizer.dbl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,10 @@ namespace CodeGen.Engine
17971797

17981798
;;And now the exceptions!
17991799
if ( tokenValue.StartsWith("REMAINING_EXCLUSIVE_MAX_")
1800-
& || tokenValue.StartsWith("REMAINING_INCLUSIVE_MAX_"))
1800+
& || tokenValue.StartsWith("REMAINING_INCLUSIVE_MAX_")
1801+
& || tokenValue.StartsWith("REPLICATION_REMAINING_INCLUSIVE_MAX_")
1802+
& || tokenValue.StartsWith("REPLICATION_REMAINING_INCLUSIVE_MAX_")
1803+
& )
18011804
begin
18021805
;;Declare the token as valid so that tokenization works.
18031806
;;Further validation will take place later during expansion.

Documentation/CodeGen.chm

848 Bytes
Binary file not shown.

Documentation/CodeGen.hsm

9.26 KB
Binary file not shown.

0 commit comments

Comments
 (0)