Permalink
Browse files

detect missing commas

  • Loading branch information...
1 parent ef78dfd commit faaebc91b68cd2d375e762ea74d7d553f524916e @elzr committed Apr 14, 2014
Showing with 24 additions and 12 deletions.
  1. +5 −0 json-test.json
  2. +19 −12 syntax/json.vim
View
@@ -6,6 +6,11 @@
"decimalCantStartWithPeriod":.1,
};
+{
+ "object1": "missingComma"
+ "object2": "value"
+}
+
// normative JSON examples from http://json.org/example.html
{"menu": {
View
@@ -18,22 +18,24 @@ syntax match jsonNoise /\%(:\|,\)/
" NOTE that for the concealing to work your conceallevel should be set to 2
" Syntax: Strings
+" Separated into a match and region because a region by itself is always greedy
+syn match jsonStringMatch /"[^\"]\+"[[:blank:]\r\n]*[,}\]]/ contains=jsonString
if has('conceal')
- syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape
+ syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained
else
- syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape
+ syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained
endif
" Syntax: JSON does not allow strings with single quotes, unlike JavaScript.
-syn region jsonStringSQ oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
+syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
" Syntax: JSON Keywords
" Separated into a match and region because a region by itself is always greedy
-syn match jsonKeywordMatch /"[^\"\:]\+"[[:blank:]\r\n]*\:/ contains=jsonKeywordRegion
+syn match jsonKeywordMatch /"[^\"\:]\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword
if has('conceal')
- syn region jsonKeywordRegion matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contained
+ syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contained
else
- syn region jsonKeywordRegion matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contained
+ syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contained
endif
" Syntax: Escape sequences
@@ -46,7 +48,7 @@ syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)
" ERROR WARNINGS **********************************************
"
" Syntax: Strings should always be enclosed with quotes.
-syn match jsonNoQuotes "\<[[:alpha:]]\+\>"
+syn match jsonNoQuotesError "\<[[:alpha:]]\+\>"
" Syntax: An integer part of 0 followed by other digits is not allowed.
syn match jsonNumError "-\=\<0\d\.\d*\>"
@@ -62,7 +64,11 @@ syn match jsonCommentError "\(/\*\)\|\(\*/\)"
syn match jsonSemicolonError ";"
" Syntax: No trailing comma after the last element of arrays or objects
-syn match jsonCommaError ",\_s*[}\]]"
+syn match jsonTrailingCommaError ",\_s*[}\]]"
+
+" Syntax: Watch out for missing commas between elements
+syn match jsonMissingCommaError /"\zs\_s\+\ze"/
+
" ********************************************** END OF ERROR WARNINGS
" Allowances for JSONP: function call at the beginning of the file,
@@ -102,14 +108,15 @@ if version >= 508 || !exists("did_json_syn_inits")
HiLink jsonBooleanTrue jsonBoolean
HiLink jsonBooleanFalse jsonBoolean
HiLink jsonBoolean Boolean
- HiLink jsonKeywordRegion Label
+ HiLink jsonKeyword Label
HiLink jsonNumError Error
HiLink jsonCommentError Error
HiLink jsonSemicolonError Error
- HiLink jsonCommaError Error
- HiLink jsonStringSQ Error
- HiLink jsonNoQuotes Error
+ HiLink jsonTrailingCommaError Error
+ HiLink jsonMissingCommaError Error
+ HiLink jsonStringSQError Error
+ HiLink jsonNoQuotesError Error
HiLink jsonQuote Quote
HiLink jsonNoise Noise
delcommand HiLink

0 comments on commit faaebc9

Please sign in to comment.