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