guix_mirror_bot pushed a commit to branch python-team
in repository guix.
commit e5584db1f857f4882d9cd544ab43b80159293733
Author: Dariqq <[email protected]>
AuthorDate: Mon Dec 22 17:22:51 2025 +0000
build: toml: Adapt for toml 1.1.0
* guix/build/toml.scm: Change to v1.1.0
Merges: guix/guix!5156
Change-Id: I6d878e4c01352c0ff7d510d3ea9f7d41b8d75e7d
Reviewed-by: Ludovic Courtès <[email protected]>
Signed-off-by: Sharlatan Hellseher <[email protected]>
---
guix/build/toml.scm | 41 ++++++++++++++++++++++++++---------------
tests/toml.scm | 20 +++++++++++++++++---
2 files changed, 43 insertions(+), 18 deletions(-)
diff --git a/guix/build/toml.scm b/guix/build/toml.scm
index 43b5bdde2d..f7dcb7413e 100644
--- a/guix/build/toml.scm
+++ b/guix/build/toml.scm
@@ -16,12 +16,12 @@
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
-;; This is a TOML parser adapted from the ABNF for v1.0.0 from
-;; https://github.com/toml-lang/toml/blob/1.0.0/toml.abnf
+;; This is a TOML parser adapted from the ABNF for v1.1.0 from
+;; https://github.com/toml-lang/toml/blob/1.1.0/toml.abnf
;; The PEG grammar tries to follow the ABNF as closely as possible with
;; few deviations commented.
;;
-;; The semantics are defined in https://toml.io/en/v1.0.0
+;; The semantics are defined in https://toml.io/en/v1.1.0
;; Currently unimplemented:
;; - Array of Tables
@@ -58,7 +58,7 @@
;; Comment
(define-peg-pattern non-ascii body (or (range #\x80 #\xd7ff)
(range #\xe000 #\x10ffff)))
-(define-peg-pattern non-eol body (or "\t" (range #\x20 #\x7f) non-ascii))
+(define-peg-pattern non-eol body (or "\t" (range #\x20 #\x7e) non-ascii))
(define-peg-pattern comment none (and "#" (* non-eol)))
@@ -107,7 +107,9 @@
non-ascii))
(define-peg-pattern escaped all (and
(ignore "\\")
- (or "\"" "\\" "b" "f" "n" "r" "t"
+ (or "\"" "\\" "b" "e" "f" "n" "r" "t"
+ (and (ignore "x")
+ HEXDIG HEXDIG)
(and (ignore "u")
HEXDIG HEXDIG HEXDIG HEXDIG)
(and (ignore "U")
@@ -244,9 +246,9 @@
(define-peg-pattern partial-time body (and time-hour
(ignore ":")
time-minute
- (ignore ":")
- time-second
- (? time-secfrac)))
+ (? (and (ignore ":")
+ time-second
+ (? time-secfrac)))))
(define-peg-pattern full-date body (and date-fullyear
(ignore "-")
date-month
@@ -295,13 +297,19 @@
;; Inline Table
(define-peg-pattern inline-table all (and (ignore "{")
- (* ws)
(? inline-table-keyvals)
- (* ws)
+ ws-comment-newline
(ignore "}")))
-(define-peg-pattern inline-table-sep none (and ws "," ws))
-(define-peg-pattern inline-table-keyvals body (and keyval
- (? (and inline-table-sep
inline-table-keyvals))))
+(define-peg-pattern inline-table-sep none ",")
+(define-peg-pattern inline-table-keyvals body (or (and ws-comment-newline
+ keyval
+ ws-comment-newline
+ inline-table-sep
+ inline-table-keyvals)
+ (and ws-comment-newline
+ keyval
+ ws-comment-newline
+ (? inline-table-sep))))
;; Parsing
@@ -369,9 +377,12 @@ evaluating escape codes."
(('escaped "\"") "\"")
(('escaped "\\") "\\")
(('escaped "b") "\b")
- (('escaped "t") "\t")
+ (('escaped "e") "\x1b")
+ (('escaped "f") "\f")
(('escaped "n") "\n")
- (('escaped (? (lambda (x) (>= (string-length x) 4)) u))
+ (('escaped "r") "\r")
+ (('escaped "t") "\t")
+ (('escaped (? (lambda (x) (>= (string-length x) 2)) u))
(list->string (list (integer->char (string->number u 16)))))
((? string? s) s))
(keyword-flatten '(escaped) value))))
diff --git a/tests/toml.scm b/tests/toml.scm
index b261856fcd..7cfa598444 100644
--- a/tests/toml.scm
+++ b/tests/toml.scm
@@ -105,7 +105,7 @@ fruit.apple.smooth = true"))
(test-equal "parse-toml: String"
'(("str" . "I'm a string. \"You can quote me\".
Name\tJos\u00E9\nLocation\tSF."))
- (parse-toml "str = \"I'm a string. \\\"You can quote me\\\".
Name\\tJos\\u00E9\\nLocation\\tSF.\""))
+ (parse-toml "str = \"I'm a string. \\\"You can quote me\\\".
Name\\tJos\\xE9\\nLocation\\tSF.\""))
(test-equal "parse-toml: Empty string"
'(("str1" . "")
@@ -403,10 +403,24 @@ fruit.apple.taste.sweet = true"))
(test-equal "parse-toml: Inline tables"
'(("name" ("first" . "Tom") ("last" . "Preston-Werner"))
("point" ("x" . 1) ("y" . 2))
- ("animal" ("type" ("name" . "pug"))))
+ ("animal" ("type" ("name" . "pug")))
+ ("contact" . (("personal" . (("name" . "Donald Duck")
+ ("email" . "[email protected]")))
+ ("work" . (("name" . "Coin cleaner")
+ ("email" . "[email protected]"))))))
(parse-toml "name = { first = \"Tom\", last = \"Preston-Werner\" }
point = { x = 1, y = 2 }
-animal = { type.name = \"pug\" }"))
+animal = { type.name = \"pug\" }
+contact = {
+ personal = {
+ name = \"Donald Duck\",
+ email = \"[email protected]\",
+ },
+ work = {
+ name = \"Coin cleaner\",
+ email = \"[email protected]\",
+ },
+}"))
(test-equal "parse-toml: Empty inline table"
'(("name")