コード例 #1
0
ファイル: Java.cs プロジェクト: blockspacer/niveum
        public IEnumerable <String> TaggedUnion(TaggedUnionDef tu)
        {
            var TagTypeString = GetSuffixedTypeString(tu.Name, tu.Version, "Tag", tu.NamespaceName());

            foreach (var _Line in Combine(Begin(), TaggedUnion(tu, TagTypeString)))
            {
                yield return(_Line);
            }
        }
コード例 #2
0
        public IEnumerable <String> TaggedUnion(TaggedUnionDef tu)
        {
            var Name    = GetEscapedIdentifier(tu.DefinitionName()) + GetGenericParameters(tu.GenericParameters);
            var TagName = GetEscapedIdentifier(GetSuffixedTypeName(tu.Name, tu.Version, "Tag", tu.NamespaceName()));

            foreach (var _Line in Combine(Combine(Begin(), "public enum "), TagName))
            {
                yield return(_Line);
            }
            yield return("{");

            var k = 0;

            foreach (var a in tu.Alternatives)
            {
                if (k == tu.Alternatives.Count - 1)
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Begin(), GetEscapedIdentifier(a.Name)), " = "), k))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
                else
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), GetEscapedIdentifier(a.Name)), " = "), k), ","))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
                k += 1;
            }
            yield return("}");

            foreach (var _Line in Combine(Begin(), GetXmlComment(tu.Description)))
            {
                yield return(_Line);
            }
            yield return("[TaggedUnion]");

            foreach (var _Line in Combine(Combine(Begin(), "public sealed class "), Name))
            {
                yield return(_Line);
            }
            yield return("{");

            foreach (var _Line in Combine(Combine(Combine(Begin(), "    [Tag] public "), TagName), " _Tag;"))
            {
                yield return(_Line);
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "public "), GetTypeString(a.Type, tu.NamespaceName())), " "), GetEscapedIdentifier(a.Name)), ";"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                if (a.Type.OnTypeRef && a.Type.TypeRef.NameMatches("Unit"))
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "public static "), Name), " "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "() { return new "), Name), " { _Tag = "), TagName), "."), GetEscapedIdentifier(a.Name)), ", "), GetEscapedIdentifier(a.Name)), " = default(Unit) }; }"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
                else
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "public static "), Name), " "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "("), GetTypeString(a.Type, tu.NamespaceName())), " Value) { return new "), Name), " { _Tag = "), TagName), "."), GetEscapedIdentifier(a.Name)), ", "), GetEscapedIdentifier(a.Name)), " = Value }; }"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "public Boolean "), GetEscapedIdentifier(Combine(Combine(Begin(), "On"), a.Name))), " { get { return _Tag == "), TagName), "."), GetEscapedIdentifier(a.Name)), "; } }"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("}");
        }
コード例 #3
0
ファイル: Java.cs プロジェクト: blockspacer/niveum
        public IEnumerable <String> TaggedUnion(TaggedUnionDef tu, String TagTypeString)
        {
            var Name = GetEscapedIdentifier(tu.DefinitionName()) + GetGenericParameters(tu.GenericParameters);

            foreach (var _Line in Combine(Begin(), GetXmlComment(tu.Description)))
            {
                yield return(_Line);
            }
            yield return("@TaggedUnion");

            foreach (var _Line in Combine(Combine(Begin(), "public final class "), Name))
            {
                yield return(_Line);
            }
            yield return("{");

            yield return("    @Tag public int _Tag;");

            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description, a.Type)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "public "), GetTypeString(a.Type, tu.NamespaceName())), " "), GetEscapedIdentifier(a.Name)), ";"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                if (a.Type.OnTypeRef && a.Type.TypeRef.NameMatches("Unit"))
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "public static "), Name), " "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "()"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "{");

                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    "), Name), " r = new "), Name), "();"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    r._Tag = "), TagTypeString), "."), GetEscapedIdentifier(a.Name)), ";"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Begin(), "    r."), GetEscapedIdentifier(a.Name)), " = Unit.Value;"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "    return r;");

                    yield return("    " + "}");
                }
                else
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "public static "), Name), " "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "("), GetTypeString(a.Type, tu.NamespaceName())), " Value)"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "{");

                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    "), Name), " r = new "), Name), "();"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    r._Tag = "), TagTypeString), "."), GetEscapedIdentifier(a.Name)), ";"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Begin(), "    r."), GetEscapedIdentifier(a.Name)), " = Value;"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "    return r;");

                    yield return("    " + "}");
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "public boolean "), GetEscapedIdentifier(Combine(Combine(Begin(), "On"), a.Name))), "() { return _Tag == "), TagTypeString), "."), GetEscapedIdentifier(a.Name)), "; }"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("}");
        }
コード例 #4
0
ファイル: Java.cs プロジェクト: blockspacer/niveum
        public IEnumerable <String> TaggedUnionTag(TaggedUnionDef tu)
        {
            var TagName = GetEscapedIdentifier(GetSuffixedTypeName(tu.Name, tu.Version, "Tag", tu.NamespaceName()));

            foreach (var _Line in Combine(Combine(Begin(), "public final class "), TagName))
            {
                yield return(_Line);
            }
            yield return("{");

            var k = 0;

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "public static final int "), GetEscapedIdentifier(a.Name)), " = "), k), ";"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                k += 1;
            }
            yield return("}");
        }
コード例 #5
0
ファイル: Python.cs プロジェクト: blockspacer/niveum
        public IEnumerable <String> TaggedUnion(TaggedUnionDef tu)
        {
            var Name    = GetEscapedIdentifier(tu.DefinitionName()) + GetGenericParameters(tu.GenericParameters);
            var TagName = GetEscapedIdentifier(GetSuffixedTypeName(tu.Name, tu.Version, "Tag", tu.NamespaceName()));

            foreach (var _Line in Combine(Combine(Combine(Begin(), "class "), TagName), "(IntEnum):"))
            {
                yield return(_Line);
            }
            var k = 0;

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Begin(), GetEscapedIdentifier(a.Name)), " = "), k))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                k += 1;
            }
            if (tu.Alternatives.Count == 0)
            {
                yield return("    " + "pass");
            }
            yield return("#TaggedUnion");

            foreach (var _Line in Combine(Combine(Combine(Begin(), "class "), Name), "(NamedTuple):"))
            {
                yield return(_Line);
            }
            foreach (var _Line in Combine(Combine(Begin(), "    "), GetXmlComment(tu.Description)))
            {
                yield return(_Line);
            }
            yield return("");

            foreach (var _Line in Combine(Combine(Begin(), "    Tag_: "), TagName))
            {
                yield return(_Line);
            }
            yield return("    Value_: Any");

            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "def "), GetEscapedIdentifier(a.Name)), "(self) -> "), GetTypeString(a.Type, tu.NamespaceName())), ":"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Begin(), "    "), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    if self.Tag_ != "), TagName), "."), GetEscapedIdentifier(a.Name)), ":"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "        raise TypeError('TagMismatch')");

                yield return("    " + "    return self.Value_");
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                if (a.Type.OnTypeRef && a.Type.TypeRef.NameMatches("Unit"))
                {
                    yield return("    " + "@staticmethod");

                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "def "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "() -> '"), Name), "':"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Begin(), "    "), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "    return "), Name), "("), TagName), "."), GetEscapedIdentifier(a.Name)), ", None)"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
                else
                {
                    yield return("    " + "@staticmethod");

                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "def "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "(Value: "), GetTypeString(a.Type, tu.NamespaceName())), ") -> '"), Name), "':"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Begin(), "    "), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "    return "), Name), "("), TagName), "."), GetEscapedIdentifier(a.Name)), ", Value)"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Combine(Combine(Begin(), "def "), GetEscapedIdentifier(Combine(Combine(Begin(), "On"), a.Name))), "(self) -> bool:"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Begin(), "    "), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), "    return self.Tag_ == "), TagName), "."), GetEscapedIdentifier(a.Name)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
        }
コード例 #6
0
        public IEnumerable <String> TaggedUnion(TaggedUnionDef tu)
        {
            var Name    = GetEscapedIdentifier(tu.DefinitionName());
            var TagName = GetEscapedIdentifier(GetSuffixedTypeName(tu.Name, tu.Version, "Tag", tu.NamespaceName()));

            foreach (var _Line in Combine(Combine(Begin(), "enum class "), TagName))
            {
                yield return(_Line);
            }
            yield return("{");

            var k = 0;

            foreach (var a in tu.Alternatives)
            {
                if (k == tu.Alternatives.Count - 1)
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Begin(), GetEscapedIdentifier(a.Name)), " = "), k))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
                else
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), GetEscapedIdentifier(a.Name)), " = "), k), ","))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
                k += 1;
            }
            yield return("};");

            foreach (var _Line in Combine(Begin(), GetXmlComment(tu.Description)))
            {
                yield return(_Line);
            }
            yield return("/* TaggedUnion */");

            foreach (var _Line in Combine(Begin(), GetGenericParameterLine(tu.GenericParameters)))
            {
                yield return(_Line);
            }
            foreach (var _Line in Combine(Combine(Combine(Begin(), "class "), Name), " final"))
            {
                yield return(_Line);
            }
            yield return("{");

            yield return("public:");

            foreach (var _Line in Combine(Combine(Combine(Begin(), "    /* Tag */ "), TagName), " _Tag;"))
            {
                yield return(_Line);
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), GetTypeString(a.Type, tu.NamespaceName())), " "), GetEscapedIdentifier(a.Name)), ";"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                if (a.Type.OnTypeRef && a.Type.TypeRef.NameMatches("Unit"))
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "static std::shared_ptr<class "), Name), "> "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "()"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "{");

                    foreach (var _Line in Combine(Combine(Combine(Begin(), "    auto r = std::make_shared<"), Name), ">();"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    r->_Tag = "), TagName), "::"), GetEscapedIdentifier(a.Name)), ";"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Begin(), "    r->"), GetEscapedIdentifier(a.Name)), " = Unit();"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "    return r;");

                    yield return("    " + "}");
                }
                else
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "static std::shared_ptr<class "), Name), "> "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "("), GetTypeString(a.Type, tu.NamespaceName())), " Value)"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "{");

                    foreach (var _Line in Combine(Combine(Combine(Begin(), "    auto r = std::make_shared<"), Name), ">();"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    r->_Tag = "), TagName), "::"), GetEscapedIdentifier(a.Name)), ";"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Begin(), "    r->"), GetEscapedIdentifier(a.Name)), " = Value;"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "    return r;");

                    yield return("    " + "}");
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Begin(), "Boolean "), GetEscapedIdentifier(Combine(Combine(Begin(), "On"), a.Name))), "() const"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "{");

                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    return _Tag == "), TagName), "::"), GetEscapedIdentifier(a.Name)), ";"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "}");
            }
            yield return("};");
        }
コード例 #7
0
        public IEnumerable <String> TaggedUnion(TaggedUnionDef tu)
        {
            var Name    = GetEscapedIdentifier(tu.DefinitionName()) + GetGenericParameters(tu.GenericParameters);
            var TagName = GetEscapedIdentifier(GetSuffixedTypeName(tu.Name, tu.Version, "Tag", tu.NamespaceName()));

            foreach (var _Line in Combine(Combine(Begin(), "Public Enum "), TagName))
            {
                yield return(_Line);
            }
            var k = 0;

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Begin(), GetEscapedIdentifier(a.Name)), " = "), k))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                k += 1;
            }
            yield return("End Enum");

            foreach (var _Line in Combine(Begin(), GetXmlComment(tu.Description)))
            {
                yield return(_Line);
            }
            yield return("<TaggedUnion()>");

            foreach (var _Line in Combine(Combine(Begin(), "Public NotInheritable Class "), Name))
            {
                yield return(_Line);
            }
            foreach (var _Line in Combine(Combine(Begin(), "    <Tag()> Public _Tag As "), TagName))
            {
                yield return(_Line);
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), "Public "), GetEscapedIdentifier(a.Name)), " As "), GetTypeString(a.Type, tu.NamespaceName())))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                if (a.Type.OnTypeRef && a.Type.TypeRef.NameMatches("Unit"))
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), "Public Shared Function "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "() As "), Name))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "    Return New "), Name), " With {._Tag = "), TagName), "."), GetEscapedIdentifier(a.Name)), ", ."), GetEscapedIdentifier(a.Name)), " = Nothing}"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "End Function");
                }
                else
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "Public Shared Function "), GetEscapedIdentifier(Combine(Combine(Begin(), "Create"), a.Name))), "(Value As "), GetTypeString(a.Type, tu.NamespaceName())), ") As "), Name))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "    Return New "), Name), " With {._Tag = "), TagName), "."), GetEscapedIdentifier(a.Name)), ", ."), GetEscapedIdentifier(a.Name)), " = Value}"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "End Function");
                }
            }
            yield return("");

            foreach (var a in tu.Alternatives)
            {
                foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Begin(), "Public Readonly Property "), GetEscapedIdentifier(Combine(Combine(Begin(), "On"), a.Name))), " As Boolean"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "    Get");

                foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), "        Return _Tag = "), TagName), "."), GetEscapedIdentifier(a.Name)))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "    End Get");

                yield return("    " + "End Property");
            }
            yield return("End Class");
        }
コード例 #8
0
        public IEnumerable <String> TaggedUnion(TaggedUnionDef tu)
        {
            var Name = GetEscapedIdentifier(tu.DefinitionName()) + GetGenericParameters(tu.GenericParameters);

            foreach (var _Line in Combine(Begin(), GetXmlComment(tu.Description)))
            {
                yield return(_Line);
            }
            foreach (var _Line in Combine(Combine(Begin(), "enum "), Name))
            {
                yield return(_Line);
            }
            yield return("{");

            foreach (var a in tu.Alternatives)
            {
                if (a.Type.OnTypeRef && a.Type.TypeRef.NameMatches("Unit"))
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Begin(), GetEscapedIdentifier(LowercaseCamelize(a.Name))), ";"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
                else
                {
                    foreach (var _Line in Combine(Begin(), GetXmlComment(a.Description)))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Combine(Combine(Begin(), GetEscapedIdentifier(LowercaseCamelize(a.Name))), "(v : "), GetTypeString(a.Type, tu.NamespaceName())), ");"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
            }
            yield return("}");
        }
コード例 #9
0
ファイル: Java.cs プロジェクト: blockspacer/niveum
        public Dictionary <String, IEnumerable <String> > GetPackageFiles(Schema Schema, String NamespaceName)
        {
            var NamespaceToClasses = new Dictionary <String, List <KeyValuePair <String, List <String> > > >();

            void AddClass(String ClassNamespaceName, String ClassName, IEnumerable <String> ClassContent)
            {
                if (!NamespaceToClasses.ContainsKey(ClassNamespaceName))
                {
                    NamespaceToClasses.Add(ClassNamespaceName, new List <KeyValuePair <String, List <String> > >());
                }
                NamespaceToClasses[ClassNamespaceName].Add(new KeyValuePair <String, List <String> >(ClassName, ClassContent.ToList()));
            }

            AddClass("niveum.lang", "Record", Attribute_Record());
            AddClass("niveum.lang", "Alias", Attribute_Alias());
            AddClass("niveum.lang", "TaggedUnion", Attribute_TaggedUnion());
            AddClass("niveum.lang", "Tag", Attribute_Tag());
            AddClass("niveum.lang", "Tuple", Attribute_Tuple());
            AddClass("niveum.lang", "Unit", Primitive_Unit());

            foreach (var c in Schema.Types)
            {
                if (c.OnPrimitive)
                {
                    continue;
                }
                else if (c.OnAlias)
                {
                    AddClass(c.NamespaceName(), c.DefinitionName(), Alias(c.Alias));
                }
                else if (c.OnRecord)
                {
                    AddClass(c.NamespaceName(), c.DefinitionName(), Record(c.Record));
                }
                else if (c.OnTaggedUnion)
                {
                    var tu      = c.TaggedUnion;
                    var TagName = GetSuffixedTypeName(tu.Name, tu.Version, "Tag", tu.NamespaceName());
                    AddClass(c.NamespaceName(), TagName, TaggedUnionTag(c.TaggedUnion));
                    AddClass(c.NamespaceName(), c.DefinitionName(), TaggedUnion(c.TaggedUnion));
                }
                else if (c.OnEnum)
                {
                    AddClass(c.NamespaceName(), c.DefinitionName(), Enum(c.Enum));
                }
                else if (c.OnClientCommand)
                {
                    var tc         = c.ClientCommand;
                    var RequestRef = GetSuffixedTypeRef(tc.Name, tc.Version, "Request");
                    var Request    = new RecordDef {
                        Name = RequestRef.Name, Version = RequestRef.Version, GenericParameters = new List <VariableDef> {
                        }, Fields = tc.OutParameters, Attributes = tc.Attributes, Description = tc.Description
                    };
                    var ReplyRef = GetSuffixedTypeRef(tc.Name, tc.Version, "Reply");
                    var Reply    = new TaggedUnionDef {
                        Name = ReplyRef.Name, Version = ReplyRef.Version, GenericParameters = new List <VariableDef> {
                        }, Alternatives = tc.InParameters, Attributes = tc.Attributes, Description = tc.Description
                    };
                    var ReplyTagName = GetSuffixedTypeName(Reply.Name, Reply.Version, "Tag", tc.NamespaceName());
                    AddClass(c.NamespaceName(), Request.DefinitionName(), Record(Request));
                    AddClass(c.NamespaceName(), ReplyTagName, TaggedUnionTag(Reply));
                    AddClass(c.NamespaceName(), Reply.DefinitionName(), TaggedUnion(Reply));
                }
                else if (c.OnServerCommand)
                {
                    var tc       = c.ServerCommand;
                    var EventRef = GetSuffixedTypeRef(tc.Name, tc.Version, "Event");
                    var Event    = new RecordDef {
                        Name = EventRef.Name, Version = EventRef.Version, GenericParameters = new List <VariableDef> {
                        }, Fields = tc.OutParameters, Attributes = tc.Attributes, Description = tc.Description
                    };
                    AddClass(c.NamespaceName(), Event.DefinitionName(), Record(Event));
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            var scg              = Schema.GetSchemaClosureGenerator();
            var sc               = scg.GetClosure(Schema.TypeRefs.Concat(Schema.Types), new List <TypeSpec> {
            });
            var Tuples           = sc.TypeSpecs.Where(t => t.OnTuple).ToList();
            var GenericTypeSpecs = sc.TypeSpecs.Where(t => t.OnGenericTypeSpec).ToList();

            foreach (var t in Tuples)
            {
                AddClass(NamespaceName, t.SimpleName(NamespaceName), Tuple(t, NamespaceName));
            }

            var GenericOptionalTypes = Schema.TypeRefs.Concat(Schema.Types).Where(t => t.NameMatches("Optional")).ToList();

            if (GenericOptionalTypes.Count > 0)
            {
                var GenericOptionalType = new TaggedUnionDef
                {
                    Name = new List <String> {
                        "Optional"
                    },
                    Version           = "",
                    GenericParameters = new List <VariableDef> {
                        new VariableDef {
                            Name = "T", Type = TypeSpec.CreateTypeRef(new TypeRef {
                                Name = new List <String> {
                                    "Type"
                                }, Version = ""
                            }), Attributes = new List <KeyValuePair <String, List <String> > > {
                            }, Description = ""
                        }
                    },
                    Alternatives = new List <VariableDef>
                    {
                        new VariableDef {
                            Name = "None", Type = TypeSpec.CreateTypeRef(new TypeRef {
                                Name = new List <String> {
                                    "Unit"
                                }, Version = ""
                            }), Attributes = new List <KeyValuePair <String, List <String> > > {
                            }, Description = ""
                        },
                        new VariableDef {
                            Name = "Some", Type = TypeSpec.CreateGenericParameterRef("T"), Attributes = new List <KeyValuePair <String, List <String> > > {
                            }, Description = ""
                        }
                    },
                    Attributes  = new List <KeyValuePair <String, List <String> > > {
                    },
                    Description = ""
                };
                {
                    var TagName = GetSuffixedTypeName(GenericOptionalType.Name, GenericOptionalType.Version, "Tag", GenericOptionalType.NamespaceName());
                    AddClass(NamespaceName, TagName, TaggedUnionTag(GenericOptionalType));
                }
                foreach (var gts in GenericTypeSpecs)
                {
                    if (gts.GenericTypeSpec.TypeSpec.OnTypeRef && gts.GenericTypeSpec.TypeSpec.TypeRef.NameMatches("Optional") && gts.GenericTypeSpec.ParameterValues.Count == 1)
                    {
                        var ElementType  = gts.GenericTypeSpec.ParameterValues.Single();
                        var Name         = "Opt" + ElementType.SimpleName(NamespaceName);
                        var Alternatives = GenericOptionalType.Alternatives.Select(a => new VariableDef {
                            Name = a.Name, Type = a.Type.OnGenericParameterRef ? ElementType : a.Type, Attributes = a.Attributes, Description = a.Description
                        }).ToList();
                        var tu = new TaggedUnionDef {
                            Name = new List <String> {
                                Name
                            }, Version = "", GenericParameters = new List <VariableDef> {
                            }, Alternatives = Alternatives, Attributes = GenericOptionalType.Attributes, Description = GenericOptionalType.Description
                        };
                        AddClass(NamespaceName, Name, TaggedUnion(tu, "OptionalTag"));
                    }
                }
            }

            return(NamespaceToClasses.SelectMany(p => p.Value.Select(v => new KeyValuePair <String, IEnumerable <String> >(String.Join("/", p.Key.Split('.').Where(NamespacePart => NamespacePart != "").Select(NamespacePart => LowercaseCamelize(NamespacePart)).Concat(new String[] { v.Key })), WrapModule(p.Key, Schema.Imports, v.Value)))).ToDictionary(p => p.Key, p => p.Value));
        }