public static ParserTranslationContext GetAncestorContext( this ParserTranslationContext context ) { var ancestor = context; var parent = ancestor.ParentContext; while( parent != null ) { ancestor = parent; parent = ancestor.ParentContext; } return ancestor; }
public static bool HasBeenParsedBy( this ParserTranslationContext context, ParserResultOrigin parser ) { var current = context; while( current != null ) { if( current.Result.Origin == parser ) return true; current = current.ParentContext; } return false; }
public void Associate(object ui, TranslationResult translationResult, ParserTranslationContext context) { if (context != null) { Contexts.Add(context); context.Jobs.Add(this); } else { if (ui != null && !ui.IsSpammingComponent()) { Components.Add(ui); } if (translationResult != null) { TranslationResults.Add(translationResult); } } }
public void Associate( UntranslatedText key, object ui, InternalTranslationResult translationResult, ParserTranslationContext context, UntranslatedTextInfo untranslatedTextInfo, bool saveResultGlobally, bool allowFallback) { AllowFallback = allowFallback || AllowFallback; if (UntranslatedTextInfo == null && untranslatedTextInfo != null) { UntranslatedTextInfo = untranslatedTextInfo; } // if just one of the things associated with this job, wants to save it, we shall! SaveResultGlobally = SaveResultGlobally || saveResultGlobally; if (context != null) { Contexts.Add(context); context.Jobs.Add(this); TranslationType |= TranslationType.Token; } else { if (ui != null && !ui.IsSpammingComponent()) { Components.Add(new KeyAnd <object>(key, ui)); } if (translationResult != null) { TranslationResults.Add(new KeyAnd <InternalTranslationResult>(key, translationResult)); } TranslationType |= TranslationType.Full; } }
public ParserTranslationContext( object component, TranslationEndpointManager endpoint, InternalTranslationResult translationResult, ParserResult result, ParserTranslationContext parentContext ) { Jobs = new HashSet<TranslationJob>(); ChildrenContexts = new List<ParserTranslationContext>(); Component = component; Result = result; Endpoint = endpoint; TranslationResult = translationResult; ParentContext = parentContext; if( parentContext != null ) { // thought: What would happen if I threw an exception after this massive anti-pattern? parentContext.ChildrenContexts.Add( this ); } var ctx = this; while( ctx != null ) { ctx = ctx.ParentContext; LevelsOfRecursion++; } }
public static int GetLevelsOfRecursion(this ParserTranslationContext context) { return(context?.LevelsOfRecursion ?? 0); }