Ejemplo n.º 1
0
        public void Transpile(TranspileOptions options)
        {
            if (File.Exists(options.InputPath))
            {
                ParseFile(options.InputPath);
            }
            else if (Directory.Exists(options.InputPath))
            {
                ParseDirectory(options.InputPath);
            }
            else
            {
                throw new CommandLineException($"Cannot find {options.InputPath}");
            }

            if (compilation.CompilationErrors.Any())
            {
                foreach (var error in compilation.CompilationErrors)
                {
                    if (!string.IsNullOrEmpty(error.FileName))
                    {
                        Console.WriteLine(error.FileName);
                    }
                    Console.WriteLine(error.Message);
                }
            }
            else
            {
                var fileNameHandler = new TranspileCommandFileNameHandler(options);
                foreach (var file in compilation.CompiledFiles)
                {
                    var outputFileName  = fileNameHandler.GetOututFileNameFromInput(file.FileName);
                    var outputDirectory = Path.GetDirectoryName(outputFileName);
                    if (!Directory.Exists(outputDirectory))
                    {
                        Directory.CreateDirectory(outputDirectory);
                    }

                    Console.WriteLine($"Transpiling to {outputFileName}");
                    var transpiler = new Sphere56TranspilerVisitor(compilation.DefinitionRepository);
                    transpiler.Visit(file.ParsedTree);
                    File.WriteAllText(outputFileName, transpiler.Output);
                }
            }
        }
 public TranspileCommandFileNameHandler(TranspileOptions transpileOptions)
 {
     this.transpileOptions = transpileOptions;
 }