74 lines
1.7 KiB
Scheme
74 lines
1.7 KiB
Scheme
#!@GUILE@ --no-auto-compile
|
|
-*- scheme -*-
|
|
!#
|
|
|
|
;; Can be called with a trailing argument pointing to the file on disk.
|
|
|
|
(use-modules
|
|
(uniseg internal)
|
|
(ice-9 pretty-print)
|
|
(ice-9 peg)
|
|
(ice-9 match)
|
|
(srfi srfi-1))
|
|
|
|
(define stdout (current-output-port))
|
|
|
|
(define url
|
|
"https://unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt")
|
|
|
|
(define emoji-ht (make-hash-table 5))
|
|
|
|
(define emoji-properties
|
|
'(emoji
|
|
emoji-presentation
|
|
emoji-modifier
|
|
emoji-modifier-base
|
|
emoji-component
|
|
emoji-extended-pictographic))
|
|
|
|
(define emoji-symbols
|
|
(map
|
|
(λ (prop) (symbol-with-prefix "char-set:" prop))
|
|
emoji-properties))
|
|
|
|
(define (string->property str comment)
|
|
(match str
|
|
("Emoji" 'emoji)
|
|
("Emoji_Presentation" 'emoji-presentation)
|
|
("Emoji_Modifier" 'emoji-modifier)
|
|
("Emoji_Modifier_Base" 'emoji-modifier-base)
|
|
("Emoji_Component" 'emoji-component)
|
|
("Extended_Pictographic" 'emoji-extended-pictographic)))
|
|
|
|
(define file "uniseg/charsets/emoji.scm")
|
|
|
|
(format stdout "Writing to ~a...\n" file)
|
|
|
|
(with-output-to-file file
|
|
(λ ()
|
|
(format #t ";; Code generated by ~a. DO NOT EDIT\n\n" (basename (current-filename)))
|
|
|
|
(pretty-print
|
|
`(define-module (uniseg charsets emoji)
|
|
#:use-module (uniseg internal)
|
|
#:use-module (ice-9 hash-table)
|
|
#:use-module (srfi srfi-1)
|
|
#:export (,@emoji-symbols
|
|
emoji-charsets)))
|
|
|
|
(define-values (process-line print-to-file)
|
|
(make-line-processor
|
|
emoji-ht
|
|
string->property
|
|
emoji-properties
|
|
emoji-symbols
|
|
'emoji-charsets
|
|
stdout))
|
|
|
|
(for-each process-line (cmdline-wget-or-file url stdout))
|
|
(print-to-file)
|
|
|
|
(display "Code generation complete.\n" stdout)))
|
|
|
|
(format stdout "Written to ~a.\n" file)
|