3 ;;; GNU Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
6 ;;; This file is part of GNU Mes.
8 ;;; GNU Mes is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Mes is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Minimal implementation of srfi-14, for nyacc.
27 ;; FIXME: have structs
28 (define (char-set . x)
32 (and (pair? x) (eq? (car x) '*char-set*)))
34 (define (char-set= a b)
35 (and (char-set? a) (char-set? b)
38 (define char-set:whitespace (char-set #\tab #\page #\return #\vtab #\newline #\space))
39 (define char-set:digit (apply char-set
42 (+ i (char->integer #\0))) (iota 10)))))
44 (define char-set:lower-case (apply char-set
47 (+ i (char->integer #\a))) (iota 26)))))
49 (define char-set:upper-case (apply char-set
52 (+ i (char->integer #\A))) (iota 26)))))
54 (define (list->char-set lst)
57 (define (string->char-set x . base)
58 (apply char-set (append (string->list x) (if (null? base) '() (cdar base)))))
60 (define (string->char-set! x base)
61 (set-cdr! (last-pair base) (string->list x))
64 (define (char-set-adjoin cs . chars)
67 (define (char-set-contains? cs x)
70 (define (char-set-complement cs)
71 (let ((ascii (map integer->char (iota 128))))
72 (list->char-set (filter (lambda (c) (not (char-set-contains? cs c))) ascii))))
74 (define (char-whitespace? c)
75 (char-set-contains? char-set:whitespace c))
77 (define (char-set-copy cs)
80 (define (char-upcase c)
81 (if (char-set-contains? char-set:lower-case c) (integer->char (- (char->integer c)
82 (- (char->integer #\a)
83 (char->integer #\A))))
86 (define (char-downcase c)
87 (if (char-set-contains? char-set:upper-case c) (integer->char (+ (char->integer c)
88 (- (char->integer #\a)
89 (char->integer #\A))))