blob: e180915f3b01cb044b3ff1875bb1be5207e16d2b [file] [log] [blame]
Reid Spencer9dce2b32006-03-14 05:54:52 +00001;; Maintainer: The LLVM team, http://llvm.org/
Misha Brukmanbdb41192003-08-11 19:10:02 +00002;; Description: Major mode for TableGen description files (part of LLVM project)
Bill Wendlingd4eeb802007-03-27 20:23:56 +00003;; Updated: 2007-03-26
4
5(require 'comint)
6(require 'custom)
7(require 'ansi-color)
Misha Brukmanbdb41192003-08-11 19:10:02 +00008
9;; Create mode-specific tables.
10(defvar tablegen-mode-syntax-table nil
11 "Syntax table used while in TableGen mode.")
12
Bill Wendlingd4eeb802007-03-27 20:23:56 +000013(defvar td-decorators-face 'td-decorators-face
14 "Face method decorators.")
15(make-face 'td-decorators-face)
16
Misha Brukmanbdb41192003-08-11 19:10:02 +000017(defvar tablegen-font-lock-keywords
Bill Wendlingd4eeb802007-03-27 20:23:56 +000018 (let ((kw (mapconcat 'identity
Bill Wendling041b3f82007-12-08 23:58:46 +000019 '("class" "defm" "def" "field" "include" "in"
Bill Wendlingd4eeb802007-03-27 20:23:56 +000020 "let" "multiclass")
21 "\\|"))
22 (type-kw (mapconcat 'identity
23 '("bit" "bits" "code" "dag" "int" "list" "string")
24 "\\|"))
25 )
26 (list
27 ;; Comments
28 '("\/\/" . font-lock-comment-face)
29 ;; Strings
30 '("\"[^\"]+\"" . font-lock-string-face)
31 ;; Hex constants
32 '("0x[0-9A-Fa-f]+" . font-lock-preprocessor-face)
33 ;; Binary constants
34 '("0b[01]+" . font-lock-preprocessor-face)
35 ;; Integer literals
36 '("[-]?[0-9]+" . font-lock-preprocessor-face)
37 ;; Floating point constants
38 '("[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?" . font-lock-preprocessor-face)
39
40 '("^[ \t]*\\(@.+\\)" 1 'td-decorators-face)
41 ;; Keywords
42 (cons (concat "\\<\\(" kw "\\)\\>[ \n\t(]") 1)
43
44 ;; Type keywords
45 (cons (concat "\\<\\(" type-kw "\\)[ \n\t(]") 1)
46 ))
47 "Additional expressions to highlight in TableGen mode.")
48(put 'tablegen-mode 'font-lock-defaults '(tablegen-font-lock-keywords))
Misha Brukmanbdb41192003-08-11 19:10:02 +000049
50;; ---------------------- Syntax table ---------------------------
51;; Shamelessly ripped from jasmin.el
Bill Wendling041b3f82007-12-08 23:58:46 +000052;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el
Misha Brukmanbdb41192003-08-11 19:10:02 +000053
54(if (not tablegen-mode-syntax-table)
55 (progn
56 (setq tablegen-mode-syntax-table (make-syntax-table))
Bill Wendling041b3f82007-12-08 23:58:46 +000057 (mapcar (function
58 (lambda (n)
59 (modify-syntax-entry (aref n 0)
60 (aref n 1)
61 tablegen-mode-syntax-table)))
Misha Brukmanbdb41192003-08-11 19:10:02 +000062 '(
63 ;; whitespace (` ')
64 [?\^m " "]
65 [?\f " "]
66 [?\n " "]
67 [?\t " "]
68 [?\ " "]
69 ;; word constituents (`w')
Misha Brukmanbdb41192003-08-11 19:10:02 +000070 [?\% "w"]
71 ;;[?_ "w "]
72 ;; comments
73 [?\; "< "]
74 [?\n "> "]
75 ;;[?\r "> "]
76 ;;[?\^m "> "]
77 ;; symbol constituents (`_')
78 ;; punctuation (`.')
79 ;; open paren (`(')
Bill Wendling041b3f82007-12-08 23:58:46 +000080 [?\( "("]
81 [?\[ "("]
82 [?\{ "("]
83 [?\< "("]
Misha Brukmanbdb41192003-08-11 19:10:02 +000084 ;; close paren (`)')
Bill Wendling041b3f82007-12-08 23:58:46 +000085 [?\) ")"]
86 [?\] ")"]
87 [?\} ")"]
88 [?\> ")"]
Misha Brukmanbdb41192003-08-11 19:10:02 +000089 ;; string quote ('"')
Bill Wendling041b3f82007-12-08 23:58:46 +000090 [?\" "\""]
Misha Brukmanbdb41192003-08-11 19:10:02 +000091 ))))
92
93;; --------------------- Abbrev table -----------------------------
94
95(defvar tablegen-mode-abbrev-table nil
96 "Abbrev table used while in TableGen mode.")
97(define-abbrev-table 'tablegen-mode-abbrev-table ())
98
99(defvar tablegen-mode-hook nil)
100(defvar tablegen-mode-map nil) ; Create a mode-specific keymap.
101
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))
Bill Wendling041b3f82007-12-08 23:58:46 +0000105 (define-key tablegen-mode-map "\t" 'tab-to-tab-stop)
Misha Brukmanbdb41192003-08-11 19:10:02 +0000106 (define-key tablegen-mode-map "\es" 'center-line)
107 (define-key tablegen-mode-map "\eS" 'center-paragraph))
108
Misha Brukmanbdb41192003-08-11 19:10:02 +0000109(defun tablegen-mode ()
110 "Major mode for editing TableGen description files.
111 \\{tablegen-mode-map}
112 Runs tablegen-mode-hook on startup."
113 (interactive)
114 (kill-all-local-variables)
115 (use-local-map tablegen-mode-map) ; Provides the local keymap.
116 (setq major-mode 'tablegen-mode)
117
Bill Wendling041b3f82007-12-08 23:58:46 +0000118 (make-local-variable 'font-lock-defaults)
Misha Brukmanbdb41192003-08-11 19:10:02 +0000119 (setq major-mode 'tablegen-mode ; This is how describe-mode
120 ; finds the doc string to print.
Bill Wendling041b3f82007-12-08 23:58:46 +0000121 mode-name "TableGen" ; This name goes into the modeline.
Misha Brukmanbdb41192003-08-11 19:10:02 +0000122 font-lock-defaults `(tablegen-font-lock-keywords))
123
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.
128
129;; Associate .td files with tablegen-mode
130(setq auto-mode-alist (append '(("\\.td$" . tablegen-mode)) auto-mode-alist))
131
132(provide 'tablegen-mode)
133;; end of tablegen-mode.el