private static int Run(Options options) { try { using (StreamReader sr = new StreamReader(File.OpenRead(options.File))) { StreamLexer parser = new StreamLexer(sr, options.Verbose, options.Debug, options.MultiError); Program prog = parser.Parse(); prog.Run(); } } catch (Exception ex) { switch (ex) { case InvalidSyntaxException exception: InvalidSyntaxException ise = exception; OutputEx(ise.Message, ise.Line, ise.Position, options.File); break; case AssertionException exception: AssertionException ae = exception; OutputEx(ae.Message, ae.Line, ae.Position, options.File); break; case MplDivideByZeroException exception: MplDivideByZeroException mdbze = exception; OutputEx(mdbze.Message, mdbze.Line, mdbze.Position, options.File); break; case RuntimeException exception: RuntimeException rte = exception; OutputEx(rte.Message, rte.Line, rte.Position, options.File); break; case UnexpectedCharacterException exception: UnexpectedCharacterException uece = exception; OutputEx(uece.Message, uece.Line, uece.Position, options.File); break; case UnsupportedCharacterException exception: UnsupportedCharacterException usce = exception; OutputEx(usce.Message, usce.Line, usce.Position, options.File); break; case MultiException exception: MultiException me = exception; OutputMultiEx(me, options.File); break; default: throw; } } return(0); }
private static void OutputMultiEx(MultiException me, string filePath) { Console.Write("-----------------------------------\n"); Console.Write($"Encountered {me.Exceptions.Count} exceptions during parsing:\n"); foreach (Exception ex in me.Exceptions) { switch (ex) { case InvalidSyntaxException exception: InvalidSyntaxException ise = exception; OutputEx(ise.Message, ise.Line, ise.Position, filePath); break; case AssertionException exception: AssertionException ae = exception; OutputEx(ae.Message, ae.Line, ae.Position, filePath); break; case MplDivideByZeroException exception: MplDivideByZeroException mdbze = exception; OutputEx(mdbze.Message, mdbze.Line, mdbze.Position, filePath); break; case RuntimeException exception: RuntimeException rte = exception; OutputEx(rte.Message, rte.Line, rte.Position, filePath); break; case UnexpectedCharacterException exception: UnexpectedCharacterException uece = exception; OutputEx(uece.Message, uece.Line, uece.Position, filePath); break; case UnsupportedCharacterException exception: UnsupportedCharacterException usce = exception; OutputEx(usce.Message, usce.Line, usce.Position, filePath); break; default: throw ex; } } }