From 0b75cd5bc0f7d0ad905bce5bebc6e47c927f64d7 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Mon, 16 Oct 2023 16:42:53 +0200 Subject: Used the dead-end checker in main analysis --- lib/qparser/parser.mly | 22 +++++++++++----------- lib/qparser/qsp_instruction.mly | 8 +++++--- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'lib/qparser') diff --git a/lib/qparser/parser.mly b/lib/qparser/parser.mly index fd3f85b..63b9577 100644 --- a/lib/qparser/parser.mly +++ b/lib/qparser/parser.mly @@ -10,9 +10,9 @@ -> Analyzer.Expression.t' * Qsp_syntax.Report.t list ; body : Analyzer.Instruction.t Qsp_syntax.S.repr list ; pos : Qsp_syntax.S.pos - ; else_ : ( + ; clauses : ( ( (Analyzer.Instruction.expression, Analyzer.Instruction.t) Qsp_syntax.S.clause list - * Analyzer.Instruction.t Qsp_syntax.S.repr list + * (Qsp_syntax.S.pos *Analyzer.Instruction.t Qsp_syntax.S.repr list) option ) option ) } @@ -49,9 +49,9 @@ line_statement: | s = terminated(inline_action, line_sep) { s } | a = action_bloc(IF, elif_else_body) - { let {loc; expression; body; pos; else_ } = a in - let elifs, else_ = match else_ with - | None -> [], [] + { let {loc; expression; body; pos; clauses } = a in + let elifs, else_ = match clauses with + | None -> [], None | Some (elifs, else_) -> (elifs, else_) in Analyzer.Instruction.if_ @@ -78,9 +78,9 @@ line_statement: line_sep { let expression = Helper.v e in - let else_ = match b with + let clauses = match b with | None -> None - | Some (elifs, else_) -> + | Some (elifs, clauses) -> let elifs = begin match elifs with | [] -> [] | _ -> @@ -91,13 +91,13 @@ line_statement: ) end in - Some (elifs, else_) + Some (elifs, clauses) in { loc = $loc ; expression ; body = s - ; else_ = else_ + ; clauses ; pos = $loc(s) } } @@ -115,8 +115,8 @@ elif: else_: | ELSE EOL+ expressions = line_statement* - { expressions } - | { [] } + { Some ($loc, expressions) } + | { None } elif_else_body: diff --git a/lib/qparser/qsp_instruction.mly b/lib/qparser/qsp_instruction.mly index fe8a51a..8272cff 100644 --- a/lib/qparser/qsp_instruction.mly +++ b/lib/qparser/qsp_instruction.mly @@ -25,7 +25,9 @@ argument(X): else_opt = preceded(ELSE, instruction)? { let loc, expr, statements, loc_s, _body = a in let elifs = [] - and else_ = Option.to_list else_opt in + and else_ = match else_opt with + | None -> None + | Some instructions -> Some ($loc(else_opt), [ instructions ]) in Analyzer.Instruction.if_ loc (loc_s, Helper.v expr, statements) @@ -33,10 +35,10 @@ argument(X): ~else_ } | a = onliner(IF) - else_= preceded(ELSE, inline_action) + else_ = preceded(ELSE, inline_action) { let loc, expr, statements, loc_s, _body = a in let elifs = [] - and else_ = [ else_ ] in + and else_ = Some ($loc(else_), [ else_ ]) in Analyzer.Instruction.if_ loc -- cgit v1.2.3