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(); } }
protected override void AddFragment(GenSegBody body, GenFragment frag) { Contract.Assert(!body.Fragment.Contains(frag), "Fragment added to body again"); body.Add(frag); }
protected abstract void AddFragment(GenSegBody body, GenFragment 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(); } }