private static void ValidateProfileContainerData(GenContainerFragmentBase container, GenDataDef genDataDef, string parentClassName, GenDataDef profileDataDef) { Assert.IsInstanceOf(typeof(ContainerFragment), container.Fragment, "Container must have a container fragment class"); var containerFragment = (ContainerFragment)container.Fragment; Assert.AreEqual(container.Body.Count, containerFragment.Body().FragmentList.Count, "Container body count"); Assert.AreEqual(container.Body.SecondaryCount, containerFragment.SecondaryBody().FragmentList.Count, "Container secondary body count"); var containerFragmentTypeName = containerFragment.GetType().Name; if (containerFragment.Primary != "Empty1") { Assert.AreEqual(containerFragment.Primary.Substring(0, containerFragmentTypeName.Length), containerFragmentTypeName); } if (container.Body.Count == 0) { Assert.AreEqual("Empty1", containerFragment.Primary, "Empty primary container name"); } if (container.Body.SecondaryCount == 0) { Assert.AreEqual("Empty1", containerFragment.Secondary, "Empty secondary container name"); } if (containerFragment.Secondary != "Empty1") { Assert.AreEqual(containerFragment.Secondary.Substring(0, containerFragmentTypeName.Length), containerFragmentTypeName); } Assert.AreEqual(container, container.Body.ParentContainer); ValidateProfileContainerPartData(container.Body.Fragment, containerFragment.Body().FragmentList, genDataDef, parentClassName, profileDataDef); ValidateProfileContainerPartData(container.Body.SecondaryFragment, containerFragment.SecondaryBody().FragmentList, genDataDef, parentClassName, profileDataDef); }
private static void ValidateProfileTextBlockData(ContainerFragment containerFragment, GenContainerFragmentBase genContainerFragment) { var textBlock = containerFragment as TextBlock; if (textBlock == null) { return; } var genTextBlock = (GenTextBlock)genContainerFragment; var s = ""; foreach (var fragment in textBlock.Body().FragmentList) { var text = fragment as Text; var placeholder = fragment as Placeholder; if (text != null) { s += text.TextValue; } else if (placeholder != null) { s += String.Format("`{0}.{1}`", placeholder.Class, placeholder.Property); } } Assert.AreEqual( genTextBlock.ProfileText(ProfileFragmentSyntaxDictionary.ActiveProfileFragmentSyntaxDictionary), s, "Text block profile text"); }
private void OutputText(GenContainerFragmentBase parentContainer, bool isPrimary, string text) { GenFragment frag = new GenBlock(new GenFragmentParams(GenDataDef, parentContainer)); ((GenBlock)frag).Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, text, isPrimary))); }
private void ScanPlaceholder(GenContainerFragmentBase parentContainer, ref GenTextBlock textBlock, bool isPrimary) { AddText(parentContainer, ref textBlock, GenDataDef.GetId(Scan.ScanName()), GenDataDef, isPrimary); if (Scan.CheckChar(Scan.Delimiter)) { Scan.SkipChar(); } }
private GenFragment ScanLookup(GenContainerFragmentBase parentContainer, bool isPrimary) { var s = Scan.ScanLookup(); var lookup = new GenLookup(new GenLookupParams(GenDataDef, parentContainer, s, isPrimary)); GenFragment frag = lookup; ScanBody(lookup.ClassId, lookup.Body, lookup, lookup.Lookup); return(frag); }
private void AddText(GenContainerFragmentBase parentContainer, ref GenTextBlock textBlock, GenDataId id, GenDataDef genDataDef, bool isPrimary) { if (id.ClassId == -1 || id.PropertyId == -1) { throw new GeneratorException(Scan.Buffer.ToString() + id, GenErrorType.ProfileError); } CheckTextBlock(parentContainer, ref textBlock, genDataDef, isPrimary); textBlock.Body.Add( new GenPlaceholderFragment(new GenPlaceholderFragmentParams(GenDataDef, textBlock, id))); }
private static void CheckTextBlock(GenDataDef genDataDef, ref GenTextBlock textBlock, GenContainerFragmentBase classProfile) { if (textBlock == null) { textBlock = new GenTextBlock(new GenFragmentParams(genDataDef, classProfile, FragmentType.TextBlock)); classProfile.Body.Add(textBlock); } }
private GenAnnotation ScanAnnotation(int classId, GenContainerFragmentBase parentContainer, bool isPrimary = true) { var frag = new GenAnnotation(new GenFragmentParams(GenDataDef, parentContainer, isPrimary)); if (Scan.CheckChar('-')) { Scan.SkipChar(); } ScanBody(classId, frag.Body, frag, frag.Annotation); return(frag); }
private GenFragment ScanSegment(GenContainerFragmentBase parentContainer, bool isPrimary) { var s = Scan.ScanSegmentClass(); var seg = ProfileFragmentSyntaxDictionary.ActiveProfileFragmentSyntaxDictionary.ParseSegmentHeading( GenDataDef, s, parentContainer, isPrimary); GenFragment frag = seg; ScanBody(seg.ClassId, seg.Body, seg, seg.Segment); return(frag); }
private GenFragment ScanFunction(GenContainerFragmentBase parentContainer, bool isPrimary) { var s = Scan.ScanFunctionName(); var func = new GenFunction(new GenFunctionParams(GenDataDef, parentContainer, s, FragmentType.Function, isPrimary)); GenFragment frag = func; ScanBlockParams(func.Body, func, func.Function, func.Function.Body()); return(frag); }
private GenFragment ScanCondition(int classId, GenContainerFragmentBase parentContainer, bool isPrimary) { var s = Scan.ScanCondition(); var c = ProfileFragmentSyntaxDictionary.ActiveProfileFragmentSyntaxDictionary.ParseCondition( GenDataDef, s); var cond = new GenCondition(new GenConditionParams(GenDataDef, parentContainer, c, isPrimary)); GenFragment frag = cond; ScanBody(classId, cond.Body, cond, cond.Condition); return(frag); }
private static void CheckTextBlock(GenContainerFragmentBase parentContainer, ref GenTextBlock textBlock, GenDataDef genDataDef, bool isPrimary) { if (textBlock == null) { textBlock = new GenTextBlock(new GenFragmentParams(genDataDef, parentContainer, FragmentType.TextBlock, isPrimary)); if (isPrimary) { parentContainer.Body.Add(textBlock); } else { parentContainer.Body.AddSecondary(textBlock); } } }
private static void SubClassProfiles(GenDataDef genDataDef, int classId, GenContainerFragmentBase profile, GenContainerFragmentBase parentContainer, GenSegment classProfile) { foreach (var subClass in genDataDef.GetClassSubClasses(classId)) { if (String.IsNullOrEmpty(subClass.SubClass.Reference)) { ClassProfile(genDataDef, subClass.SubClass.ClassId, classProfile ?? profile, parentContainer); } else { var refClass = new GenSegment(new GenSegmentParams(genDataDef, parentContainer, subClass.SubClass.Name, GenCardinality.Reference)); (classProfile ?? profile).Body.Add(refClass); } } }
private void ScanBody(int classId, GenSegBody body, GenContainerFragmentBase parentContainer, ContainerFragment containerFragment) { var saveClassId = GenDataDef.CurrentClassId; GenDataDef.CurrentClassId = classId; if (!Scan.Eof) { TokenType t; CompactPrimaryBodyParser.ScanPartialBody(classId, body, parentContainer, containerFragment, out t); if (t == TokenType.Secondary) { Scan.SkipChar(); CompactSecondaryBodyParser.ScanPartialBody(classId, body, parentContainer, containerFragment, out t); } if (t != TokenType.Close) { if (Scan.Eof && classId != 0) { //throw new Exception("<<<<Missing Segment end bracket>>>>"); OutputText(parentContainer, true, "<<<<Missing Segment end bracket>>>>"); } if (!Scan.Eof) { //throw new Exception("<<<<Unknown text in profile>>>>"); OutputText(parentContainer, true, "<<<<Unknown text in profile>>>>"); } } else { if (Scan.CheckChar(']')) { Scan.SkipChar(); } } } else if (classId != 0) { //throw new Exception("<<<<<Missing Segment end bracket>>>>>"); OutputText(parentContainer, true, "<<<<Unknown text in profile>>>>"); } GenDataDef.CurrentClassId = saveClassId; }
internal void ScanPartialBody(int classId, GenSegBody body, GenContainerFragmentBase parentContainer, ContainerFragment containerFragment, out TokenType t) { FragmentBody = IsPrimary ? containerFragment.Body() : containerFragment.SecondaryBody(); GenTextBlock textBlock = null; var s = Scan.ScanText(); if (Scan.Eof) { if (s.Length > 0) { GenCompactProfileParser.AddText(parentContainer, FragmentBody, ref textBlock, s, GenDataDef, IsPrimary); } t = TokenType.Unknown; return; } if (s.Length > 0) { GenCompactProfileParser.AddText(parentContainer, FragmentBody, ref textBlock, s, GenDataDef, IsPrimary); } t = Scan.ScanTokenType(); while (!Scan.Eof && t != TokenType.Close && t != TokenType.Secondary && t != TokenType.Unknown) { if (t != TokenType.Name && textBlock != null) { textBlock = null; } var frag = GenCompactProfileParser.ScanFragment(classId, ref t, out s, parentContainer, FragmentBody, ref textBlock, IsPrimary); if (t != TokenType.Name) { AddFragment(body, frag); } if (s.Length > 0) { GenCompactProfileParser.AddText(parentContainer, FragmentBody, ref textBlock, s, GenDataDef, IsPrimary); } t = Scan.ScanTokenType(); } }
private static void ValidateProfileSegmentData(GenDataDef genDataDef, ContainerFragment containerFragment, GenContainerFragmentBase genContainerFragment, ref string className) { var segment = containerFragment as Segment; if (segment == null) { return; } var genSegment = (GenSegment)genContainerFragment; className = segment.Class; Assert.AreEqual(genDataDef.GetClassName(genSegment.ClassId), className, "Segment class"); var cardinality = ((Segment)genSegment.Fragment).GenCardinality; Assert.AreEqual(cardinality.ToString(), segment.Cardinality); if (cardinality == GenCardinality.AllDlm || cardinality == GenCardinality.BackDlm) { Assert.AreNotEqual("Empty1", segment.Secondary); Assert.AreNotEqual(0, segment.SecondaryBody().FragmentList.Count); } }
internal GenFragment ScanFragment(int classId, ref TokenType nextToken, out string s, GenContainerFragmentBase parentContainer, FragmentBody fragmentBody, ref GenTextBlock textBlock, bool isPrimary) { Contract.Ensures(Contract.OldValue(nextToken) == TokenType.Name || Contract.Result <GenFragment>() != null); var oldToken = nextToken; GenFragment frag = null; s = ""; switch (oldToken) { case TokenType.Segment: frag = ScanSegment(parentContainer, isPrimary); break; case TokenType.Block: frag = ScanBlock(classId, parentContainer, isPrimary); break; case TokenType.Lookup: frag = ScanLookup(parentContainer, isPrimary); break; case TokenType.Condition: frag = ScanCondition(classId, parentContainer, isPrimary); break; case TokenType.Function: frag = ScanFunction(parentContainer, isPrimary); break; case TokenType.Name: ScanPlaceholder(parentContainer, ref textBlock, isPrimary); break; case TokenType.Annotation: frag = ScanAnnotation(classId, parentContainer, isPrimary); break; default: OutputText(parentContainer, isPrimary, "Unknown token type: " + nextToken); throw new GeneratorException("Unknown token type: " + nextToken + "; " + Scan.Buffer); } s = Scan.ScanText(); return(frag); }
private void ScanBlockParams(GenSegBody body, GenContainerFragmentBase parentContainer, Function function, FragmentBody fragmentBody) { Scan.ScanWhile(ScanReader.WhiteSpace); if (Scan.CheckChar(Scan.Delimiter)) { Scan.SkipChar(); } var t = Scan.ScanTokenType(); while (t != TokenType.Close) { string s; if (t != TokenType.Unknown && t != TokenType.Name) { // Parameter starts with a delimiter if (t != TokenType.Close && t != TokenType.Unknown) { // Scan contained block GenTextBlock textBlock = null; var frag = ScanFragment(GenDataDef.CurrentClassId, ref t, out s, parentContainer, fragmentBody, ref textBlock, true); body.Add(frag ?? textBlock); // Skip blank parameter separators s = s.TrimStart(); if (s != "") { body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, s))); } t = Scan.ScanTokenType(); } } else { // Parameter starts without a delimiter var block = new GenBlock(new GenFragmentParams(GenDataDef, parentContainer)); s = Scan.CheckChar('\'') ? Scan.ScanQuotedString() : Scan.ScanUntil(_parameterSeparator); while (Scan.CheckChar(' ')) { Scan.SkipChar(); } // Scan for Text and Placeholders var i = s.IndexOf(Scan.Delimiter); while (i != -1) { var w = s.Substring(0, i - 1); // Text up to first delimiter s = s.Substring(i + 1); // Text after first delimeter if (s != "") { // Some text after the first delimiter i = s.IndexOf(Scan.Delimiter); // Position of next delimiter if (i != -1) { if (w != "") { // Add Text up to first delimiter block.Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, w))); } w = s.Substring(0, i - 1); // Text between initial two delimiters block.Body.Add( new GenPlaceholderFragment(new GenPlaceholderFragmentParams(GenDataDef, parentContainer, GenDataDef.GetId(w)))); s = s.Substring(i + 1); i = s.IndexOf(Scan.Delimiter); } else { // No matching delimiter: output delimiter with text block.Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, w + Scan.Delimiter + s))); s = ""; } } else { // No text after initial delimiter: output delimiter with text block.Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, w + Scan.Delimiter))); i = -1; } } if (s != "" || block.Body.Count == 0) { // Text without placeholders block.Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, block, s))); } body.Add(block); if (Scan.CheckChar(Scan.Delimiter)) { Scan.SkipChar(); } t = Scan.ScanTokenType(); } } if (t == TokenType.Close) { Scan.SkipChar(); } }
internal static void AddText(GenContainerFragmentBase parentContainer, FragmentBody fragmentBody, ref GenTextBlock textBlock, string s, GenDataDef genDataDef, bool isPrimary) { CheckTextBlock(parentContainer, ref textBlock, genDataDef, isPrimary); textBlock.Body.Add( new GenTextFragment(new GenTextFragmentParams(genDataDef, textBlock, s))); }
private static void AddText(GenDataDef genDataDef, ref GenTextBlock textBlock, GenContainerFragmentBase classProfile, string s) { CheckTextBlock(genDataDef, ref textBlock, classProfile); textBlock.Body.Add(new GenTextFragment(new GenTextFragmentParams(genDataDef, textBlock, s))); }
private static void AddText(GenDataDef genDataDef, ref GenTextBlock textBlock, GenContainerFragmentBase classProfile, GenDataId id) { CheckTextBlock(genDataDef, ref textBlock, classProfile); textBlock.Body.Add(new GenPlaceholderFragment(new GenPlaceholderFragmentParams(genDataDef, textBlock, id))); }
private static void AddText(GenDataDef genDataDef, ref GenTextBlock textBlock, GenContainerFragmentBase classProfile, StringBuilder sb) { AddText(genDataDef, ref textBlock, classProfile, sb.ToString()); sb.Clear(); }
private static void ClassProfile(GenDataDef genDataDef, int classId, GenContainerFragmentBase profile, GenContainerFragmentBase parentContainer) { GenSegment classProfile = null; if (classId != 0) { GenTextBlock textBlock = null; var sb = new StringBuilder(); classProfile = new GenSegment( new GenSegmentParams(genDataDef, parentContainer, genDataDef.GetClassName(classId), genDataDef.GetClassIsInherited(classId) ? GenCardinality.Inheritance : GenCardinality.All)); if (!genDataDef.GetClassIsAbstract(classId)) { sb.Append(genDataDef.GetClassName(classId)); } if (genDataDef.GetClassProperties(classId).Count > 0 && !genDataDef.GetClassDef(classId).IsAbstract) { var j = 0; if ( String.Compare(genDataDef.GetClassProperties(classId)[0], "Name", StringComparison.OrdinalIgnoreCase) == 0) { sb.Append("="); AddText(genDataDef, ref textBlock, classProfile, sb); AddText(genDataDef, ref textBlock, classProfile, genDataDef.GetId(genDataDef.GetClassName(classId), "Name")); j = 1; } else { AddText(genDataDef, ref textBlock, classProfile, sb); } if (genDataDef.GetClassProperties(classId).Count > j) { AddText(genDataDef, ref textBlock, classProfile, "["); textBlock = null; var sep = ""; for (var i = j; i < genDataDef.GetClassProperties(classId).Count; i++) { var condExists = new GenCondition(new GenConditionParams(genDataDef, classProfile, new ConditionParameters { GenComparison = GenComparison.Exists, Var1 = genDataDef.GetId(genDataDef.GetClassName(classId), genDataDef.GetClassProperties(classId)[i]) })); condExists.Body.Add( new GenTextFragment(new GenTextFragmentParams(genDataDef, condExists, sep + genDataDef.GetClassProperties(classId)[i]))); var condNotTrue = new GenCondition(new GenConditionParams(genDataDef, condExists, new ConditionParameters { GenComparison = GenComparison.Ne, Var1 = genDataDef.GetId(genDataDef.GetClassName(classId), genDataDef.GetClassProperties(classId)[i]), Lit = "True", UseLit = true })); condNotTrue.Body.Add( new GenTextFragment(new GenTextFragmentParams(genDataDef, condNotTrue, "="))); var functionQuote = new GenFunction(new GenFunctionParams(genDataDef, condNotTrue, "StringOrName")); var param = new GenBlock(new GenFragmentParams(genDataDef, functionQuote)); param.Body.Add( new GenPlaceholderFragment(new GenPlaceholderFragmentParams(genDataDef, param, genDataDef.GetId(genDataDef.GetClassName(classId), genDataDef.GetClassProperties(classId)[i])))); functionQuote.Body.Add(param); condNotTrue.Body.Add(functionQuote); condExists.Body.Add(condNotTrue); classProfile.Body.Add(condExists); sep = ","; } AddText(genDataDef, ref textBlock, classProfile, "]\r\n"); } else { AddText(genDataDef, ref textBlock, classProfile, "\r\n"); } } profile.Body.Add(classProfile); } foreach (var inheritor in genDataDef.GetClassInheritors(classId)) { ClassProfile(genDataDef, inheritor.ClassId, classProfile ?? profile, classProfile); } if (!genDataDef.GetClassIsAbstract(classId)) { SubClassProfiles(genDataDef, classId, profile, classProfile ?? profile, classProfile); } if (genDataDef.GetClassIsInherited(classId)) { SubClassProfiles(genDataDef, genDataDef.GetClassParent(classId).ClassId, profile, classProfile ?? profile, classProfile); } }