public Accept ( IParserVisitor visitor ) : void | ||
visitor | IParserVisitor | |
return | void |
private static void DoParse() { try { if (OnParseStarted != null) { OnParseStarted(); } if (_parserLock.TryEnterWriteLock(200)) { try { // make sure to always parse the current file do { //var watch = Stopwatch.StartNew(); _lastParsedFilePath = Plug.CurrentFilePath; // Parse the document _ablParser = new Parser(Plug.IsCurrentFileProgress ? Npp.Text : string.Empty, _lastParsedFilePath, null, true); // visitor _parserVisitor = new ParserVisitor(true, _lastParsedFilePath, _ablParser.LineInfo); _ablParser.Accept(_parserVisitor); //watch.Stop(); //UserCommunication.Notify("Updated in " + watch.ElapsedMilliseconds + " ms", 1); } while (!_lastParsedFilePath.Equals(Plug.CurrentFilePath)); } finally { _parserLock.ExitWriteLock(); } } if (OnParseEnded != null) { OnParseEnded(); } } catch (Exception e) { ErrorHandler.ShowErrors(e, "Error in ParseCurrentDocumentTick"); } finally { _parsing = false; if (_parseRequestedWhenBusy) { ParseCurrentDocumentTick(); } } }
/// <summary> /// Parses a file. /// Remarks : it doesn't parse the document against known words since this is only useful for /// the CURRENT document and not for the others /// </summary> private static ParserVisitor ParseFile(string filePath, ParsedScopeItem scopeItem) { ParserVisitor parserVisitor; // did we already parsed this file in a previous parse session? (if we are in CodeExplorerDisplayExternalItems mode we need to parse it again anyway) if (SavedPersistent.ContainsKey(filePath)) { parserVisitor = SavedPersistent[filePath]; } else { // Parse it var ablParser = new Parser(Utils.ReadAllText(filePath), filePath, scopeItem, false); parserVisitor = new ParserVisitor(false); ablParser.Accept(parserVisitor); } return(parserVisitor); }
/// <summary> /// Parses a file. /// Remarks : it doesn't parse the document against known words since this is only useful for /// the CURRENT document and not for the others /// </summary> private static ParserVisitor ParseFile(string fileName, ParsedScopeItem scopeItem) { ParserVisitor parserVisitor; // did we already parsed this file in a previous parse session? if (_savedParserVisitors.ContainsKey(fileName)) { parserVisitor = _savedParserVisitors[fileName]; } else { // Parse it var ablParser = new Parser(Utils.ReadAllText(fileName), fileName, scopeItem); parserVisitor = new ParserVisitor(false, Path.GetFileName(fileName), ablParser.LineInfo); ablParser.Accept(parserVisitor); // save it for future uses _savedParserVisitors.Add(fileName, parserVisitor); } return(parserVisitor); }
private static void DoParse() { try { if (OnStart != null) { OnStart(); } DoInLock(() => { // make sure to always parse the current file Parser parser = null; do { _lastFilePathParsed = Npp.CurrentFile.Path; if (Npp.CurrentFile.IsProgress) { parser = new Parser(Sci.Text, _lastFilePathParsed, null, true); // visitor var visitor = new ParserVisitor(true); parser.Accept(visitor); // send completionItems if (OnEndSendCompletionItems != null) { OnEndSendCompletionItems(visitor.ParsedCompletionItemsList); } // send codeExplorerItems if (OnEndSendCodeExplorerItems != null) { OnEndSendCodeExplorerItems(visitor.ParsedExplorerItemsList); } } else { var textLexer = new TextLexer(Sci.GetTextAroundFirstVisibleLine(Config.Instance.NppAutoCompleteMaxLengthToParse), AutoCompletion.CurrentLangAdditionalChars); var textVisitor = new TextLexerVisitor(_lastFilePathParsed) { IgnoreNumbers = Config.Instance.NppAutoCompleteIgnoreNumbers, MinWordLengthRequired = Config.Instance.NppAutoCompleteMinWordLengthRequired, KnownWords = KnownWords != null ? new HashSet <string>(KnownWords, AutoCompletion.ParserStringComparer) : new HashSet <string>(AutoCompletion.ParserStringComparer) }; textLexer.Accept(textVisitor); // send completionItems if (OnEndSendCompletionItems != null) { OnEndSendCompletionItems(textVisitor.ParsedCompletionItemsList); } // send codeExplorerItems if (OnEndSendCodeExplorerItems != null) { OnEndSendCodeExplorerItems(null); } } } while (!_lastFilePathParsed.Equals(Npp.CurrentFile.Path)); if (parser != null) { _lineInfo = new Dictionary <int, LineInfo>(parser.LineInfo); } // send parserItems if (OnEndSendParserItems != null) { if (parser != null) { OnEndSendParserItems(parser.ParserErrors, parser.LineInfo, parser.ParsedItemsList); } else { OnEndSendParserItems(null, null, null); } } }); if (OnEnd != null) { OnEnd(); } } catch (Exception e) { ErrorHandler.ShowErrors(e, "Error while analyzing the current document"); } }