package datalog

  1. Overview
  2. Docs

Source file AST.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

(* this file is part of datalog. See README for the license *)

(** {1 AST for TopDown terms} *)

type term =
  | Var of string
  | Apply of string * term list
  | Int of int

type aggregate = {
  ag_left : term;
  ag_constructor : string;
  ag_var : string;
  ag_guard : term;
} (* aggregate: ag_left = ag_constructor set
    where set is the set of bindings to ag_var
    that satisfy ag_guard *)

type literal =
  | LitPos of term
  | LitNeg of term
  | LitAggr of aggregate

type clause = term * literal list

type file = clause list

exception ParseError of string

let loc_to_str pos =
  Printf.sprintf "line %d, column %d"
    pos.Lexing.pos_lnum
    (pos.Lexing.pos_cnum - pos.Lexing.pos_bol)

let print_error ?(out=stderr) msg lexbuf =
  let start = Lexing.lexeme_start_p lexbuf in
  let stop = Lexing.lexeme_end_p lexbuf in
  Printf.fprintf out "parse error between %s and %s: %s\n"
    (loc_to_str start) (loc_to_str stop) msg

let error_to_string msg lexbuf =
  let start = Lexing.lexeme_start_p lexbuf in
  let stop = Lexing.lexeme_end_p lexbuf in
  Printf.sprintf "parse error between %s and %s: %s\n"
    (loc_to_str start) (loc_to_str stop) msg
OCaml

Innovation. Community. Security.