diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/analyzer.ml | 36 | ||||
| -rw-r--r-- | lib/analyzer.mli | 10 | 
2 files changed, 16 insertions, 30 deletions
| diff --git a/lib/analyzer.ml b/lib/analyzer.ml index e4fc272..a6f5e51 100644 --- a/lib/analyzer.ml +++ b/lib/analyzer.ml @@ -1,21 +1,3 @@ -type error = { -  message : string; -  start_pos : Lexing.position; -  end_pos : Lexing.position; -} -(** Error reported when the syntax is invalid *) - -let format_error : Format.formatter -> error -> unit = - fun f e -> -  let start_c = e.start_pos.Lexing.pos_cnum - e.start_pos.Lexing.pos_bol -  and end_c = e.end_pos.Lexing.pos_cnum - e.end_pos.Lexing.pos_bol -  and start_line = e.start_pos.Lexing.pos_lnum -  and end_line = e.end_pos.Lexing.pos_lnum in - -  if start_line != end_line then -    Format.fprintf f "Lines %d-%d %s" start_line end_line e.message -  else Format.fprintf f "Line %d %d:%d %s" start_line start_c end_c e.message -  (**       Run the QSP parser and apply the analyzer over it. @@ -25,7 +7,7 @@ let parse :      (module Qsp_syntax.S.Analyzer with type Location.repr = 'a) ->      (module Encoding.S) ->      Sedlexing.lexbuf -> -    ('a, error) Result.t = +    ('a, Qsp_syntax.Report.t) Result.t =   fun (type a) (module S : Qsp_syntax.S.Analyzer with type Location.repr = a)       (module E : Encoding.S) ->    let module Parser = Parser.Make (S) in @@ -39,10 +21,22 @@ let parse :             let message =               match e.IncrementalParser.code with               | Interpreter.InvalidSyntax -> "Invalid Syntax" +             | Interpreter.UnrecoverableError -> "UnrecoverableError"               | Interpreter.MenhirCode c ->                   String.concat ""                     [ -                     "(Code "; string_of_int c; ")\n"; Parser_messages.message c; +                     String.trim @@ Parser_messages.message c; +                     " (Error code "; +                     string_of_int c; +                     ")";                     ]             in -           { message; start_pos = e.start_pos; end_pos = e.end_pos }) +           let report = +             Qsp_syntax.Report.error (e.start_pos, e.end_pos) message +           in + +           (* Discard the remaining file to read. The parser is now in a blank +              state, it does not make sense to keep feeding it with the new +              tokens. *) +           Lexer.discard lexbuf; +           report) diff --git a/lib/analyzer.mli b/lib/analyzer.mli index 43509ba..e7efdb0 100644 --- a/lib/analyzer.mli +++ b/lib/analyzer.mli @@ -1,16 +1,8 @@ -type error = { -  message : string; -  start_pos : Lexing.position; -  end_pos : Lexing.position; -} - -val format_error : Format.formatter -> error -> unit -  val parse :    (module Qsp_syntax.S.Analyzer with type Location.repr = 'a) ->    (module Encoding.S) ->    Sedlexing.lexbuf -> -  ('a, error) Result.t +  ('a, Qsp_syntax.Report.t) Result.t  (** Read the source and build a analyzis over it.   This method make the link between the source file and how to read it | 
