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