diff options
author | pommicket <pommicket@gmail.com> | 2022-12-28 18:10:34 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-28 18:10:34 -0500 |
commit | 92c2f6c5db7606515948b233470181c119f7e308 (patch) | |
tree | e77c345cdfcc2e398d9395ec0fe262ce133d42b7 | |
parent | 8ef7a72c55e66c097c0130ab17e2062ef75e4723 (diff) |
GLSL syntax highlighting
-rw-r--r-- | keywords.h | 25 | ||||
-rwxr-xr-x | keywords.py | 66 | ||||
-rw-r--r-- | lsp-write.c | 3 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | syntax.c | 30 | ||||
-rw-r--r-- | ted.cfg | 6 | ||||
-rw-r--r-- | ted.h | 2 |
7 files changed, 122 insertions, 11 deletions
@@ -343,3 +343,28 @@ static const KeywordList syntax_all_keywords_config[128] = { ['f'] = {syntax_keywords_config_f, arr_count(syntax_keywords_config_f)}, ['n'] = {syntax_keywords_config_n, arr_count(syntax_keywords_config_n)}, ['o'] = {syntax_keywords_config_o, arr_count(syntax_keywords_config_o)}, ['t'] = {syntax_keywords_config_t, arr_count(syntax_keywords_config_t)}, ['y'] = {syntax_keywords_config_y, arr_count(syntax_keywords_config_y)} }; +static const Keyword syntax_keywords_glsl_E[4] = {{"EmitStreamVertex", SYNTAX_BUILTIN},{"EmitVertex", SYNTAX_BUILTIN},{"EndPrimitive", SYNTAX_BUILTIN},{"EndStreamPrimitive", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_a[22] = {{"abs", SYNTAX_BUILTIN},{"acos", SYNTAX_BUILTIN},{"acosh", SYNTAX_BUILTIN},{"all", SYNTAX_BUILTIN},{"any", SYNTAX_BUILTIN},{"asin", SYNTAX_BUILTIN},{"asinh", SYNTAX_BUILTIN},{"atan", SYNTAX_BUILTIN},{"atanh", SYNTAX_BUILTIN},{"atomicAdd", SYNTAX_BUILTIN},{"atomicAnd", SYNTAX_BUILTIN},{"atomicCompSwap", SYNTAX_BUILTIN},{"atomicCounter", SYNTAX_BUILTIN},{"atomicCounterDecrement", SYNTAX_BUILTIN},{"atomicCounterIncrement", SYNTAX_BUILTIN},{"atomicExchange", SYNTAX_BUILTIN},{"atomicMax", SYNTAX_BUILTIN},{"atomicMin", SYNTAX_BUILTIN},{"atomicOr", SYNTAX_BUILTIN},{"atomicXor", SYNTAX_BUILTIN},{"atomic_uint", SYNTAX_KEYWORD},{"attribute", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_b[11] = {{"barrier", SYNTAX_BUILTIN},{"bitCount", SYNTAX_BUILTIN},{"bitfieldExtract", SYNTAX_BUILTIN},{"bitfieldInsert", SYNTAX_BUILTIN},{"bitfieldReverse", SYNTAX_BUILTIN},{"bool", SYNTAX_KEYWORD},{"break", SYNTAX_KEYWORD},{"buffer", SYNTAX_KEYWORD},{"bvec2", SYNTAX_KEYWORD},{"bvec3", SYNTAX_KEYWORD},{"bvec4", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_c[10] = {{"case", SYNTAX_KEYWORD},{"ceil", SYNTAX_BUILTIN},{"centroid", SYNTAX_KEYWORD},{"clamp", SYNTAX_BUILTIN},{"coherent", SYNTAX_KEYWORD},{"const", SYNTAX_KEYWORD},{"continue", SYNTAX_KEYWORD},{"cos", SYNTAX_BUILTIN},{"cosh", SYNTAX_BUILTIN},{"cross", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_d[29] = {{"dFdx", SYNTAX_BUILTIN},{"dFdxCoarse", SYNTAX_BUILTIN},{"dFdxFine", SYNTAX_BUILTIN},{"dFdy", SYNTAX_BUILTIN},{"dFdyCoarse", SYNTAX_BUILTIN},{"dFdyFine", SYNTAX_BUILTIN},{"default", SYNTAX_KEYWORD},{"degrees", SYNTAX_BUILTIN},{"determinant", SYNTAX_BUILTIN},{"discard", SYNTAX_KEYWORD},{"distance", SYNTAX_BUILTIN},{"dmat2", SYNTAX_KEYWORD},{"dmat2x2", SYNTAX_KEYWORD},{"dmat2x3", SYNTAX_KEYWORD},{"dmat2x4", SYNTAX_KEYWORD},{"dmat3", SYNTAX_KEYWORD},{"dmat3x2", SYNTAX_KEYWORD},{"dmat3x3", SYNTAX_KEYWORD},{"dmat3x4", SYNTAX_KEYWORD},{"dmat4", SYNTAX_KEYWORD},{"dmat4x2", SYNTAX_KEYWORD},{"dmat4x3", SYNTAX_KEYWORD},{"dmat4x4", SYNTAX_KEYWORD},{"do", SYNTAX_KEYWORD},{"dot", SYNTAX_BUILTIN},{"double", SYNTAX_KEYWORD},{"dvec2", SYNTAX_KEYWORD},{"dvec3", SYNTAX_KEYWORD},{"dvec4", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_e[4] = {{"else", SYNTAX_KEYWORD},{"equal", SYNTAX_BUILTIN},{"exp", SYNTAX_BUILTIN},{"exp2", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_f[16] = {{"faceforward", SYNTAX_BUILTIN},{"false", SYNTAX_KEYWORD},{"findLSB", SYNTAX_BUILTIN},{"findMSB", SYNTAX_BUILTIN},{"flat", SYNTAX_KEYWORD},{"float", SYNTAX_KEYWORD},{"floatBitsToInt", SYNTAX_BUILTIN},{"floatBitsToUint", SYNTAX_BUILTIN},{"floor", SYNTAX_BUILTIN},{"fma", SYNTAX_BUILTIN},{"for", SYNTAX_KEYWORD},{"fract", SYNTAX_BUILTIN},{"frexp", SYNTAX_BUILTIN},{"fwidth", SYNTAX_BUILTIN},{"fwidthCoarse", SYNTAX_BUILTIN},{"fwidthFine", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_g[34] = {{"gl_ClipDistance", SYNTAX_BUILTIN},{"gl_CullDistance", SYNTAX_BUILTIN},{"gl_FragCoord", SYNTAX_BUILTIN},{"gl_FragDepth", SYNTAX_BUILTIN},{"gl_FrontFacing", SYNTAX_BUILTIN},{"gl_GlobalInvocationID", SYNTAX_BUILTIN},{"gl_HelperInvocation", SYNTAX_BUILTIN},{"gl_InstanceID", SYNTAX_BUILTIN},{"gl_InvocationID", SYNTAX_BUILTIN},{"gl_Layer", SYNTAX_BUILTIN},{"gl_LocalInvocationID", SYNTAX_BUILTIN},{"gl_LocalInvocationIndex", SYNTAX_BUILTIN},{"gl_NumSamples", SYNTAX_BUILTIN},{"gl_NumWorkGroups", SYNTAX_BUILTIN},{"gl_PatchVerticesIn", SYNTAX_BUILTIN},{"gl_PointCoord", SYNTAX_BUILTIN},{"gl_PointSize", SYNTAX_BUILTIN},{"gl_Position", SYNTAX_BUILTIN},{"gl_PrimitiveID", SYNTAX_BUILTIN},{"gl_PrimitiveIDIn", SYNTAX_BUILTIN},{"gl_SampleID", SYNTAX_BUILTIN},{"gl_SampleMask", SYNTAX_BUILTIN},{"gl_SampleMaskIn", SYNTAX_BUILTIN},{"gl_SamplePosition", SYNTAX_BUILTIN},{"gl_TessCoord", SYNTAX_BUILTIN},{"gl_TessLevelInner", SYNTAX_BUILTIN},{"gl_TessLevelOuter", SYNTAX_BUILTIN},{"gl_VertexID", SYNTAX_BUILTIN},{"gl_ViewportIndex", SYNTAX_BUILTIN},{"gl_WorkGroupID", SYNTAX_BUILTIN},{"gl_WorkGroupSize", SYNTAX_BUILTIN},{"greaterThan", SYNTAX_BUILTIN},{"greaterThanEqual", SYNTAX_BUILTIN},{"groupMemoryBarrier", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_h[1] = {{"highp", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_i[62] = {{"if", SYNTAX_KEYWORD},{"iimage1D", SYNTAX_KEYWORD},{"iimage1DArray", SYNTAX_KEYWORD},{"iimage2D", SYNTAX_KEYWORD},{"iimage2DArray", SYNTAX_KEYWORD},{"iimage2DMS", SYNTAX_KEYWORD},{"iimage2DMSArray", SYNTAX_KEYWORD},{"iimage2DRect", SYNTAX_KEYWORD},{"iimage3D", SYNTAX_KEYWORD},{"iimageBuffer", SYNTAX_KEYWORD},{"iimageCube", SYNTAX_KEYWORD},{"iimageCubeArray", SYNTAX_KEYWORD},{"image1D", SYNTAX_KEYWORD},{"image1DArray", SYNTAX_KEYWORD},{"image2D", SYNTAX_KEYWORD},{"image2DArray", SYNTAX_KEYWORD},{"image2DMS", SYNTAX_KEYWORD},{"image2DMSArray", SYNTAX_KEYWORD},{"image2DRect", SYNTAX_KEYWORD},{"image3D", SYNTAX_KEYWORD},{"imageAtomicAdd", SYNTAX_BUILTIN},{"imageAtomicAnd", SYNTAX_BUILTIN},{"imageAtomicCompSwap", SYNTAX_BUILTIN},{"imageAtomicExchange", SYNTAX_BUILTIN},{"imageAtomicMax", SYNTAX_BUILTIN},{"imageAtomicMin", SYNTAX_BUILTIN},{"imageAtomicOr", SYNTAX_BUILTIN},{"imageAtomicXor", SYNTAX_BUILTIN},{"imageBuffer", SYNTAX_KEYWORD},{"imageCube", SYNTAX_KEYWORD},{"imageCubeArray", SYNTAX_KEYWORD},{"imageLoad", SYNTAX_BUILTIN},{"imageSamples", SYNTAX_BUILTIN},{"imageSize", SYNTAX_BUILTIN},{"imageStore", SYNTAX_BUILTIN},{"imulExtended", SYNTAX_BUILTIN},{"in", SYNTAX_KEYWORD},{"inout", SYNTAX_KEYWORD},{"int", SYNTAX_KEYWORD},{"intBitsToFloat", SYNTAX_BUILTIN},{"interpolateAtCentroid", SYNTAX_BUILTIN},{"interpolateAtOffset", SYNTAX_BUILTIN},{"interpolateAtSample", SYNTAX_BUILTIN},{"invariant", SYNTAX_KEYWORD},{"inverse", SYNTAX_BUILTIN},{"inversesqrt", SYNTAX_BUILTIN},{"isampler1D", SYNTAX_KEYWORD},{"isampler1DArray", SYNTAX_KEYWORD},{"isampler2D", SYNTAX_KEYWORD},{"isampler2DArray", SYNTAX_KEYWORD},{"isampler2DMS", SYNTAX_KEYWORD},{"isampler2DMSArray", SYNTAX_KEYWORD},{"isampler2DRect", SYNTAX_KEYWORD},{"isampler3D", SYNTAX_KEYWORD},{"isamplerBuffer", SYNTAX_KEYWORD},{"isamplerCube", SYNTAX_KEYWORD},{"isamplerCubeArray", SYNTAX_KEYWORD},{"isinf", SYNTAX_BUILTIN},{"isnan", SYNTAX_BUILTIN},{"ivec2", SYNTAX_KEYWORD},{"ivec3", SYNTAX_KEYWORD},{"ivec4", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_l[8] = {{"layout", SYNTAX_KEYWORD},{"ldexp", SYNTAX_BUILTIN},{"length", SYNTAX_BUILTIN},{"lessThan", SYNTAX_BUILTIN},{"lessThanEqual", SYNTAX_BUILTIN},{"log", SYNTAX_BUILTIN},{"log2", SYNTAX_BUILTIN},{"lowp", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_m[24] = {{"mat2", SYNTAX_KEYWORD},{"mat2x2", SYNTAX_KEYWORD},{"mat2x3", SYNTAX_KEYWORD},{"mat2x4", SYNTAX_KEYWORD},{"mat3", SYNTAX_KEYWORD},{"mat3x2", SYNTAX_KEYWORD},{"mat3x3", SYNTAX_KEYWORD},{"mat3x4", SYNTAX_KEYWORD},{"mat4", SYNTAX_KEYWORD},{"mat4x2", SYNTAX_KEYWORD},{"mat4x3", SYNTAX_KEYWORD},{"mat4x4", SYNTAX_KEYWORD},{"matrixCompMult", SYNTAX_BUILTIN},{"max", SYNTAX_BUILTIN},{"mediump", SYNTAX_KEYWORD},{"memoryBarrier", SYNTAX_BUILTIN},{"memoryBarrierAtomicCounter", SYNTAX_BUILTIN},{"memoryBarrierBuffer", SYNTAX_BUILTIN},{"memoryBarrierImage", SYNTAX_BUILTIN},{"memoryBarrierShared", SYNTAX_BUILTIN},{"min", SYNTAX_BUILTIN},{"mix", SYNTAX_BUILTIN},{"mod", SYNTAX_BUILTIN},{"modf", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_n[9] = {{"noise", SYNTAX_BUILTIN},{"noise1", SYNTAX_BUILTIN},{"noise2", SYNTAX_BUILTIN},{"noise3", SYNTAX_BUILTIN},{"noise4", SYNTAX_BUILTIN},{"noperspective", SYNTAX_KEYWORD},{"normalize", SYNTAX_BUILTIN},{"not", SYNTAX_BUILTIN},{"notEqual", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_o[2] = {{"out", SYNTAX_KEYWORD},{"outerProduct", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_p[11] = {{"packDouble2x32", SYNTAX_BUILTIN},{"packHalf2x16", SYNTAX_BUILTIN},{"packSnorm2x16", SYNTAX_BUILTIN},{"packSnorm4x8", SYNTAX_BUILTIN},{"packUnorm", SYNTAX_BUILTIN},{"packUnorm2x16", SYNTAX_BUILTIN},{"packUnorm4x8", SYNTAX_BUILTIN},{"patch", SYNTAX_KEYWORD},{"pow", SYNTAX_BUILTIN},{"precise", SYNTAX_KEYWORD},{"precision", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_r[9] = {{"radians", SYNTAX_BUILTIN},{"readonly", SYNTAX_KEYWORD},{"reflect", SYNTAX_BUILTIN},{"refract", SYNTAX_BUILTIN},{"removedTypes", SYNTAX_BUILTIN},{"restrict", SYNTAX_KEYWORD},{"return", SYNTAX_KEYWORD},{"round", SYNTAX_BUILTIN},{"roundEven", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_s[30] = {{"sample", SYNTAX_KEYWORD},{"sampler1D", SYNTAX_KEYWORD},{"sampler1DArray", SYNTAX_KEYWORD},{"sampler1DArrayShadow", SYNTAX_KEYWORD},{"sampler1DShadow", SYNTAX_KEYWORD},{"sampler2D", SYNTAX_KEYWORD},{"sampler2DArray", SYNTAX_KEYWORD},{"sampler2DArrayShadow", SYNTAX_KEYWORD},{"sampler2DMS", SYNTAX_KEYWORD},{"sampler2DMSArray", SYNTAX_KEYWORD},{"sampler2DRect", SYNTAX_KEYWORD},{"sampler2DRectShadow", SYNTAX_KEYWORD},{"sampler2DShadow", SYNTAX_KEYWORD},{"sampler3D", SYNTAX_KEYWORD},{"samplerBuffer", SYNTAX_KEYWORD},{"samplerCube", SYNTAX_KEYWORD},{"samplerCubeArray", SYNTAX_KEYWORD},{"samplerCubeArrayShadow", SYNTAX_KEYWORD},{"samplerCubeShadow", SYNTAX_KEYWORD},{"shared", SYNTAX_KEYWORD},{"sign", SYNTAX_BUILTIN},{"sin", SYNTAX_BUILTIN},{"sinh", SYNTAX_BUILTIN},{"smooth", SYNTAX_KEYWORD},{"smoothstep", SYNTAX_BUILTIN},{"sqrt", SYNTAX_BUILTIN},{"step", SYNTAX_BUILTIN},{"struct", SYNTAX_KEYWORD},{"subroutine", SYNTAX_KEYWORD},{"switch", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_t[26] = {{"tan", SYNTAX_BUILTIN},{"tanh", SYNTAX_BUILTIN},{"texelFetch", SYNTAX_BUILTIN},{"texelFetchOffset", SYNTAX_BUILTIN},{"texture", SYNTAX_BUILTIN},{"textureGather", SYNTAX_BUILTIN},{"textureGatherOffset", SYNTAX_BUILTIN},{"textureGatherOffsets", SYNTAX_BUILTIN},{"textureGrad", SYNTAX_BUILTIN},{"textureGradOffset", SYNTAX_BUILTIN},{"textureLod", SYNTAX_BUILTIN},{"textureLodOffset", SYNTAX_BUILTIN},{"textureOffset", SYNTAX_BUILTIN},{"textureProj", SYNTAX_BUILTIN},{"textureProjGrad", SYNTAX_BUILTIN},{"textureProjGradOffset", SYNTAX_BUILTIN},{"textureProjLod", SYNTAX_BUILTIN},{"textureProjLodOffset", SYNTAX_BUILTIN},{"textureProjOffset", SYNTAX_BUILTIN},{"textureQueryLevels", SYNTAX_BUILTIN},{"textureQueryLod", SYNTAX_BUILTIN},{"textureSamples", SYNTAX_BUILTIN},{"textureSize", SYNTAX_BUILTIN},{"transpose", SYNTAX_BUILTIN},{"true", SYNTAX_KEYWORD},{"trunc", SYNTAX_BUILTIN}}; +static const Keyword syntax_keywords_glsl_u[38] = {{"uaddCarry", SYNTAX_BUILTIN},{"uimage1D", SYNTAX_KEYWORD},{"uimage1DArray", SYNTAX_KEYWORD},{"uimage2D", SYNTAX_KEYWORD},{"uimage2DArray", SYNTAX_KEYWORD},{"uimage2DMS", SYNTAX_KEYWORD},{"uimage2DMSArray", SYNTAX_KEYWORD},{"uimage2DRect", SYNTAX_KEYWORD},{"uimage3D", SYNTAX_KEYWORD},{"uimageBuffer", SYNTAX_KEYWORD},{"uimageCube", SYNTAX_KEYWORD},{"uimageCubeArray", SYNTAX_KEYWORD},{"uint", SYNTAX_KEYWORD},{"uintBitsToFloat", SYNTAX_BUILTIN},{"umulExtended", SYNTAX_BUILTIN},{"uniform", SYNTAX_KEYWORD},{"unpackDouble2x32", SYNTAX_BUILTIN},{"unpackHalf2x16", SYNTAX_BUILTIN},{"unpackSnorm2x16", SYNTAX_BUILTIN},{"unpackSnorm4x8", SYNTAX_BUILTIN},{"unpackUnorm", SYNTAX_BUILTIN},{"unpackUnorm2x16", SYNTAX_BUILTIN},{"unpackUnorm4x8", SYNTAX_BUILTIN},{"usampler1D", SYNTAX_KEYWORD},{"usampler1DArray", SYNTAX_KEYWORD},{"usampler2D", SYNTAX_KEYWORD},{"usampler2DArray", SYNTAX_KEYWORD},{"usampler2DMS", SYNTAX_KEYWORD},{"usampler2DMSArray", SYNTAX_KEYWORD},{"usampler2DRect", SYNTAX_KEYWORD},{"usampler3D", SYNTAX_KEYWORD},{"usamplerBuffer", SYNTAX_KEYWORD},{"usamplerCube", SYNTAX_KEYWORD},{"usamplerCubeArray", SYNTAX_KEYWORD},{"usubBorrow", SYNTAX_BUILTIN},{"uvec2", SYNTAX_KEYWORD},{"uvec3", SYNTAX_KEYWORD},{"uvec4", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_v[6] = {{"varying", SYNTAX_KEYWORD},{"vec2", SYNTAX_KEYWORD},{"vec3", SYNTAX_KEYWORD},{"vec4", SYNTAX_KEYWORD},{"void", SYNTAX_KEYWORD},{"volatile", SYNTAX_KEYWORD}}; +static const Keyword syntax_keywords_glsl_w[2] = {{"while", SYNTAX_KEYWORD},{"writeonly", SYNTAX_KEYWORD}}; +static const KeywordList syntax_all_keywords_glsl[128] = { + ['E'] = {syntax_keywords_glsl_E, arr_count(syntax_keywords_glsl_E)}, ['a'] = {syntax_keywords_glsl_a, arr_count(syntax_keywords_glsl_a)}, ['b'] = {syntax_keywords_glsl_b, arr_count(syntax_keywords_glsl_b)}, ['c'] = {syntax_keywords_glsl_c, arr_count(syntax_keywords_glsl_c)}, ['d'] = {syntax_keywords_glsl_d, arr_count(syntax_keywords_glsl_d)}, ['e'] = {syntax_keywords_glsl_e, arr_count(syntax_keywords_glsl_e)}, ['f'] = {syntax_keywords_glsl_f, arr_count(syntax_keywords_glsl_f)}, ['g'] = {syntax_keywords_glsl_g, arr_count(syntax_keywords_glsl_g)}, ['h'] = {syntax_keywords_glsl_h, arr_count(syntax_keywords_glsl_h)}, ['i'] = {syntax_keywords_glsl_i, arr_count(syntax_keywords_glsl_i)}, ['l'] = {syntax_keywords_glsl_l, arr_count(syntax_keywords_glsl_l)}, ['m'] = {syntax_keywords_glsl_m, arr_count(syntax_keywords_glsl_m)}, ['n'] = {syntax_keywords_glsl_n, arr_count(syntax_keywords_glsl_n)}, ['o'] = {syntax_keywords_glsl_o, arr_count(syntax_keywords_glsl_o)}, ['p'] = {syntax_keywords_glsl_p, arr_count(syntax_keywords_glsl_p)}, ['r'] = {syntax_keywords_glsl_r, arr_count(syntax_keywords_glsl_r)}, ['s'] = {syntax_keywords_glsl_s, arr_count(syntax_keywords_glsl_s)}, ['t'] = {syntax_keywords_glsl_t, arr_count(syntax_keywords_glsl_t)}, ['u'] = {syntax_keywords_glsl_u, arr_count(syntax_keywords_glsl_u)}, ['v'] = {syntax_keywords_glsl_v, arr_count(syntax_keywords_glsl_v)}, ['w'] = {syntax_keywords_glsl_w, arr_count(syntax_keywords_glsl_w)} +}; + diff --git a/keywords.py b/keywords.py index 1779811..72de967 100755 --- a/keywords.py +++ b/keywords.py @@ -125,6 +125,70 @@ builtins_c = [ 'tss_dtor_t', 'thrd_start_t', 'once_flag', 'xtime', 'clock_t', 'time_t', 'wctrans_t', 'wctype_t', ] + +# see https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html#keywords +keywords_glsl = [ + 'const', 'uniform', 'buffer', 'shared', 'attribute', 'varying', 'coherent', + 'volatile', 'restrict', 'readonly', 'writeonly', 'atomic_uint', 'layout', + 'centroid', 'flat', 'smooth', 'noperspective', 'patch', 'sample', 'invariant', + 'precise', 'break', 'continue', 'do', 'for', 'while', 'switch', 'case', 'default', + 'if', 'else', 'subroutine', 'in', 'out', 'inout', 'int', 'void', 'bool', 'true', + 'false', 'float', 'double', 'discard', 'return', 'vec2', 'vec3', 'vec4', 'ivec2', + 'ivec3', 'ivec4', 'bvec2', 'bvec3', 'bvec4', 'uint', 'uvec2', 'uvec3', 'uvec4', + 'dvec2', 'dvec3', 'dvec4', 'mat2', 'mat3', 'mat4', 'mat2x2', 'mat2x3', 'mat2x4', + 'mat3x2', 'mat3x3', 'mat3x4', 'mat4x2', 'mat4x3', 'mat4x4', 'dmat2', 'dmat3', 'dmat4', + 'dmat2x2', 'dmat2x3', 'dmat2x4', 'dmat3x2', 'dmat3x3', 'dmat3x4', 'dmat4x2', 'dmat4x3', + 'dmat4x4', 'lowp', 'mediump', 'highp', 'precision', 'sampler1D', 'sampler1DShadow', + 'sampler1DArray', 'sampler1DArrayShadow', 'isampler1D', 'isampler1DArray', 'usampler1D', + 'usampler1DArray', 'sampler2D', 'sampler2DShadow', 'sampler2DArray', 'sampler2DArrayShadow', + 'isampler2D', 'isampler2DArray', 'usampler2D', 'usampler2DArray', 'sampler2DRect', + 'sampler2DRectShadow', 'isampler2DRect', 'usampler2DRect', 'sampler2DMS', 'isampler2DMS', + 'usampler2DMS', 'sampler2DMSArray', 'isampler2DMSArray', 'usampler2DMSArray', 'sampler3D', + 'isampler3D', 'usampler3D', 'samplerCube', 'samplerCubeShadow', 'isamplerCube', 'usamplerCube', + 'samplerCubeArray', 'samplerCubeArrayShadow', 'isamplerCubeArray', 'usamplerCubeArray', 'samplerBuffer', + 'isamplerBuffer', 'usamplerBuffer', 'image1D', 'iimage1D', 'uimage1D', 'image1DArray', 'iimage1DArray', + 'uimage1DArray', 'image2D', 'iimage2D', 'uimage2D', 'image2DArray', 'iimage2DArray', 'uimage2DArray', + 'image2DRect', 'iimage2DRect', 'uimage2DRect', 'image2DMS', 'iimage2DMS', 'uimage2DMS', + 'image2DMSArray', 'iimage2DMSArray', 'uimage2DMSArray', 'image3D', 'iimage3D', 'uimage3D', + 'imageCube', 'iimageCube', 'uimageCube', 'imageCubeArray', 'iimageCubeArray', 'uimageCubeArray', + 'imageBuffer', 'iimageBuffer', 'uimageBuffer', 'struct' +] + +# extracted from https://registry.khronos.org/OpenGL-Refpages/gl4/index.php +builtins_glsl = ['abs', 'acos', 'acosh', 'all', 'any', 'asin', 'asinh', 'atan', 'atanh', + 'atomicAdd', 'atomicAnd', 'atomicCompSwap', 'atomicCounter', 'atomicCounterDecrement', + 'atomicCounterIncrement', 'atomicExchange', 'atomicMax', 'atomicMin', 'atomicOr', + 'atomicXor', 'barrier', 'bitCount', 'bitfieldExtract', 'bitfieldInsert', 'bitfieldReverse', + 'ceil', 'clamp', 'cos', 'cosh', 'cross', 'degrees', 'determinant', 'dFdx', 'dFdxCoarse', + 'dFdxFine', 'dFdy', 'dFdyCoarse', 'dFdyFine', 'distance', 'dot', 'EmitStreamVertex', 'EmitVertex', + 'EndPrimitive', 'EndStreamPrimitive', 'equal', 'exp', 'exp2', 'faceforward', 'findLSB', 'findMSB', + 'floatBitsToInt', 'floatBitsToUint', 'floor', 'fma', 'fract', 'frexp', 'fwidth', 'fwidthCoarse', + 'fwidthFine', 'gl_ClipDistance', 'gl_CullDistance', 'gl_FragCoord', 'gl_FragDepth', 'gl_FrontFacing', + 'gl_GlobalInvocationID', 'gl_HelperInvocation', 'gl_InstanceID', 'gl_InvocationID', 'gl_Layer', + 'gl_LocalInvocationID', 'gl_LocalInvocationIndex', 'gl_NumSamples', 'gl_NumWorkGroups', + 'gl_PatchVerticesIn', 'gl_PointCoord', 'gl_PointSize', 'gl_Position', 'gl_PrimitiveID', + 'gl_PrimitiveIDIn', 'gl_SampleID', 'gl_SampleMask', 'gl_SampleMaskIn', 'gl_SamplePosition', + 'gl_TessCoord', 'gl_TessLevelInner', 'gl_TessLevelOuter', 'gl_VertexID', 'gl_ViewportIndex', + 'gl_WorkGroupID', 'gl_WorkGroupSize', 'greaterThan', 'greaterThanEqual', 'groupMemoryBarrier', + 'imageAtomicAdd', 'imageAtomicAnd', 'imageAtomicCompSwap', 'imageAtomicExchange', 'imageAtomicMax', + 'imageAtomicMin', 'imageAtomicOr', 'imageAtomicXor', 'imageLoad', 'imageSamples', 'imageSize', + 'imageStore', 'imulExtended', 'intBitsToFloat', 'interpolateAtCentroid', 'interpolateAtOffset', + 'interpolateAtSample', 'inverse', 'inversesqrt', 'isinf', 'isnan', 'ldexp', 'length', 'lessThan', + 'lessThanEqual', 'log', 'log2', 'matrixCompMult', 'max', 'memoryBarrier', 'memoryBarrierAtomicCounter', + 'memoryBarrierBuffer', 'memoryBarrierImage', 'memoryBarrierShared', 'min', 'mix', 'mod', 'modf', + 'noise', 'noise1', 'noise2', 'noise3', 'noise4', 'normalize', 'not', 'notEqual', 'outerProduct', + 'packDouble2x32', 'packHalf2x16', 'packSnorm2x16', 'packSnorm4x8', 'packUnorm', 'packUnorm2x16', + 'packUnorm4x8', 'pow', 'radians', 'reflect', 'refract', 'removedTypes', 'round', 'roundEven', + 'sign', 'sin', 'sinh', 'smoothstep', 'sqrt', 'step', 'tan', 'tanh', 'texelFetch', 'texelFetchOffset', + 'texture', 'textureGather', 'textureGatherOffset', 'textureGatherOffsets', 'textureGrad', + 'textureGradOffset', 'textureLod', 'textureLodOffset', 'textureOffset', 'textureProj', + 'textureProjGrad', 'textureProjGradOffset', 'textureProjLod', 'textureProjLodOffset', + 'textureProjOffset', 'textureQueryLevels', 'textureQueryLod', 'textureSamples', 'textureSize', + 'transpose', 'trunc', 'uaddCarry', 'uintBitsToFloat', 'umulExtended', 'unpackDouble2x32', + 'unpackHalf2x16', 'unpackSnorm2x16', 'unpackSnorm4x8', 'unpackUnorm', 'unpackUnorm2x16', + 'unpackUnorm4x8', 'usubBorrow'] +constants_glsl = [] + for x in ['char', 'char16_t', 'char32_t', 'wchar_t', 'short', 'int', 'long', 'llong', 'address', 'flag']: @@ -381,4 +445,6 @@ output_keywords(file, label(keywords_java, SYNTAX_KEYWORD) + label(constants_jav output_keywords(file, label(keywords_python, SYNTAX_KEYWORD) + label(builtins_python, SYNTAX_BUILTIN), 'python') output_keywords(file, label(builtins_html, SYNTAX_BUILTIN), 'html') output_keywords(file, label(constants_config, SYNTAX_CONSTANT), 'config') +output_keywords(file, label(keywords_glsl, SYNTAX_KEYWORD) + label(constants_glsl, SYNTAX_CONSTANT) + + label(builtins_glsl, SYNTAX_BUILTIN), 'glsl') file.close() diff --git a/lsp-write.c b/lsp-write.c index 128b61b..4c9bce3 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -30,6 +30,9 @@ static const char *lsp_language_id(Language lang) { return "latex"; case LANG_XML: return "xml"; + case LANG_GLSL: + // not specified as of LSP 3.17, but this seems like the natural choice + return "glsl"; case LANG_COUNT: break; } assert(0); @@ -1,6 +1,5 @@ /* @TODO: -- separate GLSL language - don't highlight HTML stuff for XML - more LSP stuff: - hover @@ -33,6 +33,7 @@ char const *language_comment_start(Language l) { case LANG_JSON: // JSON technically doesn't have comments but apparently some parsers support this so might as well have this here case LANG_JAVA: case LANG_GO: + case LANG_GLSL: return "// "; case LANG_CONFIG: case LANG_TED_CFG: @@ -180,7 +181,8 @@ static inline u32 syntax_keyword_len(Language lang, char32_t const *line, u32 i, return keyword_end - i; } -static void syntax_highlight_c_cpp(SyntaxState *state_ptr, bool cpp, char32_t const *line, u32 line_len, SyntaxCharType *char_types) { +// highlighting for C, C++, and GLSL +static void syntax_highlight_c_cpp(SyntaxState *state_ptr, Language lang, char32_t const *line, u32 line_len, SyntaxCharType *char_types) { SyntaxState state = *state_ptr; bool in_preprocessor = (state & SYNTAX_STATE_CPP_PREPROCESSOR) != 0; bool in_string = (state & SYNTAX_STATE_CPP_STRING) != 0; @@ -287,13 +289,22 @@ static void syntax_highlight_c_cpp(SyntaxState *state_ptr, bool cpp, char32_t co // keywords don't matter for advancing the state if (char_types && !in_single_line_comment && !in_multi_line_comment && !in_number && !in_string && !in_preprocessor && !in_char) { - u32 keyword_len = syntax_keyword_len(cpp ? LANG_CPP : LANG_C, line, i, line_len); + u32 keyword_len = syntax_keyword_len(lang, line, i, line_len); Keyword const *keyword = NULL; - if (cpp) + switch (lang) { + case LANG_CPP: keyword = syntax_keyword_lookup(syntax_all_keywords_cpp, &line[i], keyword_len); - if (!keyword) + if (!keyword) + keyword = syntax_keyword_lookup(syntax_all_keywords_c, &line[i], keyword_len); + break; + case LANG_GLSL: + keyword = syntax_keyword_lookup(syntax_all_keywords_glsl, &line[i], keyword_len); + break; + default: + assert(lang == LANG_C); keyword = syntax_keyword_lookup(syntax_all_keywords_c, &line[i], keyword_len); - + break; + } if (keyword) { SyntaxCharType type = keyword->type; for (size_t j = 0; j < keyword_len; ++j) { @@ -307,7 +318,7 @@ static void syntax_highlight_c_cpp(SyntaxState *state_ptr, bool cpp, char32_t co } break; } if (c != '\\') backslashes = 0; - if (in_number && !syntax_number_continues(LANG_CPP, line, line_len, i)) { + if (in_number && !syntax_number_continues(lang, line, line_len, i)) { in_number = false; } @@ -1605,10 +1616,13 @@ void syntax_highlight(SyntaxState *state, Language lang, char32_t const *line, u memset(char_types, 0, line_len * sizeof *char_types); break; case LANG_C: - syntax_highlight_c_cpp(state, false, line, line_len, char_types); + syntax_highlight_c_cpp(state, LANG_C, line, line_len, char_types); break; case LANG_CPP: - syntax_highlight_c_cpp(state, true, line, line_len, char_types); + syntax_highlight_c_cpp(state, LANG_CPP, line, line_len, char_types); + break; + case LANG_GLSL: + syntax_highlight_c_cpp(state, LANG_GLSL, line, line_len, char_types); break; case LANG_RUST: syntax_highlight_rust(state, line, line_len, char_types); @@ -196,6 +196,7 @@ Ctrl+Shift+r = :reload-all # 13 TypeScript # 14 JSON # 15 XML +# 16 GLSL # -1 Guess from the file extension (default) Ctrl+Space = :autocomplete @@ -322,12 +323,13 @@ cursor-line-number = #ddf line-numbers-separator = #fff3 [extensions] -C = .c, .h, .glsl +C = .c, .h C++ = .cpp, .hpp, .C, .H, .cxx, .hxx, .cc, .hh Rust = .rs Python = .py Tex = .tex -Markdown = .md +Markdown = .md +GLSL = .glsl, .tesc, .tese, .vert, .frag, .geom, .comp HTML = .html, .php, .xhtml XML = .xml, .iml Config = .cfg, .toml @@ -82,6 +82,7 @@ typedef enum { LANG_TYPESCRIPT = 13, LANG_JSON = 14, LANG_XML = 15, + LANG_GLSL = 16, LANG_COUNT } Language; @@ -107,6 +108,7 @@ static LanguageName const language_names[] = { {LANG_TYPESCRIPT, "TypeScript"}, {LANG_JSON, "JSON"}, {LANG_XML, "XML"}, + {LANG_GLSL, "GLSL"}, }; static_assert_if_possible(arr_count(language_names) == LANG_COUNT) |