Ejemplo n.º 1
0
        public void parseCode(Pnyx p, String source, bool compilePnyx = true)
        {
            // Compiles
            Script script = CSharpScript.Create(source,
                                                globalsType: typeof(Pnyx),
                                                options: ScriptOptions.Default.WithReferences(typeof(Pnyx).Assembly)
                                                );

            Task <ScriptState> parseTask = script.RunAsync(p);

            if (parseTask.IsCompletedSuccessfully)
            {
                if (p.state != FluentState.Compiled && compilePnyx)
                {
                    p.compile();                            // builds processor
                }
            }
            else
            {
                if (parseTask.Exception != null)
                {
                    throw new IllegalStateException("Script failed to run with error: {0}", parseTask.Exception.Message);
                }

                throw new IllegalStateException("Script failed to run with task in state: {0}", parseTask.Status.ToString());
            }
        }
Ejemplo n.º 2
0
        public void explicitArgs(int argCount, int?readArg, int?writeArg, String error)
        {
            String inPath  = Path.Combine(TestUtil.findTestFileLocation(), "encoding", "psalm23.unix.ansi.txt");
            String outPath = Path.Combine(TestUtil.findTestOutputLocation(), "argsOutput", Guid.NewGuid() + ".txt");

            FileUtil.assureDirectoryStructExists(outPath);

            String[] args;
            switch (argCount)
            {
            default: args = new string[0]; break;

            case 1: args = new [] { inPath }; break;

            case 2: args = new [] { inPath, outPath }; break;

            case 3: args = new [] { inPath, outPath, "junk" }; break;
            }
            ArgsInputOutput numbered = new ArgsInputOutput(args);

            using (Pnyx p = new Pnyx())
            {
                p.setSettings(processOnDispose: false);
                p.setNumberedInputOutput(numbered);

                try
                {
                    if (readArg == null)
                    {
                        p.read(inPath);
                    }
                    else
                    {
                        p.readArg(readArg.Value);
                    }

                    if (writeArg == null)
                    {
                        p.write(outPath);
                    }
                    else
                    {
                        p.writeArg(writeArg.Value);
                    }

                    p.compile();

                    Assert.Null(error);
                }
                catch (Exception err)
                {
                    Assert.Equal(error, err.Message);
                    return;
                }

                p.process();
            }

            Assert.Null(TestUtil.binaryDiff(inPath, outPath));
        }
Ejemplo n.º 3
0
 public static void helloWorld()
 {
     using (Pnyx p = new Pnyx())
     {
         p.readString("Hello World.");
         p.sed("World", "World, with love from Pnyx.."); // transforms each line
         p.grep("world", caseSensitive: false);          // filters each line
         p.writeStdout();
         p.compile();                                    // Builds processors and wires filters together
         p.process();                                    // Runs processors (All IO is done here)
     }
     // outputs: Hello World, with love from Pnyx...
 }