From f7c05ba9ec1634ec6d127e8e5b3edafc834ab2f0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 11 Jun 2021 07:36:02 -0700 Subject: pic: allow trailing exclamation. * share/txr/stdlib/pic.tl (expand-pic-num, expand-pic, pic): Allow ### to be followed by a single !. This is not counted toward the field width. * tests/018/format.tl: Cover with some tests. * txr.1: Doc updated. --- share/txr/stdlib/pic.tl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'share') diff --git a/share/txr/stdlib/pic.tl b/share/txr/stdlib/pic.tl index 25a9c70b..a6228334 100644 --- a/share/txr/stdlib/pic.tl +++ b/share/txr/stdlib/pic.tl @@ -32,6 +32,7 @@ (minus (eql [fmt 0] #\-)) (exc (pos #\! fmt)) (dot (or exc (pos #\. fmt))) + (fmt (if (and exc (eq #\! [fmt -1])) [fmt 0..-1] fmt)) (int (if dot [fmt 0..dot] fmt)) (fra (if dot [fmt (succ dot)..:] ""))) (let ((code (if (or minus plus (not zero)) @@ -80,7 +81,7 @@ ([m^$ #/\~[~#<>\|\-+0.!]/ fmt] [fmt 1..2]) ([m^$ #/\~./ fmt] (compile-error f "unrecognized escape sequence ~a" fmt)) ([m^$ #/\~/ fmt] (compile-error f "incomplete ~~ escape")) - ([m^$ #/[+\-]?0?#+([.!]#+)?/ fmt] (expand-pic-num fmt val)) + ([m^$ #/[+\-]?0?#+([.!]#+|!)?/ fmt] (expand-pic-num fmt val)) ([m^$ #/<+/ fmt] (expand-pic-align "<" fmt val)) ([m^$ #/>+/ fmt] (expand-pic-align nil fmt val)) ([m^$ #/\|+/ fmt] (expand-pic-align "^" fmt val)) @@ -89,7 +90,7 @@ (defmacro pic (:form f :env e bigfmt . args) (unless (stringp bigfmt) (compile-error f "~s is required to be a format string" bigfmt)) - (let* ((regex #/[+\-]?0?#+([.!]#+)?| \ + (let* ((regex #/[+\-]?0?#+([.!]#+|!)?| \ <+| \ >+| \ \|+| \ -- cgit v1.2.3