summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDariqq <dariqq@posteo.net>2025-12-22 17:22:51 +0000
committerSharlatan Hellseher <sharlatanus@gmail.com>2026-08-08 23:01:52 +0100
commite1c736072b64d6b8711b8e5f70a9935ffcde0640 (patch)
tree407bc474d3c7c4d6c05735756cf908c17f3941aa
parentd62469f1878026eb82630f3f787e69cc34449a03 (diff)
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 <ludo@gnu.org> Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
-rw-r--r--guix/build/toml.scm41
-rw-r--r--tests/toml.scm20
2 files changed, 43 insertions, 18 deletions
diff --git a/guix/build/toml.scm b/guix/build/toml.scm
index 43b5bdde2df..f7dcb7413e4 100644
--- a/guix/build/toml.scm
+++ b/guix/build/toml.scm
@@ -16,12 +16,12 @@
16;;; You should have received a copy of the GNU General Public License 16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. 17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18 18
19;; This is a TOML parser adapted from the ABNF for v1.0.0 from 19;; This is a TOML parser adapted from the ABNF for v1.1.0 from
20;; https://github.com/toml-lang/toml/blob/1.0.0/toml.abnf 20;; https://github.com/toml-lang/toml/blob/1.1.0/toml.abnf
21;; The PEG grammar tries to follow the ABNF as closely as possible with 21;; The PEG grammar tries to follow the ABNF as closely as possible with
22;; few deviations commented. 22;; few deviations commented.
23;; 23;;
24;; The semantics are defined in https://toml.io/en/v1.0.0 24;; The semantics are defined in https://toml.io/en/v1.1.0
25;; Currently unimplemented: 25;; Currently unimplemented:
26;; - Array of Tables 26;; - Array of Tables
27 27
@@ -58,7 +58,7 @@
58;; Comment 58;; Comment
59(define-peg-pattern non-ascii body (or (range #\x80 #\xd7ff) 59(define-peg-pattern non-ascii body (or (range #\x80 #\xd7ff)
60 (range #\xe000 #\x10ffff))) 60 (range #\xe000 #\x10ffff)))
61(define-peg-pattern non-eol body (or "\t" (range #\x20 #\x7f) non-ascii)) 61(define-peg-pattern non-eol body (or "\t" (range #\x20 #\x7e) non-ascii))
62 62
63(define-peg-pattern comment none (and "#" (* non-eol))) 63(define-peg-pattern comment none (and "#" (* non-eol)))
64 64
@@ -107,7 +107,9 @@
107 non-ascii)) 107 non-ascii))
108(define-peg-pattern escaped all (and 108(define-peg-pattern escaped all (and
109 (ignore "\\") 109 (ignore "\\")
110 (or "\"" "\\" "b" "f" "n" "r" "t" 110 (or "\"" "\\" "b" "e" "f" "n" "r" "t"
111 (and (ignore "x")
112 HEXDIG HEXDIG)
111 (and (ignore "u") 113 (and (ignore "u")
112 HEXDIG HEXDIG HEXDIG HEXDIG) 114 HEXDIG HEXDIG HEXDIG HEXDIG)
113 (and (ignore "U") 115 (and (ignore "U")
@@ -244,9 +246,9 @@
244(define-peg-pattern partial-time body (and time-hour 246(define-peg-pattern partial-time body (and time-hour
245 (ignore ":") 247 (ignore ":")
246 time-minute 248 time-minute
247 (ignore ":") 249 (? (and (ignore ":")
248 time-second 250 time-second
249 (? time-secfrac))) 251 (? time-secfrac)))))
250(define-peg-pattern full-date body (and date-fullyear 252(define-peg-pattern full-date body (and date-fullyear
251 (ignore "-") 253 (ignore "-")
252 date-month 254 date-month
@@ -295,13 +297,19 @@
295 297
296;; Inline Table 298;; Inline Table
297(define-peg-pattern inline-table all (and (ignore "{") 299(define-peg-pattern inline-table all (and (ignore "{")
298 (* ws)
299 (? inline-table-keyvals) 300 (? inline-table-keyvals)
300 (* ws) 301 ws-comment-newline
301 (ignore "}"))) 302 (ignore "}")))
302(define-peg-pattern inline-table-sep none (and ws "," ws)) 303(define-peg-pattern inline-table-sep none ",")
303(define-peg-pattern inline-table-keyvals body (and keyval 304(define-peg-pattern inline-table-keyvals body (or (and ws-comment-newline
304 (? (and inline-table-sep inline-table-keyvals)))) 305 keyval
306 ws-comment-newline
307 inline-table-sep
308 inline-table-keyvals)
309 (and ws-comment-newline
310 keyval
311 ws-comment-newline
312 (? inline-table-sep))))
305 313
306 314
307;; Parsing 315;; Parsing
@@ -369,9 +377,12 @@ evaluating escape codes."
369 (('escaped "\"") "\"") 377 (('escaped "\"") "\"")
370 (('escaped "\\") "\\") 378 (('escaped "\\") "\\")
371 (('escaped "b") "\b") 379 (('escaped "b") "\b")
372 (('escaped "t") "\t") 380 (('escaped "e") "\x1b")
381 (('escaped "f") "\f")
373 (('escaped "n") "\n") 382 (('escaped "n") "\n")
374 (('escaped (? (lambda (x) (>= (string-length x) 4)) u)) 383 (('escaped "r") "\r")
384 (('escaped "t") "\t")
385 (('escaped (? (lambda (x) (>= (string-length x) 2)) u))
375 (list->string (list (integer->char (string->number u 16))))) 386 (list->string (list (integer->char (string->number u 16)))))
376 ((? string? s) s)) 387 ((? string? s) s))
377 (keyword-flatten '(escaped) value)))) 388 (keyword-flatten '(escaped) value))))
diff --git a/tests/toml.scm b/tests/toml.scm
index b261856fcdf..7cfa5984445 100644
--- a/tests/toml.scm
+++ b/tests/toml.scm
@@ -105,7 +105,7 @@ fruit.apple.smooth = true"))
105 105
106(test-equal "parse-toml: String" 106(test-equal "parse-toml: String"
107 '(("str" . "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF.")) 107 '(("str" . "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."))
108 (parse-toml "str = \"I'm a string. \\\"You can quote me\\\". Name\\tJos\\u00E9\\nLocation\\tSF.\"")) 108 (parse-toml "str = \"I'm a string. \\\"You can quote me\\\". Name\\tJos\\xE9\\nLocation\\tSF.\""))
109 109
110(test-equal "parse-toml: Empty string" 110(test-equal "parse-toml: Empty string"
111 '(("str1" . "") 111 '(("str1" . "")
@@ -403,10 +403,24 @@ fruit.apple.taste.sweet = true"))
403(test-equal "parse-toml: Inline tables" 403(test-equal "parse-toml: Inline tables"
404 '(("name" ("first" . "Tom") ("last" . "Preston-Werner")) 404 '(("name" ("first" . "Tom") ("last" . "Preston-Werner"))
405 ("point" ("x" . 1) ("y" . 2)) 405 ("point" ("x" . 1) ("y" . 2))
406 ("animal" ("type" ("name" . "pug")))) 406 ("animal" ("type" ("name" . "pug")))
407 ("contact" . (("personal" . (("name" . "Donald Duck")
408 ("email" . "donald@duckburg.com")))
409 ("work" . (("name" . "Coin cleaner")
410 ("email" . "donald@ScroogeCorp.com"))))))
407 (parse-toml "name = { first = \"Tom\", last = \"Preston-Werner\" } 411 (parse-toml "name = { first = \"Tom\", last = \"Preston-Werner\" }
408point = { x = 1, y = 2 } 412point = { x = 1, y = 2 }
409animal = { type.name = \"pug\" }")) 413animal = { type.name = \"pug\" }
414contact = {
415 personal = {
416 name = \"Donald Duck\",
417 email = \"donald@duckburg.com\",
418 },
419 work = {
420 name = \"Coin cleaner\",
421 email = \"donald@ScroogeCorp.com\",
422 },
423}"))
410 424
411(test-equal "parse-toml: Empty inline table" 425(test-equal "parse-toml: Empty inline table"
412 '(("name") 426 '(("name")