Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GLSL and HLSL preprocessor line continuation #2350

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pygments/lexers/graphics.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.