From da0e0305f08c0ece1f05e0df07d7dbd627f9d4b6 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Thu, 6 Apr 2017 10:04:58 -0700 Subject: [PATCH] [linters] Make fail with syntax error appear at the end of the stderr in linters developer mode Reviewed By: ddino Differential Revision: D4843643 fbshipit-source-id: 13a627b --- infer/src/clang/cFrontend_checkers_main.ml | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/infer/src/clang/cFrontend_checkers_main.ml b/infer/src/clang/cFrontend_checkers_main.ml index 8a071823c..c13a8cf88 100644 --- a/infer/src/clang/cFrontend_checkers_main.ml +++ b/infer/src/clang/cFrontend_checkers_main.ml @@ -11,22 +11,18 @@ open! IStd open Lexing open Ctl_lexer +exception ALParsingException of string + let parse_al_file fname channel : CTL.al_file option = - let print_position _ lexbuf = + let pos_str lexbuf = let pos = lexbuf.lex_curr_p in - Logging.stderr "%s:%d:%d" pos.pos_fname - pos.pos_lnum (pos.pos_cnum - pos.pos_bol + 1) in + pos.pos_fname ^ ":" ^ (string_of_int pos.pos_lnum) ^ ":" ^ + (string_of_int (pos.pos_cnum - pos.pos_bol + 1)) in let parse_with_error lexbuf = try Some (Ctl_parser.al_file token lexbuf) with - | SyntaxError msg -> - Logging.err "%a: %s\n" print_position lexbuf msg; - None - | Ctl_parser.Error as e -> - Logging.stderr "\n#######################################################\ - \n\n%a: SYNTAX ERROR\n\ - \n########################################################\n@." - print_position lexbuf; - raise e in + | SyntaxError _ + | Ctl_parser.Error -> + raise (ALParsingException ( "SYNTAX ERROR at " ^ (pos_str lexbuf))) in let lexbuf = Lexing.from_channel channel in lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = fname }; parse_with_error lexbuf