1 ;;; tablegen-mode.el --- Major mode for TableGen description files (part of LLVM project)
3 ;; Maintainer: The LLVM team, http://llvm.org/
7 ;; A major mode for TableGen description files in LLVM.
13 ;; Create mode-specific tables.
16 (defvar td-decorators-face
'td-decorators-face
17 "Face method decorators.")
18 (make-face 'td-decorators-face
)
20 (defvar tablegen-font-lock-keywords
21 (let ((kw (regexp-opt '("class" "defm" "def" "field" "include" "in"
22 "let" "multiclass" "foreach" "if" "then" "else"
23 "defvar" "defset" "dump" "assert")
25 (type-kw (regexp-opt '("bit" "bits" "code" "dag" "int" "list" "string")
30 ;; '("\/\/" . font-lock-comment-face)
32 '("\"[^\"]+\"" . font-lock-string-face
)
34 '("\\<0x[0-9A-Fa-f]+\\>" . font-lock-preprocessor-face
)
36 '("\\<0b[01]+\\>" . font-lock-preprocessor-face
)
38 '("\\<[-]?[0-9]+\\>" . font-lock-preprocessor-face
)
39 ;; Floating point constants
40 '("\\<[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\>" . font-lock-preprocessor-face
)
42 '("^[ \t]*\\(@.+\\)" 1 'td-decorators-face
)
48 "Additional expressions to highlight in TableGen mode.")
49 (put 'tablegen-mode
'font-lock-defaults
'(tablegen-font-lock-keywords))
51 ;; ---------------------- Syntax table ---------------------------
53 (defvar tablegen-mode-syntax-table nil
54 "Syntax table used in `tablegen-mode' buffers.")
55 (when (not tablegen-mode-syntax-table
)
56 (setq tablegen-mode-syntax-table
(make-syntax-table))
58 (modify-syntax-entry ?\
" " tablegen-mode-syntax-table
)
59 (modify-syntax-entry ?
\t " " tablegen-mode-syntax-table
)
60 (modify-syntax-entry ?
\r " " tablegen-mode-syntax-table
)
61 (modify-syntax-entry ?
\n " " tablegen-mode-syntax-table
)
62 (modify-syntax-entry ?
\f " " tablegen-mode-syntax-table
)
63 ;; word constituents (`w')
64 (modify-syntax-entry ?\%
"w" tablegen-mode-syntax-table
)
65 (modify-syntax-entry ?\_
"w" tablegen-mode-syntax-table
)
67 (modify-syntax-entry ?
/ ". 124b" tablegen-mode-syntax-table
)
68 (modify-syntax-entry ?
* ". 23" tablegen-mode-syntax-table
)
69 (modify-syntax-entry ?
\n "> b" tablegen-mode-syntax-table
)
71 (modify-syntax-entry ?\
( "(" 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
)
76 (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
)
81 (modify-syntax-entry ?
\" "\"" tablegen-mode-syntax-table
)
84 ;; --------------------- Abbrev table -----------------------------
86 (defvar tablegen-mode-abbrev-table nil
87 "Abbrev table used while in TableGen mode.")
88 (define-abbrev-table 'tablegen-mode-abbrev-table
())
90 (defvar tablegen-mode-hook nil
)
91 (defvar tablegen-mode-map nil
) ; Create a mode-specific keymap.
93 (if (not tablegen-mode-map
)
94 () ; Do not change the keymap if it is already set up.
95 (setq tablegen-mode-map
(make-sparse-keymap))
96 (define-key tablegen-mode-map
"\t" 'tab-to-tab-stop
)
97 (define-key tablegen-mode-map
"\es" 'center-line
)
98 (define-key tablegen-mode-map
"\eS" 'center-paragraph
))
101 (defun tablegen-mode ()
102 "Major mode for editing TableGen description files.
103 \\{tablegen-mode-map}
104 Runs `tablegen-mode-hook' on startup."
106 (kill-all-local-variables)
107 (use-local-map tablegen-mode-map
) ; Provides the local keymap.
108 (make-local-variable 'font-lock-defaults
)
109 (setq major-mode
'tablegen-mode
; This is how describe-mode
110 ; finds the doc string to print.
111 mode-name
"TableGen" ; This name goes into the modeline.
112 local-abbrev-table tablegen-mode-abbrev-table
113 font-lock-defaults
`(tablegen-font-lock-keywords)
114 require-final-newline t
117 (set-syntax-table tablegen-mode-syntax-table
)
118 (make-local-variable 'comment-start
)
119 (setq comment-start
"//")
120 (setq indent-tabs-mode nil
)
121 (run-hooks 'tablegen-mode-hook
)) ; Finally, this permits the user to
122 ; customize the mode with a hook.
124 ;; Associate .td files with tablegen-mode
126 (add-to-list 'auto-mode-alist
(cons (purecopy "\\.td\\'") 'tablegen-mode
))
128 (provide 'tablegen-mode
)
130 ;;; tablegen-mode.el ends here