aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/glsl.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-11 01:27:32 +0200
committerRandy Palamar <randy@rnpnr.xyz>2024-03-27 06:04:21 -0600
commit4c4392d29df777ff702dfe99b4f3c23142976e05 (patch)
tree5355324abe18952f7d19d6cfc5dbeb5d6cb72b84 /lua/lexers/glsl.lua
parent95bf9f59f8a9a37148bdc0787db378d62c7cd032 (diff)
downloadvis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.gz
vis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.xz
update lexers to orbitalquark/scintillua@b789dde
Rather than cherry pick patches from after 6.2 we will just grab everything as is.
Diffstat (limited to 'lua/lexers/glsl.lua')
-rw-r--r--lua/lexers/glsl.lua87
1 files changed, 50 insertions, 37 deletions
diff --git a/lua/lexers/glsl.lua b/lua/lexers/glsl.lua
index 9997a13..60aad9d 100644
--- a/lua/lexers/glsl.lua
+++ b/lua/lexers/glsl.lua
@@ -1,39 +1,49 @@
--- Copyright 2006-2022 Mitchell. See LICENSE.
+-- Copyright 2006-2024 Mitchell. See LICENSE.
-- GLSL LPeg lexer.
-local lexer = require('lexer')
-local token, word_match = lexer.token, lexer.word_match
-local P, S, R = lpeg.P, lpeg.S, lpeg.R
+local lexer = lexer
+local P, S = lpeg.P, lpeg.S
-local lex = lexer.new('glsl', {inherit = lexer.load('cpp')})
+local lex = lexer.new(..., {inherit = lexer.load('ansi_c')})
--- Whitespace.
-lex:modify_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
+-- Word lists.
+lex:set_word_list(lexer.KEYWORD, {
+ 'attribute', 'const', 'uniform', 'varying', 'buffer', 'shared', 'coherent', 'volatile',
+ 'restrict', 'readonly', 'writeonly', 'layout', 'centroid', 'flat', 'smooth', 'noperspective',
+ 'patch', 'sample', 'break', 'continue', 'do', 'for', 'while', 'switch', 'case', 'default', 'if',
+ 'else', 'subroutine', 'in', 'inout', 'out', 'true', 'false', 'invariant', 'precise', 'discard',
+ 'return', 'lowp', 'mediump', 'highp', 'precision', 'struct', --
+ -- Reserved.
+ 'common', 'partition', 'active', 'asm', 'class', 'union', 'enum', 'typedef', 'template', 'this',
+ 'resource', 'goto', 'inline', 'noinline', 'public', 'static', 'extern', 'external', 'interface',
+ 'superp', 'input', 'output', 'filter', 'sizeof', 'cast', 'namespace', 'using'
+})
--- Keywords.
-lex:modify_rule('keyword', token(lexer.KEYWORD, word_match{
- 'attribute', 'const', 'in', 'inout', 'out', 'uniform', 'varying', 'invariant', 'centroid', 'flat',
- 'smooth', 'noperspective', 'layout', 'patch', 'sample', 'subroutine', 'lowp', 'mediump', 'highp',
- 'precision',
- -- Macros.
- '__VERSION__', '__LINE__', '__FILE__'
-}) + lex:get_rule('keyword'))
+lex:set_word_list(lexer.TYPE, {
+ 'atomic_uint', 'float', 'double', 'int', 'void', 'bool', 'mat2', 'mat3', 'mat4', 'dmat2', 'dmat3',
+ 'dmat4', 'mat2x2', 'mat2x3', 'mat2x4', 'dmat2x2', 'dmat2x3', 'dmat2x4', 'mat3x2', 'mat3x3',
+ 'mat3x4', 'dmat3x2', 'dmat3x3', 'dmat3x4', 'mat4x2', 'mat4x3', 'mat4x4', 'dmat4x2', 'dmat4x3',
+ 'dmat4x4', 'vec2', 'vec3', 'vec4', 'ivec2', 'ivec3', 'ivec4', 'bvec2', 'bvec3', 'bvec4', 'dvec2',
+ 'dvec3', 'dvec4', 'uint', 'uvec2', 'uvec3', 'uvec4', 'sampler1D', 'sampler2D', 'sampler3D',
+ 'samplerCube', 'sampler1DShadow', 'sampler2DShadow', 'samplerCubeShadow', 'sampler1DArray',
+ 'sampler2DArray', 'sampler1DArrayShadow', 'sampler2DArrayShadow', 'isampler1D', 'isampler2D',
+ 'isampler3D', 'isamplerCube', 'isampler1DArray', 'isampler2DArray', 'usampler1D', 'usampler2D',
+ 'usampler3D', 'usamplerCube', 'usampler1DArray', 'usampler2DArray', 'sampler2DRect',
+ 'sampler2DRectShadow', 'isampler2DRect', 'usampler2DRect', 'samplerBuffer', 'isamplerBuffer',
+ 'usamplerBuffer', 'sampler2DMS', 'isampler2DMS', 'usampler2DMS', 'sampler2DMSArray',
+ 'isampler2DMSArray', 'usampler2DMSArray', 'samplerCubeArray', 'samplerCubeArrayShadow',
+ 'isamplerCubeArray', 'usamplerCubeArray', 'image1D', 'iimage1D', 'uimage1D', 'image2D',
+ 'iimage2D', 'uimage2D', 'image3D', 'iimage3D', 'uimage3D', 'image2DRect', 'iimage2DRect',
+ 'uimage2DRect', 'imageCube', 'iimageCube', 'uimageCube', 'imageBuffer', 'iimageBuffer',
+ 'uimageBuffer', 'image1DArray', 'iimage1DArray', 'uimage1DArray', 'image2DArray', 'iimage2DArray',
+ 'uimage2DArray', 'imageCubeArray', 'iimageCubeArray', 'uimageCubeArray', 'image2DMS',
+ 'iimage2DMS', 'uimage2DMS', 'image2DMSArray', 'iimage2DMSArray', 'uimage2DMSArray',
+ -- Reserved.
+ 'long', 'short', 'half', 'fixed', 'unsigned', 'hvec2', 'hvec3', 'hvec4', 'fvec2', 'fvec3',
+ 'fvec4', 'sampler3DRect'
+})
--- Types.
--- LuaFormatter off
-lex:modify_rule('type', token(lexer.TYPE,
- S('bdiu')^-1 * 'vec' * R('24') +
- P('d')^-1 * 'mat' * R('24') * ('x' * R('24')^-1) +
- S('iu')^-1 * 'sampler' * R('13') * 'D' +
- 'sampler' * R('12') * 'D' * P('Array')^-1 * 'Shadow' +
- (S('iu')^-1 * 'sampler' * (R('12') * 'DArray' +
- word_match('Cube 2DRect Buffer 2DMS 2DMSArray 2DMSCubeArray'))) +
- word_match('samplerCubeShadow sampler2DRectShadow samplerCubeArrayShadow')) +
--- LuaFormatter on
- lex:get_rule('type') +
-
--- Functions.
-token(lexer.FUNCTION, word_match{
+lex:set_word_list(lexer.FUNCTION_BUILTIN, {
'radians', 'degrees', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'sinh', 'cosh', 'tanh',
'asinh', 'acosh', 'atanh', 'pow', 'exp', 'log', 'exp2', 'log2', 'sqrt', 'inversesqrt', 'abs',
'sign', 'floor', 'trunc', 'round', 'roundEven', 'ceil', 'fract', 'mod', 'modf', 'min', 'max',
@@ -56,10 +66,9 @@ token(lexer.FUNCTION, word_match{
'interpolateAtCentroid', 'interpolateAtSample', 'interpolateAtOffset', 'noise1', 'noise2',
'noise3', 'noise4', 'EmitStreamVertex', 'EndStreamPrimitive', 'EmitVertex', 'EndPrimitive',
'barrier'
-}) +
+})
--- Variables.
-token(lexer.VARIABLE, word_match{
+lex:set_word_list(lexer.VARIABLE, {
'gl_VertexID', 'gl_InstanceID', 'gl_Position', 'gl_PointSize', 'gl_ClipDistance',
'gl_PrimitiveIDIn', 'gl_InvocationID', 'gl_PrimitiveID', 'gl_Layer', 'gl_PatchVerticesIn',
'gl_TessLevelOuter', 'gl_TessLevelInner', 'gl_TessCoord', 'gl_FragCoord', 'gl_FrontFacing',
@@ -69,10 +78,10 @@ token(lexer.VARIABLE, word_match{
'gl_SecondaryColor', 'gl_Normal', 'gl_Vertex', 'gl_MultiTexCoord0', 'gl_MultiTexCoord1',
'gl_MultiTexCoord2', 'gl_MultiTexCoord3', 'gl_MultiTexCoord4', 'gl_MultiTexCoord5',
'gl_MultiTexCoord6', 'gl_MultiTexCoord7', 'gl_FogCoord'
-}) +
+})
--- Constants.
-token(lexer.CONSTANT, word_match{
+lex:set_word_list(lexer.CONSTANT_BUILTIN, {
+ '__LINE__', '__FILE__', '__VERSION__', --
'gl_MaxVertexAttribs', 'gl_MaxVertexUniformComponents', 'gl_MaxVaryingFloats',
'gl_MaxVaryingComponents', 'gl_MaxVertexOutputComponents', 'gl_MaxGeometryInputComponents',
'gl_MaxGeometryOutputComponents', 'gl_MaxFragmentInputComponents',
@@ -99,6 +108,10 @@ token(lexer.CONSTANT, word_match{
'gl_BackLightProduct', 'gl_TextureEnvColor', 'gl_EyePlaneS', 'gl_EyePlaneT', 'gl_EyePlaneR',
'gl_EyePlaneQ', 'gl_ObjectPlaneS', 'gl_ObjectPlaneT', 'gl_ObjectPlaneR', 'gl_ObjectPlaneQ',
'gl_Fog'
-}))
+})
+
+lex:set_word_list(lexer.PREPROCESSOR, 'extension version', true)
+
+lexer.property['scintillua.comment'] = '//'
return lex