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)); }
public List <Pnyx> parseYaml(TextReader source, ArgsInputOutput argsIo = null) { YamlStream yaml = new YamlStream(); yaml.Load(source); List <Pnyx> result = new List <Pnyx>(); foreach (YamlDocument document in yaml.Documents) { Pnyx pnyx = parseDocument(document, argsIo); result.Add(pnyx); } return(result); }
protected Pnyx parseDocument(YamlDocument document, ArgsInputOutput argsIo) { Pnyx p = new Pnyx(); p.setSettings(stdIoDefault: true); // forces STD-IN/OUT as defaults p.setNumberedInputOutput(argsIo); if (document.RootNode.NodeType != YamlNodeType.Sequence) { throw new InvalidArgumentException("Expected a YAML sequence as the document root, but found: {0}", document.RootNode.NodeType.ToString()); } YamlSequenceNode topLevel = (YamlSequenceNode)document.RootNode; parseBlock(p, topLevel); return(p); }
private static int runYaml(Dictionary <String, String> switches, String[] args) { TextReader yamlInput; if (switches.hasAny("-i", "--inline")) { if (args.Length == 0) { return(printUsage("missing inline YAML text", 3)); } yamlInput = new StringReader(args[0]); } else { if (args.Length == 0) { return(printUsage("missing YAML file", 2)); } yamlInput = new StreamReader(new FileStream(args[0], FileMode.Open, FileAccess.Read)); } // Sets arguments args = args.Skip(1).ToArray(); ArgsInputOutput argsIo = new ArgsInputOutput(args); using (yamlInput) { YamlParser parser = new YamlParser(); List <Pnyx> toExecute = parser.parseYaml(yamlInput, argsIo); foreach (Pnyx pnyx in toExecute) { using (pnyx) pnyx.process(); } } return(0); }