private static string GetCode(CommandLineOptions opts)
        {
            switch (Path.GetExtension(opts.GrammarFile)) {
                case ".bnf":
                    var gr = new BnfGrammar();
                    return gr.ToCode(File.ReadAllText(opts.GrammarFile), opts.StartParser, opts.GrammarName);
                case ".ebnf":
                    var egr = new EbnfGrammar(EbnfStyle.W3c | EbnfStyle.SquareBracketAsOptional | EbnfStyle.WhitespaceSeparator);
                    return egr.ToCode(File.ReadAllText(opts.GrammarFile), opts.StartParser, opts.GrammarName);
                case ".gold":
                    var ggr = new GoldGrammar();
                    return ggr.ToCode(File.ReadAllText(opts.GrammarFile), opts.GrammarName);
            }

            throw new Exception("Unknown Grammar. Try .ebnf .bnf .gold");
        }
		public void ToCode()
		{
			// test a round trip to code
			var code = new GoldGrammar().ToCode(goldBnf, "MyGoldGrammar");

			// execute generated code
			var generatedGoldParser = Helper.Create<Grammar>(code, "MyGoldGrammar");

			// match using generated parser
			var match = generatedGoldParser.Match(goldBnf);

			Assert.IsTrue(match.Success, "Error: {0}", match.ErrorMessage);

			// check rules
			var rules = match.Find("Rule Decl", true).Select(r => r["Nonterminal"].Text.TrimStart('<').TrimEnd('>')).ToArray();
			CollectionAssert.AreEquivalent(GOLD_RULES, rules);
		}
		public void TestParsing()
		{
			var goldParser = new GoldGrammar();
			var definition = goldParser.Build(goldBnf);

			// check rules
			CollectionAssert.AreEquivalent(GOLD_RULES, definition.Rules.Keys);
		}