public IEnumerable <String> Enum(EnumDef e) { var Name = GetEscapedIdentifier(e.DefinitionName()); var ParserName = GetEscapedIdentifier(GetSuffixedTypeName(e.Name, e.Version, "Parser", e.NamespaceName())); var WriterName = GetEscapedIdentifier(GetSuffixedTypeName(e.Name, e.Version, "Writer", e.NamespaceName())); foreach (var _Line in Combine(Begin(), GetXmlComment(e.Description))) { yield return(_Line); } foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), "public enum "), Name), " : "), GetEnumTypeString(e.UnderlyingType, e.NamespaceName()))) { yield return(_Line); } yield return("{"); var k = 0; foreach (var l in e.Literals) { if (k == e.Literals.Count - 1) { foreach (var _Line in Combine(Begin(), GetXmlComment(l.Description))) { yield return(_Line == "" ? "" : " " + _Line); } foreach (var _Line in Combine(Combine(Combine(Begin(), GetEscapedIdentifier(l.Name)), " = "), l.Value)) { yield return(_Line == "" ? "" : " " + _Line); } } else { foreach (var _Line in Combine(Begin(), GetXmlComment(l.Description))) { yield return(_Line == "" ? "" : " " + _Line); } foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), GetEscapedIdentifier(l.Name)), " = "), l.Value), ",")) { yield return(_Line == "" ? "" : " " + _Line); } } k += 1; } yield return("}"); foreach (var _Line in Combine(Begin(), GetXmlComment(e.Description))) { yield return(_Line); } foreach (var _Line in Combine(Combine(Begin(), "public static class "), ParserName)) { yield return(_Line); } yield return("{"); foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), " private static Dictionary<String, "), Name), "> d = new Dictionary<String, "), Name), ">();")) { yield return(_Line); } foreach (var _Line in Combine(Combine(Combine(Begin(), " static "), ParserName), "()")) { yield return(_Line); } yield return(" {"); var LiteralDict = e.Literals.ToDictionary(l => l.Name); var LiteralNameAdds = e.Literals.Select(l => new { Name = l.Name, NameOrDescription = l.Name }); var LiteralDescriptionAdds = e.Literals.GroupBy(l => l.Description).Where(l => l.Count() == 1).Select(l => l.Single()).Where(l => !LiteralDict.ContainsKey(l.Description)).Select(l => new { Name = l.Name, NameOrDescription = l.Description }); foreach (var l in LiteralNameAdds.Concat(LiteralDescriptionAdds)) { foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "d.Add("), GetEscapedStringLiteral(l.NameOrDescription)), ", "), Name), "."), GetEscapedIdentifier(l.Name)), ");")) { yield return(_Line == "" ? "" : " " + _Line); } } yield return(" }"); foreach (var _Line in Combine(Combine(Combine(Begin(), " public static "), Name), "? TryParse(String Value)")) { yield return(_Line); } yield return(" {"); yield return(" if (d.ContainsKey(Value)) { return d[Value]; }"); yield return(" return null;"); yield return(" }"); yield return("}"); foreach (var _Line in Combine(Begin(), GetXmlComment(e.Description))) { yield return(_Line); } foreach (var _Line in Combine(Combine(Begin(), "public static class "), WriterName)) { yield return(_Line); } yield return("{"); foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), " private static Dictionary<"), Name), ", String> d = new Dictionary<"), Name), ", String>();")) { yield return(_Line); } foreach (var _Line in Combine(Combine(Combine(Begin(), " static "), WriterName), "()")) { yield return(_Line); } yield return(" {"); foreach (var l in e.Literals) { foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "if (!d.ContainsKey("), Name), "."), GetEscapedIdentifier(l.Name)), ")) { d.Add("), Name), "."), GetEscapedIdentifier(l.Name)), ", "), GetEscapedStringLiteral(l.Description)), "); }")) { yield return(_Line == "" ? "" : " " + _Line); } } yield return(" }"); foreach (var _Line in Combine(Combine(Combine(Begin(), " public static String GetDescription("), Name), " Value)")) { yield return(_Line); } yield return(" {"); yield return(" return d[Value];"); yield return(" }"); yield return("}"); }
public IEnumerable <String> EnumFunctor(EnumDef e) { var TypeString = GetTypeString(e.GetTypeSpec(), "std"); yield return("template <>"); foreach (var _Line in Combine(Combine(Combine(Begin(), "struct hash<"), TypeString), ">")) { yield return(_Line); } yield return("{"); foreach (var _Line in Combine(Combine(Combine(Begin(), " size_t operator()(const "), TypeString), " &x) const")) { yield return(_Line); } yield return(" {"); foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), " return hash<"), GetTypeString(e.UnderlyingType, e.NamespaceName())), ">()(static_cast<"), GetTypeString(e.UnderlyingType, e.NamespaceName())), ">(x));")) { yield return(_Line); } yield return(" }"); yield return("};"); yield return("template <>"); foreach (var _Line in Combine(Combine(Combine(Begin(), "struct less<"), TypeString), ">")) { yield return(_Line); } yield return("{"); foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), " bool operator()(const "), TypeString), " &x, const "), TypeString), " &y) const")) { yield return(_Line); } yield return(" {"); foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), " return less<"), GetTypeString(e.UnderlyingType, "std")), ">()(static_cast<"), GetTypeString(e.UnderlyingType, "std")), ">(x), static_cast<"), GetTypeString(e.UnderlyingType, "std")), ">(y));")) { yield return(_Line); } yield return(" }"); yield return("};"); }
public IEnumerable <String> Enum(EnumDef e) { var Name = GetEscapedIdentifier(e.DefinitionName()); foreach (var _Line in Combine(Begin(), GetXmlComment(e.Description))) { yield return(_Line); } foreach (var _Line in Combine(Combine(Begin(), "public final class "), Name)) { yield return(_Line); } yield return("{"); var k = 0; foreach (var l in e.Literals) { foreach (var _Line in Combine(Begin(), GetXmlComment(l.Description))) { yield return(_Line == "" ? "" : " " + _Line); } foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "public static final "), GetTypeString(e.UnderlyingType, e.NamespaceName())), " "), GetEscapedIdentifier(l.Name)), " = "), l.Value), ";")) { yield return(_Line == "" ? "" : " " + _Line); } k += 1; } yield return("}"); }
public IEnumerable <String> Enum(EnumDef e) { var Name = GetEscapedIdentifier(e.DefinitionName()); var ParserName = GetEscapedIdentifier(GetSuffixedTypeName(e.Name, e.Version, "Parser", e.NamespaceName())); var WriterName = GetEscapedIdentifier(GetSuffixedTypeName(e.Name, e.Version, "Writer", e.NamespaceName())); foreach (var _Line in Combine(Begin(), GetXmlComment(e.Description))) { yield return(_Line); } foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), "Public Enum "), Name), " As "), GetEnumTypeString(e.UnderlyingType, e.NamespaceName()))) { yield return(_Line); } var k = 0; foreach (var l in e.Literals) { foreach (var _Line in Combine(Begin(), GetXmlComment(l.Description))) { yield return(_Line == "" ? "" : " " + _Line); } foreach (var _Line in Combine(Combine(Combine(Begin(), GetEscapedIdentifier(l.Name)), " = "), l.Value)) { yield return(_Line == "" ? "" : " " + _Line); } k += 1; } yield return("End Enum"); foreach (var _Line in Combine(Begin(), GetXmlComment(e.Description))) { yield return(_Line); } foreach (var _Line in Combine(Combine(Begin(), "Public NotInheritable Class "), ParserName)) { yield return(_Line); } foreach (var _Line in Combine(Combine(Combine(Begin(), " Private Shared d As New Dictionary(Of String, "), Name), ")")) { yield return(_Line); } foreach (var _Line in Combine(Combine(Combine(Begin(), " Shared Sub "), ParserName), "()")) { yield return(_Line); } var LiteralDict = e.Literals.ToDictionary(l => l.Name); var LiteralNameAdds = e.Literals.Select(l => new { Name = l.Name, NameOrDescription = l.Name }); var LiteralDescriptionAdds = e.Literals.GroupBy(l => l.Description).Where(l => l.Count() == 1).Select(l => l.Single()).Where(l => !LiteralDict.ContainsKey(l.Description)).Select(l => new { Name = l.Name, NameOrDescription = l.Description }); foreach (var l in LiteralNameAdds.Concat(LiteralDescriptionAdds)) { foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "d.Add("), GetEscapedStringLiteral(l.NameOrDescription)), ", "), Name), "."), GetEscapedIdentifier(l.Name)), ")")) { yield return(_Line == "" ? "" : " " + _Line); } } yield return(" End Sub"); foreach (var _Line in Combine(Combine(Combine(Begin(), " Public Shared Function TryParse(ByVal Value As String) As "), Name), "?")) { yield return(_Line); } yield return(" If d.ContainsKey(Value) Then Return d(Value)"); yield return(" Return Nothing"); yield return(" End Function"); yield return("End Class"); foreach (var _Line in Combine(Begin(), GetXmlComment(e.Description))) { yield return(_Line); } foreach (var _Line in Combine(Combine(Begin(), "Public NotInheritable Class "), WriterName)) { yield return(_Line); } foreach (var _Line in Combine(Combine(Combine(Begin(), " Private Shared d As New Dictionary(Of "), Name), ", String)")) { yield return(_Line); } foreach (var _Line in Combine(Combine(Combine(Begin(), " Shared Sub "), WriterName), "()")) { yield return(_Line); } foreach (var l in e.Literals) { foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "If Not d.ContainsKey("), Name), "."), GetEscapedIdentifier(l.Name)), ")) Then d.Add("), Name), "."), GetEscapedIdentifier(l.Name)), ", "), GetEscapedStringLiteral(l.Description)), ")")) { yield return(_Line == "" ? "" : " " + _Line); } } yield return(" End Sub"); foreach (var _Line in Combine(Combine(Combine(Begin(), " Public Shared Function GetDescription(ByVal Value As "), Name), ") As String")) { yield return(_Line); } yield return(" Return d(Value)"); yield return(" End Function"); yield return("End Class"); }