Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Macrogenerator starts\n");
            var macroGenerator = new MacroGenerator();

            if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
            {
                if (args[0] == "-h")
                {
                    macroGenerator.DisplayHelp();
                }
                else
                {
                    macroGenerator.ReadFromFile(args[0]);
                }
            }
            else
            {
                MacroGenerator.PrintError(ErrorCode.NoInputFilePointed, -1);
            }

            Console.WriteLine("\n\nMacrogenerator stoped");

            Console.WriteLine("Press Enter to end...");
            Console.ReadLine();
        }
Example #2
0
        public void AddMacro(Macro nMacro)
        {
            if (nMacro == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(nMacro.Name) || string.IsNullOrWhiteSpace(nMacro.Body))
            {
                MacroGenerator.PrintError(ErrorCode.AddedMacroIsEmpty, MacroGenerator.currentLineOfCode);
                return;
            }

            // Check if macro with given name and level already exists
            var lookForMacro = MacrosList.FirstOrDefault(m => m.Name.Equals(nMacro.Name) && m.Level.Equals(nMacro.Level));

            if (lookForMacro != null)
            {
                // Print information about overwritting macro
                Console.WriteLine($"\nMacro \"{lookForMacro.Name}\" with level {lookForMacro.Level} has been overwritten");

                // Remove it from list;
                MacrosList.Remove(lookForMacro);
            }

            MacrosList.Add(nMacro);

            // Sort after insert(by level)
            MacrosList = MacrosList.OrderBy(d => d.Level).ToList();
        }
Example #3
0
        public Macro FindMacro(string name, int level = 0)
        {
            // find macro with given name and level equal or lower than given then take one
            var macro = MacrosList.OrderByDescending(n => n.Level).FirstOrDefault(m => m.Name.Equals(name) && m.Level <= level);

            if (macro == null)
            {
                MacroGenerator.PrintError(ErrorCode.MacroNotFound, MacroGenerator.currentLineOfCode);
            }

            return(macro);
        }