static void Main(string[] args) { if (args.Length != 1) { DisplayDirections(); } else if (!File.Exists(args[0])) { Console.WriteLine("Could not find {0}", args[0]); Environment.Exit(1); } var code = File.ReadAllText(args[0]); EnvironmentLibrary.SetEnvArgs(true); var interpreter = new AphidInterpreter(); try { interpreter.Interpret(code); } catch (AphidParserException exception) { Console.WriteLine("Unexpected {0}\r\n\r\n{1}\r\n", exception.UnexpectedToken.Lexeme, GetCodeExcerpt(code, exception.UnexpectedToken)); } catch (AphidRuntimeException exception) { Console.WriteLine("Unexpected runtime exception\r\n\r\n{0}\r\n", exception.Message); } }
private static void RunScript(string[] args) { if (!File.Exists(args[0])) { Console.WriteLine("Could not find {0}", args[0]); Environment.Exit(1); } var ext = Path.GetExtension(args[0]).ToLower(); var isTextDocument = ext == ".alxt"; var file = Path.GetFullPath(args[0]); var interpreter = new AphidInterpreter(); interpreter.SetScriptFilename(file); EnvironmentLibrary.SetEnvArgs(true); var result = true; #if !APHID_DEBUGGING_ENABLED if (AphidConfig.Current.ScriptCaching) { var cache = new AphidByteCodeCache(interpreter.Loader.SearchPaths.ToArray()) { DisableConstantFolding = false, InlineScripts = true, }; if (AphidErrorHandling.HandleErrors) { result = AphidCli.TryAction( interpreter, () => AphidScript.Read(file), () => interpreter.Interpret(cache.Read(file)), allowErrorReporting: true); } else { interpreter.Interpret(cache.Read(file)); } } else { #endif var code = AphidScript.Read(file); if (AphidErrorHandling.HandleErrors) { result = AphidCli.TryAction( interpreter, code, () => interpreter.Interpret(code, file, isTextDocument), allowErrorReporting: true); } else { interpreter.Interpret(code, file, isTextDocument); } if (interpreter.CurrentScope.ResolveBool(AphidName.OpenRepl)) { new AphidRepl { Interpreter = interpreter }.Run(); } #if !APHID_DEBUGGING_ENABLED } #endif if (!result) { Environment.Exit(0xbad5230); } }