//A fatal compile message (the compiler has failed). public static void FatalCompile(string msg) { //Send the error message. Console.ForegroundColor = ConsoleColor.Red; ALEC.Log("FATAL - " + msg, ALECEvent.Fatal); Console.ResetColor(); //Print the compile footer. ALEC.PrintCompileFooter(); //Test mode? Throw instead of exit. if (AlgoRuntimeInformation.UnitTestMode) { throw new Exception(msg); } Environment.Exit(-1); }
//A warning compile message. public static void WarningCompile(string msg) { Console.ForegroundColor = ConsoleColor.Yellow; ALEC.Log("WARN - " + msg, ALECEvent.Warning); Console.ResetColor(); }
/// <summary> /// Runs Algo in "inline" mode (no package manager, etc). Returns an exit code. /// </summary> private static int RunAlgoInline(InlineCLIOptions opts, string[] originalArgs) { //Set developer mode on if necessary. if (opts.DeveloperMode) { AlgoRuntimeInformation.DeveloperMode = true; } if (opts.TestMode) { AlgoRuntimeInformation.UnitTestMode = true; } //Displaying any generic info and then shutting off? if (opts.ShowVersionOnly) { PrintVersionInfo(); return(0); } //Compiling a file? if (opts.Compile != null) { //Attempt to compile. ALEC.Compile(opts.Compile); return(0); } //Running the script interpreter, or the live interpreter? if (opts.ScriptFile == null) { //Run live. //Print version info. If --nohead is on, then the header info for the interpreter is skipped. if (!opts.NoHeader) { PrintVersionInfo(); Console.WriteLine("Starting interpreter...\n"); } //Create a visitor. if (visitor == null) { visitor = new algoVisitor(); //Load core library. visitor.LoadCoreLibrary(); } //Interactive interpreter. while (true) { Console.Write(">> "); string line = Console.ReadLine(); //Catch keywords and null strings. if (line == "quit" || line == "exit" || line == "stop") { break; } if (line == "help") { PrintHelp(); continue; } if (line == "clear") { Console.Clear(); continue; } if (line == "") { continue; } //Parse line. var s_chars = new AntlrInputStream(line); var s_lexer = new algoLexer(s_chars); var s_tokens = new CommonTokenStream(s_lexer); var s_parse = new algoParser(s_tokens); //Turn on continuous mode. AlgoRuntimeInformation.ContinuousMode = true; //Execute. s_parse.BuildParseTree = true; var s_tree = s_parse.compileUnit(); try { visitor.VisitCompileUnit(s_tree); } catch (Exception e) { //Internal exception. if (!AlgoRuntimeInformation.UnitTestMode) { Error.Internal(e.Message); } else { throw e; } } } return(0); } else { //Run normal script. //Does the given file location exist? string fullPath = CPFilePath.GetPlatformFilePath(new string[] { Environment.CurrentDirectory, opts.ScriptFile }); if (!File.Exists(fullPath)) { Error.FatalNoContext("No file with the name '" + opts.ScriptFile + "' exists relative to your current directory."); return(-1); } //Loading in the file arguments. List <string> args = originalArgs.ToList(); args.RemoveAll(x => x.StartsWith("-")); algoVisitor.SetConsoleArguments(args.Skip(1).ToArray()); //Read in the input. AlgoRuntimeInformation.FileLoaded = opts.ScriptFile; string input = File.ReadAllText(fullPath); var chars = new AntlrInputStream(input); var lexer = new algoLexer(chars); var tokens = new CommonTokenStream(lexer); //Debug print. if (AlgoRuntimeInformation.DeveloperMode) { ANTLRDebug.PrintTokens(lexer); } //Debug print tree. var parser = new algoParser(tokens); parser.BuildParseTree = true; var tree = parser.compileUnit(); if (AlgoRuntimeInformation.DeveloperMode) { ANTLRDebug.PrintParseList(tree, parser); //Add a gap. Console.WriteLine(" --------------------\n | BEGIN EVALUATION |\n --------------------\n"); } //Walking the tree. visitor = new algoVisitor(); visitor.LoadCoreLibrary(); visitor.VisitCompileUnit(tree); if (AlgoRuntimeInformation.DeveloperMode) { Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("\n ------------------\n | END EVALUATION |\n ------------------\n"); //Print variables. ANTLRDebug.PrintScopes(); } return(0); } }