1;; Copyright 2019 The Amber Authors. 2;; 3;; Licensed under the Apache License, Version 2.0 (the "License"); 4;; you may not use this file except in compliance with the License. 5;; You may obtain a copy of the License at 6;; 7;; https://www.apache.org/licenses/LICENSE-2.0 8;; 9;; Unless required by applicable law or agreed to in writing, software 10;; distributed under the License is distributed on an "AS IS" BASIS, 11;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12;; See the License for the specific language governing permissions and 13;; limitations under the License. 14 15;; Emacs mode for Amber script 16;; https://github.com/google/amber 17 18(defvar amber-mode-hook nil) 19 20(defvar amber-mode-map 21 (let ((map (make-keymap))) 22 ;; Add key bindings here 23 (define-key map "\C-j" 'newline-and-indent) 24 map) 25 "Keymap for Amber major mode") 26 27;;;###autoload 28(add-to-list 'auto-mode-alist '("\\.amber\\'" . amber-mode)) 29 30;; Evaluate the following to create optimized regex used for highlighting 31 32;; (regexp-opt '( 33;; "END" "SHADER" "BUFFER" "DATA_TYPE" "SIZE" "DATA" "FILL" 34;; "SERIES_FROM" "PASSTHROUGH" "PIPELINE" "ATTACH" "ENTRY_POINT" 35;; "DESCRIPTOR_SET" "INC_BY" "BINDING" "IDX" "TO" "RUN" "DRAW_RECT" 36;; "POS" "DRAW_ARRAY" "IN" "AS" "START_IDX" "COUNT" "CLEAR_COLOR" 37;; "CLEAR" "EXPECT" "TYPE" "FRAMEBUFFER" "SHADER_OPTIMIZATION" 38;; "FORMAT" "FRAMEBUFFER_SIZE" "BIND" "SAMPLER" "VERTEX_DATA" 39;; "INDEX_DATA" "INDEXED" "IMAGE_ATTACHMENT" 40;; "DEPTH_STENCIL_ATTACHMENT" "LOCATION" "DEVICE_FEATURE" 41;; "DERIVE_PIPELINE" "FROM" "COPY" "TOLERANCE" "REPEAT" 42;; ) t) 43 44;; (regexp-opt '( 45;; "vertex" "fragment" "compute" "geometry" "tessellation_evaluation" 46;; "tessellation_control" "multi" "framebuffer" "graphics" "uniform" 47;; "storage" "push_constant" "color" "depth_stencil" "EQ" "NE" "LT" 48;; "LE" "GT" "GE" "EQ_RGB" "EQ_RGBA" "EQ_BUFFER" "GLSL" "HLSL" 49;; "SPIRV-ASM" "SPIRV-HEX" "OPENCL-C" 50;; ) t) 51 52;; (regexp-opt '( 53;; "point_list" "line_list" "line_list_with_adjacency" "line_strip" 54;; "line_strip_with_adjacency" "triangle_list" 55;; "triangle_list_with_adjacency" "triangle_strip" 56;; "triangle_strip_with_adjacency" "triangle_fan" "patch_list" 57;; "float" "double" 58;; ) t) 59 60(defconst amber-font-lock-keywords-1 61 (list 62 '("\\<\\(A\\(?:S\\|TTACH\\)\\|B\\(?:IND\\(?:ING\\)?\\|UFFER\\)\\|C\\(?:LEAR\\(?:_COLOR\\)?\\|O\\(?:PY\\|UNT\\)\\)\\|D\\(?:ATA\\(?:_TYPE\\)?\\|E\\(?:PTH_STENCIL_ATTACHMENT\\|RIVE_PIPELINE\\|SCRIPTOR_SET\\|VICE_FEATURE\\)\\|RAW_\\(?:ARRAY\\|RECT\\)\\)\\|E\\(?:N\\(?:D\\|TRY_POINT\\)\\|XPECT\\)\\|F\\(?:ILL\\|ORMAT\\|R\\(?:AMEBUFFER\\(?:_SIZE\\)?\\|OM\\)\\)\\|I\\(?:DX\\|MAGE_ATTACHMENT\\|N\\(?:C_BY\\|DEX\\(?:ED\\|_DATA\\)\\)?\\)\\|LOCATION\\|P\\(?:ASSTHROUGH\\|IPELINE\\|OS\\)\\|R\\(?:EPEAT\\|UN\\)\\|S\\(?:AMPLER\\|ERIES_FROM\\|HADER\\(?:_OPTIMIZATION\\)?\\|IZE\\|TART_IDX\\)\\|T\\(?:O\\(?:LERANCE\\)?\\|YPE\\)\\|VERTEX_DATA\\)\\>" . font-lock-builtin-face) 63 '("\\<\\(EQ\\(?:_\\(?:BUFFER\\|RGBA?\\)\\)?\\|G\\(?:LSL\\|[ET]\\)\\|HLSL\\|L[ET]\\|NE\\|OPENCL-C\\|SPIRV-\\(?:ASM\\|HEX\\)\\|co\\(?:lor\\|mpute\\)\\|depth_stencil\\|fra\\(?:gment\\|mebuffer\\)\\|g\\(?:eometry\\|raphics\\)\\|multi\\|push_constant\\|storage\\|tessellation_\\(?:control\\|evaluation\\)\\|uniform\\|vertex\\)\\>" . font-lock-constant-face) 64 '("\\<\\(double\\|float\\|line_\\(?:list\\(?:_with_adjacency\\)?\\|strip\\(?:_with_adjacency\\)?\\)\\|p\\(?:\\(?:atch\\|oint\\)_list\\)\\|triangle_\\(?:fan\\|list\\(?:_with_adjacency\\)?\\|strip\\(?:_with_adjacency\\)?\\)\\)\\>" . font-lock-type-face) 65 ;; This one is hand-written, not generated by regexp-opt 66 '("\\<\\(u?int\\|vec\\|mat\\)[[:digit:]]*\\>" . font-lock-type-face) 67 ) 68 "Minimal highlighting expressions for Amber mode") 69 70(defvar amber-font-lock-keywords amber-font-lock-keywords-1 71 "Default highlighting expressions for Amber mode") 72 73(defvar amber-mode-syntax-table 74 (let ((st (make-syntax-table))) 75 (modify-syntax-entry ?_ "w" st) 76 (modify-syntax-entry ?# "<" st) 77 (modify-syntax-entry ?\n ">" st) 78 (modify-syntax-entry ?\" "\"" st) 79 st) 80 "Syntax table for amber-mode") 81 82(defun amber-mode () 83 "Major mode for editing Amber Script files" 84 (interactive) 85 (kill-all-local-variables) 86 (set-syntax-table amber-mode-syntax-table) 87 (use-local-map amber-mode-map) 88 (set (make-local-variable 'font-lock-defaults) '(amber-font-lock-keywords)) 89 (setq major-mode 'amber-mode) 90 (setq mode-name "amber") 91 (run-hooks 'amber-mode-hook)) 92 93(provide 'amber-mode) 94