Beispiel #1
0
        private static void Pack(RantPackage package, string contentPath)
        {
            foreach (var path in Directory.EnumerateFiles(contentPath, "*.*", SearchOption.AllDirectories)
                     .Where(p =>
                            p.EndsWith(".rant", StringComparison.OrdinalIgnoreCase) ||
                            p.EndsWith(".rants", StringComparison.OrdinalIgnoreCase) ||
                            p.EndsWith(".rantpgm", StringComparison.OrdinalIgnoreCase)))
            {
                RantProgram pattern;
                switch (Path.GetExtension(path).ToLower())
                {
                case ".rantpgm":
                    pattern = RantProgram.LoadFile(path);
                    break;

                default:
                    pattern = RantProgram.CompileFile(path);
                    break;
                }
                string relativePath;
                TryGetRelativePath(contentPath, path, out relativePath, true);
                pattern.Name = relativePath;
                package.AddResource(pattern);
                Console.WriteLine("+ " + pattern.Name);
            }

            foreach (string path in Directory.GetFiles(contentPath, "*.table", SearchOption.AllDirectories))
            {
                Console.WriteLine("+ " + path);
                var table = RantDictionaryTable.FromStream(Path.GetFileNameWithoutExtension(path), File.Open(path, FileMode.Open));
                package.AddResource(table);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            int    repetition = 10;
            string text;

            var rant = new RantEngine();

            rant.LoadPackage("build/AlinhamentoZuado-0.0.1.rantpkg");

            var program = RantProgram.CompileFile("alinhamentoZuado.rant");

            for (int i = 0; i < repetition; i++)
            {
                text = rant.Do(program);
                Console.WriteLine(text);
            }
        }
Beispiel #3
0
        private static void Pack(RantPackage package, string contentPath)
        {
            foreach (string path in Directory.EnumerateFiles(contentPath, "*.*", SearchOption.AllDirectories)
                     .Where(p => p.EndsWith(".rant") || p.EndsWith(".rants")))
            {
                var    pattern = RantProgram.CompileFile(path);
                string relativePath;
                TryGetRelativePath(contentPath, path, out relativePath, true);
                pattern.Name = relativePath;
                package.AddResource(pattern);
                Console.WriteLine("+ " + pattern.Name);
            }

            foreach (string path in Directory.GetFiles(contentPath, "*.table", SearchOption.AllDirectories))
            {
                Console.WriteLine("+ " + path);
                var table = RantDictionaryTable.FromStream(Path.GetFileNameWithoutExtension(path), File.Open(path, FileMode.Open));
                package.AddResource(table);
            }
        }
Beispiel #4
0
        protected override void OnRun()
        {
            foreach (var path in CmdLine.GetPaths())
            {
                try
                {
                    Console.Write($"Building {path}...");

                    var pgm     = RantProgram.CompileFile(path);
                    var pgmpath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + ".rantpgm");
                    pgm.SaveToFile(pgmpath);
                    Console.WriteLine("  Done.");
                }
                catch (RantCompilerException ex)
                {
                    throw new Exception($"Build failed for {path}.\n{ex.Message}\n");
                }
                catch (Exception ex)
                {
                    throw new Exception($"Error while building: {ex.Message}");
                }
            }
        }
Beispiel #5
0
 public void Reload()
 {
     this.Program = RantProgram.CompileFile(RantPath);
 }
Beispiel #6
0
        private static void PrintOutput(RantEngine engine, string source, bool isFile = false)
        {
            try
            {
                var sw = new Stopwatch();

                sw.Start();
                var pattern = isFile
                    ? source.EndsWith(".rantpgm")
                        ? RantProgram.LoadFile(source)
                        : RantProgram.CompileFile(source)
                    : RantProgram.CompileString(source);
                sw.Stop();

                var compileTime = sw.Elapsed;

                sw.Restart();
                var output = USE_SEED
                    ? engine.Do(pattern, SEED, 0, PATTERN_TIMEOUT)
                    : engine.Do(pattern, 0, PATTERN_TIMEOUT);
                sw.Stop();

                var runTime = sw.Elapsed;

                bool writeToFile = !string.IsNullOrEmpty(Property("out"));
                foreach (var chan in output)
                {
                    if (chan.Name != "main")
                    {
                        if (Flag("main"))
                        {
                            continue;
                        }
                        if (!writeToFile)
                        {
                            ForegroundColor = ConsoleColor.DarkCyan;
                            WriteLine($"{chan.Name}:");
                            ResetColor();
                        }
                    }
                    ForegroundColor = ConsoleColor.Green;
                    if (chan.Value.Length > 0)
                    {
                        if (pattern.Type == RantProgramOrigin.File && writeToFile)
                        {
                            string path = Property("out");
                            File.WriteAllText(
                                Path.Combine(Path.GetDirectoryName(path),
                                             Path.GetFileNameWithoutExtension(path) +
                                             (chan.Name != "main"
                                        ? $".{chan.Name}{Path.GetExtension(path)}"
                                        : Path.GetExtension(path))),
                                chan.Value);
                        }
                        else
                        {
#if DEBUG
                            WriteLine($"'{chan.Value}'");
#else
                            WriteLine(chan.Value.Normalize(NormalizationForm.FormC));
#endif
                        }
                    }
                    else if (!writeToFile)
                    {
                        ForegroundColor = ConsoleColor.DarkGray;
                        if (pattern.Type != RantProgramOrigin.File)
                        {
                            WriteLine("[Empty]");
                        }
                    }
                    ResetColor();
                    WriteLine();
                }

                if (!Flag("nostats"))
                {
                    PrintStats(
                        new Stat("Seed",
                                 $"{output.Seed:X16}{(output.BaseGeneration != 0 ? ":" + output.BaseGeneration : string.Empty)}"),
                        new Stat(isFile && source.EndsWith(".rantpgm") ? "Load Time" : "Compile Time", compileTime.ToString("c")),
                        new Stat("Run Time", runTime.ToString("c"))
                        );
                    WriteLine();
                }
                if (isFile && Flag("wait"))
                {
                    Console.ReadKey();
                }
            }
#if !DEBUG
            catch (RantRuntimeException e)
            {
                ForegroundColor = ConsoleColor.Red;
                WriteLine(e);
            }
            catch (RantCompilerException e)
            {
                ForegroundColor = ConsoleColor.Yellow;
                WriteLine(e.Message);
            }
            catch (Exception e)
            {
                WriteLine(e.ToString()); // Print the whole stack trace if it isn't a Rant error
            }
#endif
            finally
            {
                ResetColor();
            }
        }