/// <summary> /// Inform about substrings. /// </summary> /// <param name="ctx">The context.</param> /// <param name="name">The name.</param> /// <param name="fakeChild">True if it's a fake child.</param> /// <param name="splitter">The <see cref="Splitter"/>.</param> private void InformSubstrings(ParserRuleContext ctx, string name, bool fakeChild, Splitter splitter) { var text = AntlrUtils.GetSourceText(ctx); var path = this.Inform(ctx, name, text, fakeChild); var ranges = this.analyzer.GetRequiredInformRanges(path); if (ranges.Count > 4) { // Benchmarks showed this to be the breakeven point. (see below) var splitList = splitter.CreateSplitList(text); foreach (var range in ranges) { var value = splitter.GetSplitRange(text, splitList, range); if (value != null) { this.Inform(ctx, ctx, name + range, value, true); } } } else { foreach (var range in ranges) { var value = splitter.GetSplitRange(text, range); if (value != null) { this.Inform(ctx, ctx, name + range, value, true); } } } }
/// <summary> /// It walks to the next step in the tree. /// If the next step is null returns the provided value or source text of the node as result. /// </summary> /// <param name="tree">The node tree.</param> /// <param name="value">The provided value.</param> /// <returns>The <see cref="WalkList.WalkResult"/>.</returns> protected WalkList.WalkResult WalkNextStep(IParseTree tree, string value) { if (this.NextStep is null) { var res = value; if (value is null) { res = AntlrUtils.GetSourceText((ParserRuleContext)tree); } if (this.Verbose) { Logger.Info($"{this.Logprefix} Final (implicit) step: {res}"); } return(new WalkList.WalkResult(tree, res)); } if (this.Verbose) { Logger.Info($"{this.Logprefix} Tree: >>>{AntlrUtils.GetSourceText((ParserRuleContext)tree)}<<<"); Logger.Info($"{this.Logprefix} Enter step({this.stepNr}): {this.NextStep}"); } var result = this.NextStep.Walk(tree, value); if (this.Verbose) { Logger.Info($"{this.Logprefix} Result: >>>{(result is null ? "null" : result.ToString())}<<<"); Logger.Info($"{this.Logprefix} Leave step({(result is null ? "-" : "+")}): {this.NextStep}"); } return(result); }
/// <summary> /// If value is null returns the value of the text value of the node. /// Otherwise it just return the provided value. /// </summary> /// <param name="tree">The node tree.</param> /// <param name="value">The provided value.</param> /// <returns>The value.</returns> protected string GetActualValue(IParseTree tree, string value) { if (value is null) { return(AntlrUtils.GetSourceText((ParserRuleContext)tree)); } return(value); }
/// <summary> /// Inform about a node. /// </summary> /// <param name="ctx">The context.</param> /// <param name="path">The name.</param> /// <returns>The inform result.</returns> private string Inform(IParseTree ctx, string path) { return(this.Inform(ctx, path, AntlrUtils.GetSourceText((ParserRuleContext)ctx))); }