Пример #1
0
        private static void ProcessMacroEntities(ExpansionSettings settings, Logger logger)
        {
            // Default to .map, if no extension was specified (unless there's an extensionless file that matches):
            var inputPath = settings.InputPath;

            if (!Path.HasExtension(settings.InputPath) && !File.Exists(settings.InputPath))
            {
                inputPath = Path.ChangeExtension(settings.InputPath, ".map");
            }

            if (settings.OutputPath == null)
            {
                settings.OutputPath = inputPath;
            }

            if (settings.Directory == null)
            {
                settings.Directory = Path.GetDirectoryName(settings.InputPath);
            }


            logger.Info($"Starting to expand macros in '{settings.InputPath}'.");

            var expandedMap = MacroExpander.ExpandMacros(inputPath, settings, logger);

            // TODO: Create a backup if the target file already exists! -- how many backups to make? -- make a setting for this behavior?
            using (var file = File.Create(settings.OutputPath))
            {
                logger.Info($"Finished macro expansion. Saving to '{settings.OutputPath}'.");
                MapFormat.Save(expandedMap, file);
            }
        }
Пример #2
0
        public void TestSimpleParse()
        {
            string line = "(seq (defmacro inc (x) (+ x 1)) (inc 2))";

            Node node = HighLevel.Parse(line);

            Assert.IsNotNull(node);

            Env env = new Env(null);

            node = MacroExpander.ExpandMacros(node, env);
            string serialization = NodeOps.Serialize(node);

            Assert.AreEqual("(seq (+ 2 1))", serialization);
        }
Пример #3
0
        private static Node ExpandMacros(Node node, Env env)
        {
            int times         = 0;
            int numExpansions = 1;

            while (numExpansions > 0)
            {
                node          = MacroExpander.ExpandMacros(node, env, out int expansionCount);
                numExpansions = expansionCount;
                times++;

                if (times > 100)
                {
                    Console.WriteLine("Too many expansions. Likely a bug.");
                    return(node);
                }
            }

            return(node);
        }