private BuildResult <Parser <JsonToken, JSon> > BuildEbnfJsonParser() { var parserInstance = new EbnfJsonParser(); var builder = new ParserBuilder <JsonToken, JSon>(); var result = builder.BuildParser(parserInstance, ParserType.EBNF_LL_RECURSIVE_DESCENT, "root"); return(result); }
private static void testGenericLexerJson() { var sw = new Stopwatch(); var source = File.ReadAllText("test.json"); var wp = new EbnfJsonParser(); sw.Reset(); sw.Start(); var wbuilder = new ParserBuilder <JsonToken, JSon>(); var buildResult = wbuilder.BuildParser(wp, ParserType.EBNF_LL_RECURSIVE_DESCENT, "root"); var parser = buildResult.Result; var r = parser.Parse(source); sw.Stop(); Console.WriteLine($"json regex parser : {sw.ElapsedMilliseconds} ms"); if (r.IsError) { r.Errors.ForEach(e => Console.WriteLine(e.ToString())); } sw.Reset(); sw.Start(); wbuilder = new ParserBuilder <JsonToken, JSon>(); buildResult = wbuilder.BuildParser(wp, ParserType.EBNF_LL_RECURSIVE_DESCENT, "root"); parser = buildResult.Result; parser.Lexer = new JSONLexer(); r = parser.Parse(source); Console.WriteLine($"json hard coded lexer : {sw.ElapsedMilliseconds} ms"); sw.Stop(); sw.Reset(); sw.Start(); var wpg = new EbnfJsonGenericParser(); var wbuilderGen = new ParserBuilder <JsonTokenGeneric, JSon>(); var buildResultgen = wbuilderGen.BuildParser(wpg, ParserType.EBNF_LL_RECURSIVE_DESCENT, "root"); var parserGen = buildResultgen.Result; var rGen = parserGen.Parse(source); sw.Stop(); Console.WriteLine($"json generic parser : {sw.ElapsedMilliseconds} ms"); if (rGen.IsError) { rGen.Errors.ForEach(e => Console.WriteLine(e.ToString())); } ; }