Skip to content

Commit 50f427f

Browse files
committed
Handle errors for Sakura directive + make them qualified
1 parent 43b647e commit 50f427f

2 files changed

Lines changed: 60 additions & 20 deletions

File tree

lib/Ast.ml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,20 @@ module Expr = struct
6666
Logger.simply_error "Trying to extract a variable wrongly";
6767
exit 1
6868

69+
let extract_qualified_func_label :
70+
func -> string Location.with_location * string Location.with_location =
71+
function
72+
| { name = [], name; _ } ->
73+
Logger.error name.loc "Expected functor to have an unqualified label";
74+
exit 1
75+
| { name = [ qualifier ], name; _ } -> (qualifier, name)
76+
| { name = qualifier :: _, _; _ } ->
77+
Logger.error qualifier.loc "Expected functor to have a single qualifier";
78+
exit 1
79+
6980
let extract_func_label : func -> string = function
7081
| { name = [], name; _ } -> name.content
7182
| { name = first_segment :: _, _; _ } ->
72-
Logger.simply_error first_segment.content;
7383
Logger.error first_segment.loc
7484
"Expected functor to have an unqualified label";
7585
exit 1

lib/database/Directive.ml

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
open Compiler.Types
22

3+
module Error = struct
4+
module Set = BatSet.String
5+
6+
let supported_directives =
7+
Set.of_list [ "persisted"; "ephemeral"; "constraint"; "stored" ]
8+
9+
let treat_error_cases
10+
((qualifier, name) :
11+
string Location.with_location * string Location.with_location)
12+
(arity : int) : unit =
13+
if arity <> 0 then (
14+
Logger.error qualifier.loc "Sakura directives should be qualified atoms";
15+
exit 1)
16+
else if qualifier.content = "sakura" then (
17+
if Set.mem name.content supported_directives then ()
18+
else Logger.error name.loc @@ "Undefined Sakura directive:" ^ name.content;
19+
exit 1)
20+
else (
21+
Logger.error qualifier.loc
22+
"Sakura directives should be qualified with 'sakura'";
23+
exit 1)
24+
end
25+
326
let compile (directive_loc : Location.location)
427
({ arity; _ } as func : Ast.Expr.func) (body : Ast.Clause.t list list)
528
(step : Ast.Clause.t list * t -> t)
@@ -17,22 +40,29 @@ let compile (directive_loc : Location.location)
1740
| "project", 0, _ ->
1841
Logger.error directive_loc "Sakura does not support project directive";
1942
exit 1
20-
| "persisted", _, _ ->
21-
Logger.error directive_loc
22-
"TODO: persisted directive is not yet implemented";
23-
exit 1
24-
| "ephemeral", _, _ ->
25-
Logger.error directive_loc
26-
"TODO: ephemeral directive is not yet implemented";
27-
exit 1
28-
| "constraint", _, _ ->
29-
Logger.error directive_loc
30-
"TODO: constraint directive is not yet implemented";
31-
exit 1
32-
| "stored", _, _ ->
33-
Logger.unreachable directive_loc
34-
"Stored procedures are not supported in Sakura yet";
35-
exit 1
36-
| _ ->
37-
Logger.simply_unreachable "Unknown directive for Sakura";
38-
exit 1
43+
| _ -> (
44+
let open Location in
45+
let ((qualifier, name) as func_label) =
46+
Ast.Expr.extract_qualified_func_label func
47+
in
48+
match (qualifier.content, name.content, arity) with
49+
| "sakura", "persisted", 0 ->
50+
Logger.error directive_loc
51+
"TODO: persisted directive is not yet implemented";
52+
exit 1
53+
| "sakura", "ephemeral", 0 ->
54+
Logger.error directive_loc
55+
"TODO: ephemeral directive is not yet implemented";
56+
exit 1
57+
| "sakura", "constraint", 0 ->
58+
Logger.error directive_loc
59+
"TODO: constraint directive is not yet implemented";
60+
exit 1
61+
| "sakura", "stored", 0 ->
62+
Logger.unreachable directive_loc
63+
"Stored procedures are not supported in Sakura yet";
64+
exit 1
65+
| _ ->
66+
Error.treat_error_cases func_label arity;
67+
Logger.simply_unreachable "Unknown directive for Sakura";
68+
exit 1)

0 commit comments

Comments
 (0)