glsl.vim (17319B)
1 " Vim syntax file the OpenGL Shading Language 2 " Language: GLSL 3 " Author: Nathan Cournia <nathan@cournia.com> 4 " Date: June 30, 2004 5 " File Types: .frag .vert .glsl .fp .vp 6 " Version: 1.10.00 7 " Notes: Adapted from c.vim - Bram Moolenaar <bram.vim.org> 8 " Adapted from cg.vim - Kevin Bjorke <kbjorke@nvidia.com> 9 10 " For version 5.x: Clear all syntax items 11 " For version 6.x: Quit when a syntax file was already loaded 12 if version < 600 13 syntax clear 14 elseif exists("b:current_syntax") 15 finish 16 endif 17 18 " a bunch of useful keywords 19 syn keyword glslConditional if else 20 syn keyword glslStatement break return continue discard 21 syn keyword glslRepeat while for do 22 syn keyword glslTodo contained TODO FIXME XXX 23 24 " glslCommentGroup allows adding matches for special things in comments 25 syn cluster glslCommentGroup contains=glslTodo 26 27 "catch errors caused by wrong parenthesis and brackets 28 syn cluster glslParenGroup contains=glslParenError,glslIncluded,glslSpecial,glslCommentSkip,glslCommentString,glslComment2String,@glslCommentGroup,glslCommentStartError,glslUserCont,glslUserLabel,glslBitField,glslCommentSkip,glslOctalZero,glslCppOut,glslCppOut2,glslCppSkip,glslFormat,glslNumber,glslFloat,glslOctal,glslOctalError,glslNumbersCom 29 if exists("c_no_bracket_error") 30 syn region glslParen transparent start='(' end=')' contains=ALLBUT,@glslParenGroup,glslCppParen,glslCppString 31 " glslCppParen: same as glslParen but ends at end-of-line; used in glslDefine 32 syn region glslCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@glslParenGroup,glslParen,glslString 33 syn match glslParenError display ")" 34 syn match glslErrInParen display contained "[{}]" 35 else 36 syn region glslParen transparent start='(' end=')' contains=ALLBUT,@glslParenGroup,glslCppParen,glslErrInBracket,glslCppBracket,glslCppString 37 " glslCppParen: same as glslParen but ends at end-of-line; used in glslDefine 38 syn region glslCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@glslParenGroup,glslErrInBracket,glslParen,glslBracket,glslString 39 syn match glslParenError display "[\])]" 40 syn match glslErrInParen display contained "[\]{}]" 41 syn region glslBracket transparent start='\[' end=']' contains=ALLBUT,@glslParenGroup,glslErrInParen,glslCppParen,glslCppBracket,glslCppString 42 " glslCppBracket: same as glslParen but ends at end-of-line; used in glslDefine 43 syn region glslCppBracket transparent start='\[' skip='\\$' excludenl end=']' end='$' contained contains=ALLBUT,@glslParenGroup,glslErrInParen,glslParen,glslBracket,glslString 44 syn match glslErrInBracket display contained "[);{}]" 45 endif 46 47 "integer number, or floating point number without a dot and with "f". 48 syn case ignore 49 syn match glslNumbers display transparent "\<\d\|\.\d" contains=glslNumber,glslFloat,glslOctalError,glslOctal 50 " Same, but without octal error (for comments) 51 syn match glslNumbersCom display contained transparent "\<\d\|\.\d" contains=glslNumber,glslFloat,glslOctal 52 syn match glslNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>" 53 "hex number 54 syn match glslNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>" 55 " Flag the first zero of an octal number as something special 56 syn match glslOctal display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=glslOctalZero 57 syn match glslOctalZero display contained "\<0" 58 syn match glslFloat display contained "\d\+f" 59 "floating point number, with dot, optional exponent 60 syn match glslFloat display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=" 61 "floating point number, starting with a dot, optional exponent 62 syn match glslFloat display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>" 63 "floating point number, without dot, with exponent 64 syn match glslFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>" 65 " flag an octal number with wrong digits 66 syn match glslOctalError display contained "0\o*[89]\d*" 67 syn case match 68 69 if exists("c_comment_strings") 70 " A comment can contain glslString, glslCharacter and glslNumber. 71 " But a "*/" inside a glslString in a glslComment DOES end the comment! So we 72 " need to use a special type of glslString: glslCommentString, which also ends on 73 " "*/", and sees a "*" at the start of the line as glslomment again. 74 " Unfortunately this doesn't very well work for // type of comments :-( 75 syntax match glslCommentSkip contained "^\s*\*\($\|\s\+\)" 76 syntax region glslCommentString contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=glslSpecial,glslCommentSkip 77 syntax region glslComment2String contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=glslSpecial 78 syntax region glslCommentL start="//" skip="\\$" end="$" keepend contains=@glslCommentGroup,glslComment2String,glslCharacter,glslNumbersCom,glslSpaceError 79 syntax region glslComment matchgroup=glslCommentStart start="/\*" matchgroup=NONE end="\*/" contains=@glslCommentGroup,glslCommentStartError,glslCommentString,glslCharacter,glslNumbersCom,glslSpaceError 80 else 81 syn region glslCommentL start="//" skip="\\$" end="$" keepend contains=@glslCommentGroup,glslSpaceError 82 syn region glslComment matchgroup=glslCommentStart start="/\*" matchgroup=NONE end="\*/" contains=@glslCommentGroup,glslCommentStartError,glslSpaceError 83 endif 84 " keep a // comment separately, it terminates a preproc. conditional 85 syntax match glslCommentError display "\*/" 86 syntax match glslCommentStartError display "/\*"me=e-1 contained 87 88 syn keyword glslType void 89 syn keyword glslType bool bvec2 bvec3 bvec4 90 syn keyword glslType int ivec2 ivec3 ivec4 91 syn keyword glslType float vec2 vec3 vec4 92 syn keyword glslType mat2 mat3 mat4 93 syn keyword glslType sampler1D sampler2D sampler3D samplerCUBE sampler1DShadow sampler2DShadow 94 95 syn keyword glslStructure struct 96 97 syn keyword glslStorageClass const attribute varying uniform 98 syn keyword glslStorageClass in out inout 99 100 syn keyword glslConstant __LINE__ __FILE__ __VERSION__ 101 102 syn keyword glslConstant true false 103 104 syn region glslPreCondit start="^\s*#\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=glslComment,glslCppString,glslCharacter,glslCppParen,glslParenError,glslNumbers,glslCommentError,glslSpaceError 105 syn match glslPreCondit display "^\s*#\s*\(else\|endif\)\>" 106 syn region glslCppOut start="^\s*#\s*if\s\+0\+\>" end=".\|$" contains=glslCppOut2 107 syn region glslCppOut2 contained start="0" end="^\s*#\s*\(endif\>\|else\>\|elif\>\)" contains=glslSpaceError,glslCppSkip 108 syn region glslCppSkip contained start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*#\s*endif\>" contains=glslSpaceError,glslCppSkip 109 "syn match glslLineSkip "\\$" 110 syn cluster glslPreProglslGroup contains=glslPreCondit,glslIncluded,glslInclude,glslDefine,glslErrInParen,glslErrInBracket,glslUserLabel,glslSpecial,glslOctalZero,glslCppOut,glslCppOut2,glslCppSkip,glslFormat,glslNumber,glslFloat,glslOctal,glslOctalError,glslNumbersCom,glslString,glslCommentSkip,glslCommentString,glslComment2String,@glslCommentGroup,glslCommentStartError,glslParen,glslBracket,glslMulti 111 syn region glslDefine start="^\s*#\s*\(define\|undef\)\>" skip="\\$" end="$" end="//"me=s-1 contains=ALLBUT,@glslPreProglslGroup 112 syn region glslPreProc start="^\s*#\s*\(pragma\>\|line\>\|error\>\|version\>\|extension\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@glslPreProglslGroup 113 114 " Highlight User Labels 115 syn cluster glslMultiGroup contains=glslIncluded,glslSpecial,glslCommentSkip,glslCommentString,glslComment2String,@glslCommentGroup,glslCommentStartError,glslUserCont,glslUserLabel,glslBitField,glslOctalZero,glslCppOut,glslCppOut2,glslCppSkip,glslFormat,glslNumber,glslFloat,glslOctal,glslOctalError,glslNumbersCom,glslCppParen,glslCppBracket,glslCppString 116 syn region glslMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@glslMultiGroup 117 " Avoid matching foo::bar() in C++ by requiring that the next char is not ':' 118 syn cluster glslLabelGroup contains=glslUserLabel 119 syn match glslUserCont display "^\s*\I\i*\s*:$" contains=@glslLabelGroup 120 syn match glslUserCont display ";\s*\I\i*\s*:$" contains=@glslLabelGroup 121 syn match glslUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@glslLabelGroup 122 syn match glslUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@glslLabelGroup 123 124 syn match glslUserLabel display "\I\i*" contained 125 126 " Avoid recognizing most bitfields as labels 127 syn match glslBitField display "^\s*\I\i*\s*:\s*[1-9]"me=e-1 128 syn match glslBitField display ";\s*\I\i*\s*:\s*[1-9]"me=e-1 129 130 syn keyword glslState gl_Position gl_PointSize gl_ClipVertex 131 syn keyword glslState gl_FragCoord gl_FrontFacing gl_FragColor gl_FragData gl_FragDepth 132 133 " vertex attributes 134 syn keyword glslState gl_Color gl_SecondaryColor gl_Normal gl_Vertex gl_FogCoord 135 syn match glslState display "gl_MultiTexCoord\d\+" 136 137 " varying variables 138 syn keyword glslState gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor gl_TexCoord gl_FogFragCoord 139 140 " uniforms 141 syn keyword glslUniform gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix gl_NormalMatrix gl_TextureMatrix 142 syn keyword glslUniform gl_NormalScale gl_DepthRange gl_ClipPlane gl_Point gl_FrontMaterial gl_BackMaterial 143 syn keyword glslUniform gl_LightSource gl_LightModel gl_FrontLightModelProduct gl_BackLightModelProduct 144 syn keyword glslUniform gl_FrontLightProduct gl_BackLightProduct glTextureEnvColor 145 syn keyword glslUniform gl_TextureEnvColor gl_Fog 146 syn match glslUniform display "gl_EyePlane[STRQ]" 147 syn match glslUniform display "gl_ObjectPlane[STRQ]" 148 syn keyword glslUniform gl_ModelViewMatrixInverse gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse 149 syn keyword glslUniform gl_TextureMatrixInverse gl_ModelViewMatrixTranspose gl_ProjectionMatrixTranspose 150 syn keyword glslUniform gl_ModelViewProjectionMatrixTranspose gl_TextureMatrixTranspose gl_ModelViewMatrixInverseTranspose 151 syn keyword glslUniform gl_ProjectionMatrixInverseTranspose gl_ModelViewProjectionMatrixInverseTranspose gl_TextureMatrixInverseTranspose 152 153 " uniform types 154 syn keyword glslType gl_DepthRangeParameters gl_PointParameters gl_MaterialParameters 155 syn keyword glslType gl_LightSourceParameters gl_LightModelParameters gl_LightModelProducts 156 syn keyword glslType gl_LightProducts gl_FogParameters 157 158 " constants 159 syn keyword glslConstant gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords gl_MaxVertexAttribs 160 syn keyword glslConstant gl_MaxVertexUniformComponents gl_MaxVaryingFloats gl_MaxVertexTextureImageUnits 161 syn keyword glslConstant gl_MaxCombinedTextureImageUnits gl_MaxTextureImageUnits gl_MaxFragmentUniformComponents 162 syn keyword glslConstant gl_MaxDrawBuffers 163 164 " swizzling 165 syn match glslSwizzle /\.[xyzw]\{1,4\}\>/ 166 syn match glslSwizzle /\.[rgba]\{1,4\}\>/ 167 syn match glslSwizzle /\.[stpq]\{1,4\}\>/ 168 169 " built in functions 170 syn keyword glslFunc radians degrees sin cos tan asin acos atan pow exp2 log2 sqrt inversesqrt 171 syn keyword glslFunc abs sign floor ceil fract mod min max clamp mix step smoothstep 172 syn keyword glslFunc length distance dot cross normalize ftransform faceforward reflect 173 syn keyword glslFunc matrixcompmult lessThan lessThanEqual greaterThan greaterThanEqual equal notEqual any all not 174 syn keyword glslFunc texture1D texture1DProj texture1DLod texture1DProjLod 175 syn keyword glslFunc texture2D texture2DProj texture2DLod texture2DProjLod 176 syn keyword glslFunc texture3D texture3DProj texture3DLod texture3DProjLod 177 syn keyword glslFunc textureCube textureCubeLod 178 syn keyword glslFunc shadow1D shadow1DProj shadow1DLod shadow1DProjLod 179 syn keyword glslFunc shadow2D shadow2DProj shadow2DLod shadow2DProjLod 180 syn keyword glslFunc dFdx dFdy fwidth noise1 noise2 noise3 noise4 181 syn keyword glslFunc refract exp log 182 183 " highlight unsupported keywords 184 syn keyword glslUnsupported asm 185 syn keyword glslUnsupported class union enum typedef template this packed 186 syn keyword glslUnsupported goto switch default 187 syn keyword glslUnsupported inline noinline volatile public static extern external interface 188 syn keyword glslUnsupported long short double half fixed unsigned 189 syn keyword glslUnsupported input output 190 syn keyword glslUnsupported hvec2 hvec3 hvec4 dvec2 dvec3 dvec4 fvec2 fvec3 fvec4 191 syn keyword glslUnsupported sampler2DRect sampler3DRect sampler2DRectShadow 192 syn keyword glslUnsupported sizeof cast 193 syn keyword glslUnsupported namespace using 194 195 "wtf? 196 "let b:c_minlines = 50 " #if 0 constructs can be long 197 "exec "syn sync ccomment glslComment minlines=" . b:c_minlines 198 199 " Define the default highlighting. 200 " For version 5.7 and earlier: only when not done already 201 " For version 5.8 and later: only when an item doesn't have highlighting yet 202 if version >= 508 || !exists("did_glsl_syn_inits") 203 if version < 508 204 let did_glsl_syn_inits = 1 205 command -nargs=+ HiLink hi link <args> 206 else 207 command -nargs=+ HiLink hi def link <args> 208 endif 209 210 HiLink glslFormat glslSpecial 211 HiLink glslCppString glslString 212 HiLink glslCommentL glslComment 213 HiLink glslCommentStart glslComment 214 HiLink glslLabel Label 215 HiLink glslUserLabel Label 216 HiLink glslConditional Conditional 217 HiLink glslRepeat Repeat 218 HiLink glslCharacter Character 219 HiLink glslSpecialCharacter glslSpecial 220 HiLink glslNumber Number 221 HiLink glslOctal Number 222 HiLink glslOctalZero PreProc " link this to Error if you want 223 HiLink glslFloat Float 224 HiLink glslOctalError glslError 225 HiLink glslParenError glslError 226 HiLink glslErrInParen glslError 227 HiLink glslErrInBracket glslError 228 HiLink glslCommentError glslError 229 HiLink glslCommentStartError glslError 230 HiLink glslSpaceError glslError 231 HiLink glslSpecialError glslError 232 HiLink glslOperator Operator 233 HiLink glslStructure Structure 234 HiLink glslStorageClass StorageClass 235 HiLink glslInclude Include 236 HiLink glslPreProc PreProc 237 HiLink glslDefine Macro 238 HiLink glslIncluded glslString 239 HiLink glslError Error 240 HiLink glslStatement Statement 241 HiLink glslPreCondit PreCondit 242 HiLink glslType Type 243 HiLink glslConstant Constant 244 HiLink glslCommentString glslString 245 HiLink glslComment2String glslString 246 HiLink glslCommentSkip glslComment 247 HiLink glslString String 248 HiLink glslComment Comment 249 HiLink glslSpecial SpecialChar 250 HiLink glslSwizzle SpecialChar 251 HiLink glslTodo Todo 252 HiLink glslCppSkip glslCppOut 253 HiLink glslCppOut2 glslCppOut 254 HiLink glslCppOut Comment 255 HiLink glslUniform glslType 256 HiLink glslState glslType 257 HiLink glslFunc glslStatement 258 HiLink glslUnsupported glslError 259 260 delcommand HiLink 261 endif 262 263 let b:current_syntax = "glsl" 264 265 " vim: ts=8