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

Conversation

bitsawer
Copy link
Contributor

Both shading languages allow their preprocessor to use line continuation with backlashes \, if they are the last character on a line before newline or carriage return. This PR adds support for that:

// Multiline replacement using backslashes for continuation:
#define SAMPLE(param1, param2, param3, param4) long_function_call( \
        param1, \
        param2, \
        param3, \
        param4 \
)

Noticed this problem when generating Godot's documentation for its shader preprocessor (which is very similar to GLSL and HLSL preprocessor). Notice how the first shader code block in https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/shader_preprocessor.html does not get syntax highlighting at all as the current lexer produces an error because of \ characters. This PR fixes the issue and the code block is highlighted correctly.

@Anteru
Copy link
Collaborator

Anteru commented Feb 22, 2023

Thanks! Could you please add/extend an example file with this so we can capture future regressions? You'll need to run pytest --update-goldens afterwards.

Copy link
Contributor

@jeanas jeanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pygments/lexers/graphics.py Outdated Show resolved Hide resolved
@jeanas
Copy link
Contributor

jeanas commented Feb 22, 2023

Well, we raced. At least we're consistent with each other :-)

@bitsawer
Copy link
Contributor Author

Thanks for the feedback! Removed "\r?" and added some tests, let me know if I missed something.

@jeanas jeanas merged commit ea05e21 into pygments:master Feb 23, 2023
@jeanas
Copy link
Contributor

jeanas commented Feb 23, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants