Skip to content

Commit

Permalink
Merge pull request #2357 from bitsawer/shader_lang_preprocessor_changes
Browse files Browse the repository at this point in the history
Fix GLSL and HLSL preprocessor directive start
  • Loading branch information
Anteru committed Feb 26, 2023
2 parents f589ac6 + 61219ae commit 875b858
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
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'^#(?:.*\\\n)*.*$', 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'^#(?:.*\\\n)*.*$', Comment.Preproc),
(r'#(?:.*\\\n)*.*$', Comment.Preproc),
(r'//.*$', Comment.Single),
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
(r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
Expand Down
6 changes: 6 additions & 0 deletions tests/examplefiles/glsl/glsl.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* Fragment shader */

// Macro inside a single-line comment: #define COMMENT_MACRO 1

/* Macro inside a block comment: #define COMMENT_MACRO 2 */

# define INDENTED_MACRO 5.0

#define SINGLELINE_MACRO 10.0

#define MULTILINE_MACRO(a, b) vec2( \
Expand Down
8 changes: 8 additions & 0 deletions tests/examplefiles/glsl/glsl.frag.output

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

6 changes: 6 additions & 0 deletions tests/examplefiles/glsl/glsl.vert
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* Vertex shader */

// Macro inside a single-line comment: #define COMMENT_MACRO 1

/* Macro inside a block comment: #define COMMENT_MACRO 2 */

# define INDENTED_MACRO 5.0

#define SINGLELINE_MACRO 10.0

#define MULTILINE_MACRO(a, b) vec2( \
Expand Down
8 changes: 8 additions & 0 deletions tests/examplefiles/glsl/glsl.vert.output

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

6 changes: 6 additions & 0 deletions tests/examplefiles/hlsl/example.hlsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// A few random snippets of HLSL shader code I gathered...

// Macro inside a single-line comment: #define COMMENT_MACRO 1

/* Macro inside a block comment: #define COMMENT_MACRO 2 */

# define INDENTED_MACRO 5.0

#define SINGLELINE_MACRO 10.0

#define MULTILINE_MACRO(a, b) float2( \
Expand Down
8 changes: 8 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 875b858

Please sign in to comment.