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(); } }
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(); } }
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, 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(); } }
int MakeStringFromToken(List<Token> tokens, int pos, Dictionary<Reference, string> referencePaths, IndentingStringBuilder sb) { var token = tokens[pos]; int skip = 0; string fieldnameColon = null; switch (token.Tokenkind) { case TokenType.StartScope: sb.AppendFormatLine("{{"); sb.Indent(); break; case TokenType.EndScope: sb.DeIndent(); sb.AppendFormatLine("}}"); break; case TokenType.StartEnumeration: sb.AppendFormatLine("["); sb.Indent(); break; case TokenType.EndEnumeration: sb.DeIndent(); sb.AppendFormatLine("]{0}", OptionalComma(tokens, pos)); break; case TokenType.SimpleFieldValue: { // fieldname is empty if the ROOT-element-name has not been supplied fieldnameColon = GetEmptyOrFieldname(token, "\"{0}\" : "); var optinalComma = OptionalComma(tokens, pos); sb.AppendFormatLine("{0}{1}{2}", fieldnameColon, token.Value, optinalComma); break; } case TokenType.SeenBeforeWithReference: { // fieldname is empty if the ROOT-element-name has not been supplied fieldnameColon = GetEmptyOrFieldname(token, "\"{0}\" : "); var seenBeforeReference = " " + referencePaths[token.ReferenceNo]; sb.AppendFormatLine("{0}{1}{2}", fieldnameColon, seenBeforeReference, OptionalComma(tokens, pos)); break; } case TokenType.FieldnameWithTypeAndReference: // if we are part of an idex, do not print the field name as it has alreadty been printed if (token.Field.SimpleKeyInArrayOrDictionary == null) { // fieldname is empty if the ROOT-element-name has not been supplied fieldnameColon = GetEmptyOrFieldname(token, "\"{0}\" :"); // inline-print empty collections string optionalValue = ""; bool isNextEmptyEnumeration = pos + 2 < tokens.Count // TODO optimize by introducing a variable holding "count-2" && tokens[pos + 1].Tokenkind == TokenType.StartEnumeration && tokens[pos + 2].Tokenkind == TokenType.EndEnumeration; if (isNextEmptyEnumeration) { skip += 2; optionalValue = (fieldnameColon == "" ? "" : " ") + "[]"; } sb.AppendFormatLine("{0}{1}{2}", fieldnameColon, optionalValue, OptionalComma(tokens, pos+skip)); } break; default: throw new ArgumentOutOfRangeException(); } return skip; }
int MakeStringFromToken(List <Token> tokens, int pos, Dictionary <Reference, string> referencePaths, IndentingStringBuilder sb) { var token = tokens[pos]; int skip = 0; string fieldnameColon = null; switch (token.Tokenkind) { case TokenType.StartScope: sb.AppendFormatLine("{{"); sb.Indent(); break; case TokenType.EndScope: sb.DeIndent(); sb.AppendFormatLine("}}"); break; case TokenType.StartEnumeration: { fieldnameColon = ""; if (pos + 1 < tokens.Count) { var nextToken = tokens[pos + 1]; if (nextToken.Tokenkind == TokenType.EndEnumeration) { sb.AppendFormatLine("[]"); skip++; break; } if (nextToken.Tokenkind == TokenType.SimpleFieldValue && nextToken.Field.SimpleKeyInArrayOrDictionary != null && nextToken.Field.Name != null) { fieldnameColon = string.Format("\"{0}\" : ", nextToken.Field.Name); } } sb.AppendFormatLine("{0}[", fieldnameColon); sb.Indent(); } break; case TokenType.EndEnumeration: sb.DeIndent(); sb.AppendFormatLine("]{0}", OptionalComma(tokens, pos)); break; case TokenType.SimpleFieldValue: { if (token.Field.SimpleKeyInArrayOrDictionary == null) { // fieldname is empty if the ROOT-element-name has not been supplied fieldnameColon = GetEmptyOrFieldname(token, "\"{0}\" : "); var optinalComma = OptionalComma(tokens, pos); sb.AppendFormatLine("{0}{1}{2}", fieldnameColon, token.Value, optinalComma); } else { fieldnameColon = ""; var keyval = string.Format("{{ {0} : {1} }}", token.Field.SimpleKeyInArrayOrDictionary, token.Value); sb.AppendFormatLine("{0}{1}{2}", fieldnameColon, keyval, OptionalComma(tokens, pos + skip)); } break; } case TokenType.SeenBeforeWithReference: { // fieldname is empty if the ROOT-element-name has not been supplied fieldnameColon = GetEmptyOrFieldname(token, "\"{0}\" : "); var seenBeforeReference = " " + referencePaths[token.ReferenceNo]; sb.AppendFormatLine("{0}{1}{2}", fieldnameColon, seenBeforeReference, OptionalComma(tokens, pos)); break; } case TokenType.FieldnameWithTypeAndReference: // if we are part of an idex, do not print the field name as it has alreadty been printed if (token.Field.SimpleKeyInArrayOrDictionary == null) { // fieldname is empty if the ROOT-element-name has not been supplied fieldnameColon = GetEmptyOrFieldname(token, "\"{0}\" :"); // inline-print empty collections string optionalValue = ""; bool isNextEmptyEnumeration = pos + 2 < tokens.Count && // TODO optimize by introducing a variable holding "count-2" tokens[pos + 1].Tokenkind == TokenType.StartEnumeration && tokens[pos + 2].Tokenkind == TokenType.EndEnumeration; if (isNextEmptyEnumeration) { skip += 2; optionalValue = (fieldnameColon == "" ? "" : " ") + "[]"; } sb.AppendFormatLine("{0}{1}{2}", fieldnameColon, optionalValue, OptionalComma(tokens, pos + skip)); } break; default: throw new ArgumentOutOfRangeException(); } return(skip); }
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; }
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); }