Skip to content

Commit 2fae1ae

Browse files
committed
Merge branch 'toml-0.4' into toml-0.5
2 parents fb7dca6 + 4f988e2 commit 2fae1ae

File tree

2 files changed

+80
-74
lines changed

2 files changed

+80
-74
lines changed

autoload/vital/__vital__/Text/TOML.vim

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ endfunction
2626
"
2727
" private api
2828
"
29-
" work around: '[^\r\n]*' doesn't work well in old-vim, but "[^\r\n]*" works well
30-
let s:skip_pattern = '\C^\%(\_s\+\|' . "#[^\r\n]*" . '\)'
29+
let s:skip_pattern = '\C^\%(\%(\s\|\r\?\n\)\+\|#[^\r\n]*\)'
3130
let s:bare_key_pattern = '\%([A-Za-z0-9_-]\+\)'
3231

3332
function! s:_skip(input) abort
34-
while s:_match(a:input, '\%(\_s\|#\)')
33+
while s:_match(a:input, '\%(\s\|\r\?\n\|#\)')
3534
let a:input.p = matchend(a:input.text, s:skip_pattern, a:input.p)
3635
endwhile
3736
endfunction
@@ -67,14 +66,10 @@ function! s:_eof(input) abort
6766
endfunction
6867

6968
function! s:_error(input) abort
70-
let buf = []
71-
let offset = 0
72-
while (a:input.p + offset) < a:input.length && a:input.text[a:input.p + offset] !~# "[\r\n]"
73-
let buf += [a:input.text[a:input.p + offset]]
74-
let offset += 1
75-
endwhile
69+
let s = matchstr(a:input.text, s:regex_prefix . '.\{-}\ze\%(\r\?\n\|$\)', a:input.p)
70+
let s = substitute(s, '\r', '\\r', 'g')
7671

77-
throw printf("vital: Text.TOML: Illegal TOML format at `%s'.", join(buf, ''))
72+
throw printf("vital: Text.TOML: Illegal TOML format at `%s'.", s)
7873
endfunction
7974

8075
function! s:_parse(input) abort
@@ -168,8 +163,8 @@ endfunction
168163
function! s:_multiline_basic_string(input) abort
169164
let s = s:_consume(a:input, '"\{3}\%(\\.\|\_.\)\{-}"\{,2}"\{3}')
170165
let s = s[3 : -4]
171-
let s = substitute(s, "^\n", '', '')
172-
let s = substitute(s, '\\\s*' . "\n" . '\_s*', '', 'g')
166+
let s = substitute(s, '^\r\?\n', '', '')
167+
let s = substitute(s, '\\\%(\s\|\r\?\n\)*', '', 'g')
173168
return s:_unescape(s)
174169
endfunction
175170

@@ -181,7 +176,7 @@ endfunction
181176
function! s:_multiline_literal(input) abort
182177
let s = s:_consume(a:input, "'\\{3}.\\{-}'\\{,2}'\\{3}")
183178
let s = s[3 : -4]
184-
let s = substitute(s, "^\n", '', '')
179+
let s = substitute(s, '^\r\?\n', '', '')
185180
return s
186181
endfunction
187182

test/Text/TOML.vim

Lines changed: 72 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -148,48 +148,57 @@ function! s:suite.__parse__()
148148
let multiline_basic_strings = themis#suite('Multi-line basic strings')
149149

150150
function! multiline_basic_strings.trims_first_newline()
151-
let data = s:TOML.parse(join([
152-
\ 'str1 = """',
153-
\ 'Roses are red',
154-
\ 'Violets are blue"""',
155-
\], "\n"))
156-
157-
call s:assert.same(data.str1, "Roses are red\nViolets are blue")
151+
for newline in ["\n", "\r\n"]
152+
let data = s:TOML.parse(join([
153+
\ 'str1 = """',
154+
\ 'Roses are red',
155+
\ 'Violets are blue"""',
156+
\], newline))
157+
158+
call s:assert.same(data.str1, join([
159+
\ 'Roses are red',
160+
\ 'Violets are blue'
161+
\], newline))
162+
endfor
158163
endfunction
159164

160165
function! multiline_basic_strings.trims_whitespaces_after_backslash()
161-
let data = s:TOML.parse(join([
162-
\ 'str2 = """',
163-
\ 'The quick brown \',
164-
\ '',
165-
\ '',
166-
\ ' fox jumps over \',
167-
\ ' the lazy dog."""',
168-
\ 'str3 = """\',
169-
\ ' The quick brown \',
170-
\ ' fox jumps over \',
171-
\ ' the lazy dog.\',
172-
\ ' """',
173-
\], "\n"))
174-
175-
call s:assert.same(data.str2, 'The quick brown fox jumps over the lazy dog.')
176-
call s:assert.same(data.str3, 'The quick brown fox jumps over the lazy dog.')
166+
for newline in ["\n", "\r\n"]
167+
let data = s:TOML.parse(join([
168+
\ 'str2 = """',
169+
\ 'The quick brown \',
170+
\ '',
171+
\ '',
172+
\ ' fox jumps over \',
173+
\ ' the lazy dog."""',
174+
\ 'str3 = """\',
175+
\ ' The quick brown \',
176+
\ ' fox jumps over \',
177+
\ ' the lazy dog.\',
178+
\ ' """',
179+
\], newline))
180+
181+
call s:assert.same(data.str2, 'The quick brown fox jumps over the lazy dog.')
182+
call s:assert.same(data.str3, 'The quick brown fox jumps over the lazy dog.')
183+
endfor
177184
endfunction
178185

179186
function! multiline_basic_strings.includes_escaped_character()
180-
let data = s:TOML.parse(join([
181-
\ 'str4 = """Here are two quotation marks: "". Simple enough."""',
182-
\ 'str5 = """Here are three quotation marks: ""\"."""',
183-
\ 'str6 = """Here are fifteen quotation marks: ""\"""\"""\"""\"""\"."""',
184-
\ '',
185-
\ '# "This," she said, "is just a pointless statement."',
186-
\ 'str7 = """"This," she said, "is just a pointless statement.""""',
187-
\], "\n"))
188-
189-
call s:assert.same(data.str4, 'Here are two quotation marks: "". Simple enough.')
190-
call s:assert.same(data.str5, 'Here are three quotation marks: """.')
191-
call s:assert.same(data.str6, 'Here are fifteen quotation marks: """"""""""""""".')
192-
call s:assert.same(data.str7, '"This," she said, "is just a pointless statement."')
187+
for newline in ["\n", "\r\n"]
188+
let data = s:TOML.parse(join([
189+
\ 'str4 = """Here are two quotation marks: "". Simple enough."""',
190+
\ 'str5 = """Here are three quotation marks: ""\"."""',
191+
\ 'str6 = """Here are fifteen quotation marks: ""\"""\"""\"""\"""\"."""',
192+
\ '',
193+
\ '# "This," she said, "is just a pointless statement."',
194+
\ 'str7 = """"This," she said, "is just a pointless statement.""""',
195+
\], newline))
196+
197+
call s:assert.same(data.str4, 'Here are two quotation marks: "". Simple enough.')
198+
call s:assert.same(data.str5, 'Here are three quotation marks: """.')
199+
call s:assert.same(data.str6, 'Here are fifteen quotation marks: """"""""""""""".')
200+
call s:assert.same(data.str7, '"This," she said, "is just a pointless statement."')
201+
endfor
193202
endfunction
194203
endfunction
195204

@@ -208,31 +217,33 @@ function! s:suite.__parse__()
208217
endfunction
209218

210219
function! parse.multiline_literal_string()
211-
let data = s:TOML.parse(join([
212-
\ 'regex2 = ''''''I [dw]on''t need \d{2} apples''''''',
213-
\ 'lines = ''''''',
214-
\ 'The first newline is',
215-
\ 'trimmed in raw strings.',
216-
\ ' All other whitespace',
217-
\ ' is preserved.',
218-
\ '''''''',
219-
\ '',
220-
\ 'quot15 = ''''''Here fifteen quotation marks: """""""""""""""''''''',
221-
\ '',
222-
\ "# 'That's still pointless', she said.",
223-
\ "str = ''''That's still pointless', she said.'''",
224-
\], "\n"))
225-
226-
call s:assert.same(data.regex2, 'I [dw]on''t need \d{2} apples')
227-
call s:assert.same(data.lines, join([
228-
\ 'The first newline is',
229-
\ 'trimmed in raw strings.',
230-
\ ' All other whitespace',
231-
\ ' is preserved.',
232-
\ '',
233-
\], "\n"))
234-
call s:assert.same(data.quot15, 'Here fifteen quotation marks: """""""""""""""')
235-
call s:assert.same(data.str, '''That''s still pointless'', she said.')
220+
for newline in ["\n", "\r\n"]
221+
let data = s:TOML.parse(join([
222+
\ 'regex2 = ''''''I [dw]on''t need \d{2} apples''''''',
223+
\ 'lines = ''''''',
224+
\ 'The first newline is',
225+
\ 'trimmed in raw strings.',
226+
\ ' All other whitespace',
227+
\ ' is preserved.',
228+
\ '''''''',
229+
\ '',
230+
\ 'quot15 = ''''''Here fifteen quotation marks: """""""""""""""''''''',
231+
\ '',
232+
\ "# 'That's still pointless', she said.",
233+
\ "str = ''''That's still pointless', she said.'''",
234+
\], newline))
235+
236+
call s:assert.same(data.regex2, 'I [dw]on''t need \d{2} apples')
237+
call s:assert.same(data.lines, join([
238+
\ 'The first newline is',
239+
\ 'trimmed in raw strings.',
240+
\ ' All other whitespace',
241+
\ ' is preserved.',
242+
\ '',
243+
\], newline))
244+
call s:assert.same(data.quot15, 'Here fifteen quotation marks: """""""""""""""')
245+
call s:assert.same(data.str, '''That''s still pointless'', she said.')
246+
endfor
236247
endfunction
237248

238249
function! parse.__integer__()

0 commit comments

Comments
 (0)