diff --git a/lib/rouge/lexers/gherkin/keywords.rb b/lib/rouge/lexers/gherkin/keywords.rb index 4b6b355490..56e64cd318 100644 --- a/lib/rouge/lexers/gherkin/keywords.rb +++ b/lib/rouge/lexers/gherkin/keywords.rb @@ -4,7 +4,6 @@ # DO NOT EDIT # This file is automatically generated by `rake builtins:gherkin`. # See tasks/builtins/gherkin.rake for more info. -# See tasks/builtins/gherkin.rake for more info. module Rouge module Lexers diff --git a/lib/rouge/lexers/glsl.rb b/lib/rouge/lexers/glsl.rb index e4b3ab751c..efa3d834b9 100644 --- a/lib/rouge/lexers/glsl.rb +++ b/lib/rouge/lexers/glsl.rb @@ -5,11 +5,7 @@ module Rouge module Lexers - # This file defines the GLSL language lexer to the Rouge - # syntax highlighter. - # - # Author: Sri Harsha Chilakapati - class Glsl < C + class GLSL < RegexLexer tag 'glsl' filenames '*.glsl', '*.frag', '*.vert', '*.geom', '*.vs', '*.gs', '*.shader' mimetypes 'x-shader/x-vertex', 'x-shader/x-fragment', 'x-shader/x-geometry' @@ -17,150 +13,57 @@ class Glsl < C title "GLSL" desc "The GLSL shader language" - def self.keywords - @keywords ||= Set.new %w( - 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 - true false - discard return - lowp mediump highp precision - struct + lazy { require_relative "glsl/builtins" } - row_major column_major packed std140 std43 binding offset align location - early_fragment_tests - ) - end + state :root do + rule %r/\s+/, Text + rule %r(/[*].*?[*]/)m, Comment::Multiline + rule %r(//.*$), Comment - def self.keywords_type - @keywords_type ||= Set.new %w( - int void bool float double + rule %r/^#(?:[^\n]|\\\r?\n)*/, Comment::Preproc + rule %r/defined\b/, Comment::Preproc + rule %r/__(?:LINE|FILE|VERSION)__\b/, Keyword::Constant + rule %r/(?:true|false)\b/, Keyword::Pseudo - 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 - 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 - atomic_uint + rule %r/0x\h+u?/i, Num::Hex + rule %r/(?:\d+[.]\d*|[.]\d+)(?:e[+-]?\d+)?(?:l?f)?/i, Num::Float + rule %r/\d+(?:e[+-]?\d+)(?:l?f)?/i, Num::Float + rule %r/[1-9]\d*u?/i, Num::Integer + rule %r/0[0-7]+/, Num::Oct + rule %r/0/, Num::Integer + rule %r([-.+/*%<>\[\](){}^|&~=!:;,?]), Punctuation - texture1D texture1DArray - itexture1D itexture1DArray utexture1D utexture1DArray - texture2D texture2DArray - itexture2D itexture2DArray utexture2D utexture2DArray - texture2DRect itexture2DRect utexture2DRect - texture2DMS itexture2DMS utexture2DMS - texture2DMSArray itexture2DMSArray utexture2DMSArray - texture3D itexture3D utexture3D - textureCube itextureCube utextureCube - textureCubeArray itextureCubeArray utextureCubeArray - textureBuffer itextureBuffer utextureBuffer - sampler samplerShadow - subpassInput isubpassInput usubpassInput - subpassInputMS isubpassInputMS usubpassInputMS - ) - end + rule %r/\w+/ do |m| + if KEYWORDS.include?(m[0]) + token Keyword + elsif TYPES.include?(m[0]) + token Keyword::Type + else + fallthrough! + end + end - def self.reserved - @reserved ||= Set.new %w( - common partition active - asm - class union enum typedef template this - resource - goto - inline noinline public static extern external interface - long short half fixed unsigned superp - input output - hvec2 hvec3 hvec4 fvec2 fvec3 fvec4 - filter - sizeof cast - namespace using - sampler3DRect - ) - end + rule %r/\w+(?=\s*[(])/ do |m| + if BUILTINS.include?(m[0]) + token Name::Builtin + else + token Name::Function + end + end - def self.builtins - @builtins ||= Set.new %w( - gl_VertexID gl_VertexIndex gl_InstanceID gl_InstanceIndex gl_PerVertex gl_Position gl_PointSize gl_ClipDistance gl_CullDistance - gl_PrimitiveIDIn gl_InvocationID gl_PrimitiveID gl_Layer gl_ViewportIndex - gl_MaxPatchVertices gl_PatchVerticesIn gl_TessLevelOuter gl_TessLevelInner - gl_TessCoord gl_FragCoord gl_FrontFacing gl_PointCoord gl_SampleID gl_SamplePosition - gl_FragColor gl_FragData gl_MaxDrawBuffers gl_FragDepth gl_SampleMask - gl_ClipVertex gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor - gl_TexCoord gl_FogFragCoord gl_Color gl_SecondaryColor gl_Normal - gl_MultiTexCord0 gl_MultiTexCord1 gl_MultiTexCord2 gl_MultiTexCord3 - gl_MultiTexCord4 gl_MultiTexCord5 gl_MultiTexCord6 gl_MultiTexCord7 - gl_FogCoord gl_MaxVertexAttribs gl_MaxVertexUniformComponents - gl_MaxVaryingFloats gl_MaxVaryingComponents gl_MaxVertexOutputComponents - gl_MaxGeometryInputComponents gl_MaxGeometryOutputComponents - gl_MaxFragmentInputComponents gl_MaxVertexTextureImageUnits - gl_MaxCombinedTextureImageUnits gl_MaxTextureImageUnits - gl_MaxFragmentUniformComponents gl_MaxClipDistances - gl_MaxGeometryTextureImageUnits gl_MaxGeometryUniformComponents - gl_MaxGeometryVaryingComponents gl_MaxTessControlInputComponents - gl_MaxTessControlOutputComponents gl_MaxTessControlTextureImageUnits - gl_MaxTessControlUniformComponents gl_MaxTessControlTotalOutputComponents - gl_MaxTessEvaluationInputComponents gl_MaxTessEvaluationOutputComponents - gl_MaxTessEvaluationTextureImageUnits gl_MaxTessEvaluationUniformComponents - gl_MaxTessPatchComponents gl_MaxTessGenLevel gl_MaxViewports - gl_MaxVertexUniformVectors gl_MaxFragmentUniformVectors gl_MaxVaryingVectors - gl_MaxTextureUnits gl_MaxTextureCoords gl_MaxClipPlanes gl_DepthRange - gl_DepthRangeParameters gl_ModelViewMatrix gl_ProjectionMatrix - gl_ModelViewProjectionMatrix gl_TextureMatrix gl_NormalMatrix - gl_ModelViewMatrixInverse gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse - gl_TextureMatrixInverse gl_ModelViewMatrixTranspose - gl_ModelViewProjectionMatrixTranspose gl_TextureMatrixTranspose - gl_ModelViewMatrixInverseTranspose gl_ProjectionMatrixInverseTranspose - gl_ModelViewProjectionMatrixInverseTranspose - gl_TextureMatrixInverseTranspose gl_NormalScale gl_ClipPlane gl_PointParameters - gl_Point gl_MaterialParameters gl_FrontMaterial gl_BackMaterial - gl_LightSourceParameters gl_LightSource gl_MaxLights gl_LightModelParameters - gl_LightModel gl_LightModelProducts gl_FrontLightModelProduct - gl_BackLightModelProduct gl_LightProducts gl_FrontLightProduct - gl_BackLightProduct gl_TextureEnvColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR - gl_EyePlaneQ gl_ObjectPlaneS gl_ObjectPlaneT gl_ObjectPlaneR gl_ObjectPlaneQ - gl_FogParameters gl_Fog - gl_DrawID gl_BaseVertex gl_BaseInstance - gl_NumWorkGroups gl_WorkGroupID gl_LocalInvocationID gl_GlobalInvocationID gl_LocalInvocationIndex - gl_WorkGroupSize gl_HelperInvocation - ) + rule %r/\w+/ do |m| + if GL_VARS.include?(m[0]) + token Name::Constant + elsif BUILTINS.include?(m[0]) + token Name::Builtin + else + token Name + end + end end end + + # backcompat + Glsl = GLSL end end diff --git a/lib/rouge/lexers/glsl/builtins.rb b/lib/rouge/lexers/glsl/builtins.rb new file mode 100644 index 0000000000..d1acf69b8e --- /dev/null +++ b/lib/rouge/lexers/glsl/builtins.rb @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- # +# frozen_string_literal: true + +# DO NOT EDIT +# This file is automatically generated by `rake builtins:glsl`. +# See tasks/builtins/glsl.rake for more info. + +module Rouge + module Lexers + class GLSL + BUILTINS = Set["EmitStreamVertex", "EmitVertex", "EndPrimitive", "EndStreamPrimitive", "abs", "acos", "acosh", "all", "allInvocations", "allInvocationsEqual", "any", "anyInvocation", "asin", "asinh", "atan", "atanh", "atomicAdd", "atomicAnd", "atomicCompSwap", "atomicCounter", "atomicCounterAdd", "atomicCounterAnd", "atomicCounterCompSwap", "atomicCounterDecrement", "atomicCounterExchange", "atomicCounterIncrement", "atomicCounterMax", "atomicCounterMin", "atomicCounterOr", "atomicCounterSubtract", "atomicCounterXor", "atomicExchange", "atomicMax", "atomicMin", "atomicOr", "atomicXor", "barrier", "bitCount", "bitfieldExtract", "bitfieldInsert", "bitfieldReverse", "ceil", "clamp", "cos", "cosh", "cross", "dFdx", "dFdxCoarse", "dFdxFine", "dFdy", "dFdyCoarse", "dFdyFine", "degrees", "determinant", "distance", "dot", "equal", "exp", "exp2", "faceforward", "findLSB", "findMSB", "floatBitsToInt", "floatBitsToUint", "floor", "fma", "fract", "frexp", "ftransform", "fwidth", "fwidthCoarse", "fwidthFine", "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", "neighbor", "noise1", "noise2", "noise3", "noise4", "normalize", "not", "notEqual", "outerProduct", "packDouble2x32", "packHalf2x16", "packSnorm2x16", "packSnorm4x8", "packUnorm2x16", "packUnorm4x8", "pow", "radians", "reflect", "refract", "round", "roundEven", "shadow1D", "shadow1DLod", "shadow1DProj", "shadow1DProjLod", "shadow2D", "shadow2DLod", "shadow2DProj", "shadow2DProjLod", "sign", "sin", "sinh", "smoothstep", "sqrt", "step", "subpassLoad", "tan", "tanh", "texelFetch", "texelFetchOffset", "texture", "texture1DLod", "texture1DProj", "texture1DProjLod", "texture2DLod", "texture2DProj", "texture2DProjLod", "texture3DLod", "texture3DProj", "texture3DProjLod", "textureCubeLod", "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", "unpackUnorm2x16", "unpackUnorm4x8", "usubBorrow"] + KEYWORDS = Set["active", "asm", "attribute", "break", "buffer", "case", "cast", "centroid", "class", "coherent", "common", "const", "continue", "default", "discard", "do", "else", "enum", "extern", "external", "false", "filter", "fixed", "flat", "for", "fvec2", "fvec3", "fvec4", "goto", "half", "highp", "hvec2", "hvec3", "hvec4", "if", "in", "inline", "inout", "input", "interface", "invariant", "layout", "long", "lowp", "mediump", "namespace", "noinline", "noperspective", "out", "output", "partition", "patch", "precise", "precision", "public", "readonly", "resource", "restrict", "return", "sample", "sampler3DRect", "shared", "short", "sizeof", "smooth", "static", "struct", "subroutine", "superp", "switch", "template", "this", "true", "typedef", "uniform", "union", "unsigned", "using", "varying", "volatile", "while", "writeonly"] + TYPES = Set["atomic_uint", "bool", "bvec2", "bvec3", "bvec4", "dmat2", "dmat2x2", "dmat2x3", "dmat2x4", "dmat3", "dmat3x2", "dmat3x3", "dmat3x4", "dmat4", "dmat4x2", "dmat4x3", "dmat4x4", "double", "dvec2", "dvec3", "dvec4", "float", "iimage1D", "iimage1DArray", "iimage2D", "iimage2DArray", "iimage2DMS", "iimage2DMSArray", "iimage2DRect", "iimage3D", "iimageBuffer", "iimageCube", "iimageCubeArray", "image1D", "image1DArray", "image2D", "image2DArray", "image2DMS", "image2DMSArray", "image2DRect", "image3D", "imageBuffer", "imageCube", "imageCubeArray", "int", "isampler1D", "isampler1DArray", "isampler2D", "isampler2DArray", "isampler2DMS", "isampler2DMSArray", "isampler2DRect", "isampler3D", "isamplerBuffer", "isamplerCube", "isamplerCubeArray", "isubpassInput", "isubpassInputMS", "itexture1D", "itexture1DArray", "itexture2D", "itexture2DArray", "itexture2DMS", "itexture2DMSArray", "itexture2DRect", "itexture3D", "itextureBuffer", "itextureCube", "itextureCubeArray", "ivec2", "ivec3", "ivec4", "mat2", "mat2x2", "mat2x3", "mat2x4", "mat3", "mat3x2", "mat3x3", "mat3x4", "mat4", "mat4x2", "mat4x3", "mat4x4", "sampler", "sampler1D", "sampler1DArray", "sampler1DArrayShadow", "sampler1DShadow", "sampler2D", "sampler2DArray", "sampler2DArrayShadow", "sampler2DMS", "sampler2DMSArray", "sampler2DRect", "sampler2DRectShadow", "sampler2DShadow", "sampler3D", "samplerBuffer", "samplerCube", "samplerCubeArray", "samplerCubeArrayShadow", "samplerCubeShadow", "samplerShadow", "subpassInput", "subpassInputMS", "texture1D", "texture1DArray", "texture2D", "texture2DArray", "texture2DMS", "texture2DMSArray", "texture2DRect", "texture3D", "textureBuffer", "textureCube", "textureCubeArray", "uimage1D", "uimage1DArray", "uimage2D", "uimage2DArray", "uimage2DMS", "uimage2DMSArray", "uimage2DRect", "uimage3D", "uimageBuffer", "uimageCube", "uimageCubeArray", "uint", "usampler1D", "usampler1DArray", "usampler2D", "usampler2DArray", "usampler2DMS", "usampler2DMSArray", "usampler2DRect", "usampler3D", "usamplerBuffer", "usamplerCube", "usamplerCubeArray", "usubpassInput", "usubpassInputMS", "utexture1D", "utexture1DArray", "utexture2D", "utexture2DArray", "utexture2DMS", "utexture2DMSArray", "utexture2DRect", "utexture3D", "utextureBuffer", "utextureCube", "utextureCubeArray", "uvec2", "uvec3", "uvec4", "vec2", "vec3", "vec4", "void"] + GL_VARS = Set["gl_BackColor", "gl_BackLightModelProduct", "gl_BackLightProduct", "gl_BackMaterial", "gl_BackSecondaryColor", "gl_BaseInstance", "gl_BaseVertex", "gl_BoundingBox", "gl_ClipDistance", "gl_ClipPlane", "gl_ClipVertex", "gl_Color", "gl_CullDistance", "gl_DepthRange", "gl_DepthRangeParameters", "gl_DrawID", "gl_EyePlaneQ", "gl_EyePlaneR", "gl_EyePlaneS", "gl_EyePlaneT", "gl_Fog", "gl_FogCoord", "gl_FogFragCoord", "gl_FogParameters", "gl_FragColor", "gl_FragCoord", "gl_FragData", "gl_FragDepth", "gl_FrontColor", "gl_FrontFacing", "gl_FrontLightModelProduct", "gl_FrontLightProduct", "gl_FrontMaterial", "gl_FrontSecondaryColor", "gl_GlobalInvocationID", "gl_HelperInvocation", "gl_InstanceID", "gl_InstanceIndex", "gl_InvocationID", "gl_Layer", "gl_LightModel", "gl_LightModelParameters", "gl_LightModelProducts", "gl_LightProducts", "gl_LightSource", "gl_LightSourceParameters", "gl_LocalInvocationID", "gl_LocalInvocationIndex", "gl_MaterialParameters", "gl_MaxAtomicCounterBindings", "gl_MaxAtomicCounterBufferSize", "gl_MaxClipDistances", "gl_MaxClipPlanes", "gl_MaxCombinedAtomicCounterBuffers", "gl_MaxCombinedAtomicCounters", "gl_MaxCombinedClipAndCullDistances", "gl_MaxCombinedImageUniforms", "gl_MaxCombinedImageUnitsAndFragmentOutputs", "gl_MaxCombinedShaderOutputResources", "gl_MaxCombinedTextureImageUnits", "gl_MaxComputeAtomicCounterBuffers", "gl_MaxComputeAtomicCounters", "gl_MaxComputeImageUniforms", "gl_MaxComputeTextureImageUnits", "gl_MaxComputeUniformComponents", "gl_MaxComputeWorkGroupCount", "gl_MaxComputeWorkGroupSize", "gl_MaxCullDistances", "gl_MaxDrawBuffers", "gl_MaxFragmentAtomicCounterBuffers", "gl_MaxFragmentAtomicCounters", "gl_MaxFragmentImageUniforms", "gl_MaxFragmentInputComponents", "gl_MaxFragmentInputVectors", "gl_MaxFragmentUniformComponents", "gl_MaxFragmentUniformVectors", "gl_MaxGeometryAtomicCounterBuffers", "gl_MaxGeometryAtomicCounters", "gl_MaxGeometryImageUniforms", "gl_MaxGeometryInputComponents", "gl_MaxGeometryOutputComponents", "gl_MaxGeometryOutputVertices", "gl_MaxGeometryTextureImageUnits", "gl_MaxGeometryTotalOutputComponents", "gl_MaxGeometryUniformComponents", "gl_MaxGeometryVaryingComponents", "gl_MaxImageSamples", "gl_MaxImageUnits", "gl_MaxInputAttachments", "gl_MaxLights", "gl_MaxPatchVertices", "gl_MaxProgramTexelOffset", "gl_MaxSamples", "gl_MaxTessControlAtomicCounterBuffers", "gl_MaxTessControlAtomicCounters", "gl_MaxTessControlImageUniforms", "gl_MaxTessControlInputComponents", "gl_MaxTessControlOutputComponents", "gl_MaxTessControlTextureImageUnits", "gl_MaxTessControlTotalOutputComponents", "gl_MaxTessControlUniformComponents", "gl_MaxTessEvaluationAtomicCounterBuffers", "gl_MaxTessEvaluationAtomicCounters", "gl_MaxTessEvaluationImageUniforms", "gl_MaxTessEvaluationInputComponents", "gl_MaxTessEvaluationOutputComponents", "gl_MaxTessEvaluationTextureImageUnits", "gl_MaxTessEvaluationUniformComponents", "gl_MaxTessGenLevel", "gl_MaxTessPatchComponents", "gl_MaxTextureCoords", "gl_MaxTextureImageUnits", "gl_MaxTextureUnits", "gl_MaxTransformFeedbackBuffers", "gl_MaxTransformFeedbackInterleavedComponents", "gl_MaxVaryingComponents", "gl_MaxVaryingFloats", "gl_MaxVaryingVectors", "gl_MaxVertexAtomicCounterBuffers", "gl_MaxVertexAtomicCounters", "gl_MaxVertexAttribs", "gl_MaxVertexImageUniforms", "gl_MaxVertexOutputComponents", "gl_MaxVertexOutputVectors", "gl_MaxVertexTextureImageUnits", "gl_MaxVertexUniformComponents", "gl_MaxVertexUniformVectors", "gl_MaxViewports", "gl_MinProgramTexelOffset", "gl_ModelViewMatrix", "gl_ModelViewMatrixInverse", "gl_ModelViewMatrixInverseTranspose", "gl_ModelViewMatrixTranspose", "gl_ModelViewProjectionMatrix", "gl_ModelViewProjectionMatrixInverse", "gl_ModelViewProjectionMatrixInverseTranspose", "gl_ModelViewProjectionMatrixTranspose", "gl_MultiTexCoord0", "gl_MultiTexCoord1", "gl_MultiTexCoord2", "gl_MultiTexCoord3", "gl_MultiTexCoord4", "gl_MultiTexCoord5", "gl_MultiTexCoord6", "gl_MultiTexCoord7", "gl_Normal", "gl_NormalMatrix", "gl_NormalScale", "gl_NumSamples", "gl_NumWorkGroups", "gl_ObjectPlaneQ", "gl_ObjectPlaneR", "gl_ObjectPlaneS", "gl_ObjectPlaneT", "gl_PatchVerticesIn", "gl_PerFragment", "gl_PerVertex", "gl_Point", "gl_PointCoord", "gl_PointParameters", "gl_PointSize", "gl_Position", "gl_PrimitiveID", "gl_PrimitiveIDIn", "gl_ProjectionMatrix", "gl_ProjectionMatrixInverse", "gl_ProjectionMatrixInverseTranspose", "gl_ProjectionMatrixTranspose", "gl_SampleID", "gl_SampleMask", "gl_SampleMaskIn", "gl_SamplePosition", "gl_SecondaryColor", "gl_TessCoord", "gl_TessLevelInner", "gl_TessLevelOuter", "gl_TexCoord", "gl_TextureEnvColor", "gl_TextureMatrix", "gl_TextureMatrixInverse", "gl_TextureMatrixInverseTranspose", "gl_TextureMatrixTranspose", "gl_Vertex", "gl_VertexID", "gl_VertexIndex", "gl_ViewportIndex", "gl_WorkGroupID", "gl_WorkGroupSize", "gl_color", "gl_in", "gl_out"] + end + end +end diff --git a/spec/visual/samples/glsl b/spec/visual/samples/glsl index d70f3e0993..8d5ee8178c 100644 --- a/spec/visual/samples/glsl +++ b/spec/visual/samples/glsl @@ -1,4 +1,5 @@ #version 330 core +#extension all : enable /** * The Material structure stores the details about the material @@ -89,3 +90,150 @@ void main() { fragColor = getBaseColor() * getDirectionalLight(); } + +// https://github.com/graphitemaster/glsl-parser/blob/main/tests/arrays.glsl +float a[1]; +float b[1][2]; +float c[1][2][3]; +float d[1][2][3][4]; +float[2] e[3]; // float[2][3] +float[3][2] f; // float[2][3] +// structure array! +struct foo1 { float a; }; +foo1 bar1[1][2]; +foo1[1] bar2[2]; +foo1[1] aa[1], bb; + +// https://github.com/graphitemaster/glsl-parser/blob/main/tests/booleans.glsl +void test() { + bool test_uninitialized; + bool test_true_initialized = true; + bool test_false_initialized = false; + bool test_assign; + test_assign = test_true_initialized; + test_assign = test_false_initialized; + test_assign = true; + test_assign = false; +} + +// https://github.com/graphitemaster/glsl-parser/blob/main/tests/switch.glsl +void test() { + // simple test + int i = 10; + switch (i) { + case 0: break; + default: break; + } + // nested + switch (i) { + case 0: + switch (1) { + case 1: + break; + default: + break; + } + break; + default: + break; + } +} + +// https://github.com/graphitemaster/glsl-parser/blob/main/tests/floating_point_literals.glsl +void test() { + float test_float_uninitialized; + float test_float_initialized = 1.5; + float test_float_f_lower = 1.5f; + float test_float_f_upper = 1.5F; + double test_double_uininitialized; + double test_double_initialized = 1.5; + double test_double_lf_lower = 1.5lf; + double test_double_lf_upper = 1.5LF; + float test_float_f_zero = 1.0f; +} + +// https://github.com/graphitemaster/glsl-parser/blob/main/tests/integer_literals.glsl +void test() { + int test_uninitialized_int; + int test_initialized_int = 42; + uint test_uninitialized_uint; + uint test_initialized_uint_no_suffix = 42; + uint test_initialized_uint_suffix = 42u; + uint test_hex_no_suffix_upper = 0xFF; + uint test_hex_suffix_upper = 0xFFu; + uint test_hex_no_suffix_lower = 0xff; + uint test_hex_suffix_lower = 0xffu; + uint test_hex_no_suffix_mixed = 0xFf; + uint test_hex_suffix_mixed = 0xFfU; + int test_negative = -1; + uint test_octal = 0777; +} + +// https://github.com/graphitemaster/glsl-parser/blob/main/tests/ternary.glsl +void main() { + float a = 0, b = 0, c = 0, d = 0; + float w = (a ? a,b : b,c); + float z = a ? b ? c : d : w; +} + +// https://github.com/laurentlb/shader-minifier/blob/master/tests/unit/decimals.frag +void test () { + x(3.141592653589793); + x(3.1415927); + //x(1e308); + //x(3e38); + //x(1e37); + x(1e28); + x(125.663704/180.); + x(.6981316889); + x(100000005.); + x(1.24e27); + x(1.20e27); + x(1.00e27); + x(1.24e4); + x(1.20e4); + x(1.00e4); + x(1.24e3); + x(1.20e3); + x(1.00e3); + x(1.24e2); + x(1.20e2); + x(1.00e2); + x(1.24e1); + x(1.20e1); + x(1.00e1); + x(1.24e0); + x(1.20e0); + x(1.00e0); + x(1.24e-1); + x(1.20e-1); + x(1.00e-1); + x(1.24e-2); + x(1.20e-2); + x(1.00e-2); + x(1.24e-3); + x(1.20e-3); + x(1.00e-3); + x(1.24e-4); + x(1.20e-4); + x(1.00e-4); + x(1.24e-27); + x(1.20e-27); + x(1.00e-27); + x(6e-29); + x(8e-46); + //x(3e-324); +} + +// https://github.com/laurentlb/shader-minifier/blob/master/tests/unit/numbers.frag +uint large() { return 3812015801U; } + +vec4 f() +{ +float oct = float(042) / 1000.; +float oct2 = float(-071) / 1000.; +int dec = 65535; +int dec2 = -65536; +float n = oct - oct2 + float(4 * 0x0) + float(dec + dec2) / 20.; +return vec4(n,n,n,0.); +} diff --git a/tasks/builtins/gherkin.rake b/tasks/builtins/gherkin.rake index 107076f05b..8fd0f51b68 100644 --- a/tasks/builtins/gherkin.rake +++ b/tasks/builtins/gherkin.rake @@ -57,7 +57,6 @@ class GherkinBuiltins < BuiltinsGenerator yield "# DO NOT EDIT" yield "# This file is automatically generated by `rake builtins:gherkin`." yield "# See tasks/builtins/gherkin.rake for more info." - yield "# See tasks/builtins/gherkin.rake for more info." yield "" yield "module Rouge" yield " module Lexers" diff --git a/tasks/builtins/glsl.rake b/tasks/builtins/glsl.rake new file mode 100644 index 0000000000..a6e59a5367 --- /dev/null +++ b/tasks/builtins/glsl.rake @@ -0,0 +1,92 @@ +require_relative '../task_helper' + +namespace :builtins do + task :glsl do + GLSLBuiltins.process('./lib/rouge/lexers/glsl/builtins.rb') + end +end + +class GLSLBuiltins < BuiltinsGenerator + FUNCTIONS_ADOC = 'https://raw.githubusercontent.com/KhronosGroup/GLSL/refs/heads/main/chapters/builtinfunctions.adoc' + BASICS_ADOC = 'https://raw.githubusercontent.com/KhronosGroup/GLSL/refs/heads/main/chapters/basics.adoc' + VARIABLES_ADOC = 'https://github.com/KhronosGroup/GLSL/blob/main/chapters/variables.adoc' + BUILTINS_ADOC = 'https://raw.githubusercontent.com/KhronosGroup/GLSL/refs/heads/main/chapters/builtins.adoc' + + def fetch + [ + URI.open(FUNCTIONS_ADOC).read, + URI.open(BASICS_ADOC).read, + URI.open(VARIABLES_ADOC).read, + URI.open(BUILTINS_ADOC).read, + ] + + # [jneen] alternate option for testing when ratelimited by Github + # [ + # File.read('/tmp/builtinfunctions.adoc'), + # File.read('/tmp/basics.adoc'), + # File.read('/tmp/variables.adoc'), + # File.read('/tmp/builtins.adoc'), + # ] + end + + def parse_sections(text) + text.gsub!(/^(ifdef|endif)::.*$/, '') + + sections = {} + text.scan(/\[\[([\w-]+)\]\]\n(.*?)(?=\[\[|\z)/m).each do |(header, text)| + sections[header] = text + end + + sections + end + + def parse + functions, basics, variables, builtins = @input + + variables = parse_sections(variables) + basics = parse_sections(basics) + + out = {} + + out[:builtins] = functions.scan(/\w+ (\w+)[(]/).flatten.sort.uniq + + # false positives + out[:builtins] -= ['ComputeAccessedLod', '_', 'array'] + + out[:types] = variables['basic-types'].scan(/[*](\w+)[*]/).flatten.sort.uniq + + out[:keywords] = basics['keywords'].scan(/[*](\w+)[*]/).flatten.sort.uniq + + out[:glvars] = builtins.scan(/\b_(gl_\w+)_\b/).flatten + out[:glvars] += builtins.scan(/\bgl_\w+\b/).flatten + out[:glvars].sort! + out[:glvars].uniq! + + # make unique + out[:keywords] -= out[:types] + out[:builtins] -= out[:keywords] + out[:builtins] -= out[:types] + + out + end + + def generate + yield "# -*- coding: utf-8 -*- #" + yield "# frozen_string_literal: true" + yield "" + yield "# DO NOT EDIT" + yield "# This file is automatically generated by `rake builtins:glsl`." + yield "# See tasks/builtins/glsl.rake for more info." + yield "" + yield "module Rouge" + yield " module Lexers" + yield " class GLSL" + yield " BUILTINS = Set#{@keywords[:builtins].inspect}" + yield " KEYWORDS = Set#{@keywords[:keywords].inspect}" + yield " TYPES = Set#{@keywords[:types].inspect}" + yield " GL_VARS = Set#{@keywords[:glvars].inspect}" + yield " end" + yield " end" + yield "end" + end +end