summaryrefslogtreecommitdiff
path: root/schemantic/iri.scm
diff options
context:
space:
mode:
Diffstat (limited to 'schemantic/iri.scm')
-rw-r--r--schemantic/iri.scm43
1 files changed, 43 insertions, 0 deletions
diff --git a/schemantic/iri.scm b/schemantic/iri.scm
new file mode 100644
index 0000000..54cb5e5
--- /dev/null
+++ b/schemantic/iri.scm
@@ -0,0 +1,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))))
+