void MakeTokenString(Token token, IndentingStringBuilder sb, Stack <string> endTags, Token previous) { string tagName = GetTagName(token); switch (token.Tokenkind) { case TokenType.StartScope: sb.Indent(); endTags.Push(GetTagName(previous)); break; case TokenType.EndScope: sb.DeIndent(); sb.AppendFormatLine("</{0}>", endTags.Pop()); break; case TokenType.StartEnumeration: sb.Indent(); sb.AppendFormatLine("<Enumeration>"); endTags.Push(GetTagName(previous)); break; case TokenType.EndEnumeration: sb.AppendFormatLine("</Enumeration>"); sb.DeIndent(); sb.AppendFormatLine("</{0}>", endTags.Pop()); break; case TokenType.SimpleFieldValue: sb.AppendFormatLine("<{0}>{1}</{0}>", tagName, token.Value); break; case TokenType.SeenBeforeWithReference: var seenBeforeReference = string.Format(" ref='{0}'", token.ReferenceNo.Number); sb.AppendFormatLine("<{0}{1} />", tagName, seenBeforeReference); break; case TokenType.FieldnameWithTypeAndReference: var optionReferenceInfo = token.ReferenceNo != null ? string.Format(" ref='{0}'", token.ReferenceNo.Number) : ""; var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType) .Replace('<', '(') .Replace('>', ')'); sb.AppendFormatLine("<{0} type='{1}'{2}>", tagName, fieldType, optionReferenceInfo); break; default: throw new ArgumentOutOfRangeException(); } }
void MakeTokenString(Token token, IndentingStringBuilder sb) { switch (token.Tokenkind) { case TokenType.StartScope: sb.AppendFormatLine("{{"); sb.Indent(); break; case TokenType.EndScope: sb.DeIndent(); sb.AppendFormatLine("}}"); break; case TokenType.StartEnumeration: case TokenType.EndEnumeration: break; case TokenType.SimpleFieldValue: sb.AppendFormatLine("{0}{1}", MakeFieldnameAssign(token), token.Value); break; case TokenType.SeenBeforeWithReference: var seenBeforeReference = " -> " + token.ReferenceNo.Number; sb.AppendFormatLine("{0}{1}", MakeFieldnameAssign(token), seenBeforeReference); break; case TokenType.FieldnameWithTypeAndReference: var optionReferenceInfo = token.ReferenceNo == null ? "" : string.Format(", ref: {0}", token.ReferenceNo.Number); var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType); sb.AppendFormatLine("{0}new {1}(){2}", MakeFieldnameAssign(token), fieldType, optionReferenceInfo); break; default: throw new ArgumentOutOfRangeException(); } }
int MakeTokenString(List <Token> tokens, int pos, IndentingStringBuilder sb, Stack <string> endTags, Token previous) { int skip = 0; Token token = tokens[pos]; string tagName = GetTagName(token); switch (token.Tokenkind) { case TokenType.StartScope: sb.Indent(); endTags.Push(GetTagName(previous)); break; case TokenType.EndScope: sb.DeIndent(); sb.AppendFormatLine("</{0}>", endTags.Pop()); break; case TokenType.StartEnumeration: if (pos + 1 < tokens.Count) { var nextToken = tokens[pos + 1]; if (nextToken.Tokenkind == TokenType.EndEnumeration) { sb.AppendFormatLine("<Enumeration></Enumeration>"); skip++; break; } if (nextToken.Tokenkind == TokenType.SimpleFieldValue && nextToken.Field.SimpleKeyInArrayOrDictionary != null) { tagName = GetTagName(nextToken); endTags.Push(tagName); sb.AppendFormatLine("<{0}>", tagName); sb.Indent(); sb.AppendFormatLine("<Enumeration>"); break; } } endTags.Push(previous == null ? null : GetTagName(previous)); sb.Indent(); sb.AppendFormatLine("<Enumeration>"); break; case TokenType.EndEnumeration: sb.AppendFormatLine("</Enumeration>"); sb.DeIndent(); var endtag = endTags.Pop(); if (endtag != null) { sb.AppendFormatLine("</{0}>", endtag); } break; case TokenType.SimpleFieldValue: if (token.Field.SimpleKeyInArrayOrDictionary != null) { sb.AppendFormatLine( "<key>{0}</key><value>{1}</value>", token.Field.SimpleKeyInArrayOrDictionary, token.Value); } else { sb.AppendFormatLine("<{0}>{1}</{0}>", tagName, token.Value); } break; case TokenType.SeenBeforeWithReference: var seenBeforeReference = string.Format(" ref='{0}'", token.ReferenceNo.Number); sb.AppendFormatLine("<{0}{1} />", tagName, seenBeforeReference); break; case TokenType.FieldnameWithTypeAndReference: var optionReferenceInfo = token.ReferenceNo != null ? string.Format(" ref='{0}'", token.ReferenceNo.Number) : ""; var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType) .Replace('<', '(') .Replace('>', ')'); sb.AppendFormatLine("<{0} type='{1}'{2}>", tagName, fieldType, optionReferenceInfo); break; default: throw new ArgumentOutOfRangeException(); } return(skip); }