├── README.md ├── bin └── vim.pl ├── compiler └── sourcepawn.vim ├── ftdetect └── sourcepawn.vim └── syntax └── sourcepawn.vim /README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | ## About 4 | 5 | SourcePawn support files. 6 | 7 | - filetype detect 8 | - syntax highlight 9 | - errorformat (makeprg set your self) 10 | 11 | ## Install 12 | 13 | 14 | ### manual install 15 | 16 | download zip and extract your $HOME/.vim directory 17 | 18 | > https://github.com/withgod/vim-sourcepawn/zipball/master 19 | 20 | ### Vundle 21 | 22 | > Bundle 'withgod/vim-sourcepawn.git' 23 | 24 | ### Option 25 | 26 | put your .vimrc 27 | 28 | " for sourcepawn quickfix 29 | au FileType sourcepawn setlocal makeprg=/path/to/spcomp\ % 30 | 31 | ## Changelog 32 | 33 | ### 2013-09-30 pmrowla 34 | 35 | - Sourcemod 1.5 API support 36 | - C-style syntax to use whats in c.vim from vim 7.3. 37 | - https://github.com/withgod/vim-sourcepawn/pull/1 38 | 39 | ### 2012-02-29 withgod 40 | 41 | - few fix, make package and hosting github. 42 | 43 | ### 2009-01-05 Fyren 44 | 45 | - function generator perl script by Fyren 46 | - http://forums.alliedmods.net/showpost.php?p=738511&postcount=3 47 | - http://forums.alliedmods.net/showpost.php?p=745042&postcount=6 48 | - http://forums.alliedmods.net/showpost.php?p=745042&postcount=7 49 | 50 | ### 2007-12-31 naris 51 | 52 | - vim plugin created by naris 53 | - http://forums.alliedmods.net/showthread.php?t=65085 54 | 55 | -------------------------------------------------------------------------------- /bin/vim.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | # 3 | # ./bin/vim.pl ~/games/sourcemod-1.4.1-mac/addons/sourcemod/scripting/include 4 | # 5 | use strict; 6 | use POSIX qw(strftime); 7 | 8 | my $group = 4; 9 | 10 | if (\$ARGV != 1 && !-d $ARGV[0]) { 11 | die "missing parameter. require script parameter. \$SOURCEMOD/scripting/include"; 12 | } 13 | 14 | my @files = <$ARGV[0]/*.inc>; 15 | 16 | #these header and footer strings come from naris' original SourcePawn syntax file 17 | #skip way down below them for actual code 18 | my $current_date = strftime("%Y-%m-%d %H:%M:%S %z", localtime()); 19 | my $sm_version = `grep SOURCEMOD_VERSION $ARGV[0]/version.inc | awk '{print \$3}' | sed 's/"//g'`; 20 | my $header = <<"HEADER"; 21 | " Vim syntax file 22 | " Language: SourcePawn 23 | " URL: https://github.com/withgod/vim-sourcepawn 24 | " Generated by vim.pl 25 | " Generated at $current_date 26 | " Sourcemod Version $sm_version 27 | HEADER 28 | 29 | $header .= <<'HEADER'; 30 | " Quit when a (custom) syntax file was already loaded 31 | if exists("b:current_syntax") 32 | finish 33 | endif 34 | 35 | " A bunch of useful C keywords 36 | syn keyword cStatement goto break return continue assert state sleep exit public normal 37 | syn keyword cLabel case default 38 | syn keyword cConditional if else switch 39 | syn keyword cRepeat while for do 40 | 41 | syn keyword cTodo contained TODO FIXME XXX 42 | 43 | " It's easy to accidentally add a space after a backslash that was intended 44 | " for line continuation. Some compilers allow it, which makes it 45 | " unpredicatable and should be avoided. 46 | syn match cBadContinuation contained "\\\s\+$" 47 | 48 | " cCommentGroup allows adding matches for special things in comments 49 | syn cluster cCommentGroup contains=cTodo,cBadContinuation 50 | 51 | " String and Character constants 52 | " Highlight special characters (those which have a backslash) differently 53 | syn match cSpecial display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)" 54 | if !exists("c_no_utf") 55 | syn match cSpecial display contained "\\\(u\x\{4}\|U\x\{8}\)" 56 | endif 57 | if exists("c_no_cformat") 58 | syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell 59 | " cCppString: same as cString, but ends at end of line 60 | syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,@Spell 61 | else 62 | if !exists("c_no_c99") " ISO C99 63 | syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained 64 | else 65 | syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained 66 | endif 67 | syn match cFormat display "%%" contained 68 | syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell 69 | " cCppString: same as cString, but ends at end of line 70 | syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell 71 | endif 72 | 73 | syn match cCharacter "L\='[^\\]'" 74 | syn match cCharacter "L'[^']*'" contains=cSpecial 75 | if exists("c_gnu") 76 | syn match cSpecialError "L\='\\[^'\"?\\abefnrtv]'" 77 | syn match cSpecialCharacter "L\='\\['\"?\\abefnrtv]'" 78 | else 79 | syn match cSpecialError "L\='\\[^'\"?\\abfnrtv]'" 80 | syn match cSpecialCharacter "L\='\\['\"?\\abfnrtv]'" 81 | endif 82 | syn match cSpecialCharacter display "L\='\\\o\{1,3}'" 83 | syn match cSpecialCharacter display "'\\x\x\{1,2}'" 84 | syn match cSpecialCharacter display "L'\\x\x\+'" 85 | 86 | "when wanted, highlight trailing white space 87 | if exists("c_space_errors") 88 | if !exists("c_no_trail_space_error") 89 | syn match cSpaceError display excludenl "\s\+$" 90 | endif 91 | if !exists("c_no_tab_space_error") 92 | syn match cSpaceError display " \+\t"me=e-1 93 | endif 94 | endif 95 | 96 | " This should be before cErrInParen to avoid problems with #define ({ xxx }) 97 | if exists("c_curly_error") 98 | syntax match cCurlyError "}" 99 | syntax region cBlock start="{" end="}" contains=ALLBUT,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell fold 100 | else 101 | syntax region cBlock start="{" end="}" transparent fold 102 | endif 103 | 104 | "catch errors caused by wrong parenthesis and brackets 105 | " also accept <% for {, %> for }, <: for [ and :> for ] (C99) 106 | " But avoid matching <::. 107 | syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom 108 | if exists("c_no_curly_error") 109 | syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell 110 | " cCppParen: same as cParen but ends at end-of-line; used in cDefine 111 | syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell 112 | syn match cParenError display ")" 113 | syn match cErrInParen display contained "^[{}]\|^<%\|^%>" 114 | elseif exists("c_no_bracket_error") 115 | syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell 116 | " cCppParen: same as cParen but ends at end-of-line; used in cDefine 117 | syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell 118 | syn match cParenError display ")" 119 | syn match cErrInParen display contained "[{}]\|<%\|%>" 120 | else 121 | syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell 122 | " cCppParen: same as cParen but ends at end-of-line; used in cDefine 123 | syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell 124 | syn match cParenError display "[\])]" 125 | syn match cErrInParen display contained "[\]{}]\|<%\|%>" 126 | syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString,@Spell 127 | " cCppBracket: same as cParen but ends at end-of-line; used in cDefine 128 | syn region cCppBracket transparent start='\[\|<::\@!' skip='\\$' excludenl end=']\|:>' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell 129 | syn match cErrInBracket display contained "[);{}]\|<%\|%>" 130 | endif 131 | 132 | "integer number, or floating point number without a dot and with "f". 133 | syn case ignore 134 | syn match cNumbers display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal 135 | " Same, but without octal error (for comments) 136 | syn match cNumbersCom display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal 137 | syn match cNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>" 138 | "hex number 139 | syn match cNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>" 140 | " Flag the first zero of an octal number as something special 141 | syn match cOctal display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero 142 | syn match cOctalZero display contained "\<0" 143 | syn match cFloat display contained "\d\+f" 144 | "floating point number, with dot, optional exponent 145 | syn match cFloat display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=" 146 | "floating point number, starting with a dot, optional exponent 147 | syn match cFloat display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>" 148 | "floating point number, without dot, with exponent 149 | syn match cFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>" 150 | if !exists("c_no_c99") 151 | "hexadecimal floating point number, optional leading digits, with dot, with exponent 152 | syn match cFloat display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>" 153 | "hexadecimal floating point number, with leading digits, optional dot, with exponent 154 | syn match cFloat display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>" 155 | endif 156 | 157 | " flag an octal number with wrong digits 158 | syn match cOctalError display contained "0\o*[89]\d*" 159 | syn case match 160 | 161 | if exists("c_comment_strings") 162 | " A comment can contain cString, cCharacter and cNumber. 163 | " But a "*/" inside a cString in a cComment DOES end the comment! So we 164 | " need to use a special type of cString: cCommentString, which also ends on 165 | " "*/", and sees a "*" at the start of the line as comment again. 166 | " Unfortunately this doesn't very well work for // type of comments :-( 167 | syntax match cCommentSkip contained "^\s*\*\($\|\s\+\)" 168 | syntax region cCommentString contained start=+L\=\\\@" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError 206 | syn match cPreCondit display "^\s*\(%:\|#\)\s*\(else\|endif\)\>" 207 | if !exists("c_no_if0") 208 | if !exists("c_no_if0_fold") 209 | syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2 fold 210 | else 211 | syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2 212 | endif 213 | syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip 214 | syn region cCppSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppSkip 215 | endif 216 | syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ 217 | syn match cIncluded display contained "<[^>]*>" 218 | syn match cInclude display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded 219 | "syn match cLineSkip "\\$" 220 | 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 221 | syn region cDefine start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell 222 | syn region cPreProc start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell 223 | 224 | " Highlight User Labels 225 | 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 226 | syn region cMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup,@Spell 227 | " Avoid matching foo::bar() in C++ by requiring that the next char is not ':' 228 | syn cluster cLabelGroup contains=cUserLabel 229 | syn match cUserCont display "^\s*\I\i*\s*:$" contains=@cLabelGroup 230 | syn match cUserCont display ";\s*\I\i*\s*:$" contains=@cLabelGroup 231 | syn match cUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup 232 | syn match cUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup 233 | 234 | syn match cUserLabel display "\I\i*" contained 235 | 236 | " Avoid recognizing most bitfields as labels 237 | syn match cBitField display "^\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType 238 | syn match cBitField display ";\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType 239 | 240 | if exists("c_minlines") 241 | let b:c_minlines = c_minlines 242 | else 243 | if !exists("c_no_if0") 244 | let b:c_minlines = 50 " #if 0 constructs can be long 245 | else 246 | let b:c_minlines = 15 " mostly for () constructs 247 | endif 248 | endif 249 | if exists("c_curly_error") 250 | syn sync fromstart 251 | else 252 | exec "syn sync ccomment cComment minlines=" . b:c_minlines 253 | endif 254 | 255 | " Define the default highlighting. 256 | " Only used when an item doesn't have highlighting yet 257 | hi def link cFormat cSpecial 258 | hi def link cCppString cString 259 | hi def link cCommentL cComment 260 | hi def link cCommentStart cComment 261 | hi def link cLabel Label 262 | hi def link cUserLabel Label 263 | hi def link cConditional Conditional 264 | hi def link cRepeat Repeat 265 | hi def link cCharacter Character 266 | hi def link cSpecialCharacter cSpecial 267 | hi def link cNumber Number 268 | hi def link cOctal Number 269 | hi def link cOctalZero PreProc " link this to Error if you want 270 | hi def link cFloat Float 271 | hi def link cOctalError cError 272 | hi def link cParenError cError 273 | hi def link cErrInParen cError 274 | hi def link cErrInBracket cError 275 | hi def link cCommentError cError 276 | hi def link cCommentStartError cError 277 | hi def link cSpaceError cError 278 | hi def link cSpecialError cError 279 | hi def link cCurlyError cError 280 | hi def link cOperator Operator 281 | hi def link cStructure Structure 282 | hi def link cStorageClass StorageClass 283 | hi def link cInclude Include 284 | hi def link cPreProc PreProc 285 | hi def link cDefine Macro 286 | hi def link cIncluded cString 287 | hi def link cError Error 288 | hi def link cStatement Statement 289 | hi def link cPreCondit PreCondit 290 | hi def link cType Type 291 | hi def link cConstant Constant 292 | hi def link cCommentString cString 293 | hi def link cComment2String cString 294 | hi def link cCommentSkip cComment 295 | hi def link cString String 296 | hi def link cComment Comment 297 | hi def link cSpecial SpecialChar 298 | hi def link cTodo Todo 299 | hi def link cBadContinuation Error 300 | hi def link cCppSkip cCppOut 301 | hi def link cCppOut2 cCppOut 302 | hi def link cCppOut Comment 303 | 304 | hi def link cFunction Function 305 | hi def link cForward Function 306 | 307 | let b:current_syntax = "sourcepawn" 308 | 309 | " vim: ts=8 310 | FOOTER 311 | 312 | print $header; 313 | 314 | for my $file (@files) 315 | { 316 | my @constants; 317 | my @tags; 318 | my @functions; 319 | my @forwards; 320 | my $inEnum = 0; 321 | 322 | open(FILE, $file) or die "couldn't open $file: $!"; 323 | 324 | foreach () 325 | { 326 | if ($inEnum == 0) 327 | { 328 | if (/^\s*#define\s+([^_]\w+)\s+\S/) { push(@constants, $1); } 329 | elsif (/^\s*public(?:\s+const)?\s+(?:\w+:)?([^_](?>\w+))(?!:)/) { push(@constants, $1); } 330 | elsif (/^\s*(?:native|stock)\s+(?:\w+:)?(\w+)\(/) { push(@functions, $1); } 331 | elsif (/^\s*functag public\s+(?:\w+:)?(\w+)/) { push(@tags, $1); } 332 | elsif (/^\s*enum\s+(\w+)/) { push(@tags, $1); $inEnum = 1; } 333 | elsif (/^\s*(?:struct|funcenum)\s+(\w+)/) { push(@tags, $1); } 334 | elsif (/^\s*forward\s+(?:\w+:)?(\w+)\(/) { push(@forwards, $1); } 335 | } 336 | else 337 | { 338 | if (/^\s*}/) { $inEnum = 0; } 339 | elsif (/^\t?(\w+)/) { push(@constants, $1); } 340 | } 341 | } 342 | 343 | my $_file = $file; 344 | $_file =~ s/\Q$ARGV[0]\E\/?//; 345 | print "\n\" $_file\n"; 346 | 347 | if (@constants % $group) { push @constants, ("") x ($group - (@constants % $group)); } 348 | if (@tags % $group) { push @tags, ("") x ($group - (@tags % $group)); } 349 | if (@functions % $group) { push @functions, ("") x ($group - (@functions % $group)); } 350 | if (@forwards % $group) { push @forwards, ("") x ($group - (@forwards % $group)); } 351 | 352 | $, = " "; 353 | for (my $i = 0; $i <= $#functions; $i += $group) { print "syn keyword\tcFunction\t@functions[$i .. $i + $group - 1]\n"; } 354 | for (my $i = 0; $i <= $#constants; $i += $group) { print "syn keyword\tcConstant\t@constants[$i .. $i + $group - 1]\n"; } 355 | for (my $i = 0; $i <= $#tags; $i += $group) { print "syn keyword\tcTag\t\t@tags[$i .. $i + $group - 1]\n"; } 356 | for (my $i = 0; $i <= $#forwards; $i += $group) { print "syn keyword\tcForward\t@forwards[$i .. $i + $group - 1]\n"; } 357 | } 358 | 359 | 360 | print $footer; 361 | -------------------------------------------------------------------------------- /compiler/sourcepawn.vim: -------------------------------------------------------------------------------- 1 | " spcomp dosent support run into $PATH 2 | " set your .vimrc 3 | " CompilerSet makeprg=spcomp\ % 4 | CompilerSet errorformat=%f\(%l\)\ :\ fatal\ %t%*[^0-9]%n:\ %m,%f\(%l\)\ :\ %t%*[^0-9]%n:\ %m 5 | 6 | -------------------------------------------------------------------------------- /ftdetect/sourcepawn.vim: -------------------------------------------------------------------------------- 1 | " SourcePawn 2 | au BufNewFile,BufRead *.sp set filetype=sourcepawn 3 | "au BufNewFile,BufRead *.inc set filetype=sourcepawn 4 | 5 | au FileType sourcepawn compiler sourcepawn 6 | 7 | -------------------------------------------------------------------------------- /syntax/sourcepawn.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: SourcePawn 3 | " URL: https://github.com/withgod/vim-sourcepawn 4 | " Generated by vim.pl 5 | " Generated at 2017-09-15 15:39:36 +0900 6 | " Sourcemod Version 1.8.0-manual 7 | 8 | " Quit when a (custom) syntax file was already loaded 9 | if exists("b:current_syntax") 10 | finish 11 | endif 12 | 13 | " A bunch of useful C keywords 14 | syn keyword cStatement goto break return continue assert state sleep exit public normal 15 | syn keyword cLabel case default 16 | syn keyword cConditional if else switch 17 | syn keyword cRepeat while for do 18 | 19 | syn keyword cTodo contained TODO FIXME XXX 20 | 21 | " It's easy to accidentally add a space after a backslash that was intended 22 | " for line continuation. Some compilers allow it, which makes it 23 | " unpredicatable and should be avoided. 24 | syn match cBadContinuation contained "\\\s\+$" 25 | 26 | " cCommentGroup allows adding matches for special things in comments 27 | syn cluster cCommentGroup contains=cTodo,cBadContinuation 28 | 29 | " String and Character constants 30 | " Highlight special characters (those which have a backslash) differently 31 | syn match cSpecial display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)" 32 | if !exists("c_no_utf") 33 | syn match cSpecial display contained "\\\(u\x\{4}\|U\x\{8}\)" 34 | endif 35 | if exists("c_no_cformat") 36 | syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell 37 | " cCppString: same as cString, but ends at end of line 38 | syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,@Spell 39 | else 40 | if !exists("c_no_c99") " ISO C99 41 | syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained 42 | else 43 | syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained 44 | endif 45 | syn match cFormat display "%%" contained 46 | syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell 47 | " cCppString: same as cString, but ends at end of line 48 | syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell 49 | endif 50 | 51 | syn match cCharacter "L\='[^\\]'" 52 | syn match cCharacter "L'[^']*'" contains=cSpecial 53 | if exists("c_gnu") 54 | syn match cSpecialError "L\='\\[^'\"?\\abefnrtv]'" 55 | syn match cSpecialCharacter "L\='\\['\"?\\abefnrtv]'" 56 | else 57 | syn match cSpecialError "L\='\\[^'\"?\\abfnrtv]'" 58 | syn match cSpecialCharacter "L\='\\['\"?\\abfnrtv]'" 59 | endif 60 | syn match cSpecialCharacter display "L\='\\\o\{1,3}'" 61 | syn match cSpecialCharacter display "'\\x\x\{1,2}'" 62 | syn match cSpecialCharacter display "L'\\x\x\+'" 63 | 64 | "when wanted, highlight trailing white space 65 | if exists("c_space_errors") 66 | if !exists("c_no_trail_space_error") 67 | syn match cSpaceError display excludenl "\s\+$" 68 | endif 69 | if !exists("c_no_tab_space_error") 70 | syn match cSpaceError display " \+\t"me=e-1 71 | endif 72 | endif 73 | 74 | " This should be before cErrInParen to avoid problems with #define ({ xxx }) 75 | if exists("c_curly_error") 76 | syntax match cCurlyError "}" 77 | syntax region cBlock start="{" end="}" contains=ALLBUT,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell fold 78 | else 79 | syntax region cBlock start="{" end="}" transparent fold 80 | endif 81 | 82 | "catch errors caused by wrong parenthesis and brackets 83 | " also accept <% for {, %> for }, <: for [ and :> for ] (C99) 84 | " But avoid matching <::. 85 | syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom 86 | if exists("c_no_curly_error") 87 | syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell 88 | " cCppParen: same as cParen but ends at end-of-line; used in cDefine 89 | syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell 90 | syn match cParenError display ")" 91 | syn match cErrInParen display contained "^[{}]\|^<%\|^%>" 92 | elseif exists("c_no_bracket_error") 93 | syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell 94 | " cCppParen: same as cParen but ends at end-of-line; used in cDefine 95 | syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell 96 | syn match cParenError display ")" 97 | syn match cErrInParen display contained "[{}]\|<%\|%>" 98 | else 99 | syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell 100 | " cCppParen: same as cParen but ends at end-of-line; used in cDefine 101 | syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell 102 | syn match cParenError display "[\])]" 103 | syn match cErrInParen display contained "[\]{}]\|<%\|%>" 104 | syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString,@Spell 105 | " cCppBracket: same as cParen but ends at end-of-line; used in cDefine 106 | syn region cCppBracket transparent start='\[\|<::\@!' skip='\\$' excludenl end=']\|:>' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell 107 | syn match cErrInBracket display contained "[);{}]\|<%\|%>" 108 | endif 109 | 110 | "integer number, or floating point number without a dot and with "f". 111 | syn case ignore 112 | syn match cNumbers display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal 113 | " Same, but without octal error (for comments) 114 | syn match cNumbersCom display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal 115 | syn match cNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>" 116 | "hex number 117 | syn match cNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>" 118 | " Flag the first zero of an octal number as something special 119 | syn match cOctal display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero 120 | syn match cOctalZero display contained "\<0" 121 | syn match cFloat display contained "\d\+f" 122 | "floating point number, with dot, optional exponent 123 | syn match cFloat display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=" 124 | "floating point number, starting with a dot, optional exponent 125 | syn match cFloat display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>" 126 | "floating point number, without dot, with exponent 127 | syn match cFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>" 128 | if !exists("c_no_c99") 129 | "hexadecimal floating point number, optional leading digits, with dot, with exponent 130 | syn match cFloat display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>" 131 | "hexadecimal floating point number, with leading digits, optional dot, with exponent 132 | syn match cFloat display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>" 133 | endif 134 | 135 | " flag an octal number with wrong digits 136 | syn match cOctalError display contained "0\o*[89]\d*" 137 | syn case match 138 | 139 | if exists("c_comment_strings") 140 | " A comment can contain cString, cCharacter and cNumber. 141 | " But a "*/" inside a cString in a cComment DOES end the comment! So we 142 | " need to use a special type of cString: cCommentString, which also ends on 143 | " "*/", and sees a "*" at the start of the line as comment again. 144 | " Unfortunately this doesn't very well work for // type of comments :-( 145 | syntax match cCommentSkip contained "^\s*\*\($\|\s\+\)" 146 | syntax region cCommentString contained start=+L\=\\\@" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError 744 | syn match cPreCondit display "^\s*\(%:\|#\)\s*\(else\|endif\)\>" 745 | if !exists("c_no_if0") 746 | if !exists("c_no_if0_fold") 747 | syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2 fold 748 | else 749 | syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2 750 | endif 751 | syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip 752 | syn region cCppSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppSkip 753 | endif 754 | syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ 755 | syn match cIncluded display contained "<[^>]*>" 756 | syn match cInclude display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded 757 | "syn match cLineSkip "\\$" 758 | 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 759 | syn region cDefine start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell 760 | syn region cPreProc start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell 761 | 762 | " Highlight User Labels 763 | 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 764 | syn region cMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup,@Spell 765 | " Avoid matching foo::bar() in C++ by requiring that the next char is not ':' 766 | syn cluster cLabelGroup contains=cUserLabel 767 | syn match cUserCont display "^\s*\I\i*\s*:$" contains=@cLabelGroup 768 | syn match cUserCont display ";\s*\I\i*\s*:$" contains=@cLabelGroup 769 | syn match cUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup 770 | syn match cUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup 771 | 772 | syn match cUserLabel display "\I\i*" contained 773 | 774 | " Avoid recognizing most bitfields as labels 775 | syn match cBitField display "^\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType 776 | syn match cBitField display ";\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType 777 | 778 | if exists("c_minlines") 779 | let b:c_minlines = c_minlines 780 | else 781 | if !exists("c_no_if0") 782 | let b:c_minlines = 50 " #if 0 constructs can be long 783 | else 784 | let b:c_minlines = 15 " mostly for () constructs 785 | endif 786 | endif 787 | if exists("c_curly_error") 788 | syn sync fromstart 789 | else 790 | exec "syn sync ccomment cComment minlines=" . b:c_minlines 791 | endif 792 | 793 | " Define the default highlighting. 794 | " Only used when an item doesn't have highlighting yet 795 | hi def link cFormat cSpecial 796 | hi def link cCppString cString 797 | hi def link cCommentL cComment 798 | hi def link cCommentStart cComment 799 | hi def link cLabel Label 800 | hi def link cUserLabel Label 801 | hi def link cConditional Conditional 802 | hi def link cRepeat Repeat 803 | hi def link cCharacter Character 804 | hi def link cSpecialCharacter cSpecial 805 | hi def link cNumber Number 806 | hi def link cOctal Number 807 | hi def link cOctalZero PreProc " link this to Error if you want 808 | hi def link cFloat Float 809 | hi def link cOctalError cError 810 | hi def link cParenError cError 811 | hi def link cErrInParen cError 812 | hi def link cErrInBracket cError 813 | hi def link cCommentError cError 814 | hi def link cCommentStartError cError 815 | hi def link cSpaceError cError 816 | hi def link cSpecialError cError 817 | hi def link cCurlyError cError 818 | hi def link cOperator Operator 819 | hi def link cStructure Structure 820 | hi def link cStorageClass StorageClass 821 | hi def link cInclude Include 822 | hi def link cPreProc PreProc 823 | hi def link cDefine Macro 824 | hi def link cIncluded cString 825 | hi def link cError Error 826 | hi def link cStatement Statement 827 | hi def link cPreCondit PreCondit 828 | hi def link cType Type 829 | hi def link cConstant Constant 830 | hi def link cCommentString cString 831 | hi def link cComment2String cString 832 | hi def link cCommentSkip cComment 833 | hi def link cString String 834 | hi def link cComment Comment 835 | hi def link cSpecial SpecialChar 836 | hi def link cTodo Todo 837 | hi def link cBadContinuation Error 838 | hi def link cCppSkip cCppOut 839 | hi def link cCppOut2 cCppOut 840 | hi def link cCppOut Comment 841 | 842 | hi def link cFunction Function 843 | hi def link cForward Function 844 | 845 | let b:current_syntax = "sourcepawn" 846 | 847 | " vim: ts=8 848 | --------------------------------------------------------------------------------