From 69d775b3d3a8f5bdb920630c7bdf6ec1b264b203 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Fri, 24 Oct 2025 08:09:46 +0300 Subject: Configure a custom readtable explicitly --- src/inline-bots.lisp | 6 +++--- src/main.lisp | 6 +++--- src/readtable.lisp | 14 ++++++++++++++ src/rw-lock.lisp | 8 ++++---- src/state.lisp | 6 +++--- src/tg/method-macros.lisp | 7 +++---- src/tg/type-macros.lisp | 9 ++++----- 7 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 src/readtable.lisp (limited to 'src') diff --git a/src/inline-bots.lisp b/src/inline-bots.lisp index f4d8a8d..db9d8ff 100644 --- a/src/inline-bots.lisp +++ b/src/inline-bots.lisp @@ -3,16 +3,16 @@ (defpackage :ukkoclot/src/inline-bots (:documentation "This package deals with removing unwanted inline bot usage") (:use :c2cl :ukkoclot/src/tg) - (:import-from :com.dieggsy.f-string :enable-f-strings) (:import-from :conf) (:import-from :log) + (:import-from :named-readtables :in-readtable) (:import-from :serapeum :->) (:import-from :state) + (:import-from :ukkoclot/src/readtable :readtable) (:local-nicknames (:db :ukkoclot/src/db)) (:export :blacklist-inline-bot :on-inline-bot :whitelist-inline-bot)) (in-package :ukkoclot/src/inline-bots) - -(enable-f-strings) +(in-readtable readtable) (-> blacklist-inline-bot (integer) (values &optional)) (defun blacklist-inline-bot (inline-bot-id) diff --git a/src/main.lisp b/src/main.lisp index 13da5af..f435bf3 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -5,12 +5,13 @@ (:nicknames :ukkoclot) (:use :c2cl :iterate :ukkoclot/src/inline-bots :ukkoclot/src/tg) (:import-from :alexandria :when-let) - (:import-from :com.dieggsy.f-string :enable-f-strings) (:import-from :conf) (:import-from :log) + (:import-from :named-readtables :in-readtable) (:import-from :serapeum :-> :drop) (:import-from :state :*state* :make-state) (:import-from :str) + (:import-from :ukkoclot/src/readtable :readtable) (:import-from :ukkoclot/src/db :with-db) (:import-from :ukkoclot/src/serializing :fixup-value) (:import-from :ukkoclot/src/strings :escape-xml :is-tg-whitespace :is-tg-whitespace-str) @@ -18,8 +19,7 @@ (:jzon :com.inuoe.jzon)) (:export :main)) (in-package :ukkoclot/src/main) - -(enable-f-strings) +(in-readtable readtable) (defvar *in-prod* nil) diff --git a/src/readtable.lisp b/src/readtable.lisp new file mode 100644 index 0000000..ee5af0a --- /dev/null +++ b/src/readtable.lisp @@ -0,0 +1,14 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/src/readtable + (:documentation "Defines the custom readtable used within this project.") + (:use :c2cl) + (:import-from :named-readtables :defreadtable) + (:import-from :com.dieggsy.f-string :f-string-reader) + (:export :readtable)) +(in-package :ukkoclot/src/readtable) + +(defreadtable readtable + (:merge :standard) + (:dispatch-macro-char #\# #\f #'f-string-reader) + (:case :upcase)) diff --git a/src/rw-lock.lisp b/src/rw-lock.lisp index b8d08b1..2a5e2c3 100644 --- a/src/rw-lock.lisp +++ b/src/rw-lock.lisp @@ -4,10 +4,12 @@ (:documentation "Implementation of a shared/read-write lock.") (:use :c2cl :bt2 :iterate) (:import-from :alexandria :whichever :with-gensyms) - (:import-from :com.dieggsy.f-string :enable-f-strings) + (:import-from :named-readtables :in-readtable) + ;; These imports make this SBCL-dependent, but technically speaking we could live without them. (:import-from :sb-sys :allow-with-interrupts :with-local-interrupts :without-interrupts) (:import-from :serapeum :->) + (:import-from :ukkoclot/src/readtable :readtable) (:export #:rw-lock #:rw-lock-p @@ -19,9 +21,7 @@ #:release-write-lock #:with-write-lock)) (in-package :ukkoclot/src/rw-lock) - -(eval-when (:compile-toplevel :load-toplevel :execute) - (enable-f-strings)) +(in-readtable readtable) ;; TODO: Use atomic-integer in best-case for read locks to decrease contention (defstruct (rw-lock (:constructor make-rw-lock%)) diff --git a/src/state.lisp b/src/state.lisp index 9f1a38f..e2052e3 100644 --- a/src/state.lisp +++ b/src/state.lisp @@ -4,10 +4,11 @@ (:documentation "Holds the global state") (:nicknames :state) (:use :c2cl :ukkoclot/src/rw-lock) - (:import-from :com.dieggsy.f-string :enable-f-strings) (:import-from :conf :config :*config* :bot-token) + (:import-from :named-readtables :in-readtable) (:import-from :serapeum :->) (:import-from :ukkoclot/src/db :db) + (:import-from :ukkoclot/src/readtable :readtable) (:export #:*state* #:state @@ -22,8 +23,7 @@ #:id% #:set-id%)) (in-package :ukkoclot/src/state) - -(enable-f-strings) +(in-readtable readtable) (defstruct (state (:constructor make-state%)) (lock (make-rw-lock :name "state's lock") :type rw-lock :read-only t) diff --git a/src/tg/method-macros.lisp b/src/tg/method-macros.lisp index 9ab9e89..17903df 100644 --- a/src/tg/method-macros.lisp +++ b/src/tg/method-macros.lisp @@ -4,16 +4,15 @@ (:documentation "Macros for easy defining TG methods.") (:use :c2cl :iterate) (:import-from :alexandria :make-keyword :with-gensyms) - (:import-from :com.dieggsy.f-string :enable-f-strings) + (:import-from :named-readtables :in-readtable) (:import-from :serapeum :-> :take) (:import-from :state) (:import-from :str) + (:import-from :ukkoclot/src/readtable :readtable) (:import-from :ukkoclot/src/transport :do-call :http-method) (:export :define-tg-method)) (in-package :ukkoclot/src/tg/method-macros) - -(eval-when (:compile-toplevel :load-toplevel :execute) - (enable-f-strings)) +(in-readtable readtable) (eval-when (:compile-toplevel :load-toplevel :execute) (defstruct (param (:constructor make-param%)) name type default skip-if-default) diff --git a/src/tg/type-macros.lisp b/src/tg/type-macros.lisp index 02437ec..97cce1c 100644 --- a/src/tg/type-macros.lisp +++ b/src/tg/type-macros.lisp @@ -4,18 +4,17 @@ (:documentation "Macros for easy defining TG types.") (:use :c2cl :iterate) (:import-from :alexandria :make-keyword :symbolicate :with-gensyms) - (:import-from :com.dieggsy.f-string :enable-f-strings) + (:import-from :named-readtables :in-readtable) (:import-from :serapeum :->) (:import-from :str) - (:import-from :ukkoclot/src/serializing :parse-value) (:import-from :ukkoclot/src/hash-tables :gethash-lazy) + (:import-from :ukkoclot/src/readtable :readtable) + (:import-from :ukkoclot/src/serializing :parse-value) (:local-nicknames (:jzon :com.inuoe.jzon)) (:export :define-tg-type)) (in-package :ukkoclot/src/tg/type-macros) - -(eval-when (:compile-toplevel :load-toplevel :execute) - (enable-f-strings)) +(in-readtable readtable) (eval-when (:compile-toplevel :load-toplevel :execute) (defstruct (field (:constructor make-field%)) name type default skip-if-default) -- cgit v1.2.3