public Variable GetVariable(string name, ParserRuleContext ctx) { if (ctx.GetType().IsAssignableFrom(StatementContextType) && _environmentsByContext.TryGetValue(ctx, out var env)) { return(env.GetVariable(name)); } var statementAncestor = ctx.FindParentOfType <QuestScriptParser.StatementContext>(); if (statementAncestor != null && _environmentsByContext.TryGetValue(statementAncestor, out var statementEnvironment)) { return(statementEnvironment.GetVariable(name)); } return(null); }
public static bool HasParentOfType <TParent>(this ParserRuleContext ctx) where TParent : ParserRuleContext { return(ctx.FindParentOfType <TParent>() != null); }