示例#1
0
        public override void ExitMacroInstruction([NotNull] GoToParser.MacroInstructionContext context)
        {
            base.ExitMacroInstruction(context);

            var macroContext = context.macro();
            var name         = macroContext.macroName().GetText();
            var @params      = macroContext.macroParams();

            if (_macrosBodies.TryGetValue(name, out GoToParser.MacroBodyContext body))
            {
                var macroBody     = _tokenStream.GetText(body.Start, body.Stop);
                var macroParams   = _macrosParams[name];
                var macroReplaced = macroBody;

                for (var i = 0; i < macroParams.ChildCount; i++)
                {
                    var sourceParam = macroParams.GetChild(i);
                    var targetParam = @params.GetChild(i);
                    macroReplaced = macroReplaced.Replace(sourceParam.GetText(), targetParam.GetText());
                    _rewrittenTokenStream.Replace(context.Start, context.Stop, macroReplaced);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>MacroInstruction</c>
 /// labeled alternative in <see cref="GoToParser.instruction"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitMacroInstruction([NotNull] GoToParser.MacroInstructionContext context)
 {
     return(VisitChildren(context));
 }
示例#3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>MacroInstruction</c>
 /// labeled alternative in <see cref="GoToParser.instruction"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitMacroInstruction([NotNull] GoToParser.MacroInstructionContext context)
 {
 }