xsd.scm
| 1 | ;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu> |
| 2 | ;;;; |
| 3 | ;;;; This library is free software; you can redistribute it and/or |
| 4 | ;;;; modify it under the terms of the GNU Lesser General Public |
| 5 | ;;;; License as published by the Free Software Foundation; either |
| 6 | ;;;; version 3 of the License, or (at your option) any later version. |
| 7 | ;;;; |
| 8 | ;;;; This library is distributed in the hope that it will be useful, |
| 9 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | ;;;; Lesser General Public License for more details. |
| 12 | ;;;; |
| 13 | ;;;; You should have received a copy of the GNU Lesser General Public |
| 14 | ;;;; License along with this library; if not, write to the Free Software |
| 15 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 | ;;;; |
| 17 | |
| 18 | (define-module (rdf xsd) |
| 19 | #:use-module (ice-9 match) |
| 20 | #:use-module (rdf rdf) |
| 21 | #:export (datatypes)) |
| 22 | |
| 23 | ;; This module implements the xsd datatypes, as presented in https://www.w3.org/TR/rdf11-concepts/#xsd-datatypes |
| 24 | |
| 25 | (define (make-xsd-datatype iri description lexical? value? lexical->value |
| 26 | value->lexical) |
| 27 | (make-rdf-datatype |
| 28 | (list (string-append "http://www.w3.org/2001/XMLSchema#" iri)) |
| 29 | description |
| 30 | lexical? |
| 31 | value? |
| 32 | lexical->value |
| 33 | value->lexical)) |
| 34 | |
| 35 | (define-public string |
| 36 | (make-xsd-datatype |
| 37 | "string" |
| 38 | "Character strings (but not all Unicode character strings)" |
| 39 | string? |
| 40 | string? |
| 41 | identity |
| 42 | identity)) |
| 43 | |
| 44 | (define-public boolean |
| 45 | (make-xsd-datatype |
| 46 | "boolean" |
| 47 | "true, false" |
| 48 | (lambda (lexical) |
| 49 | (member lexical '("true" "false" "0" "1"))) |
| 50 | boolean? |
| 51 | (lambda (lexical) |
| 52 | (match lexical |
| 53 | ("true" #t) |
| 54 | ("1" #t) |
| 55 | ("false" #f) |
| 56 | ("0" #f))) |
| 57 | (lambda (value) |
| 58 | (match value |
| 59 | (#t "true") |
| 60 | (#f "false"))))) |
| 61 | |
| 62 | (define-public decimal |
| 63 | (make-xsd-datatype |
| 64 | "decimal" |
| 65 | "Arbitrary-precision decimal numbers" |
| 66 | string->number |
| 67 | number? |
| 68 | string->number |
| 69 | number->string)) |
| 70 | |
| 71 | (define-public integer |
| 72 | (make-xsd-datatype |
| 73 | "integer" |
| 74 | "Arbitrary-size integer numbers" |
| 75 | (lambda (lexical) |
| 76 | (integer? (string->number lexical))) |
| 77 | integer? |
| 78 | string->number |
| 79 | number->string)) |
| 80 | |
| 81 | (define datatypes |
| 82 | (list string boolean decimal integer)) |
| 83 |