Пример #1
0
        public static CompilationUnitSyntax Transpile(FileSyntax file, string namespaceName, string className, bool nativeAttributes, params UsingDirectiveSyntax[] usingDirectives)
        {
#pragma warning disable SA1116 // Split parameters should start on line after declaration
            return(JassTranspilerHelper.GetCompilationUnit(new SyntaxList <UsingDirectiveSyntax>(usingDirectives),
                                                           JassTranspilerHelper.GetNamespaceDeclaration(namespaceName,
                                                                                                        JassTranspilerHelper.GetClassDeclaration(className, file.Transpile(), nativeAttributes))));

#pragma warning restore SA1116 // Split parameters should start on line after declaration
        }
Пример #2
0
 public LoadData CsvFile(
     string filePath,
     AnyValue key      = null,
     FileSyntax syntax = null,
     FileSchema schema = null
     )
 {
     SetConnectionOnClients();
     return(Client.CsvFile(filePath, key, syntax, schema));
 }
Пример #3
0
        public void Render(FileSyntax file)
        {
            if (file.StartFileEmpty is null)
            {
                Render(file.StartFileLineDelimiter);
            }

            Render(file.DeclarationList);
            Render(file.FunctionList);
        }
Пример #4
0
 public LoadData CsvString(
     string data,
     AnyValue key      = null,
     FileSyntax syntax = null,
     FileSchema schema = null
     )
 {
     SetConnectionOnClients();
     return(Client.JsonString(data, key, syntax, schema));
 }
Пример #5
0
 public bool LoadCSV(
     string rel,
     string data             = null,
     string path             = null,
     AnyValue[] key          = null,
     FileSyntax syntax       = null,
     FileSchema schema       = null,
     Integration integration = null
     )
 {
     SetConnectionOnClients();
     return(Client.LoadCSV(rel, data, path, key, syntax, schema, integration));
 }
Пример #6
0
 public bool LoadEdb(
     string rel,
     string contentType,
     string data       = null,
     string path       = null,
     AnyValue key      = null,
     FileSyntax syntax = null,
     FileSchema schema = null
     )
 {
     SetConnectionOnClients();
     return(Client.LoadEdb(rel, contentType, data, path, key, syntax, schema));
 }
Пример #7
0
        private static void RenderFunctionToFile(string path, FileSyntax fileSyntax)
        {
            using (var fileStream = FileProvider.OpenNewWrite(path))
            {
                using (var writer = new StreamWriter(fileStream, new UTF8Encoding(false, true)))
                {
                    var mainAndConfigRenderer = new JassRenderer(writer);
                    mainAndConfigRenderer.SetNewlineString(true, true);
                    mainAndConfigRenderer.Comments           = false;
                    mainAndConfigRenderer.Indentation        = 4;
                    mainAndConfigRenderer.OptionalWhitespace = true;
                    mainAndConfigRenderer.OmitEmptyLines     = false;
                    mainAndConfigRenderer.InlineConstants    = false;

                    mainAndConfigRenderer.Render(fileSyntax);
                }
            }
        }
Пример #8
0
        public static void TranspileTypesToLua(FileSyntax file, string namespaceAndClassPrefix, string outputPath)
        {
            new FileInfo(outputPath).Directory.Create();
            using (var fileStream = File.OpenWrite(outputPath))
            {
                using (var streamWriter = new StreamWriter(fileStream))
                {
                    streamWriter.WriteLine("local define = System.defStc");
                    streamWriter.WriteLine("local setmetatable = setmetatable");
                    streamWriter.WriteLine();

                    WriteDeclr(streamWriter, "handle", null);

                    foreach (var declaration in file.DeclarationList)
                    {
                        var typeDef = declaration.Declaration.TypeDefinition;
                        if (typeDef != null)
                        {
                            WriteDeclr(streamWriter, typeDef.NewTypeNameNode.ValueText, typeDef.BaseTypeNode.HandleIdentifierNode.ValueText);
                        }
                    }
                }
            }

            void WriteDeclr(TextWriter writer, string newType, string baseType)
            {
                writer.WriteLine($"local {newType} = define(\"{namespaceAndClassPrefix}.{newType}\", {{");

                var       members     = new List <string>();
                const int indentCount = 2;
                var       indentation = new string(' ', indentCount);

                // members.Add($"__ctor__ = function(this, {}");
                if (baseType != null)
                {
                    // Should be: CSharpLua.LuaAst.LuaIdentifierNameSyntax.Inherits, but referencing that project requires updating this project to .NET standard 2.1
                    members.Add($"{"base"} = {{ {baseType} }}");
                }

                writer.WriteLine(members.Select(line => $"{indentation}{line}").Aggregate((accum, next) => $"{accum},\r\n{next}"));
                writer.WriteLine("})");
            }
        }
Пример #9
0
        public static void TranspileTypesToLua(FileSyntax file, string namespaceAndClassPrefix, string outputPath)
        {
            new FileInfo(outputPath).Directory.Create();
            using (var fileStream = File.OpenWrite(outputPath))
            {
                using (var streamWriter = new StreamWriter(fileStream))
                {
                    streamWriter.WriteLine("local define = System.defStc");
                    streamWriter.WriteLine("local setmetatable = setmetatable");
                    streamWriter.WriteLine();

                    WriteDeclr(streamWriter, "handle", null);

                    foreach (var declaration in file.DeclarationList)
                    {
                        var typeDef = declaration.Declaration.TypeDefinition;
                        if (typeDef != null)
                        {
                            WriteDeclr(streamWriter, typeDef.NewTypeNameNode.ValueText, typeDef.BaseTypeNode.HandleIdentifierNode.ValueText);
                        }
                    }
                }
            }

            void WriteDeclr(TextWriter writer, string newType, string baseType)
            {
                writer.WriteLine($"local {newType} = define(\"{namespaceAndClassPrefix}.{newType}\", {{");

                if (baseType != null)
                {
                    writer.WriteLine($"  __inherits__ = {{ {baseType} }}");
                }

                writer.WriteLine("})");
            }
        }