Skip to content

Commit 7bb6840

Browse files
committed
Fix for multi-line string
1 parent 282ec85 commit 7bb6840

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

src/clj_toml/core.clj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@
9797
9898
;; Multiline Basic String
9999
100-
ml-basic-string = <ml-basic-string-delim> ml-basic-body <ml-basic-string-delim>
100+
ml-basic-string = <ml-basic-string-beg-delim> ml-basic-body <ml-basic-string-end-delim>
101101
102-
ml-basic-string-delim = 3quotation-mark
102+
ml-basic-string-beg-delim = 3quotation-mark 0*1ml-newline
103+
ml-basic-string-end-delim = 3quotation-mark
103104
104-
<ml-basic-body> = *( ml-basic-char / ml-newline / ( escape ws ml-newline ) )
105+
<ml-basic-body> = *( ml-basic-char / ml-newline / <( escape 1*99( wschar / ml-newline ) )> ) ; `1*99` is workaround, `1*(...)` is not working.
105106
<ml-basic-char> = ml-basic-unescaped / escaped
106107
<ml-basic-unescaped> = %x20-5B / %x5D-7E / %x80-10FFFF
107108
@@ -115,9 +116,10 @@
115116
116117
;; Multiline Literal String
117118
118-
ml-literal-string = <ml-literal-string-delim> ml-literal-body <ml-literal-string-delim>
119+
ml-literal-string = <ml-literal-string-beg-delim> ml-literal-body <ml-literal-string-end-delim>
119120
120-
ml-literal-string-delim = 3apostrophe
121+
ml-literal-string-beg-delim = 3apostrophe 0*1ml-newline
122+
ml-literal-string-end-delim = 3apostrophe
121123
122124
<ml-literal-body> = *( ml-literal-char / ml-newline )
123125
<ml-literal-char> = %x09 / %x20-10FFFF

test/clj_toml/core_test.clj

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,38 @@
3333
(testing "Strings (literal)"
3434
(is (= (parse-string "str = 'Comes$as\\is<:>'")
3535
{"str" "Comes$as\\is<:>"})))
36-
(testing "Strings (multiline)")
37-
(testing "Strings (multiline literal)"))
36+
(testing "Strings (multiline)"
37+
(is (= (parse-string (s/join "\n" ["key1 = \"\"\""
38+
"Roses are red"
39+
"Violets are blue\"\"\""]))
40+
{"key1" "Roses are red\nViolets are blue"}))
41+
(is (= (parse-string (s/join "\n" ["key1 = \"\"\""
42+
"The quick brown \\"
43+
""
44+
" fox jumps over \\"
45+
" the lazy dog.\"\"\""]))
46+
{"key1" "The quick brown fox jumps over the lazy dog."}))
47+
(is (= (parse-string (s/join "\n" ["key1 = \"\"\"\\"
48+
" The quick brown \\"
49+
" fox jumps over \\"
50+
" the lazy dog.\\"
51+
" \"\"\""]))
52+
{"key1" "The quick brown fox jumps over the lazy dog."})))
53+
(testing "Strings (multiline literal)"
54+
(is (= (parse-string "regex2 = '''I [dw]on't need \\d{2} apples'''")
55+
{"regex2" "I [dw]on't need \\d{2} apples"}))
56+
(is (= (parse-string (s/join "\n" ["lines = '''"
57+
"The first newline is"
58+
"trimmed in raw strings."
59+
" All other whitespace"
60+
" is preserved."
61+
"'''"]))
62+
{"lines" (s/join "\n" ["The first newline is"
63+
"trimmed in raw strings."
64+
" All other whitespace"
65+
" is preserved."
66+
""])}))
67+
))
3868

3969
(deftest integer-test
4070
(testing "Integer numbers"

0 commit comments

Comments
 (0)