@@ -96,6 +96,7 @@ namespace CodeGen.Engine
9696 structureTokenExpanders.Add("STRUCTURE_PLURAL", expandStructurePlural)
9797 structureTokenExpanders.Add("STRUCTURE_SIZE", expandStructureSize)
9898 structureTokenExpanders.Add("STRUCTURE_TAG_AND_COUNT", expandStructureTagAndCount)
99+ structureTokenExpanders.Add("STRUCTURE_TAG_EXPRESSION", expandStructureTagExpression)
99100 structureTokenExpanders.Add("STRUCTURE_TAG_OR_COUNT", expandStructureTagOrCount)
100101 structureTokenExpanders.Add("STRUCTURE_TAG_PARTS", expandStructureTagParts)
101102 structureTokenExpanders.Add("STRUCTURE_TYPE", expandStructureType)
@@ -790,6 +791,88 @@ namespace CodeGen.Engine
790791 mreturn ExpandStructureToken(tkn, template, loops, doExpand)
791792 endmethod
792793
794+ private static method expandStructureTagExpression, string
795+ tkn, @Token
796+ template, @FileNode
797+ loops, @IEnumerable<LoopNode>
798+ endparams
799+ proc
800+ lambda doExpand(str)
801+ begin
802+ data expression = String.Empty
803+
804+ foreach data tag in str.Tags as @RpsTag
805+ begin
806+ ; Add the connector before the next part of the expression
807+ using tag.ComparisonConnector select
808+ (RpsTagComparison.None),
809+ nop
810+ (RpsTagComparison.CompareOr),
811+ expression = String.Format("{0}||",expression)
812+ (RpsTagComparison.CompareAnd),
813+ begin
814+ ;Whenever we encounter an AND connector, we need to wrap the previous expression in
815+ ;parentheses to ensure correct operator precedence, since OR has lower precedence than AND
816+ expression = String.Format("({0})&&",expression)
817+ end
818+ endusing
819+
820+ ;Figure out the comparison operator
821+ data tagOperator, string
822+ using tag.ComparisonOperator select
823+ (RpsTagOperator.OpLT),
824+ tagOperator = "<"
825+ (RpsTagOperator.OpGE),
826+ tagOperator = ">="
827+ (RpsTagOperator.OpLE),
828+ tagOperator = "<="
829+ (RpsTagOperator.OpNE),
830+ tagOperator = "!="
831+ (RpsTagOperator.OpEQ),
832+ tagOperator = "=="
833+ (RpsTagOperator.OpGT),
834+ tagOperator = ">"
835+ endusing
836+
837+ ;Figure out the comparison value
838+ data tagValue, string
839+ foreach data field in str.Fields as @RpsField
840+ begin
841+ if (field.OriginalName == tag.Field)
842+ begin
843+ using (field.DataType) select
844+ (RpsFieldDataType.Alpha, RpsFieldDataType.User),
845+ begin
846+ data tmplen, int, field.Size
847+ if (tmplen > 15)
848+ tmplen = 15
849+ if (tag.ComparisonValue.Length > 0) then
850+ begin
851+ data tmpval, a15, tag.ComparisonValue
852+ tagValue = String.Format("""{0}""", tmpval(1:tmplen))
853+ end
854+ else
855+ begin
856+ data spaces, a15, " " ;15 is the max length of a tag comparison in RPS
857+ tagValue = String.Format("""{0}""", spaces(1:tmplen))
858+ end
859+ end
860+ (),
861+ tagValue = tag.ComparisonValue
862+ endusing
863+ exitloop
864+ end
865+ end
866+
867+ ;Add the next part of the expression
868+ expression = String.Format("{0}sfld.{1}{2}{3}",expression,tag.Field,tagOperator,tagValue)
869+
870+ end
871+ mreturn expression
872+ end
873+ mreturn ExpandStructureToken(tkn, template, loops, doExpand)
874+ endmethod
875+
793876 private static method expandStructureTagOrCount, string
794877 tkn, @Token
795878 template, @FileNode
0 commit comments