// wrap the VBA code with a Module public override void ExitStartRule(VBAParser.StartRuleContext context) { // if an option is present it must before everything else // therefore we have to check where to put the module start var baseText = $"Imports System {Environment.NewLine}{Environment.NewLine}Imports Microsoft.VisualBasic{Environment.NewLine}Imports System.Math{Environment.NewLine}Imports System.Linq{Environment.NewLine}Imports System.Collections.Generic{Environment.NewLine}{Environment.NewLine}Module {FileName}{Environment.NewLine}"; if (TokenImport != null) { // add imports and module Rewriter.InsertAfter(TokenImport, $"{Environment.NewLine}{baseText}"); } else { // add imports and module Rewriter.InsertBefore(context.Start, baseText); } Rewriter.InsertAfter(context.Stop.StopIndex, $"{Environment.NewLine}End Module"); }
public override bool VisitStartRule(VBAParser.StartRuleContext context) { return(Visit(context.module())); }