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

(define-module (schemantic iri)
  #:use-module (oop goops)
  #:use-module (oop goops describe)

  #:use-module (web uri)

  #:use-module (ice-9 optargs)
  #:use-module (ice-9 exceptions)

  #:export (<iri>
            make-iri
            iri?
            iri-value
            define-namespace))

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

(define-method (equal? (x <iri>) (y <iri>))
  (equal? (iri-value x) (iri-value y)))

(define-generic make-iri)
(define-method (make-iri (s <string>)) (make <iri> #:value s))
(define-method (make-iri (iri <iri>)) iri)
(define-method (make-iri (x <top>))
  (if (uri? x)
      (make-iri (uri->string x))
      (no-applicable-method)))

(define (iri? x)
  "Returns true if x is an iri"
  (is-a? x <iri>))

;; Syntax for defining new namespace

(define-syntax-rule (define-namespace name uri)
  (define (name id)
    (make-iri (string-append uri id))))