Skip to content

Commit

Permalink
refactor: rename modules in bottom-up lib
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Oct 9, 2018
1 parent 57761bb commit 895e763
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .ocamlinit
Expand Up @@ -4,10 +4,10 @@
#install_printer Datalog.Default.pp_term;;
#install_printer Datalog.Default.pp_literal;;
#install_printer Datalog.Default.pp_clause;;
#install_printer Datalog.TopDown.Default.T.fmt;;
#install_printer Datalog.TopDown.Default.Lit.fmt;;
#install_printer Datalog.TopDown.Default.C.fmt;;
module CI = Datalog.CamlInterface;;
#install_printer Datalog_top_down.Default.T.fmt;;
#install_printer Datalog_top_down.Default.Lit.fmt;;
#install_printer Datalog_top_down.Default.C.fmt;;
module CI = Datalog_caml_interface;;
module CI_T = CI.Logic.T;;
module CI_DB = CI.Logic.DB;;
#install_printer CI.Rel1.fmt;;
Expand Down
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -54,15 +54,16 @@ then be unified with the goal.

## CamlInterface

The module `CamlInterface` contains a universal embedding of OCaml's types,
The module `Datalog_caml_interface` in the library `datalog.caml_interface`
contains a universal embedding of OCaml's types,
with helpers to build unary, binary, and ternary atoms that directly relate
OCaml values.

Small example:

```ocaml
# module CI = Datalog.CamlInterface;;
# module CI = Datalog_caml_interface;;
# let edge = CI.Rel2.create ~k1:CI.Univ.int ~k2:CI.Univ.int "edge";;
val edge : (int, int) CI.Rel2.t = <abstr>
# let db = CI.Logic.DB.create();;
Expand Down Expand Up @@ -90,7 +91,7 @@ One can also directly load a Datalog file (atoms: ints and strings) and access
it using (properly typed) relations:

```ocaml
# let db = CI.Logic.create ();;
# let db = CI.Logic.DB.create ();;
val db : CI.Logic.t = <abstr>
# CI.Parse.load_file db "tests/clique10.pl";;
- : bool = true
Expand Down Expand Up @@ -128,7 +129,7 @@ It is recommended to use opam: `opam install datalog`.

Manual build:

You need **OCaml >= 4.20** with [dune](https://github.com/ocaml/dune). Just type in the root directory:
You need **OCaml >= 4.02** with [dune](https://github.com/ocaml/dune). Just type in the root directory:

```sh
$ make
Expand All @@ -145,14 +146,13 @@ There are two ways to use `datalog`:
$ datalog_cli <problem_file>
```

- The library, that should be in `_build/datalog.a`. It is also registered to
OCamlfind (in the `datalog` subdirectory). It exports a `Datalog` packed
module. See the `.mli` files for documentation, or the man pages.
For both `Datalog.TopDown` and `Datalog.BottomUp`, functors are
- The libraries `datalog`, `datalog.top_down`, `datalog.unix`, `datalog.caml_interface`.
See the `.mli` files for documentation, or the online documentation.
For both `Datalog_top_down` and `Datalog.BottomUp`, functors are
provided to use your own datatype for symbols (constants);
however, a default implementation with strings as symbols is available as
`Datalog.Default` (which is used by the parser `Datalog.BottomUpParser`)
for bottom-up and in `Datalog.TopDown.Default` for top-down.
`Datalog.Default` (which is used by the parser `Datalog.Parser`)
for bottom-up and in `Datalog_top_down.Default` for top-down.

A few example files, suffixed with `.pl`, can be found in `tests/`. For instance, you
can try:
Expand Down
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,7 @@
(* this file is part of datalog. See README for the license *)

{
open BottomUpParser
open Parser

let print_location lexbuf =
let open Lexing in
Expand Down
28 changes: 14 additions & 14 deletions src/bottom_up/bottomUpParser.mly → src/bottom_up/Parser.mly
Expand Up @@ -18,19 +18,19 @@ this file is part of datalog. See README for the license
%token <string> INT

%start parse_literal
%type <BottomUpAst.literal> parse_literal
%type <AST.literal> parse_literal

%start parse_literals
%type <BottomUpAst.literal list> parse_literals
%type <AST.literal list> parse_literals

%start parse_clause
%type <BottomUpAst.clause> parse_clause
%type <AST.clause> parse_clause

%start parse_file
%type <BottomUpAst.file> parse_file
%type <AST.file> parse_file

%start parse_query
%type <BottomUpAst.query> parse_query
%type <AST.query> parse_query

%%

Expand All @@ -54,23 +54,23 @@ clauses:
| clause clauses { $1 :: $2 }

clause:
| literal DOT { BottomUpAst.Clause ($1, []) }
| literal IF literals DOT { BottomUpAst.Clause ($1, $3) }
| literal DOT { AST.Clause ($1, []) }
| literal IF literals DOT { AST.Clause ($1, $3) }

literals:
| literal { [$1] }
| literal COMMA literals { $1 :: $3 }

literal:
| LOWER_WORD { BottomUpAst.Atom ($1, []) }
| LOWER_WORD { AST.Atom ($1, []) }
| LOWER_WORD LEFT_PARENTHESIS args RIGHT_PARENTHESIS
{ BottomUpAst.Atom ($1, $3) }
{ AST.Atom ($1, $3) }

query:
| LEFT_PARENTHESIS args RIGHT_PARENTHESIS IF signed_literals
{
let pos_literals, neg_literal = $5 in
BottomUpAst.Query ($2, pos_literals, neg_literal)
AST.Query ($2, pos_literals, neg_literal)
}

signed_literals:
Expand All @@ -86,7 +86,7 @@ args:
| term COMMA args { $1 :: $3 }

term:
| INT { BottomUpAst.Const $1 }
| LOWER_WORD { BottomUpAst.Const $1 }
| UPPER_WORD { BottomUpAst.Var $1 }
| SINGLE_QUOTED { BottomUpAst.Quoted $1 }
| INT { AST.Const $1 }
| LOWER_WORD { AST.Const $1 }
| UPPER_WORD { AST.Var $1 }
| SINGLE_QUOTED { AST.Quoted $1 }
2 changes: 1 addition & 1 deletion src/bottom_up/default.ml
Expand Up @@ -3,7 +3,7 @@

(** {1 Default literal base, where symbols are just strings} *)

module A = BottomUpAst
module A = AST

module StringSymbol = BottomUp.Hashcons(struct
type t = string
Expand Down
8 changes: 4 additions & 4 deletions src/bottom_up/default.mli
Expand Up @@ -11,7 +11,7 @@ module StringSymbol : BottomUp.SymbolType with type t = string
This is a ready-to-use instance of {!BottomUp.Make}, with hashconsed strings
as symbols. It also features some handy conversion functions from
{! BottomUpBottomUpAst}.
{! BottomUpAST}.
*)

include BottomUp.S with type symbol = string
Expand All @@ -23,8 +23,8 @@ type vartbl = {

val mk_vartbl : unit -> vartbl

val literal_of_ast : ?tbl:vartbl -> BottomUpAst.literal -> literal
val literal_of_ast : ?tbl:vartbl -> AST.literal -> literal

val clause_of_ast : BottomUpAst.clause -> clause
val clause_of_ast : AST.clause -> clause

val query_of_ast : BottomUpAst.query -> (int array * literal list * literal list)
val query_of_ast : AST.query -> (int array * literal list * literal list)
4 changes: 2 additions & 2 deletions src/bottom_up/dune
Expand Up @@ -12,5 +12,5 @@
(libraries)
(flags :standard -color always -safe-string -warn-error -a+8 -w -50))

(ocamlyacc (modules bottomUpParser))
(ocamllex (modules bottomUpLexer))
(ocamlyacc (modules Parser))
(ocamllex (modules Lexer))
4 changes: 2 additions & 2 deletions src/bottom_up_cli/datalog_cli.ml
Expand Up @@ -5,8 +5,8 @@
their fixpoint *)

module DLogic = Datalog.Default
module DParser = Datalog.BottomUpParser
module DLexer = Datalog.BottomUpLexer
module DParser = Datalog.Parser
module DLexer = Datalog.Lexer

let progress = ref false
let print_input = ref false
Expand Down

0 comments on commit 895e763

Please sign in to comment.