diff options
author | Nathan Reed <nathaniel.reed@gmail.com> | 2016-12-29 17:48:53 -0800 |
---|---|---|
committer | Nathan Reed <nathaniel.reed@gmail.com> | 2016-12-29 17:48:53 -0800 |
commit | 7fd626cad80ee0257ac4ac5b1365d5cbb52ac247 (patch) | |
tree | 8a440e58ffa6692a1023b0ad4dea67bdfd265af6 | |
parent | c8f8ac0ef923681e47ff852809c28978fa790176 (diff) | |
download | pygments-7fd626cad80ee0257ac4ac5b1365d5cbb52ac247.tar.gz |
Add string literal parsing to HLSL lexer (copied from the one for C++).
- Also added a snippet to the example file where a string shows up (uncommon in HLSL).
-rw-r--r-- | pygments/lexers/graphics.py | 9 | ||||
-rw-r--r-- | tests/examplefiles/example.hlsl | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/pygments/lexers/graphics.py b/pygments/lexers/graphics.py index a5da2375..b47e12b1 100644 --- a/pygments/lexers/graphics.py +++ b/pygments/lexers/graphics.py @@ -102,6 +102,7 @@ class HLSLShaderLexer(RegexLexer): (r'0[xX][0-9a-fA-F]*', Number.Hex), (r'0[0-7]*', Number.Oct), (r'[1-9][0-9]*', Number.Integer), + (r'"', String, 'string'), (words(( 'asm','asm_fragment','break','case','cbuffer','centroid','class', 'column_major','compile','compile_fragment','const','continue', @@ -217,6 +218,14 @@ class HLSLShaderLexer(RegexLexer): (r'\\$', Comment.Preproc), # backslash at end of line -- usually macro continuation (r'\s+', Text), ], + 'string': [ + (r'"', String, '#pop'), + (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|' + r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape), + (r'[^\\"\n]+', String), # all other characters + (r'\\\n', String), # line continuation + (r'\\', String), # stray backslash + ], } diff --git a/tests/examplefiles/example.hlsl b/tests/examplefiles/example.hlsl index 77f1fa49..21d0a672 100644 --- a/tests/examplefiles/example.hlsl +++ b/tests/examplefiles/example.hlsl @@ -155,3 +155,14 @@ void main( o_rgb = diffuseColor * diffuseLight;
}
+
+[domain("quad")]
+void ds(
+ in float edgeFactors[4] : SV_TessFactor,
+ in float insideFactors[2] : SV_InsideTessFactor,
+ in OutputPatch<VData, 4> inp,
+ in float2 uv : SV_DomainLocation,
+ out float4 o_pos : SV_Position)
+{
+ o_pos = lerp(lerp(inp[0].pos, inp[1].pos, uv.x), lerp(inp[2].pos, inp[3].pos, uv.x), uv.y);
+}
|