diff --git a/syntax/toml.vim b/syntax/toml.vim index 94b7ffd..0ede1dc 100644 --- a/syntax/toml.vim +++ b/syntax/toml.vim @@ -45,9 +45,14 @@ syn match tomlKey /\v(^|[{,])\s*\zs[[:alnum:]._-]+\ze\s*\=/ contains=tomlDotInKe syn region tomlKeyDq oneline start=/\v(^|[{,])\s*\zs"/ end=/"\ze\s*=/ contains=tomlEscape syn region tomlKeySq oneline start=/\v(^|[{,])\s*\zs'/ end=/'\ze\s*=/ -syn region tomlTable oneline start=/^\s*\[[^\[]/ end=/\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey +" Match table and table array headers. Distinguish from inline arrays by +" allowing commas only inside single or double quotes. +let s:HEADER_RE = '^\s*\[\[=%(([''"])%(\1@!.|\\"){-}\1|[^,''"]{-1,}){-1,}\]\]=\s*%(#|$)' +exe 'syn region tomlFold start=/\v' . s:HEADER_RE . '/ end=/\v%(' . s:HEADER_RE . ')@=/ fold transparent' -syn region tomlTableArray oneline start=/^\s*\[\[/ end=/\]\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey +syn region tomlTable oneline start=/^\s*\[[^\[]/ end=/\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey containedin=tomlFold contained + +syn region tomlTableArray oneline start=/^\s*\[\[/ end=/\]\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey containedin=tomlFold contained syn region tomlKeyValueArray start=/=\s*\[\zs/ end=/\]/ contains=@tomlValue diff --git a/test/test.toml b/test/test.toml index c81aba1..2a14608 100644 --- a/test/test.toml +++ b/test/test.toml @@ -26,6 +26,12 @@ apple.type = "fruit" 3.14159 = "pi" "127.0.0.1" = "value" +[foo."".'bar, actually'] # Empty string as key, key with a comma +foldbug = [ + ["a"] , # BUG: Remove comma to trigger folding bug +] +'' = "empty" + [[foo.quux]] e = 2