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 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 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(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); } } }
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 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); } }
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 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 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); }