Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dl2u の改修 #37

Merged
merged 6 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions bin/dl2u.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
open Birds
open Utils

let sort rules =
let open Result in
match Inlining.sort_rules rules with
| Error err ->
error @@ Inlining.string_of_error err
| Ok rules ->
ok rules

let simplify rules =
let open Result in
match Simplification.simplify rules with
| Error err ->
error @@ Simplification.string_of_error err
| Result.Ok rules ->
ok rules

let convert ast =
let open Result in
match Ast2sql.convert_expr_to_operation_based_sql ast with
| Error err ->
error @@ Ast2sql.show_error err
| Result.Ok operations ->
let result =
operations
|> List.map Ast2sql.stringify_sql_operation
|> String.concat "\n"
in
ok result

let main (ast : Expr.expr) =
let open ResultMonad in
sort ast.rules >>= fun rules ->
simplify rules >>= fun rules ->
let ast = { ast with rules = rules } in
convert ast

let _ =
if Array.length Sys.argv < 2 then
print_endline "Invalid arguments. File name must be passed."
Expand All @@ -7,11 +45,5 @@ let _ =
let chan = open_in filename in
let lexbuf = Lexing.from_channel chan in
let ast = Parser.main Lexer.token lexbuf in
match Ast2sql.convert_expr_to_operation_based_sql ast with
| Result.Error err ->
print_endline @@ Ast2sql.show_error err
| Result.Ok operations ->
List.iter (fun op ->
print_endline @@ Ast2sql.stringify_sql_operation op
) operations
print_endline @@ Result.fold ~ok:Fun.id ~error:Fun.id @@ main ast
end
5 changes: 5 additions & 0 deletions examples/dl2u1.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source ed('EMP_NAME':string,'DEPT_NAME':string).
source eed('EMP_NAME':string,'DEPT_NAME':string).
+eed(E, D) :- ed(E, D), D = 'A', E <> 'Joe', ¬eed(E, D).
-eed(E, D) :- ed(V1, D), eed(E, D), E = 'Joe', D = 'A', V1 <> 'Joe', ¬eed(V1, D).
+ed(E, D) :- ed(V1, D), E = 'Joe', D = 'A', V1 <> 'Joe', ¬ed(E, D), ¬eed(V1, D).
15 changes: 15 additions & 0 deletions examples/dl2u2.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
source a('AA':int, 'BB':string).
source b('BB':string, 'CC':int).

v(A,B,C) :- a(A,B), b(B,C).

-v(GENV1, GENV2, GENV3) :- v(GENV1, GENV2, GENV3) , GENV3 = 3 , GENV1 <> 4.
+v(GENV1, GENV2, GENV3) :- GENV1 = 4 , -v(GENV1_2, GENV2, GENV3).

uv(A,B,C) :- v(A, B, C), not -v(A,B,C).
uv(A,B,C) :- +v(A,B,C).

-a(A, B) :- a(A, B), not uv(A, B, _).
-b(B, C) :- b(B, C), uv(_, B, _), not uv(_, B, C).
+a(A, B) :- uv(A, B, _), not a(A, B).
+b(B, C) :- uv(_, B, C), not b(B, C).
6 changes: 6 additions & 0 deletions examples/dl2u3.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source x('A':int, 'B':string).
source y('A':int, 'B':string).

+y(D, E) :- D <> 2, D <> 3, +x(D, E), y(D, E).
-x(A, B) :- A = 1, x(A, B).
+x(A, B) :- A <> 1, x(A, B).
3 changes: 3 additions & 0 deletions examples/rulesort1.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
v(X, Y) :- X = 1, Y = 2.
+f(X) :- v(X, Y), X = 1.
-f(X) :- +f(X), X = 1.
Loading
Loading