public void BnfToCode() { // roundtrip to generated code then back again var bnfParser = new BnfGrammar(); // generate code from bnf var code = bnfParser.ToCode(postalAddressBnf, "postal-address", "PostalGrammar"); // execute the code and test var addressParser = Helper.Create <Grammar>(code, "PostalGrammar"); TestAddress(addressParser); }
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"); }