1 ;; Maintainer: The LLVM team, http://llvm.org/
2 ;; Description: Major mode for TableGen description files (part of LLVM project)
5 ;; Create mode-specific tables.
6 (defvar tablegen-mode-syntax-table nil
7 "Syntax table used while in TableGen mode.")
9 (defvar tablegen-font-lock-keywords
12 '("\/\/.*" . font-lock-comment-face)
14 '("\"[^\"]+\"" . font-lock-string-face)
16 '("0x[0-9A-Fa-f]+" . font-lock-preprocessor-face)
18 '("0b[01]+" . font-lock-preprocessor-face)
20 '("[-]?[0-9]+" . font-lock-preprocessor-face)
21 ;; Floating point constants
22 '("[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?" . font-lock-preprocessor-face)
24 '("include\\|def\\|let\\|in\\|code\\|dag\\|field" . font-lock-keyword-face)
26 '("class\\|int\\|string\\|list\\|bits?" . font-lock-type-face)
28 "Syntax highlighting for TableGen"
31 ;; ---------------------- Syntax table ---------------------------
32 ;; Shamelessly ripped from jasmin.el
33 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html
35 (if (not tablegen-mode-syntax-table)
37 (setq tablegen-mode-syntax-table (make-syntax-table))
38 (mapcar (function (lambda (n)
39 (modify-syntax-entry (aref n 0)
41 tablegen-mode-syntax-table)))
49 ;; word constituents (`w')
59 ;; symbol constituents (`_')
73 ;; --------------------- Abbrev table -----------------------------
75 (defvar tablegen-mode-abbrev-table nil
76 "Abbrev table used while in TableGen mode.")
77 (define-abbrev-table 'tablegen-mode-abbrev-table ())
79 (defvar tablegen-mode-hook nil)
80 (defvar tablegen-mode-map nil) ; Create a mode-specific keymap.
82 (if (not tablegen-mode-map)
83 () ; Do not change the keymap if it is already set up.
84 (setq tablegen-mode-map (make-sparse-keymap))
85 (define-key tablegen-mode-map "\t" 'tab-to-tab-stop)
86 (define-key tablegen-mode-map "\es" 'center-line)
87 (define-key tablegen-mode-map "\eS" 'center-paragraph))
90 (defun tablegen-mode ()
91 "Major mode for editing TableGen description files.
93 Runs tablegen-mode-hook on startup."
95 (kill-all-local-variables)
96 (use-local-map tablegen-mode-map) ; Provides the local keymap.
97 (setq major-mode 'tablegen-mode)
99 (make-local-variable 'font-lock-defaults)
100 (setq major-mode 'tablegen-mode ; This is how describe-mode
101 ; finds the doc string to print.
102 mode-name "TableGen" ; This name goes into the modeline.
103 font-lock-defaults `(tablegen-font-lock-keywords))
105 (setq local-abbrev-table tablegen-mode-abbrev-table)
106 (set-syntax-table tablegen-mode-syntax-table)
107 (run-hooks 'tablegen-mode-hook)) ; Finally, this permits the user to
108 ; customize the mode with a hook.
110 ;; Associate .td files with tablegen-mode
111 (setq auto-mode-alist (append '(("\\.td$" . tablegen-mode)) auto-mode-alist))
113 (provide 'tablegen-mode)
114 ;; end of tablegen-mode.el