Skip to content

Commit

Permalink
Fix GLSL and HLSL preprocessor line continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsawer committed Feb 22, 2023
1 parent b4e9027 commit ce88071
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pygments/lexers/graphics.py
Expand Up @@ -30,7 +30,7 @@ class GLShaderLexer(RegexLexer):

tokens = {
'root': [
(r'^#.*$', Comment.Preproc),
(r'^#(?:.*\\\n?)*.*$', Comment.Preproc),
(r'//.*$', Comment.Single),
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
(r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
Expand Down Expand Up @@ -161,7 +161,7 @@ class HLSLShaderLexer(RegexLexer):

tokens = {
'root': [
(r'^#.*$', Comment.Preproc),
(r'^#(?:.*\\\n?)*.*$', Comment.Preproc),
(r'//.*$', Comment.Single),
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
(r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
Expand Down
8 changes: 8 additions & 0 deletions tests/examplefiles/glsl/glsl.frag
@@ -1,4 +1,12 @@
/* Fragment shader */

#define SINGLELINE_MACRO 10.0

#define MULTILINE_MACRO(a, b) vec2( \
a, \
b \
)

void main()
{
gl_FragColor[0] = gl_FragCoord[0] / 400.0;
Expand Down
8 changes: 7 additions & 1 deletion tests/examplefiles/glsl/glsl.frag.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/examplefiles/glsl/glsl.vert
@@ -1,4 +1,12 @@
/* Vertex shader */

#define SINGLELINE_MACRO 10.0

#define MULTILINE_MACRO(a, b) vec2( \
a, \
b \
)

uniform float waveTime;
uniform float waveWidth;
uniform float waveHeight;
Expand Down
8 changes: 7 additions & 1 deletion tests/examplefiles/glsl/glsl.vert.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/examplefiles/hlsl/example.hlsl
@@ -1,5 +1,12 @@
// A few random snippets of HLSL shader code I gathered...

#define SINGLELINE_MACRO 10.0

#define MULTILINE_MACRO(a, b) float2( \
a, \
b \
)

[numthreads(256, 1, 1)]
void cs_main(uint3 threadId : SV_DispatchThreadID)
{
Expand Down
6 changes: 6 additions & 0 deletions tests/examplefiles/hlsl/example.hlsl.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ce88071

Please sign in to comment.