示例#1
0
        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");
        }
示例#2
0
		public void EbnfToCode()
		{
			var ebnfGrammar = new EbnfGrammar(EbnfStyle.Iso14977 | EbnfStyle.UseCommentRuleWithSeparator);

			var code = ebnfGrammar.ToCode(ebnf, "syntax", "MyEbnfGrammar");

			var myEbnf = Helper.Create<Grammar>(code, "MyEbnfGrammar");
			SetEbnfRules(myEbnf);

			var match = myEbnf.Match(ebnf);
			Assert.IsTrue(match.Success, match.ErrorMessage);
		}