1 ;;; tablegen-mode.el --- Major mode for TableGen description files (part of LLVM project)
3 ;; Maintainer: The LLVM team, http://llvm.org/
6 ;; A major mode for TableGen description files in LLVM.
12 ;; Create mode-specific tables.
15 (defvar td-decorators-face
'td-decorators-face
16 "Face method decorators.")
17 (make-face 'td-decorators-face
)
19 (defvar tablegen-font-lock-keywords
20 (let ((kw (regexp-opt '("class" "defm" "def" "field" "include" "in"
21 "let" "multiclass" "foreach")
23 (type-kw (regexp-opt '("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 (defvar tablegen-mode-syntax-table nil
55 "Syntax table used in `tablegen-mode' buffers.")
56 (when (not tablegen-mode-syntax-table
)
57 (setq tablegen-mode-syntax-table
(make-syntax-table))
59 (modify-syntax-entry ?\
" " tablegen-mode-syntax-table
)
60 (modify-syntax-entry ?
\t " " tablegen-mode-syntax-table
)
61 (modify-syntax-entry ?
\r " " tablegen-mode-syntax-table
)
62 (modify-syntax-entry ?
\n " " tablegen-mode-syntax-table
)
63 (modify-syntax-entry ?
\f " " tablegen-mode-syntax-table
)
64 ;; word constituents (`w')
65 (modify-syntax-entry ?\%
"w" tablegen-mode-syntax-table
)
66 (modify-syntax-entry ?\_
"w" tablegen-mode-syntax-table
)
68 (modify-syntax-entry ?
/ ". 124b" tablegen-mode-syntax-table
)
69 (modify-syntax-entry ?
* ". 23" tablegen-mode-syntax-table
)
70 (modify-syntax-entry ?
\n "> b" tablegen-mode-syntax-table
)
72 (modify-syntax-entry ?\
( "(" tablegen-mode-syntax-table
)
73 (modify-syntax-entry ?\
[ "(" tablegen-mode-syntax-table
)
74 (modify-syntax-entry ?\
{ "(" tablegen-mode-syntax-table
)
75 (modify-syntax-entry ?\
< "(" tablegen-mode-syntax-table
)
77 (modify-syntax-entry ?\
) ")" tablegen-mode-syntax-table
)
78 (modify-syntax-entry ?\
] ")" tablegen-mode-syntax-table
)
79 (modify-syntax-entry ?\
} ")" tablegen-mode-syntax-table
)
80 (modify-syntax-entry ?\
> ")" tablegen-mode-syntax-table
)
82 (modify-syntax-entry ?
\" "\"" tablegen-mode-syntax-table
)
85 ;; --------------------- Abbrev table -----------------------------
87 (defvar tablegen-mode-abbrev-table nil
88 "Abbrev table used while in TableGen mode.")
89 (define-abbrev-table 'tablegen-mode-abbrev-table
())
91 (defvar tablegen-mode-hook nil
)
92 (defvar tablegen-mode-map nil
) ; Create a mode-specific keymap.
94 (if (not tablegen-mode-map
)
95 () ; Do not change the keymap if it is already set up.
96 (setq tablegen-mode-map
(make-sparse-keymap))
97 (define-key tablegen-mode-map
"\t" 'tab-to-tab-stop
)
98 (define-key tablegen-mode-map
"\es" 'center-line
)
99 (define-key tablegen-mode-map
"\eS" 'center-paragraph
))
102 (defun tablegen-mode ()
103 "Major mode for editing TableGen description files.
104 \\{tablegen-mode-map}
105 Runs `tablegen-mode-hook' on startup."
107 (kill-all-local-variables)
108 (use-local-map tablegen-mode-map
) ; Provides the local keymap.
109 (make-local-variable 'font-lock-defaults
)
110 (setq major-mode
'tablegen-mode
; This is how describe-mode
111 ; finds the doc string to print.
112 mode-name
"TableGen" ; This name goes into the modeline.
113 local-abbrev-table tablegen-mode-abbrev-table
114 font-lock-defaults
`(tablegen-font-lock-keywords)
115 require-final-newline t
118 (set-syntax-table tablegen-mode-syntax-table
)
119 (make-local-variable 'comment-start
)
120 (setq comment-start
"//")
121 (setq indent-tabs-mode nil
)
122 (run-hooks 'tablegen-mode-hook
)) ; Finally, this permits the user to
123 ; customize the mode with a hook.
125 ;; Associate .td files with tablegen-mode
127 (add-to-list 'auto-mode-alist
(cons (purecopy "\\.td\\'") 'tablegen-mode
))
129 (provide 'tablegen-mode
)
131 ;;; tablegen-mode.el ends here