Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 1 | " Vim syntax file for the D programming language (version 0.149). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | " |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 3 | " Language: D |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4 | " Maintainer: Jason Mills<jmills@cs.mun.ca> |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 5 | " When emailing me, please put the word vim somewhere in the subject |
| 6 | " to ensure the email does not get marked as spam. |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 7 | " Last Change: 2006 Apr 30 |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 8 | " Version: 0.15 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9 | " |
| 10 | " Options: |
| 11 | " d_comment_strings - set to highlight strings and numbers in comments |
| 12 | " |
| 13 | " d_hl_operator_overload - set to highlight D's specially named functions |
| 14 | " that when overloaded implement unary and binary operators (e.g. cmp). |
| 15 | " |
| 16 | " Todo: |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 17 | " - Must determine a better method of sync'ing than simply setting minlines |
| 18 | " to a large number for /+ +/. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 19 | " |
| 20 | " - Several keywords (namely, in and out) are both storage class and |
| 21 | " statements, depending on their context. Must use some matching to figure |
| 22 | " out which and highlight appropriately. For now I have made such keywords |
| 23 | " statements. |
| 24 | " |
| 25 | " - Mark contents of the asm statement body as special |
| 26 | " |
| 27 | |
| 28 | " Quit when a syntax file was already loaded |
| 29 | if exists("b:current_syntax") |
| 30 | finish |
| 31 | endif |
| 32 | |
| 33 | " Keyword definitions |
| 34 | " |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 35 | syn keyword dExternal import package module extern |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 36 | syn keyword dConditional if else switch iftype |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 37 | syn keyword dBranch goto break continue |
| 38 | syn keyword dRepeat while for do foreach |
| 39 | syn keyword dBoolean true false |
| 40 | syn keyword dConstant null |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 41 | syn keyword dConstant __FILE__ __LINE__ __DATE__ __TIME__ __TIMESTAMP__ |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 42 | syn keyword dTypedef alias typedef |
| 43 | syn keyword dStructure template interface class enum struct union |
| 44 | syn keyword dOperator new delete typeof typeid cast align is |
| 45 | syn keyword dOperator this super |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | if exists("d_hl_operator_overload") |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 47 | syn keyword dOpOverload opNeg opCom opPostInc opPostDec opCast opAdd opSub opSub_r |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 48 | syn keyword dOpOverload opMul opDiv opDiv_r opMod opMod_r opAnd opOr opXor |
| 49 | syn keyword dOpOverload opShl opShl_r opShr opShr_r opUShr opUShr_r opCat |
| 50 | syn keyword dOpOverload opCat_r opEquals opEquals opCmp opCmp opCmp opCmp |
| 51 | syn keyword dOpOverload opAddAssign opSubAssign opMulAssign opDivAssign |
| 52 | syn keyword dOpOverload opModAssign opAndAssign opOrAssign opXorAssign |
| 53 | syn keyword dOpOverload opShlAssign opShrAssign opUShrAssign opCatAssign |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 54 | syn keyword dOpOverload opIndex opIndexAssign opCall opSlice opSliceAssign opPos |
| 55 | syn keyword dOpOverload opAdd_r opMul_r opAnd_r opOr_r opXor_r |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 56 | endif |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 57 | syn keyword dType ushort int uint long ulong float |
| 58 | syn keyword dType void byte ubyte double bit char wchar ucent cent |
| 59 | syn keyword dType short bool dchar |
| 60 | syn keyword dType real ireal ifloat idouble creal cfloat cdouble |
| 61 | syn keyword dDebug deprecated unittest |
| 62 | syn keyword dExceptions throw try catch finally |
| 63 | syn keyword dScopeDecl public protected private export |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 64 | syn keyword dStatement version debug return with invariant body scope |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 65 | syn keyword dStatement in out inout asm mixin |
| 66 | syn keyword dStatement function delegate |
| 67 | syn keyword dStorageClass auto static override final const abstract volatile |
| 68 | syn keyword dStorageClass synchronized |
| 69 | syn keyword dPragma pragma |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 70 | |
| 71 | |
| 72 | " Assert is a statement and a module name. |
| 73 | syn match dAssert "^assert\>" |
| 74 | syn match dAssert "[^.]\s*\<assert\>"ms=s+1 |
| 75 | |
| 76 | " Marks contents of the asm statment body as special |
| 77 | " |
| 78 | " TODO |
| 79 | "syn match dAsmStatement "\<asm\>" |
| 80 | "syn region dAsmBody start="asm[\n]*\s*{"hs=e+1 end="}"he=e-1 contains=dAsmStatement |
| 81 | " |
| 82 | "hi def link dAsmBody dUnicode |
| 83 | "hi def link dAsmStatement dStatement |
| 84 | |
| 85 | " Labels |
| 86 | " |
| 87 | " We contain dScopeDecl so public: private: etc. are not highlighted like labels |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 88 | syn match dUserLabel "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=dLabel,dScopeDecl |
| 89 | syn keyword dLabel case default |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 90 | |
| 91 | " Comments |
| 92 | " |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 93 | syn keyword dTodo contained TODO FIXME TEMP XXX |
| 94 | syn match dCommentStar contained "^\s*\*[^/]"me=e-1 |
| 95 | syn match dCommentStar contained "^\s*\*$" |
| 96 | syn match dCommentPlus contained "^\s*+[^/]"me=e-1 |
| 97 | syn match dCommentPlus contained "^\s*+$" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 98 | if exists("d_comment_strings") |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 99 | syn region dBlockCommentString contained start=+"+ end=+"+ end=+\*/+me=s-1,he=s-1 contains=dCommentStar,dUnicode,dEscSequence,@Spell |
| 100 | syn region dNestedCommentString contained start=+"+ end=+"+ end="+"me=s-1,he=s-1 contains=dCommentPlus,dUnicode,dEscSequence,@Spell |
| 101 | syn region dLineCommentString contained start=+"+ end=+$\|"+ contains=dUnicode,dEscSequence,@Spell |
| 102 | syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell |
| 103 | syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell |
| 104 | syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 105 | else |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 106 | syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell |
| 107 | syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell |
| 108 | syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 109 | endif |
| 110 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 111 | hi link dLineCommentString dBlockCommentString |
| 112 | hi link dBlockCommentString dString |
| 113 | hi link dNestedCommentString dString |
| 114 | hi link dCommentStar dBlockComment |
| 115 | hi link dCommentPlus dNestedComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 116 | |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 117 | " /+ +/ style comments and strings that span multiple lines can cause |
| 118 | " problems. To play it safe, set minlines to a large number. |
| 119 | syn sync minlines=200 |
| 120 | " Use ccomment for /* */ style comments |
| 121 | syn sync ccomment dBlockComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 122 | |
| 123 | " Characters |
| 124 | " |
| 125 | syn match dSpecialCharError contained "[^']" |
| 126 | |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 127 | " Escape sequences (oct,specal char,hex,wchar, character entities \&xxx;) |
| 128 | " These are not contained because they are considered string litterals |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 129 | syn match dEscSequence "\\\(\o\{1,3}\|[\"\\'\\?ntbrfva]\|u\x\{4}\|U\x\{8}\|x\x\x\)" |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 130 | syn match dEscSequence "\\&[^;& \t]\+;" |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 131 | syn match dCharacter "'[^']*'" contains=dEscSequence,dSpecialCharError |
| 132 | syn match dCharacter "'\\''" contains=dEscSequence |
| 133 | syn match dCharacter "'[^\\]'" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | |
| 135 | " Unicode characters |
| 136 | " |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 137 | syn match dUnicode "\\u\d\{4\}" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 139 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 140 | " String. |
| 141 | " |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 142 | syn region dString start=+"+ end=+"[cwd]\=+ contains=dEscSequence,@Spell |
| 143 | syn region dRawString start=+`+ skip=+\\`+ end=+`[cwd]\=+ contains=@Spell |
| 144 | syn region dRawString start=+r"+ skip=+\\"+ end=+"[cwd]\=+ contains=@Spell |
| 145 | syn region dHexString start=+x"+ skip=+\\"+ end=+"[cwd]\=+ contains=@Spell |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 146 | |
| 147 | " Numbers |
| 148 | " |
| 149 | syn case ignore |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 150 | |
| 151 | syn match dDec display "\<\d[0-9_]*\(u\=l\=\|l\=u\=\)\>" |
| 152 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 153 | " Hex number |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 154 | syn match dHex display "\<0x[0-9a-f_]\+\(u\=l\=\|l\=u\=\)\>" |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 155 | |
| 156 | syn match dOctal display "\<0[0-7_]\+\(u\=l\=\|l\=u\=\)\>" |
| 157 | " flag an octal number with wrong digits |
| 158 | syn match dOctalError display "\<0[0-7_]*[89][0-9_]*" |
| 159 | |
| 160 | " binary numbers |
| 161 | syn match dBinary display "\<0b[01_]\+\(u\=l\=\|l\=u\=\)\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 162 | |
| 163 | "floating point without the dot |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 164 | syn match dFloat display "\<\d[0-9_]*\(fi\=\|l\=i\)\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 165 | "floating point number, with dot, optional exponent |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 166 | syn match dFloat display "\<\d[0-9_]*\.[0-9_]*\(e[-+]\=[0-9_]\+\)\=[fl]\=i\=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 167 | "floating point number, starting with a dot, optional exponent |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 168 | syn match dFloat display "\(\.[0-9_]\+\)\(e[-+]\=[0-9_]\+\)\=[fl]\=i\=\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 169 | "floating point number, without dot, with exponent |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 170 | "syn match dFloat display "\<\d\+e[-+]\=\d\+[fl]\=\>" |
| 171 | syn match dFloat display "\<\d[0-9_]*e[-+]\=[0-9_]\+[fl]\=\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | |
| 173 | "floating point without the dot |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 174 | syn match dHexFloat display "\<0x[0-9a-f_]\+\(fi\=\|l\=i\)\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 175 | "floating point number, with dot, optional exponent |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 176 | syn match dHexFloat display "\<0x[0-9a-f_]\+\.[0-9a-f_]*\(p[-+]\=[0-9_]\+\)\=[fl]\=i\=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 177 | "floating point number, without dot, with exponent |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 178 | syn match dHexFloat display "\<0x[0-9a-f_]\+p[-+]\=[0-9_]\+[fl]\=i\=\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 179 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 180 | syn case match |
| 181 | |
| 182 | " Pragma (preprocessor) support |
| 183 | " TODO: Highlight following Integer and optional Filespec. |
| 184 | syn region dPragma start="#\s*\(line\>\)" skip="\\$" end="$" |
| 185 | |
| 186 | |
| 187 | " The default highlighting. |
| 188 | " |
| 189 | hi def link dBinary Number |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 190 | hi def link dDec Number |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 191 | hi def link dHex Number |
| 192 | hi def link dOctal Number |
| 193 | hi def link dFloat Float |
| 194 | hi def link dHexFloat Float |
| 195 | hi def link dDebug Debug |
| 196 | hi def link dBranch Conditional |
| 197 | hi def link dConditional Conditional |
| 198 | hi def link dLabel Label |
| 199 | hi def link dUserLabel Label |
| 200 | hi def link dRepeat Repeat |
| 201 | hi def link dExceptions Exception |
| 202 | hi def link dAssert Statement |
| 203 | hi def link dStatement Statement |
| 204 | hi def link dScopeDecl dStorageClass |
| 205 | hi def link dStorageClass StorageClass |
| 206 | hi def link dBoolean Boolean |
| 207 | hi def link dUnicode Special |
| 208 | hi def link dRawString String |
| 209 | hi def link dString String |
| 210 | hi def link dHexString String |
| 211 | hi def link dCharacter Character |
| 212 | hi def link dEscSequence SpecialChar |
| 213 | hi def link dSpecialCharError Error |
| 214 | hi def link dOctalError Error |
| 215 | hi def link dOperator Operator |
| 216 | hi def link dOpOverload Operator |
| 217 | hi def link dConstant Constant |
| 218 | hi def link dTypedef Typedef |
| 219 | hi def link dStructure Structure |
| 220 | hi def link dTodo Todo |
| 221 | hi def link dType Type |
| 222 | hi def link dLineComment Comment |
| 223 | hi def link dBlockComment Comment |
| 224 | hi def link dNestedComment Comment |
| 225 | hi def link dExternal Include |
| 226 | hi def link dPragma PreProc |
| 227 | |
| 228 | let b:current_syntax = "d" |
Bram Moolenaar | 5baddf0 | 2006-03-12 21:53:56 +0000 | [diff] [blame] | 229 | |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 230 | " vim: ts=8 noet |