public override void EnterEveryRule([ValidatedNotNull] ParserRuleContext context) { context.ValidateNotNull(nameof(context)); string typeName = context.GetType( ).Name; Push(new XElement(typeName.Substring(0, typeName.Length - ContextTypeNameSuffix.Length))); }
public static SourceSpan GetSourceSpan([ValidatedNotNull] this ParserRuleContext ctx) { ctx.ValidateNotNull(nameof(ctx)); return(new SourceSpan(ctx.Start.Line , ctx.Start.Column , ctx.Stop.Line , ctx.Stop.Column )); }
/// <summary>Gets a character based interval from a <see cref="ParserRuleContext"/></summary> /// <param name="ruleContext">context to get the interval from</param> /// <returns>Character based interval covered by the context</returns> public static Interval GetCharInterval(this ParserRuleContext ruleContext) { ruleContext.ValidateNotNull(nameof(ruleContext)); if (ruleContext.start.Type == Recognizer <IToken, Antlr4.Runtime.Atn.ParserATNSimulator> .Eof) { return(Interval.Invalid); } int startChar = ruleContext.Start.StartIndex; int endChar = ruleContext.Stop.StopIndex - 1; return(Interval.Of(Min(startChar, endChar), Max(startChar, endChar))); }
public override void ExitEveryRule([ValidatedNotNull] ParserRuleContext context) { context.ValidateNotNull(nameof(context)); base.ExitEveryRule(context); if (ActiveNode is null) { throw new InvalidOperationException("ActiveNode is null!"); } ActiveNode.Add(new XAttribute("Text", context.GetSourceText(Recognizer))); ActiveNode.Add(new XAttribute("RuleIndex", context.RuleIndex)); ActiveNode.Add(new XAttribute("SourceInterval", context.SourceInterval.ToString( ))); if (context.exception != null) { ActiveNode.Add(new XAttribute("Exception", context.exception)); } Pop( ); }
/// <inheritdoc/> public virtual void ExitEveryRule(ParserRuleContext ctx) { ctx.ValidateNotNull(nameof(ctx)); Trace.TraceInformation($"exit[{ctx.SourceInterval}] {Parser.RuleNames[ ctx.RuleIndex ]} [{ctx.GetType( ).Name}] Lt(1)='{( ( ITokenStream )Parser.InputStream ).Lt( 1 ).Text}'"); }