aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorStefan Monnier2020-01-15 16:50:50 -0500
committerStefan Monnier2020-01-15 16:50:50 -0500
commita70feb0d730e5c70d7f75cff4fea66ec2ddf38dd (patch)
tree0e57ee83f1d47131aafedc8089434347a5107b4d /admin
parent576dfc8aa260957f4d0dc0c68cdcb8232a536f42 (diff)
downloademacs-a70feb0d730e5c70d7f75cff4fea66ec2ddf38dd.tar.gz
emacs-a70feb0d730e5c70d7f75cff4fea66ec2ddf38dd.zip
* admin/unidata/unidata-gen.el: Use lexical-binding
(unidata-prop): Use defstruct to define the 6 accessor functions. (unidata-gen-table-character, unidata-gen-table, unidata-gen-table-name) (unidata-check): Move common code out of `if`. (unidata-word-list-diff, unidata-split-decomposition): Move common code out of `if`; use `push`.
Diffstat (limited to 'admin')
-rw-r--r--admin/unidata/unidata-gen.el159
1 files changed, 77 insertions, 82 deletions
diff --git a/admin/unidata/unidata-gen.el b/admin/unidata/unidata-gen.el
index 71959d633c5..73453cb9e47 100644
--- a/admin/unidata/unidata-gen.el
+++ b/admin/unidata/unidata-gen.el
@@ -1,4 +1,4 @@
1;; unidata-gen.el -- Create files containing character property data. 1;; unidata-gen.el -- Create files containing character property data -*- lexical-binding:t -*-
2 2
3;; Copyright (C) 2008-2020 Free Software Foundation, Inc. 3;; Copyright (C) 2008-2020 Free Software Foundation, Inc.
4 4
@@ -349,13 +349,10 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
349 (n o c))))) 349 (n o c)))))
350 350
351;; Functions to access the above data. 351;; Functions to access the above data.
352(defsubst unidata-prop-prop (proplist) (nth 0 proplist)) 352(cl-defstruct (unidata-prop
353(defsubst unidata-prop-index (proplist) (nth 1 proplist)) 353 (:type list)
354(defsubst unidata-prop-generator (proplist) (nth 2 proplist)) 354 (:constructor nil))
355(defsubst unidata-prop-docstring (proplist) (nth 3 proplist)) 355 prop index generator docstring describer default val-list)
356(defsubst unidata-prop-describer (proplist) (nth 4 proplist))
357(defsubst unidata-prop-default (proplist) (nth 5 proplist))
358(defsubst unidata-prop-val-list (proplist) (nth 6 proplist))
359 356
360 357
361;; SIMPLE TABLE 358;; SIMPLE TABLE
@@ -383,11 +380,11 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
383;; 3rd: 0 (corresponding to uniprop_encode_character in chartab.c) 380;; 3rd: 0 (corresponding to uniprop_encode_character in chartab.c)
384;; 4th to 5th: nil 381;; 4th to 5th: nil
385 382
386(defun unidata-gen-table-character (prop prop-idx &rest ignore) 383(defun unidata-gen-table-character (prop prop-idx &rest _ignore)
387 (let ((table (make-char-table 'char-code-property-table)) 384 (let ((table (make-char-table 'char-code-property-table))
388 (vec (make-vector 128 0)) 385 (vec (make-vector 128 0))
389 (tail unidata-list) 386 (tail unidata-list)
390 elt range val idx slot) 387 elt range val)
391 (if (functionp prop-idx) 388 (if (functionp prop-idx)
392 (setq tail (funcall prop-idx) 389 (setq tail (funcall prop-idx)
393 prop-idx 1)) 390 prop-idx 1))
@@ -395,9 +392,9 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
395 (setq elt (car tail) tail (cdr tail)) 392 (setq elt (car tail) tail (cdr tail))
396 (setq range (car elt) 393 (setq range (car elt)
397 val (nth prop-idx elt)) 394 val (nth prop-idx elt))
398 (if (= (length val) 0) 395 (setq val (if (= (length val) 0)
399 (setq val nil) 396 nil
400 (setq val (string-to-number val 16))) 397 (string-to-number val 16)))
401 (if (consp range) 398 (if (consp range)
402 (if val 399 (if val
403 (set-char-table-range table range val)) 400 (set-char-table-range table range val))
@@ -419,8 +416,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
419 (setq first-index last-index))) 416 (setq first-index last-index)))
420 (setq tail (cdr tail))) 417 (setq tail (cdr tail)))
421 (when first-index 418 (when first-index
422 (let ((str (string 1 first-index)) 419 (let ((str (string 1 first-index)))
423 c)
424 (while (<= first-index last-index) 420 (while (<= first-index last-index)
425 (setq str (format "%s%c" str (or (aref vec first-index) 0)) 421 (setq str (format "%s%c" str (or (aref vec first-index) 0))
426 first-index (1+ first-index))) 422 first-index (1+ first-index)))
@@ -502,7 +498,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
502 ;; bidi.c:bidi_get_type and bidi.c:bidi_get_category. 498 ;; bidi.c:bidi_get_type and bidi.c:bidi_get_category.
503 (bidi-warning "\ 499 (bidi-warning "\
504** Found new bidi-class `%s', please update bidi.c and dispextern.h") 500** Found new bidi-class `%s', please update bidi.c and dispextern.h")
505 tail elt range val val-code idx slot 501 tail elt range val val-code
506 prev-range-data) 502 prev-range-data)
507 (setq val-list (cons nil (copy-sequence val-list))) 503 (setq val-list (cons nil (copy-sequence val-list)))
508 (setq tail val-list val-code 0) 504 (setq tail val-list val-code 0)
@@ -510,9 +506,9 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
510 (while tail 506 (while tail
511 (setcar tail (cons (car tail) val-code)) 507 (setcar tail (cons (car tail) val-code))
512 (setq tail (cdr tail) val-code (1+ val-code))) 508 (setq tail (cdr tail) val-code (1+ val-code)))
513 (if (consp default-value) 509 (setq default-value (if (consp default-value)
514 (setq default-value (copy-sequence default-value)) 510 (copy-sequence default-value)
515 (setq default-value (list default-value))) 511 (list default-value)))
516 (setcar default-value 512 (setcar default-value
517 (unidata-encode-val val-list (car default-value))) 513 (unidata-encode-val val-list (car default-value)))
518 (set-char-table-range table t (car default-value)) 514 (set-char-table-range table t (car default-value))
@@ -602,17 +598,17 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
602 (if (= count 128) 598 (if (= count 128)
603 (if val 599 (if val
604 (set-char-table-range table (cons start limit) val-code)) 600 (set-char-table-range table (cons start limit) val-code))
605 (if (= val-code 0) 601 (set-char-table-range table (cons start limit)
606 (set-char-table-range table (cons start limit) str) 602 (if (= val-code 0)
607 (if (> count 2) 603 str
608 (setq str (concat str (string val-code (+ count 128)))) 604 (concat str (if (> count 2)
609 (if (= count 2) 605 (string val-code (+ count 128))
610 (setq str (concat str (string val-code val-code))) 606 (if (= count 2)
611 (setq str (concat str (string val-code))))) 607 (string val-code val-code)
612 (set-char-table-range table (cons start limit) str)))))) 608 (string val-code))))))))))
613 609
614 (set-char-table-extra-slot table 0 prop) 610 (set-char-table-extra-slot table 0 prop)
615 (set-char-table-extra-slot table 4 (vconcat (mapcar 'car val-list))) 611 (set-char-table-extra-slot table 4 (vconcat (mapcar #'car val-list)))
616 table)) 612 table))
617 613
618(defun unidata-gen-table-symbol (prop index default-value val-list) 614(defun unidata-gen-table-symbol (prop index default-value val-list)
@@ -679,8 +675,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
679 (let ((beg 0) 675 (let ((beg 0)
680 (end 0) 676 (end 0)
681 (len1 (length l1)) 677 (len1 (length l1))
682 (len2 (length l2)) 678 (len2 (length l2)))
683 result)
684 (when (< len1 16) 679 (when (< len1 16)
685 (while (and l1 (eq (car l1) (car l2))) 680 (while (and l1 (eq (car l1) (car l2)))
686 (setq beg (1+ beg) 681 (setq beg (1+ beg)
@@ -688,13 +683,13 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
688 (while (and (< end len1) (< end len2) 683 (while (and (< end len1) (< end len2)
689 (eq (nth (- len1 end 1) l1) (nth (- len2 end 1) l2))) 684 (eq (nth (- len1 end 1) l1) (nth (- len2 end 1) l2)))
690 (setq end (1+ end)))) 685 (setq end (1+ end))))
691 (if (= (+ beg end) 0) 686 (let ((result (list (if (= (+ beg end) 0)
692 (setq result (list -1)) 687 -1
693 (setq result (list (+ (* beg 16) (+ beg (- len1 end)))))) 688 (+ (* beg 16) (+ beg (- len1 end)))))))
694 (while (< end len2) 689 (while (< end len2)
695 (setcdr result (cons (nth (- len2 end 1) l2) (cdr result))) 690 (push (nth (- len2 end 1) l2) (cdr result))
696 (setq end (1+ end))) 691 (setq end (1+ end)))
697 result)) 692 result)))
698 693
699;; Return a compressed form of the vector VEC. Each element of VEC is 694;; Return a compressed form of the vector VEC. Each element of VEC is
700;; a list of symbols of which names can be concatenated to form a 695;; a list of symbols of which names can be concatenated to form a
@@ -703,7 +698,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
703;; elements is usually small. 698;; elements is usually small.
704 699
705(defun unidata-word-list-compress (vec) 700(defun unidata-word-list-compress (vec)
706 (let (last-elt last-idx diff-head tail elt val) 701 (let (last-elt last-idx diff-head elt val)
707 (dotimes (i 128) 702 (dotimes (i 128)
708 (setq elt (aref vec i)) 703 (setq elt (aref vec i))
709 (when elt 704 (when elt
@@ -768,7 +763,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
768 (vec (make-vector 128 nil)) 763 (vec (make-vector 128 nil))
769 (idx 0) 764 (idx 0)
770 (case-fold-search nil) 765 (case-fold-search nil)
771 c word-list tail-list last-list word diff-head) 766 c word-list tail-list last-list diff-head)
772 (while (< i len) 767 (while (< i len)
773 (setq c (aref val i)) 768 (setq c (aref val i))
774 (if (< c 3) 769 (if (< c 3)
@@ -784,7 +779,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
784 (setq diff-head 779 (setq diff-head
785 (prog1 (aref val i) (setq i (1+ i))))) 780 (prog1 (aref val i) (setq i (1+ i)))))
786 (setq tail-list (nthcdr (% diff-head 16) last-list)) 781 (setq tail-list (nthcdr (% diff-head 16) last-list))
787 (dotimes (i (/ diff-head 16)) 782 (dotimes (_ (/ diff-head 16))
788 (setq word-list (nconc word-list (list (car l))) 783 (setq word-list (nconc word-list (list (car l)))
789 l (cdr l)))))) 784 l (cdr l))))))
790 (setq word-list 785 (setq word-list
@@ -808,7 +803,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
808 (setcdr tail (cons elt (cdr tail))) 803 (setcdr tail (cons elt (cdr tail)))
809 (setcar tail " "))) 804 (setcar tail " ")))
810 (setq tail (cddr tail))) 805 (setq tail (cddr tail)))
811 (setq name (apply 'concat name)))) 806 (setq name (apply #'concat name))))
812 (aset table c name) 807 (aset table c name)
813 (if (= c char) 808 (if (= c char)
814 (setq val name)))) 809 (setq val name))))
@@ -872,7 +867,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
872 (vec (make-vector 128 nil)) 867 (vec (make-vector 128 nil))
873 (idx 0) 868 (idx 0)
874 (case-fold-search nil) 869 (case-fold-search nil)
875 c word-list tail-list last-list word diff-head) 870 c word-list tail-list last-list diff-head)
876 (while (< i len) 871 (while (< i len)
877 (setq c (aref val i)) 872 (setq c (aref val i))
878 (if (< c 3) 873 (if (< c 3)
@@ -888,7 +883,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
888 (setq diff-head 883 (setq diff-head
889 (prog1 (aref val i) (setq i (1+ i))))) 884 (prog1 (aref val i) (setq i (1+ i)))))
890 (setq tail-list (nthcdr (% diff-head 16) last-list)) 885 (setq tail-list (nthcdr (% diff-head 16) last-list))
891 (dotimes (i (/ diff-head 16)) 886 (dotimes (_ (/ diff-head 16))
892 (setq word-list (nconc word-list (list (car l))) 887 (setq word-list (nconc word-list (list (car l)))
893 l (cdr l)))))) 888 l (cdr l))))))
894 (setq word-list 889 (setq word-list
@@ -945,7 +940,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
945 (word-list (list nil)) 940 (word-list (list nil))
946 word-table 941 word-table
947 block-list block-word-table block-end 942 block-list block-word-table block-end
948 tail elt range val idx slot) 943 tail elt range val idx)
949 (setq tail unidata-list) 944 (setq tail unidata-list)
950 (setq block-end -1) 945 (setq block-end -1)
951 (while tail 946 (while tail
@@ -984,9 +979,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
984 (push (list val range) block-list)))) 979 (push (list val range) block-list))))
985 (let* ((start (ash (ash range -7) 7)) 980 (let* ((start (ash (ash range -7) 7))
986 (limit (+ start 127)) 981 (limit (+ start 127))
987 (first tail) 982 (vec (make-vector 128 nil)))
988 (vec (make-vector 128 nil))
989 c name len)
990 (if (<= start block-end) 983 (if (<= start block-end)
991 ;; START overlap with the previous block. 984 ;; START overlap with the previous block.
992 (aset table range (nth prop-idx elt)) 985 (aset table range (nth prop-idx elt))
@@ -1037,10 +1030,10 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
1037 (cdr (assq elt word-list)))) 1030 (cdr (assq elt word-list))))
1038 (setcar tail (string code)) 1031 (setcar tail (string code))
1039 (setq tail (cdr tail))) 1032 (setq tail (cdr tail)))
1040 (aset vec i (mapconcat 'identity (aref vec i) ""))))) 1033 (aset vec i (mapconcat #'identity (aref vec i) "")))))
1041 (set-char-table-range 1034 (set-char-table-range
1042 table (cons idx (+ idx 127)) 1035 table (cons idx (+ idx 127))
1043 (mapconcat 'identity vec ""))))) 1036 (mapconcat #'identity vec "")))))
1044 1037
1045 (setq block-word-table (make-vector (length block-list) nil)) 1038 (setq block-word-table (make-vector (length block-list) nil))
1046 (setq idx 0) 1039 (setq idx 0)
@@ -1086,19 +1079,18 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
1086 (or (byte-code-function-p (symbol-function fun)) 1079 (or (byte-code-function-p (symbol-function fun))
1087 (byte-compile fun)))) 1080 (byte-compile fun))))
1088 1081
1089(defun unidata-gen-table-name (prop index &rest ignore) 1082(defun unidata-gen-table-name (prop index &rest _ignore)
1090 (let* ((table (unidata-gen-table-word-list prop index 'unidata-split-name)) 1083 (let* ((table (unidata-gen-table-word-list prop index 'unidata-split-name))
1091 (word-tables (char-table-extra-slot table 4))) 1084 (word-tables (char-table-extra-slot table 4)))
1092 (unidata--ensure-compiled 'unidata-get-name 'unidata-put-name) 1085 (unidata--ensure-compiled 'unidata-get-name 'unidata-put-name)
1093 (set-char-table-extra-slot table 1 (symbol-function 'unidata-get-name)) 1086 (set-char-table-extra-slot table 1 (symbol-function 'unidata-get-name))
1094 (set-char-table-extra-slot table 2 (symbol-function 'unidata-put-name)) 1087 (set-char-table-extra-slot table 2 (symbol-function 'unidata-put-name))
1095 1088
1096 (if (eq prop 'name) 1089 (set-char-table-extra-slot table 4
1097 (set-char-table-extra-slot table 4 1090 (if (eq prop 'name)
1098 (vector (car word-tables) 1091 (vector (car word-tables)
1099 (cdr word-tables) 1092 (cdr word-tables)
1100 unidata-name-jamo-name-table)) 1093 unidata-name-jamo-name-table)
1101 (set-char-table-extra-slot table 4
1102 (vector (car word-tables)))) 1094 (vector (car word-tables))))
1103 table)) 1095 table))
1104 1096
@@ -1107,24 +1099,25 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
1107 str 1099 str
1108 (let ((len (length str)) 1100 (let ((len (length str))
1109 (l nil) 1101 (l nil)
1110 (idx 0) 1102 (idx 0))
1111 c)
1112 (if (= len 0) 1103 (if (= len 0)
1113 nil 1104 nil
1114 (dotimes (i len) 1105 (dotimes (i len)
1115 (setq c (aref str i)) 1106 (let ((c (aref str i)))
1116 (if (= c 32) 1107 (when (= c ?\s)
1117 (setq l (if (= (aref str idx) ?<) 1108 (push (if (= (aref str idx) ?<)
1118 (cons (intern (substring str (1+ idx) (1- i))) l) 1109 (intern (substring str (1+ idx) (1- i)))
1119 (cons (string-to-number (substring str idx i) 16) l)) 1110 (string-to-number (substring str idx i) 16))
1120 idx (1+ i)))) 1111 l)
1121 (if (= (aref str idx) ?<) 1112 (setq idx (1+ i)))))
1122 (setq l (cons (intern (substring str (1+ idx) (1- len))) l)) 1113 (push (if (= (aref str idx) ?<)
1123 (setq l (cons (string-to-number (substring str idx len) 16) l))) 1114 (intern (substring str (1+ idx) (1- len)))
1115 (string-to-number (substring str idx len) 16))
1116 l)
1124 (nreverse l))))) 1117 (nreverse l)))))
1125 1118
1126 1119
1127(defun unidata-gen-table-decomposition (prop index &rest ignore) 1120(defun unidata-gen-table-decomposition (prop index &rest _ignore)
1128 (let* ((table (unidata-gen-table-word-list prop index 'unidata-split-decomposition)) 1121 (let* ((table (unidata-gen-table-word-list prop index 'unidata-split-decomposition))
1129 (word-tables (char-table-extra-slot table 4))) 1122 (word-tables (char-table-extra-slot table 4)))
1130 (unidata--ensure-compiled 'unidata-get-decomposition 1123 (unidata--ensure-compiled 'unidata-get-decomposition
@@ -1167,7 +1160,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
1167 (forward-line))) 1160 (forward-line)))
1168 result)) 1161 result))
1169 1162
1170(defun unidata-gen-table-special-casing (prop prop-idx &rest ignore) 1163(defun unidata-gen-table-special-casing (prop prop-idx &rest _ignore)
1171 (let ((table (make-char-table 'char-code-property-table))) 1164 (let ((table (make-char-table 'char-code-property-table)))
1172 (set-char-table-extra-slot table 0 prop) 1165 (set-char-table-extra-slot table 0 prop)
1173 (mapc (lambda (entry) 1166 (mapc (lambda (entry)
@@ -1175,7 +1168,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
1175 ;; If character maps to a single character, the mapping is already 1168 ;; If character maps to a single character, the mapping is already
1176 ;; covered by regular casing property. Don’t store those. 1169 ;; covered by regular casing property. Don’t store those.
1177 (when (/= (length v) 1) 1170 (when (/= (length v) 1)
1178 (set-char-table-range table ch (apply 'string v))))) 1171 (set-char-table-range table ch (apply #'string v)))))
1179 (or unidata-gen-table-special-casing--cache 1172 (or unidata-gen-table-special-casing--cache
1180 (setq unidata-gen-table-special-casing--cache 1173 (setq unidata-gen-table-special-casing--cache
1181 (unidata-gen-table-special-casing--do-load)))) 1174 (unidata-gen-table-special-casing--do-load))))
@@ -1353,7 +1346,7 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
1353 ;; unidata-gen-table-special-casing--do-load and there is no other file 1346 ;; unidata-gen-table-special-casing--do-load and there is no other file
1354 ;; to compare those values with. This is why we’re skipping the check 1347 ;; to compare those values with. This is why we’re skipping the check
1355 ;; for special casing properties. 1348 ;; for special casing properties.
1356 (unless (eq generator 'unidata-gen-table-special-casing) 1349 (unless (eq generator #'unidata-gen-table-special-casing)
1357 (setq table (progn 1350 (setq table (progn
1358 (message "Generating %S table..." prop) 1351 (message "Generating %S table..." prop)
1359 (funcall generator prop index default-value val-list)) 1352 (funcall generator prop index default-value val-list))
@@ -1369,19 +1362,21 @@ Property value is a symbol `o' (Open), `c' (Close), or `n' (None)."
1369 (and (stringp val1) 1362 (and (stringp val1)
1370 (= (length val1) 0) 1363 (= (length val1) 0)
1371 (setq val1 nil)) 1364 (setq val1 nil))
1372 (if val1 1365 (setq val1
1373 (cond ((eq generator 'unidata-gen-table-symbol) 1366 (if val1
1374 (setq val1 (intern val1))) 1367 (cond ((eq generator #'unidata-gen-table-symbol)
1375 ((eq generator 'unidata-gen-table-integer) 1368 (intern val1))
1376 (setq val1 (string-to-number val1))) 1369 ((eq generator #'unidata-gen-table-integer)
1377 ((eq generator 'unidata-gen-table-character) 1370 (string-to-number val1))
1378 (setq val1 (string-to-number val1 16))) 1371 ((eq generator #'unidata-gen-table-character)
1379 ((eq generator 'unidata-gen-table-decomposition) 1372 (string-to-number val1 16))
1380 (setq val1 (unidata-split-decomposition val1)))) 1373 ((eq generator #'unidata-gen-table-decomposition)
1381 (cond ((eq prop 'decomposition) 1374 (unidata-split-decomposition val1))
1382 (setq val1 (list char))) 1375 (t val1))
1383 ((eq prop 'bracket-type) 1376 (cond ((eq prop 'decomposition)
1384 (setq val1 'n)))) 1377 (list char))
1378 ((eq prop 'bracket-type)
1379 'n))))
1385 (setq val2 (aref table char)) 1380 (setq val2 (aref table char))
1386 (when decoder 1381 (when decoder
1387 (setq val2 (funcall decoder char val2 table))) 1382 (setq val2 (funcall decoder char val2 table)))