aboutsummaryrefslogtreecommitdiff
path: root/lib/qparser
diff options
context:
space:
mode:
authorChimrod <>2023-10-14 15:32:13 +0200
committerChimrod <>2023-10-18 09:49:47 +0200
commitf85abcb996b8d189a646e6aeea8aa4ce068f7570 (patch)
tree658bb3448777435b569a5b0871468317611bf47c /lib/qparser
parentf135a5fcb6c9827d07025a143b190cbbf8eddc15 (diff)
Used the type S.repr in Syntax/Location.t
Diffstat (limited to 'lib/qparser')
-rw-r--r--lib/qparser/analyzer.ml53
-rw-r--r--lib/qparser/analyzer.mli4
-rw-r--r--lib/qparser/parser.mly2
3 files changed, 31 insertions, 28 deletions
diff --git a/lib/qparser/analyzer.ml b/lib/qparser/analyzer.ml
index fba96e0..06960f6 100644
--- a/lib/qparser/analyzer.ml
+++ b/lib/qparser/analyzer.ml
@@ -4,10 +4,11 @@
See [syntax/S]
*)
let parse :
- (module Qsp_syntax.S.Analyzer with type Location.repr = 'a) ->
+ type a.
+ (module Qsp_syntax.S.Analyzer with type Location.t = a) ->
Lexbuf.t ->
- ('a, Qsp_syntax.Report.t) Result.t =
- fun (type a) (module S : Qsp_syntax.S.Analyzer with type Location.repr = a) ->
+ (a * Qsp_syntax.Report.t list, Qsp_syntax.Report.t) Result.t =
+ fun (module S : Qsp_syntax.S.Analyzer with type Location.t = a) ->
let module Parser = Parser.Make (S) in
let module IncrementalParser =
Interpreter.Interpreter (Parser.MenhirInterpreter) in
@@ -34,28 +35,30 @@ let parse :
Error err
in
- Result.map_error
- (fun e ->
- let message =
- match e.IncrementalParser.code with
- | Interpreter.InvalidSyntax -> "Invalid Syntax"
- | Interpreter.UnrecoverableError -> "UnrecoverableError"
- | Interpreter.Custom msg -> msg
- | Interpreter.MenhirCode c ->
- let message_content =
- try Parser_messages.message c
- with Not_found ->
- String.concat "" [ "(Error code "; string_of_int c; ")" ]
- in
+ evaluation
+ |> Result.map (fun e -> e [])
+ |> Result.map_error (fun e ->
+ let message =
+ match e.IncrementalParser.code with
+ | Interpreter.InvalidSyntax -> "Invalid Syntax"
+ | Interpreter.UnrecoverableError -> "UnrecoverableError"
+ | Interpreter.Custom msg -> msg
+ | Interpreter.MenhirCode c ->
+ let message_content =
+ try Parser_messages.message c
+ with Not_found ->
+ String.concat "" [ "(Error code "; string_of_int c; ")" ]
+ in
- String.concat "" [ String.trim @@ message_content ]
- in
- let report = Qsp_syntax.Report.error (e.start_pos, e.end_pos) message in
+ String.concat "" [ String.trim @@ message_content ]
+ in
+ 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. *)
- let () = try Lexer.discard l with _ -> () 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. *)
+ let () = try Lexer.discard l with _ -> () in
- report)
- evaluation
+ report)
diff --git a/lib/qparser/analyzer.mli b/lib/qparser/analyzer.mli
index 30b6625..e6dcc14 100644
--- a/lib/qparser/analyzer.mli
+++ b/lib/qparser/analyzer.mli
@@ -1,7 +1,7 @@
val parse :
- (module Qsp_syntax.S.Analyzer with type Location.repr = 'a) ->
+ (module Qsp_syntax.S.Analyzer with type Location.t = 'a) ->
Lexbuf.t ->
- ('a, Qsp_syntax.Report.t) Result.t
+ ('a * Qsp_syntax.Report.t list, 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
diff --git a/lib/qparser/parser.mly b/lib/qparser/parser.mly
index 556a9ec..fd3f85b 100644
--- a/lib/qparser/parser.mly
+++ b/lib/qparser/parser.mly
@@ -21,7 +21,7 @@
%}
%parameter<Analyzer: Qsp_syntax.S.Analyzer>
-%start <Analyzer.Location.repr>main
+%start <Analyzer.Location.t Qsp_syntax.S.repr>main
%on_error_reduce expression instruction unary_operator assignation_operator
%%