public static void ParseAllFiles() { // create unique temporary folder var testDir = Path.Combine(Npp.ConfigDirectory, "Tests", "ParseAllFiles_" + DateTime.Now.ToString("yy.MM.dd_HH-mm-ss-fff")); string outNotif = ""; var outFile = Path.Combine(testDir, "out.txt"); if (!Utils.CreateDirectory(testDir)) { return; } var parserErrors = ""; var watch2 = Stopwatch.StartNew(); foreach (var file in Directory.EnumerateFiles(ProEnvironment.Current.BaseLocalPath, "*", SearchOption.AllDirectories)) { if (file.TestAgainstListOfPatterns(Config.Instance.FilesPatternProgress)) { string outStr = file + " >>> "; var watch = Stopwatch.StartNew(); ProLexer proLexer = new ProLexer(Utils.ReadAllText(file)); outStr += "ProLexer (" + watch.ElapsedMilliseconds + " ms), "; Parser parser = new Parser(proLexer, "", null, true); outStr += "Parser (" + watch.ElapsedMilliseconds + " ms), "; if (parser.ParserErrors != null && parser.ParserErrors.Count > 0) { outNotif += file.ToHtmlLink() + "<br>"; parserErrors += file + "<br>" + parser.ParseErrorsInHtml + "<br>"; } /* * var parserVisitor = new ParserVisitor(true); * parser.Accept(parserVisitor); * outStr += "Visitor (" + watch.ElapsedMilliseconds + " ms)\r\n"; */ watch.Stop(); Utils.FileAppendAllText(outFile, outStr + "\r\n"); } } Utils.FileAppendAllText(outFile, "\r\n\r\n" + parserErrors); watch2.Stop(); Utils.FileAppendAllText(outFile, "\r\n\r\nTotal time : " + watch2.ElapsedMilliseconds); UserCommunication.Notify(outNotif + "<br>Done :<br>" + outFile.ToHtmlLink(), 0); }
public static void RunParserTests(string content) { // create unique temporary folder var testDir = Path.Combine(Npp.ConfigDirectory, "Tests", "RunParserTests_" + DateTime.Now.ToString("yy.MM.dd_HH-mm-ss-fff")); var perfFile = Path.Combine(testDir, "perfs.txt"); if (!Utils.CreateDirectory(testDir)) { return; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // LEXER //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% var outLocation = Path.Combine(testDir, "Lexer_out.txt"); //------------ var watch = Stopwatch.StartNew(); //------------ ProLexer proLexer = new ProLexer(content); //-------------- watch.Stop(); //-------------- OutputLexerVisitor lexerVisitor = new OutputLexerVisitor(); proLexer.Accept(lexerVisitor); Utils.FileWriteAllText(outLocation, lexerVisitor.Output.ToString()); File.AppendAllText(perfFile, @"LEXER DONE in " + watch.ElapsedMilliseconds + @" ms > nb items = " + lexerVisitor.NbItems + "\r\n"); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // PARSER //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% outLocation = Path.Combine(testDir, "Parser_out.txt"); //------------ watch = Stopwatch.StartNew(); //------------ Parser parser = new Parser(proLexer, "", null, true); //-------------- watch.Stop(); //------------ OutputParserVisitor parserVisitor = new OutputParserVisitor(); parser.Accept(parserVisitor); Utils.FileWriteAllText(outLocation, parserVisitor.Output.ToString()); File.AppendAllText(perfFile, @"PARSER DONE in " + watch.ElapsedMilliseconds + @" ms > nb items = " + parser.ParsedItemsList.Count + "\r\n"); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // LINE INFO //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% outLocation = Path.Combine(testDir, "LineInfo_out.txt"); StringBuilder lineInfo = new StringBuilder(); var i = 0; var dic = parser.LineInfo; while (dic.ContainsKey(i)) { lineInfo.AppendLine(i + 1 + " > " + dic[i].BlockDepth + " , " + dic[i].Scope + " , " + dic[i].Scope.ScopeType + " , " + dic[i].Scope.Name); i++; } Utils.FileWriteAllText(outLocation, lineInfo.ToString()); File.AppendAllText(perfFile, @"nb items in Line info = " + parser.LineInfo.Count + "\r\n"); UserCommunication.Notify("Done :<br>" + testDir.ToHtmlLink()); }
public static bool EvaluateExpression(string expression) { ProLexer proLexer = new ProLexer(expression); return(EvaluateExpression(proLexer.GetTokensList)); }