예제 #1
0
        private static DMPreprocessor Preprocess(List <string> files)
        {
            DMPreprocessor preprocessor = new DMPreprocessor(true, !Settings.SuppressUnimplementedWarnings);

            if (!Settings.NoStandard)
            {
                string compilerDirectory   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string dmStandardDirectory = Path.Combine(compilerDirectory ?? string.Empty, "DMStandard");
                if (!File.Exists(Path.Combine(dmStandardDirectory, "_Standard.dm")))
                {
                    Error(new CompilerError(Location.Unknown, "DMStandard not found."));
                    return(null);
                }
                preprocessor.IncludeFile(dmStandardDirectory, "_Standard.dm");
            }

            VerbosePrint("Preprocessing");
            foreach (string file in files)
            {
                string directoryPath = Path.GetDirectoryName(file);
                string fileName      = Path.GetFileName(file);

                preprocessor.IncludeFile(directoryPath, fileName);
            }

            return(preprocessor);
        }
예제 #2
0
        public static bool Compile(DMCompilerSettings settings)
        {
            ErrorCount   = 0;
            WarningCount = 0;
            Settings     = settings;
            if (Settings.Files == null)
            {
                return(false);
            }

            //TODO: Only use InvariantCulture where necessary instead of it being the default
            CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

            _compileStartTime = DateTime.Now;

            if (settings.SuppressUnimplementedWarnings)
            {
                Warning(new CompilerWarning(Location.Internal, "Unimplemented proc & var warnings are currently suppressed"));
            }

            DMPreprocessor preprocessor      = Preprocess(settings.Files);
            bool           successfulCompile = preprocessor is not null && Compile(preprocessor);

            if (successfulCompile)
            {
                //Output file is the first file with the extension changed to .json
                string outputFile        = Path.ChangeExtension(settings.Files[0], "json");
                List <DreamMapJson> maps = ConvertMaps(preprocessor.IncludedMaps);

                if (ErrorCount > 0)
                {
                    successfulCompile = false;
                }
                else
                {
                    var output = SaveJson(maps, preprocessor.IncludedInterface, outputFile);
                    if (ErrorCount > 0)
                    {
                        successfulCompile = false;
                    }
                    else
                    {
                        Console.WriteLine($"Compilation succeeded with {WarningCount} warnings");
                        Console.WriteLine(output);
                    }
                }
            }
            if (!successfulCompile)
            {
                Console.WriteLine($"Compilation failed with {ErrorCount} errors and {WarningCount} warnings");
            }

            TimeSpan duration = DateTime.Now - _compileStartTime;

            Console.WriteLine($"Total time: {duration.ToString(@"mm\:ss")}");

            return(successfulCompile);
        }
예제 #3
0
        public static bool Compile(DMCompilerSettings settings)
        {
            Settings = settings;
            if (Settings.Files == null)
            {
                return(false);
            }

            //TODO: Only use InvariantCulture where necessary instead of it being the default
            CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

            _compileStartTime = DateTime.Now;

            if (settings.SuppressUnimplementedWarnings)
            {
                Warning(new CompilerWarning(Location.Unknown, "Unimplemented proc & var warnings are currently suppressed"));
            }

            DMPreprocessor preprocessor = Preprocess(settings.Files);

            if (settings.DumpPreprocessor)
            {
                StringBuilder result = new();
                foreach (Token t in preprocessor.GetResult())
                {
                    result.Append(t.Text);
                }

                string output = Path.Join(Path.GetDirectoryName(settings.Files?[0]) ?? AppDomain.CurrentDomain.BaseDirectory, "preprocessor_dump.dm");
                File.WriteAllText(output, result.ToString());
                Console.WriteLine($"Preprocessor output dumped to {output}");
            }

            bool successfulCompile = preprocessor is not null && Compile(preprocessor.GetResult());

            if (successfulCompile)
            {
                Console.WriteLine($"Compilation succeeded with {WarningCount} warnings");

                //Output file is the first file with the extension changed to .json
                string outputFile        = Path.ChangeExtension(settings.Files[0], "json");
                List <DreamMapJson> maps = ConvertMaps(preprocessor.IncludedMaps);

                SaveJson(maps, preprocessor.IncludedInterface, outputFile);
            }
            else
            {
                Console.WriteLine($"Compilation failed with {ErrorCount} errors and {WarningCount} warnings");
            }

            TimeSpan duration = DateTime.Now - _compileStartTime;

            Console.WriteLine($"Total time: {duration.ToString(@"mm\:ss")}");

            return(successfulCompile);
        }
예제 #4
0
        private static DMPreprocessor Preprocess(List <string> files)
        {
            if (!Settings.NoStandard)
            {
                string compilerDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string dmStandard        = Path.Join(compilerDirectory ?? string.Empty, "DMStandard", "_Standard.dm");

                if (!File.Exists(dmStandard))
                {
                    Error(new CompilerError(Location.Internal, "DMStandard not found."));
                    return(null);
                }

                files.Add(dmStandard);
            }

            if (Settings.DumpPreprocessor)
            {
                //Preprocessing is done twice because the output is used up when dumping it
                DMPreprocessor dumpPreproc = new DMPreprocessor(true);
                dumpPreproc.IncludeFiles(files);

                StringBuilder result = new();
                foreach (Token t in dumpPreproc)
                {
                    result.Append(t.Text);
                }

                string outputDir  = Path.GetDirectoryName(Settings.Files[0]);
                string outputPath = Path.Combine(outputDir, "preprocessor_dump.dm");

                File.WriteAllText(outputPath, result.ToString());
                Console.WriteLine($"Preprocessor output dumped to {outputPath}");
            }

            DMPreprocessor preproc = new DMPreprocessor(true);

            preproc.IncludeFiles(files);
            return(preproc);
        }
예제 #5
0
        private static List <DreamMapJson> ConvertMaps(List <string> mapPaths)
        {
            List <DreamMapJson> maps = new();

            foreach (string mapPath in mapPaths)
            {
                VerbosePrint($"Converting map {mapPath}");

                DMPreprocessor preprocessor = new DMPreprocessor(false, !Settings.SuppressUnimplementedWarnings);
                preprocessor.IncludeFile(Path.GetDirectoryName(mapPath), Path.GetFileName(mapPath));

                DMLexer      lexer  = new DMLexer(mapPath, preprocessor.GetResult());
                DMMParser    parser = new DMMParser(lexer);
                DreamMapJson map    = parser.ParseMap();

                if (parser.Errors.Count > 0)
                {
                    foreach (CompilerError error in parser.Errors)
                    {
                        Error(error);
                    }

                    continue;
                }

                if (parser.Warnings.Count > 0)
                {
                    foreach (CompilerWarning warning in parser.Warnings)
                    {
                        Warning(warning);
                    }
                }

                maps.Add(map);
            }

            return(maps);
        }