mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-30 22:36:50 +01:00
guix: toml: Fix parsing empty strings in arrays.
Change-Id: Id14d4008391a01820ade754fa9c2ca8e88b8c7f9
This commit is contained in:
parent
b59cdd59eb
commit
63cb43d56c
2 changed files with 36 additions and 6 deletions
|
@ -97,7 +97,7 @@ (define-peg-pattern string all (or ml-basic-string
|
||||||
|
|
||||||
;; Basic String
|
;; Basic String
|
||||||
(define-peg-pattern basic-string body (and (ignore "\"")
|
(define-peg-pattern basic-string body (and (ignore "\"")
|
||||||
(* basic-char)
|
(or (+ basic-char) "")
|
||||||
(ignore "\"")))
|
(ignore "\"")))
|
||||||
(define-peg-pattern basic-char body (or basic-unescaped escaped))
|
(define-peg-pattern basic-char body (or basic-unescaped escaped))
|
||||||
(define-peg-pattern basic-unescaped body (or wschar
|
(define-peg-pattern basic-unescaped body (or wschar
|
||||||
|
@ -116,9 +116,11 @@ (define-peg-pattern escaped all (and
|
||||||
|
|
||||||
;; Multiline Basic String
|
;; Multiline Basic String
|
||||||
(define-peg-pattern ml-basic-string body (and
|
(define-peg-pattern ml-basic-string body (and
|
||||||
ml-basic-string-delim
|
ml-basic-string-delim
|
||||||
(? ignore-newline)
|
(? ignore-newline)
|
||||||
ml-basic-body
|
;; Force the result of the empty string
|
||||||
|
;; to be a string, not no token.
|
||||||
|
(and ml-basic-body "")
|
||||||
ml-basic-string-delim))
|
ml-basic-string-delim))
|
||||||
(define-peg-pattern ml-basic-string-delim none "\"\"\"")
|
(define-peg-pattern ml-basic-string-delim none "\"\"\"")
|
||||||
(define-peg-pattern ml-basic-body body (and
|
(define-peg-pattern ml-basic-body body (and
|
||||||
|
@ -145,7 +147,7 @@ (define-peg-pattern mlb-escaped-nl none (and "\\" ws newline
|
||||||
|
|
||||||
;; Literal String
|
;; Literal String
|
||||||
(define-peg-pattern literal-string body (and (ignore "'")
|
(define-peg-pattern literal-string body (and (ignore "'")
|
||||||
(* literal-char)
|
(or (+ literal-char) "")
|
||||||
(ignore "'")))
|
(ignore "'")))
|
||||||
(define-peg-pattern literal-char body (or "\x09"
|
(define-peg-pattern literal-char body (or "\x09"
|
||||||
(range #\x20 #\x26)
|
(range #\x20 #\x26)
|
||||||
|
@ -156,7 +158,9 @@ (define-peg-pattern literal-char body (or "\x09"
|
||||||
(define-peg-pattern ml-literal-string body (and
|
(define-peg-pattern ml-literal-string body (and
|
||||||
ml-literal-string-delim
|
ml-literal-string-delim
|
||||||
(? ignore-newline)
|
(? ignore-newline)
|
||||||
ml-literal-body
|
;; Force the result of the empty string
|
||||||
|
;; to be a string, not no token.
|
||||||
|
(and ml-literal-body "")
|
||||||
ml-literal-string-delim))
|
ml-literal-string-delim))
|
||||||
(define-peg-pattern ml-literal-string-delim none "'''")
|
(define-peg-pattern ml-literal-string-delim none "'''")
|
||||||
(define-peg-pattern ml-literal-body body (and
|
(define-peg-pattern ml-literal-body body (and
|
||||||
|
@ -475,4 +479,3 @@ (define (parse-toml-file file)
|
||||||
"Parse and evaluate toml document from file FILE."
|
"Parse and evaluate toml document from file FILE."
|
||||||
|
|
||||||
(parse-toml (call-with-input-file file get-string-all)))
|
(parse-toml (call-with-input-file file get-string-all)))
|
||||||
|
|
||||||
|
|
|
@ -305,6 +305,33 @@ (define-module (test-toml)
|
||||||
2, # this is ok
|
2, # this is ok
|
||||||
]"))
|
]"))
|
||||||
|
|
||||||
|
(test-equal "parse-toml: Arrays of empty strings"
|
||||||
|
'(("empty1" "")
|
||||||
|
("empty2" "" "")
|
||||||
|
("empty3" "" "" "")
|
||||||
|
("emptyraw1" "")
|
||||||
|
("emptyraw2" "" "")
|
||||||
|
("emptyraw3" "" "" "")
|
||||||
|
("emptyml1" "")
|
||||||
|
("emptyml2" "" "")
|
||||||
|
("emptyml3" "" "" "")
|
||||||
|
("emptyrawml1" "")
|
||||||
|
("emptyrawml2" "" "")
|
||||||
|
("emptyrawml3" "" "" ""))
|
||||||
|
(parse-toml "empty1 = [ \"\" ]
|
||||||
|
empty2 = [ \"\", \"\" ]
|
||||||
|
empty3 = [ \"\", \"\", \"\" ]
|
||||||
|
emptyraw1 = [ '' ]
|
||||||
|
emptyraw2 = [ '', '' ]
|
||||||
|
emptyraw3 = [ '', '', '' ]
|
||||||
|
emptyml1 = [ \"\"\"\"\"\" ]
|
||||||
|
emptyml2 = [ \"\"\"\"\"\", \"\"\"\"\"\" ]
|
||||||
|
emptyml3 = [ \"\"\"\"\"\", \"\"\"\"\"\", \"\"\"\"\"\" ]
|
||||||
|
emptyrawml1 = [ '''''' ]
|
||||||
|
emptyrawml2 = [ '''''', '''''' ]
|
||||||
|
emptyrawml3 = [ '''''', '''''', '''''' ]
|
||||||
|
"))
|
||||||
|
|
||||||
(test-equal "parse-toml: Tables"
|
(test-equal "parse-toml: Tables"
|
||||||
'(("table-1" ("key1" . "some string")
|
'(("table-1" ("key1" . "some string")
|
||||||
("key2" . 123))
|
("key2" . 123))
|
||||||
|
|
Loading…
Reference in a new issue