aboutsummaryrefslogtreecommitdiff
path: root/lib/qparser/parser.mly
diff options
context:
space:
mode:
authorChimrod <>2023-10-07 12:24:37 +0200
committerChimrod <>2023-10-18 09:49:47 +0200
commitc2f87ff1e6e5676968804cd50b86fc2f0f9ad672 (patch)
treeab0770cc70bbe6ed26606200110cc503390ac420 /lib/qparser/parser.mly
parenta70c88bd727c7938c3d8d1355bf5474546d7d72e (diff)
Made explicit the use of the report in the parser
Diffstat (limited to 'lib/qparser/parser.mly')
-rw-r--r--lib/qparser/parser.mly58
1 files changed, 50 insertions, 8 deletions
diff --git a/lib/qparser/parser.mly b/lib/qparser/parser.mly
index 84c1af8..8547e17 100644
--- a/lib/qparser/parser.mly
+++ b/lib/qparser/parser.mly
@@ -1,6 +1,23 @@
%{
module T = Qsp_syntax.T
+ open StdLabels
+
+ type action_block =
+ { loc : Qsp_syntax.S.pos
+ ; expression :
+ Qsp_syntax.Report.t list
+ -> Analyzer.Expression.t' * Qsp_syntax.Report.t list
+ ; body : Analyzer.Instruction.t Qsp_syntax.S.repr list
+ ; pos : Qsp_syntax.S.pos
+ ; else_ : (
+ ( Analyzer.Instruction.clause list
+ * Analyzer.Instruction.t Qsp_syntax.S.repr list
+ ) option )
+ }
+
+ module Helper = Qsp_syntax.S.Helper(Analyzer.Expression)
+ module HelperI = Qsp_syntax.S.Helper(Analyzer.Instruction)
%}
%parameter<Analyzer: Qsp_syntax.S.Analyzer>
@@ -13,10 +30,11 @@ main:
| before_location*
LOCATION_START
EOL+
- expressions = line_statement*
+ instructions = line_statement*
LOCATION_END
{
- Analyzer.Location.location $loc expressions
+ let instructions = List.map instructions ~f:(HelperI.v) in
+ Analyzer.Location.location $loc instructions
}
before_location:
@@ -31,20 +49,20 @@ line_statement:
| s = terminated(inline_action, line_sep)
{ s }
| a = action_bloc(IF, elif_else_body)
- { let loc, expression, statements, loc_s, body = a in
- let elifs, else_ = match body with
+ { let {loc; expression; body; pos; else_ } = a in
+ let elifs, else_ = match else_ with
| None -> [], []
| Some (elifs, else_) -> (elifs, else_)
in
Analyzer.Instruction.if_
loc
- (loc_s, expression, statements)
+ (pos, expression, body)
~elifs
~else_
}
| a = action_bloc(ACT, empty_body)
- { let loc, label, statements, _, _ = a in
- Analyzer.Instruction.act loc ~label statements
+ { let {loc; expression; body; _} = a in
+ Analyzer.Instruction.act loc ~label:expression body
}
(** Represent an instruction which can either be on a single line,
@@ -58,7 +76,31 @@ line_statement:
b = BODY
END TOKEN?
line_sep
- { $loc, e, s, $loc(s), b }
+ {
+ let expression = Helper.v e in
+ let else_ = match b with
+ | None -> None
+ | Some (elifs, else_) ->
+ let elifs = begin match elifs with
+ | [] -> []
+ | _ ->
+ List.map elifs
+ ~f:(fun ((pos:Qsp_syntax.S.pos), e, instructions) ->
+ let e = Helper.v e in
+ (pos, e, instructions)
+ )
+
+ end in
+ Some (elifs, else_)
+ in
+
+ { loc = $loc
+ ; expression
+ ; body = s
+ ; else_ = else_
+ ; pos = $loc(s)
+ }
+ }
empty_body:
| { None }