/// <summary> /// Loads this fixture /// </summary> /// <param name="reporter">The reported to use</param> /// <param name="name">The fixture's name</param> public Fixture(Reporter reporter, string name) { reporter.Info("Loading fixture " + name); Stream stream = typeof(Program).Assembly.GetManifestResourceStream(name); TextReader reader = new StreamReader(stream, Encoding.UTF8); string content = reader.ReadToEnd(); reader.Close(); BaseLRParser parser = parserFixture.GetParser(content); ParseResult result = parser.Parse(); foreach (ParseError error in result.Errors) { reporter.Error(error, result.Input, error.Position); } ASTNode fixtureNode = result.Root; this.name = fixtureNode.Value; tests = new List <Test>(); foreach (ASTNode testNode in fixtureNode.Children) { Test test; switch (testNode.Symbol.Name) { case "test_output": test = new OutputTest(testNode, result.Input); break; default: test = new ParsingTest(testNode, result.Input); break; } tests.Add(test); } }
/// <summary> /// Executes the parseit program /// </summary> /// <param name="args">The command line arguments</param> /// <returns>The error code, or 0 if none</returns> public static int Main(string[] args) { // If no argument is given, print the help screen and return OK if (args == null || args.Length != 2) { PrintHelp(); return(0); } TextReader input = new StreamReader(Console.OpenStandardInput(), Encoding.UTF8, false); Assembly assembly = Assembly.LoadFile(Path.GetFullPath(args[0])); Type parserType = assembly.GetType(args[1]); ConstructorInfo parserCtor = parserType.GetConstructors()[0]; ParameterInfo[] parameters = parserCtor.GetParameters(); Type lexerType = parameters[0].ParameterType; ConstructorInfo lexerCtor = lexerType.GetConstructor(new [] { typeof(TextReader) }); object lexer = lexerCtor.Invoke(new object[] { input }); BaseLRParser parser = (BaseLRParser)parserCtor.Invoke(new [] { lexer }); ParseResult result = parser.Parse(); StringBuilder builder = new StringBuilder(); Serialize(builder, result); Console.WriteLine(builder.ToString()); return(0); }