Home | History | Annotate | Download | only in emacs
      1 ;; Maintainer:  The LLVM team, http://llvm.org/
      2 ;; Description: Major mode for TableGen description files (part of LLVM project)
      3 ;; Updated:     2007-12-18
      4 
      5 (require 'comint)
      6 (require 'custom)
      7 (require 'ansi-color)
      8 
      9 ;; Create mode-specific tables.
     10 (defvar td-decorators-face 'td-decorators-face
     11   "Face method decorators.")
     12 (make-face 'td-decorators-face)
     13 
     14 (defvar tablegen-font-lock-keywords
     15   (let ((kw (regexp-opt '("class" "defm" "def" "field" "include" "in"
     16                          "let" "multiclass" "foreach")
     17                         'words))
     18         (type-kw (regexp-opt '("bit" "bits" "code" "dag" "int" "list" "string")
     19                              'words))
     20         )
     21     (list
     22      ;; Comments
     23 ;;     '("\/\/" . font-lock-comment-face)
     24      ;; Strings
     25      '("\"[^\"]+\"" . font-lock-string-face)
     26      ;; Hex constants
     27      '("\\<0x[0-9A-Fa-f]+\\>" . font-lock-preprocessor-face)
     28      ;; Binary constants
     29      '("\\<0b[01]+\\>" . font-lock-preprocessor-face)
     30      ;; Integer literals
     31      '("\\<[-]?[0-9]+\\>" . font-lock-preprocessor-face)
     32      ;; Floating point constants
     33      '("\\<[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\>" . font-lock-preprocessor-face)
     34 
     35      '("^[ \t]*\\(@.+\\)" 1 'td-decorators-face)
     36      ;; Keywords
     37      (cons (concat kw "[ \n\t(]") 1)
     38 
     39      ;; Type keywords
     40      (cons (concat type-kw "[ \n\t(]") 1)
     41      ))
     42   "Additional expressions to highlight in TableGen mode.")
     43 (put 'tablegen-mode 'font-lock-defaults '(tablegen-font-lock-keywords))
     44 
     45 ;; ---------------------- Syntax table ---------------------------
     46 ;; Shamelessly ripped from jasmin.el
     47 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el
     48 
     49 (defvar tablegen-mode-syntax-table nil
     50   "Syntax table used in `tablegen-mode' buffers.")
     51 (when (not tablegen-mode-syntax-table)
     52   (setq tablegen-mode-syntax-table (make-syntax-table))
     53   ;; whitespace (` ')
     54   (modify-syntax-entry ?\   " "      tablegen-mode-syntax-table)
     55   (modify-syntax-entry ?\t  " "      tablegen-mode-syntax-table)
     56   (modify-syntax-entry ?\r  " "      tablegen-mode-syntax-table)
     57   (modify-syntax-entry ?\n  " "      tablegen-mode-syntax-table)
     58   (modify-syntax-entry ?\f  " "      tablegen-mode-syntax-table)
     59   ;; word constituents (`w')
     60   (modify-syntax-entry ?\%  "w"      tablegen-mode-syntax-table)
     61   (modify-syntax-entry ?\_  "w"      tablegen-mode-syntax-table)
     62   ;; comments
     63   (modify-syntax-entry ?/   ". 124b" tablegen-mode-syntax-table)
     64   (modify-syntax-entry ?*   ". 23"   tablegen-mode-syntax-table)
     65   (modify-syntax-entry ?\n  "> b"    tablegen-mode-syntax-table)
     66   ;; open paren (`(')
     67   (modify-syntax-entry ?\(  "("      tablegen-mode-syntax-table)
     68   (modify-syntax-entry ?\[  "("      tablegen-mode-syntax-table)
     69   (modify-syntax-entry ?\{  "("      tablegen-mode-syntax-table)
     70   (modify-syntax-entry ?\<  "("      tablegen-mode-syntax-table)
     71   ;; close paren (`)')
     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)
     76   ;; string quote ('"')
     77   (modify-syntax-entry ?\"  "\""     tablegen-mode-syntax-table)
     78   )
     79 
     80 ;; --------------------- Abbrev table -----------------------------
     81 
     82 (defvar tablegen-mode-abbrev-table nil
     83   "Abbrev table used while in TableGen mode.")
     84 (define-abbrev-table 'tablegen-mode-abbrev-table ())
     85 
     86 (defvar tablegen-mode-hook nil)
     87 (defvar tablegen-mode-map nil)   ; Create a mode-specific keymap.
     88 
     89 (if (not tablegen-mode-map)
     90     ()  ; Do not change the keymap if it is already set up.
     91   (setq tablegen-mode-map (make-sparse-keymap))
     92   (define-key tablegen-mode-map "\t"  'tab-to-tab-stop)
     93   (define-key tablegen-mode-map "\es" 'center-line)
     94   (define-key tablegen-mode-map "\eS" 'center-paragraph))
     95 
     96 (defun tablegen-mode ()
     97   "Major mode for editing TableGen description files.
     98   \\{tablegen-mode-map}
     99   Runs tablegen-mode-hook on startup."
    100   (interactive)
    101   (kill-all-local-variables)
    102   (use-local-map tablegen-mode-map)      ; Provides the local keymap.
    103   (make-local-variable 'font-lock-defaults)
    104   (setq major-mode 'tablegen-mode        ; This is how describe-mode
    105                                          ;   finds the doc string to print.
    106 	mode-name             "TableGen" ; This name goes into the modeline.
    107         local-abbrev-table    tablegen-mode-abbrev-table
    108 	font-lock-defaults    `(tablegen-font-lock-keywords)
    109 	require-final-newline t
    110         )
    111 
    112   (set-syntax-table tablegen-mode-syntax-table)
    113   (make-local-variable 'comment-start)
    114   (setq comment-start "//")
    115   (run-hooks 'tablegen-mode-hook))       ; Finally, this permits the user to
    116                                          ;   customize the mode with a hook.
    117 
    118 ;; Associate .td files with tablegen-mode
    119 (setq auto-mode-alist (append '(("\\.td$" . tablegen-mode)) auto-mode-alist))
    120 
    121 (provide 'tablegen-mode)
    122 ;; end of tablegen-mode.el
    123