public override string ToString() { if (stringForm == null) { var thisRef = this; UnicodeCategory[] categories; ParserCompilerExtensions.PropagateUnicodeCategories(ref thisRef, out categories); if (categories != null && categories.Length > 0) { var thisRefString = GetSetString(thisRef, categories); var thisString = GetSetString(this); if (thisRefString.Length > thisString.Length) { stringForm = thisString; } else { stringForm = thisRefString; } } else { stringForm = GetSetString(this); } } return(stringForm); }
private static string GetSetString(RegularLanguageSet set, UnicodeCategory[] categories = null) { StringBuilder sb = new StringBuilder(); sb.Append("["); if (set.IsNegativeSet) { sb.Append('^'); } var ranges = set.GetRange(); foreach (var element in ranges) { switch (element.Which) { case SwitchPairElement.SingleCharacter: sb.Append(EncodeChar(element.A.Value)); break; case SwitchPairElement.CharacterRange: sb.AppendFormat("{0}-{1}", EncodeChar(element.B.Value.Start), EncodeChar(element.B.Value.End)); break; default: break; } } if (categories != null) { foreach (var category in categories) { sb.Append(ParserCompilerExtensions.GetUnicodeCategoryString(category)); } } sb.Append("]"); return(sb.ToString()); }
internal void Reparse() { /* * * If there's presently a parse in progress, * exit. Odds are this shouldn't happen, but * it could. Overlapping parses could lead * to thread locks. The active parse * will likely error out due to a rift * in the active parser state caused by the * text change delta. * * * Also, if there's no outliner, there's no need * to parse the file. * */ if (this.CurrentlyParsing || !this.OutlinerEnabled)// || //this.BufferChanging) { return; } try { this.CurrentlyParsing = true; this.ClearReclassifications(); this.ClearOutlines(); CurrentParseResults = this.Parser.BeginParse(); this.ParseIncludes(this.CurrentParseResults.Result.Includes); if (this.CurrentParseResults.SyntaxErrors.HasErrors) { foreach (var ce in this.CurrentParseResults.SyntaxErrors) { foreach (var token in tokens) { if (InRangeOf(token.Key, ce.Start, ce.End == LineColumnPair.Zero ? ce.Start : ce.End)) { ReclassifyToken(token.Key, ReclassificationKind.Error); break; } } } } else { (from handler in this.RelativeScopeFiles.Values select handler.CurrentParseResults.Result).Union(new IOilexerGrammarFile[] { this.CurrentParseResults.Result }).InitLookups(this.ResolutionAssistant); this.CompilationErrors = new CompilerErrorCollection(); ((OilexerGrammarFile)this.CurrentParseResults.Result).IdentityResolution(this.CompilationErrors); foreach (var ce in (from e in this.CompilationErrors let sourceError = e as ICompilerSourceError where sourceError != null select sourceError)) { foreach (var token in tokens) { if (InRangeOf(token.Key, ce.Start, ce.End == LineColumnPair.Zero ? ce.Start : ce.End)) { ReclassifyToken(token.Key, ReclassificationKind.Error); break; } } } } ReclassifyTokens(); ParserCompilerExtensions.ClearLookups(); if (!creatingOutliner) { this.Outliner.MakeTagChanges(); } this.ClearReclassifications(); } catch (Exception e) { Trace.WriteLine(e.Message); } finally { this.CurrentlyParsing = false; } }