1 ;; Maintainer: The LLVM team, http://llvm.org/
2 ;; Description: Major mode for TableGen description files (part of LLVM project)
9 ;; Create mode-specific tables.
10 (defvar tablegen-mode-syntax-table nil
11 "Syntax table used while in TableGen mode.")
13 (defvar td-decorators-face 'td-decorators-face
14 "Face method decorators.")
15 (make-face 'td-decorators-face)
17 (defvar tablegen-font-lock-keywords
18 (let ((kw (mapconcat 'identity
19 '("class" "defm" "def" "field" "include" "in"
22 (type-kw (mapconcat 'identity
23 '("bit" "bits" "code" "dag" "int" "list" "string")
28 '("\/\/" . font-lock-comment-face)
30 '("\"[^\"]+\"" . font-lock-string-face)
32 '("0x[0-9A-Fa-f]+" . font-lock-preprocessor-face)
34 '("0b[01]+" . font-lock-preprocessor-face)
36 '("[-]?[0-9]+" . font-lock-preprocessor-face)
37 ;; Floating point constants
38 '("[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?" . font-lock-preprocessor-face)
40 '("^[ \t]*\\(@.+\\)" 1 'td-decorators-face)
42 (cons (concat "\\<\\(" kw "\\)\\>[ \n\t(]") 1)
45 (cons (concat "\\<\\(" type-kw "\\)[ \n\t(]") 1)
47 "Additional expressions to highlight in TableGen mode.")
48 (put 'tablegen-mode 'font-lock-defaults '(tablegen-font-lock-keywords))
50 ;; ---------------------- Syntax table ---------------------------
51 ;; Shamelessly ripped from jasmin.el
52 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el
54 (if (not tablegen-mode-syntax-table)
56 (setq tablegen-mode-syntax-table (make-syntax-table))
59 (modify-syntax-entry (aref n 0)
61 tablegen-mode-syntax-table)))
69 ;; word constituents (`w')
77 ;; symbol constituents (`_')
93 ;; --------------------- Abbrev table -----------------------------
95 (defvar tablegen-mode-abbrev-table nil
96 "Abbrev table used while in TableGen mode.")
97 (define-abbrev-table 'tablegen-mode-abbrev-table ())
99 (defvar tablegen-mode-hook nil)
100 (defvar tablegen-mode-map nil) ; Create a mode-specific keymap.
102 (if (not tablegen-mode-map)
103 () ; Do not change the keymap if it is already set up.
104 (setq tablegen-mode-map (make-sparse-keymap))
105 (define-key tablegen-mode-map "\t" 'tab-to-tab-stop)
106 (define-key tablegen-mode-map "\es" 'center-line)
107 (define-key tablegen-mode-map "\eS" 'center-paragraph))
109 (defun tablegen-mode ()
110 "Major mode for editing TableGen description files.
111 \\{tablegen-mode-map}
112 Runs tablegen-mode-hook on startup."
114 (kill-all-local-variables)
115 (use-local-map tablegen-mode-map) ; Provides the local keymap.
116 (setq major-mode 'tablegen-mode)
118 (make-local-variable 'font-lock-defaults)
119 (setq major-mode 'tablegen-mode ; This is how describe-mode
120 ; finds the doc string to print.
121 mode-name "TableGen" ; This name goes into the modeline.
122 font-lock-defaults `(tablegen-font-lock-keywords))
124 (setq local-abbrev-table tablegen-mode-abbrev-table)
125 (set-syntax-table tablegen-mode-syntax-table)
126 (run-hooks 'tablegen-mode-hook)) ; Finally, this permits the user to
127 ; customize the mode with a hook.
129 ;; Associate .td files with tablegen-mode
130 (setq auto-mode-alist (append '(("\\.td$" . tablegen-mode)) auto-mode-alist))
132 (provide 'tablegen-mode)
133 ;; end of tablegen-mode.el