Esempio n. 1
0
        public override void ExitSubStmt([NotNull] BosParser.SubStmtContext context)
        {
            var newlineTokens = context.NEWLINE();

            foreach (var tkn in newlineTokens)
            {
                IToken tk = tkn.Symbol;
                RewriteComment(tk);
            }
        }
Esempio n. 2
0
        public override void EnterSubStmt([NotNull] BosParser.SubStmtContext context)
        {
            if (context.ambiguousIdentifier().GetText().Trim() == "Main_Run" ||
                context.ambiguousIdentifier().GetText().Trim() == "Main_Sub" ||
                context.ambiguousIdentifier().GetText().Trim() == "Main")
            {
                IsMainFile = true;
                StreamRewriter.Replace(context.ambiguousIdentifier().Start, "Main");

                if (context.block() == null)
                {
                    return; // Empty Main Statement
                }
                // Some function of VB.Net are culture-aware,
                // this means, for instance, that when parsing a double from a
                // string it searches for the proper-culture decimal separator
                // (e.g, ',' or '.'). So, we set a culture that ensure
                // that VB.Net uses a decimal separator '.'
                string startWatchStr       = $"{ Environment.NewLine} Dim sw As System.Diagnostics.Stopwatch = System.Diagnostics.Stopwatch.StartNew(){Environment.NewLine}";
                string invariantCultureStr = $"{Environment.NewLine}System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture{Environment.NewLine}";

                // StreamRewriter.InsertBefore(null, startWatchStr);
                StreamRewriter.InsertBefore(context.block().Start, startWatchStr);
                StreamRewriter.InsertBefore(context.block().Start, invariantCultureStr);

                // Make the program wait at the end
                var waitStr      = $"{Environment.NewLine}Console.WriteLine(\"Press any key to exit the program\"){Environment.NewLine}Console.ReadKey(){Environment.NewLine}";
                var stopWatchStr = $"{ Environment.NewLine}" +
                                   $"sw.Stop(){ Environment.NewLine}" +
                                   $"Console.WriteLine($\"Time elapsed {{sw.Elapsed}}\"){Environment.NewLine}";
                // InsertBefore reverses the position of the transpiled lines,
                // so at the end one has stopWatchStr and then waitStr
                StreamRewriter.InsertAfter(context.block()?.Stop, waitStr);
                StreamRewriter.InsertAfter(context.block()?.Stop, stopWatchStr);
            }
            //base.EnterSubStmt(context);
        }