Prism.languages.hlsl = Prism.languages.extend('c', { // Regarding keywords and class names: // The list of all keywords was split into 'keyword' and 'class-name' tokens based on whether they are capitalized. // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-reserved-words 'class-name': [ Prism.languages.c['class-name'], /\b(?:AppendStructuredBuffer|BlendState|Buffer|ByteAddressBuffer|CompileShader|ComputeShader|ConsumeStructuredBuffer|DepthStencilState|DepthStencilView|DomainShader|GeometryShader|Hullshader|InputPatch|LineStream|OutputPatch|PixelShader|PointStream|RWBuffer|RWByteAddressBuffer|RWStructuredBuffer|RWTexture(?:1D|1DArray|2D|2DArray|3D)|RasterizerState|RenderTargetView|SamplerComparisonState|SamplerState|StructuredBuffer|Texture(?:1D|1DArray|2D|2DArray|2DMS|2DMSArray|3D|Cube|CubeArray)|TriangleStream|VertexShader)\b/, ], keyword: [ // HLSL keyword /\b(?:asm|asm_fragment|auto|break|case|catch|cbuffer|centroid|char|class|column_major|compile|compile_fragment|const|const_cast|continue|default|delete|discard|do|dynamic_cast|else|enum|explicit|export|extern|for|friend|fxgroup|goto|groupshared|if|in|inline|inout|interface|line|lineadj|linear|long|matrix|mutable|namespace|new|nointerpolation|noperspective|operator|out|packoffset|pass|pixelfragment|point|precise|private|protected|public|register|reinterpret_cast|return|row_major|sample|sampler|shared|short|signed|sizeof|snorm|stateblock|stateblock_state|static|static_cast|string|struct|switch|tbuffer|technique|technique10|technique11|template|texture|this|throw|triangle|triangleadj|try|typedef|typename|uniform|union|unorm|unsigned|using|vector|vertexfragment|virtual|void|volatile|while)\b/, // scalar, vector, and matrix types /\b(?:bool|double|dword|float|half|int|min(?:10float|12int|16(?:float|int|uint))|uint)(?:[1-4](?:x[1-4])?)?\b/, ], // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-grammar#floating-point-numbers number: /(?:(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[eE][+-]?\d+)?|\b0x[\da-fA-F]+)[fFhHlLuU]?\b/, boolean: /\b(?:false|true)\b/, }); c306119d8b69'/>
path: root/public/prism/prism-tt2.js
blob: f550bf9798bafd5f0be93e317432ada96dd6ccb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(function (Prism) {
  Prism.languages.tt2 = Prism.languages.extend('clike', {
    comment: /#.*|\[%#[\s\S]*?%\]/,
    keyword:
      /\b(?:BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|ELSE|ELSIF|END|FILTER|FINAL|FOREACH|GET|IF|IN|INCLUDE|INSERT|LAST|MACRO|META|NEXT|PERL|PROCESS|RAWPERL|RETURN|SET|STOP|SWITCH|TAGS|THROW|TRY|UNLESS|USE|WHILE|WRAPPER)\b/,
    punctuation: /[[\]{},()]/,
  });

  Prism.languages.insertBefore('tt2', 'number', {
    operator: /=[>=]?|!=?|<=?|>=?|&&|\|\|?|\b(?:and|not|or)\b/,
    variable: {
      pattern: /\b[a-z]\w*(?:\s*\.\s*(?:\d+|\$?[a-z]\w*))*\b/i,
    },
  });

  Prism.languages.insertBefore('tt2', 'keyword', {
    delimiter: {
      pattern: /^(?:\[%|%%)-?|-?%\]$/,
      alias: 'punctuation',
    },
  });

  Prism.languages.insertBefore('tt2', 'string', {
    'single-quoted-string': {
      pattern: /'[^\\']*(?:\\[\s\S][^\\']*)*'/,
      greedy: true,
      alias: 'string',
    },
    'double-quoted-string': {
      pattern: /"[^\\"]*(?:\\[\s\S][^\\"]*)*"/,
      greedy: true,
      alias: 'string',
      inside: {
        variable: {
          pattern: /\$(?:[a-z]\w*(?:\.(?:\d+|\$?[a-z]\w*))*)/i,
        },
      },
    },
  });

  // The different types of TT2 strings "replace" the C-like standard string
  delete Prism.languages.tt2.string;

  Prism.hooks.add('before-tokenize', function (env) {
    var tt2Pattern = /\[%[\s\S]+?%\]/g;
    Prism.languages['markup-templating'].buildPlaceholders(
      env,
      'tt2',
      tt2Pattern
    );
  });

  Prism.hooks.add('after-tokenize', function (env) {
    Prism.languages['markup-templating'].tokenizePlaceholders(env, 'tt2');
  });
})(Prism);