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