summaryrefslogtreecommitdiff
path: root/schemantic/literal.scm
blob: 617f732a247a3516fb19c1a647526c9e57235cd3 (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
; SPDX-FileCopyrightText: 2020 pukkamustard <pukkamustard@posteo.net>
;
; SPDX-License-Identifier: GPL-3.0-or-later

(define-module (schemantic literal)
  #:use-module (oop goops)

  #:use-module (schemantic iri)

  #:export (<literal>
            literal?
            make-literal
            make-generic-literal
            literal-value
            literal-lexical
            literal-canonical
            literal-datatype))

(define-class <literal> ()
  (value #:init-keyword #:value #:getter literal-value))

(define (literal? x)
  (is-a? x <literal>))

(define-generic make-literal)
(define-method (make-literal (l <literal>)) l)

(define-generic literal-lexical)
(define-generic literal-canonical)
(define-generic literal-datatype)

;; Generic literal

(define-class <generic-literal> (<literal>)
  (datatype #:init-keyword #:datatype))

(define-method (literal-datatype (l <generic-literal>)) (slot-ref l 'datatype))

(define* (make-generic-literal value #:key datatype)
  (if (iri? datatype)
      (make <generic-literal> #:value value #:datatype datatype)
      #f))