aboutsummaryrefslogtreecommitdiff
path: root/lib/core/literal.ml
blob: 42e31e7bcb6a790c64b42fe878c140dfcb2627a3 (plain)
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
(*
 * SPDX-FileCopyrightText: 2021 petites singularités <ps-dream@lesoiseaux.io>
 * SPDX-FileCopyrightText: 2021 pukkamustard <pukkamustard@posteo.net>
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 *)

module Iri = Uri

type t = {
  value: string;
  datatype: Iri.t;
  language: string option;
}

let make value ?language datatype =
  { value; datatype; language }

let canonical literal =
  literal.value

let datatype literal =
  literal.datatype

let language literal =
  literal.language

let equal a b =
  (String.equal a.value b.value)
  &&
  (Iri.equal a.datatype b.datatype)
  &&
  (Option.equal String.equal a.language b.language)

let compare a b =
  let result = String.compare
      (Iri.to_string a.datatype ^ canonical a)
      (Iri.to_string b.datatype ^ canonical b)
  in
  Format.printf "compare literal: %d\n" result;
  result

let pp ppf literal =
  (* TODO print the datatype and language *)
  Fmt.pf ppf "@[<h 1><literal@ %s>@]" (canonical literal)