static void LoadGlobals(RegenCompiler compiler) { foreach (var content in Globals) { compiler.CompileGlobal(content); } }
private static RegenCompiler _prepareCompiler() { var compiler = new RegenCompiler(); //compile all globals foreach (var glob in RegenEngine.Globals) { compiler.CompileGlobal(glob); } return(compiler); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs _) { ThreadHelper.ThrowIfNotOnUIThread(); // open the file in a VS code window and activate the pane DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE; Document doc = dte?.ActiveDocument; string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName); Logger.Log("Searching for *.regen files at: " + solutionDir); var files = Directory.GetFiles(solutionDir, "*.regen", SearchOption.AllDirectories); if (files.Length == 0) { return; } RegenEngine.Globals.Clear(); //clear existing. foreach (var file in files) { Logger.Log($"Loading globals from {file}"); try { var content = File.ReadAllText(file); var compiler = new RegenCompiler(); compiler.CompileGlobal(content); //just compile to see if it is compilable. RegenEngine.Globals.Add(content); } catch (Exception e) { Logger.Log($"Failed parsing \"{file}\", stopping load..."); Logger.Log(e); break; } } // now set the cursor to the beginning of the function //textSelection.MoveToPoint(function.StartPoint); void Message(string msg) { // Show a message box to prove we were here VsShellUtilities.ShowMessageBox( this.package, msg, "Regen", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } }
public static CodeFrame CompileFrame(CodeFrame frame, string code) { var compiler = new RegenCompiler(); //todo modules here? var parsedCode = ExpressionParser.Parse(frame.Input); LoadGlobals(compiler); //handle globals var globals = CodeFrame.CreateGlobals(code); foreach (var globalFrame in globals) { compiler.CompileGlobal(globalFrame.Input); } frame.Output = compiler.Compile(parsedCode); return(frame); }