From 6fd720c07e3e361932e01bfbdbe4637c8f610649 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Sun, 4 Feb 2024 10:37:04 +0100 Subject: Added a general context for each test --- lib/qparser/analyzer.ml | 19 ++++++++++++++----- lib/qparser/analyzer.mli | 5 ++++- lib/qparser/parser.mly | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'lib/qparser') diff --git a/lib/qparser/analyzer.ml b/lib/qparser/analyzer.ml index e3a2774..6d09021 100644 --- a/lib/qparser/analyzer.ml +++ b/lib/qparser/analyzer.ml @@ -4,19 +4,25 @@ See [syntax/S] *) let parse : - type a. - (module Qsp_syntax.S.Analyzer with type Location.t = a) -> + type a context. + (module Qsp_syntax.S.Analyzer + with type Location.t = a + and type context = context) -> Lexbuf.t -> + context -> (a * Qsp_syntax.Report.t list, Qsp_syntax.Report.t) Result.t = - fun (module S : Qsp_syntax.S.Analyzer with type Location.t = a) -> + fun (module S : Qsp_syntax.S.Analyzer + with type Location.t = a + and type context = context) -> let module Parser = Parser.Make (S) in let module IncrementalParser = Interpreter.Interpreter (Parser.MenhirInterpreter) in - fun l -> + fun l context -> let lexer = Lexbuf.tokenize Lexer.main l in let init = Parser.Incremental.main (fst (Lexbuf.positions l)) in + (* Firslty, check if we are able to read the whole syntax from the source *) let evaluation = try IncrementalParser.of_lexbuf lexer l init with | Lexer.LexError message -> @@ -35,8 +41,11 @@ let parse : Error err in + (* Then apply the checks over the result of the parsing *) evaluation - |> Result.map (fun r -> (r, S.Location.v r)) + |> Result.map (fun r -> + let r' = r context in + (r', S.Location.v r')) |> Result.map_error (fun e -> let message = match e.IncrementalParser.code with diff --git a/lib/qparser/analyzer.mli b/lib/qparser/analyzer.mli index e6dcc14..8033601 100644 --- a/lib/qparser/analyzer.mli +++ b/lib/qparser/analyzer.mli @@ -1,6 +1,9 @@ val parse : - (module Qsp_syntax.S.Analyzer with type Location.t = 'a) -> + (module Qsp_syntax.S.Analyzer + with type Location.t = 'a + and type context = 'context) -> Lexbuf.t -> + 'context -> ('a * Qsp_syntax.Report.t list, Qsp_syntax.Report.t) Result.t (** Read the source and build a analyzis over it. diff --git a/lib/qparser/parser.mly b/lib/qparser/parser.mly index 861d8b9..9501884 100644 --- a/lib/qparser/parser.mly +++ b/lib/qparser/parser.mly @@ -18,7 +18,7 @@ %} %parameter -%start <(Analyzer.Location.t)>main +%start <(Analyzer.context -> Analyzer.Location.t)>main %on_error_reduce expression instruction unary_operator assignation_operator %% @@ -31,7 +31,7 @@ main: LOCATION_END { let instructions = List.map instructions ~f:(Analyzer.Instruction.v) in - Analyzer.Location.location $loc instructions + fun context -> Analyzer.Location.location context $loc instructions } before_location: -- cgit v1.2.3