Ok, please find attached my corrections to the c.vim file. (Diff instructions.) Many thanks go to Tony for his invaluable help. Especially with the diff command.

Synopsis:

Because hex values have the suffixes and the underscores it took a while to come up with something which would handle all of the various aspects of and combinations of items. My simplest effort would catch the errors but would also catch the unwanted errors as well. (ie: It was catching errors it should not have caught because they were not errors reallys.) Even this solution is not perfect because in some of the test cases the trailing "ul" would sometimes turn light blue (which is - I believe standard text/instructions in my color scheme) instead of the entire number being bold white (my set-up for errors). Still, the hex values would completely show up as an error. Which was my main goal.

Changes:

The main changes are that there is now a cHex and a cHexError. These have been inserted into the same locations as cOctal and cOctalError respectively. Although cHex only takes one line, the cHexError required four separate lines. I've left the old cNumber line for catching hexidecimal numbers in the file. I've tested these changes on about ten different lines of code. So feedback is welcome if, for some reason, you find they do not work properly.

Mark

*** c.vim       Mon Sep 11 23:56:51 2006
--- /home/Mark/ftp/vim70/runtime/syntax/c.vim   Mon May  1 03:39:56 2006
***************
*** 67,73 ****
  "catch errors caused by wrong parenthesis and brackets
  " also accept <% for {, %> for }, <: for [ and :> for ] (C99)
  " But avoid matching <::.
! syn cluster   cParenGroup 
contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cCommentSkip,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cHex,cOctal,cOctalError,cHexError,cNumbersCom
  if exists("c_no_curly_error")
    syn region  cParen          transparent start='(' end=')' 
contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell
    " cCppParen: same as cParen but ends at end-of-line; used in cDefine
--- 67,73 ----
  "catch errors caused by wrong parenthesis and brackets
  " also accept <% for {, %> for }, <: for [ and :> for ] (C99)
  " But avoid matching <::.
! syn cluster   cParenGroup     
contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cCommentSkip,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
  if exists("c_no_curly_error")
    syn region  cParen          transparent start='(' end=')' 
contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell
    " cCppParen: same as cParen but ends at end-of-line; used in cDefine
***************
*** 94,106 ****
  
  "integer number, or floating point number without a dot and with "f".
  syn case ignore
! syn match     cNumbers        display transparent "\<\d\|\.\d" 
contains=cNumber,cFloat,cOctalError,cHexError,cOctal,cHex
  " Same, but without octal error (for comments)
! syn match     cNumbersCom     display contained transparent "\<\d\|\.\d" 
contains=cNumber,cFloat,cOctal,cHex
  syn match     cNumber         display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
  "hex number
! "syn match    cNumber         display contained 
"0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
! syn match     cHex            display contained 
"0x\(\x\|_\x\)\+\(u\=l\{0,2}\|ll\=u\)\>"
  " Flag the first zero of an octal number as something special
  syn match     cOctal          display contained 
"0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
  syn match     cOctalZero      display contained "\<0"
--- 94,105 ----
  
  "integer number, or floating point number without a dot and with "f".
  syn case ignore
! syn match     cNumbers        display transparent "\<\d\|\.\d" 
contains=cNumber,cFloat,cOctalError,cOctal
  " Same, but without octal error (for comments)
! syn match     cNumbersCom     display contained transparent "\<\d\|\.\d" 
contains=cNumber,cFloat,cOctal
  syn match     cNumber         display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
  "hex number
! syn match     cNumber         display contained 
"0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
  " Flag the first zero of an octal number as something special
  syn match     cOctal          display contained 
"0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
  syn match     cOctalZero      display contained "\<0"
***************
*** 119,130 ****
  endif
  
  " flag an octal number with wrong digits
! syn match     cOctalError     display contained "0\o+[89a-zA-Z]\+\d*"
! "syn match    cHexError       display contained 
"0x!\(\x\+\(u\=l\{0,2}\|ll\=u\)\>\)\|0x!\(\x\+\(_\x\x\)\+\(u\=l\{0,2}\|ll\=u\)\>\)"
! syn match     cHexError       display contained 
"0x\(\x\|_\x\)\+[g-km-tv-zG-KM-TV-Z]\+\(u\=l\{0,2}\|ll\=u\)\?"
! syn match     cHexError       display contained 
"0x[g-zG-Z]\+\(\x\|_\x\)\+\(u\=l\{0,2}\|ll\=u\)\?"
! syn match     cHexError       display contained 
"0x\x\+_[g-zG-Z]\+\(\x\|_\x\)\+\(u\=l\{0,2}\|ll\=u\)\?"
! syn match     cHexError       display contained 
"0x\(\x\|_\x\)\+[g-zG-Z]\+\(\x\|_\x\)\+\(u\=l\{0,2}\|ll\=u\)\?"
  syn case match
  
  if exists("c_comment_strings")
--- 118,124 ----
  endif
  
  " flag an octal number with wrong digits
! syn match     cOctalError     display contained "0\o*[89]\d*"
  syn case match
  
  if exists("c_comment_strings")
***************
*** 278,289 ****
  syn match     cIncluded       display contained "<[^>]*>"
  syn match     cInclude        display "^\s*\(%:\|#\)\s*include\>\s*["<]" 
contains=cIncluded
  "syn match cLineSkip  "\\$"
! syn cluster   cPreProcGroup 
contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cHex,cOctalError,cHexError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti
  syn region    cDefine         start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" 
skip="\\$" end="$" end="//"me=s-1 contains=ALLBUT,@cPreProcGroup,@Spell
  syn region    cPreProc        
start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" 
skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
  
  " Highlight User Labels
! syn cluster   cMultiGroup 
contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cHex,cOctalError,cHexError,cNumbersCom,cCppParen,cCppBracket,cCppString
  syn region    cMulti          transparent start='?' skip='::' end=':' 
contains=ALLBUT,@cMultiGroup,@Spell
  " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  syn cluster   cLabelGroup     contains=cUserLabel
--- 272,283 ----
  syn match     cIncluded       display contained "<[^>]*>"
  syn match     cInclude        display "^\s*\(%:\|#\)\s*include\>\s*["<]" 
contains=cIncluded
  "syn match cLineSkip  "\\$"
! syn cluster   cPreProcGroup   
contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti
  syn region    cDefine         start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" 
skip="\\$" end="$" end="//"me=s-1 contains=ALLBUT,@cPreProcGroup,@Spell
  syn region    cPreProc        
start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" 
skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
  
  " Highlight User Labels
! syn cluster   cMultiGroup     
contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString
  syn region    cMulti          transparent start='?' skip='::' end=':' 
contains=ALLBUT,@cMultiGroup,@Spell
  " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  syn cluster   cLabelGroup     contains=cUserLabel
***************
*** 323,333 ****
  hi def link cSpecialCharacter cSpecial
  hi def link cNumber           Number
  hi def link cOctal            Number
- hi def link cHex              Number
  hi def link cOctalZero                PreProc  " link this to Error if you 
want
  hi def link cFloat            Float
  hi def link cOctalError               cError
- hi def link cHexError         cError
  hi def link cParenError               cError
  hi def link cErrInParen               cError
  hi def link cErrInBracket     cError
--- 317,325 ----

Reply via email to