glsl_highlight_rules.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. define(function(require, exports, module) {
  31. "use strict";
  32. var oop = require("../lib/oop");
  33. var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
  34. var glslHighlightRules = function() {
  35. var keywords = (
  36. "attribute|const|uniform|varying|break|continue|do|for|while|" +
  37. "if|else|in|out|inout|float|int|void|bool|true|false|" +
  38. "lowp|mediump|highp|precision|invariant|discard|return|mat2|mat3|" +
  39. "mat4|vec2|vec3|vec4|ivec2|ivec3|ivec4|bvec2|bvec3|bvec4|sampler2D|" +
  40. "samplerCube|struct"
  41. );
  42. var buildinConstants = (
  43. "radians|degrees|sin|cos|tan|asin|acos|atan|pow|" +
  44. "exp|log|exp2|log2|sqrt|inversesqrt|abs|sign|floor|ceil|fract|mod|" +
  45. "min|max|clamp|mix|step|smoothstep|length|distance|dot|cross|" +
  46. "normalize|faceforward|reflect|refract|matrixCompMult|lessThan|" +
  47. "lessThanEqual|greaterThan|greaterThanEqual|equal|notEqual|any|all|" +
  48. "not|dFdx|dFdy|fwidth|texture2D|texture2DProj|texture2DLod|" +
  49. "texture2DProjLod|textureCube|textureCubeLod|" +
  50. "gl_MaxVertexAttribs|gl_MaxVertexUniformVectors|gl_MaxVaryingVectors|" +
  51. "gl_MaxVertexTextureImageUnits|gl_MaxCombinedTextureImageUnits|" +
  52. "gl_MaxTextureImageUnits|gl_MaxFragmentUniformVectors|gl_MaxDrawBuffers|" +
  53. "gl_DepthRangeParameters|gl_DepthRange|" +
  54. // The following two are only for MIME x-shader/x-vertex.
  55. "gl_Position|gl_PointSize|" +
  56. // The following five are only for MIME x-shader/x-fragment.
  57. "gl_FragCoord|gl_FrontFacing|gl_PointCoord|gl_FragColor|gl_FragData"
  58. );
  59. var keywordMapper = this.createKeywordMapper({
  60. "variable.language": "this",
  61. "keyword": keywords,
  62. "constant.language": buildinConstants
  63. }, "identifier");
  64. this.$rules = new c_cppHighlightRules().$rules;
  65. this.$rules.start.forEach(function(rule) {
  66. if (typeof rule.token == "function")
  67. rule.token = keywordMapper;
  68. })
  69. };
  70. oop.inherits(glslHighlightRules, c_cppHighlightRules);
  71. exports.glslHighlightRules = glslHighlightRules;
  72. });