Exemple #1
0
        private static bool Compile(List <Token> preprocessedTokens)
        {
            DMLexer  dmLexer  = new DMLexer(null, preprocessedTokens);
            DMParser dmParser = new DMParser(dmLexer, !Settings.SuppressUnimplementedWarnings);

            VerbosePrint("Parsing");
            DMASTFile astFile = dmParser.File();

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

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

            if (astFile == null)
            {
                return(false);
            }

            DMASTSimplifier astSimplifier = new DMASTSimplifier();

            VerbosePrint("Constant folding");
            astSimplifier.SimplifyAST(astFile);

            DMObjectBuilder dmObjectBuilder = new DMObjectBuilder();

            dmObjectBuilder.BuildObjectTree(astFile);

            if (ErrorCount > 0)
            {
                return(false);
            }

            return(true);
        }
Exemple #2
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);
        }