Example #1
0
 private static int parse(String file, Option<String> out) throws UserError, IOException {
   int return_code = 0;
   try {
     CompilationUnit unit = Parser.parseFileConvertExn(new File(file));
     System.out.println("Ok");
     if (out.isSome()) {
       try {
         ASTIO.writeJavaAst(unit, out.unwrap());
         System.out.println("Dumped parse tree to " + out.unwrap());
       } catch (IOException e) {
         throw new IOException("IOException " + e + "while writing " + out.unwrap());
       }
     }
   } catch (ParserError e) {
     if (Debug.stackTraceOn()) {
       System.err.println(e.getMessage());
       e.printStackTrace();
     } else {
       System.err.println(turnOnDebugMessage);
     }
     return_code = 1;
   } catch (ProgramError e) {
     failureBoilerplate(e);
     return_code = 1;
   } catch (CompilerBug e) {
     failureBoilerplate(e);
     return_code = 1;
   } catch (InterpreterBug e) {
     failureBoilerplate(e);
     return_code = 1;
   } catch (FileNotFoundException f) {
     throw new UserError(file + " not found");
   } finally {
     try {
       Files.rm(ProjectProperties.preparserErrorLog(file));
     } catch (IOException e) {
     }
   }
   return return_code;
 }