|
| 1 | +;;; antlrv4-mode.el --- major mode for antlrv4 -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +(eval-when-compile |
| 4 | + (require 'rx)) |
| 5 | + |
| 6 | +(defconst antlrv4-mode-syntax-table |
| 7 | + (let ((table (make-syntax-table))) |
| 8 | + |
| 9 | + ;; space is whitespace |
| 10 | + (modify-syntax-entry ?\s " ") |
| 11 | + |
| 12 | + ;; ' is a string delimiter |
| 13 | + (modify-syntax-entry ?' "\"" table) |
| 14 | + ;; " is not a string delimiter too |
| 15 | + ;;(modify-syntax-entry ?\" "-" table) |
| 16 | + |
| 17 | + ;; / is punctuation, but // is a comment starter |
| 18 | + (modify-syntax-entry ?/ ". 12" table) |
| 19 | + ;; \n is a comment ender |
| 20 | + (modify-syntax-entry ?\n ">" table) |
| 21 | + |
| 22 | + ;; - and _ are word constituents |
| 23 | + (modify-syntax-entry ?_ "w" table) |
| 24 | + (modify-syntax-entry ?- "w" table) |
| 25 | + |
| 26 | + ;; symbols |
| 27 | + (modify-syntax-entry ?* "_" table) |
| 28 | + (modify-syntax-entry ?+ "_" table) |
| 29 | + (modify-syntax-entry ?? "_" table) |
| 30 | + (modify-syntax-entry ?! "_" table) |
| 31 | + (modify-syntax-entry ?= "_" table) |
| 32 | + |
| 33 | + ;; punctations |
| 34 | + (modify-syntax-entry ?: "." table) |
| 35 | + (modify-syntax-entry ?\; "." table) |
| 36 | + (modify-syntax-entry ?| "." table) |
| 37 | + (modify-syntax-entry ?\( "." table) |
| 38 | + (modify-syntax-entry ?\) "." table) |
| 39 | + |
| 40 | + ;; valid brackets |
| 41 | + (modify-syntax-entry ?\( "()" table) |
| 42 | + (modify-syntax-entry ?\) ")(" table) |
| 43 | + |
| 44 | + table)) |
| 45 | + |
| 46 | +(defvar antlrv4-mode-abbrev-table nil |
| 47 | + "Abbreviation table used in `antlrv4-mode' buffers.") |
| 48 | + |
| 49 | +(define-abbrev-table 'antlrv4-mode-abbrev-table |
| 50 | + '()) |
| 51 | + |
| 52 | +;font-lock-warning-face |
| 53 | +;font-lock-function-name-face |
| 54 | +;font-lock-function-call-face |
| 55 | +;font-lock-variable-name-face |
| 56 | +;font-lock-variable-use-face |
| 57 | +;font-lock-keyword-face |
| 58 | +;font-lock-comment-face |
| 59 | +;font-lock-comment-delimiter-face |
| 60 | +;font-lock-type-face |
| 61 | +;font-lock-constant-face |
| 62 | +;font-lock-builtin-face |
| 63 | +;font-lock-preprocessor-face |
| 64 | +;font-lock-string-face |
| 65 | +;font-lock-doc-face |
| 66 | +;font-lock-doc-markup-face |
| 67 | +;font-lock-negation-char-face |
| 68 | +;font-lock-escape-face |
| 69 | +;font-lock-number-face |
| 70 | +;font-lock-operator-face |
| 71 | +;font-lock-property-name-face |
| 72 | +;font-lock-property-use-face |
| 73 | +;font-lock-punctuation-face |
| 74 | +;font-lock-bracket-face |
| 75 | +;font-lock-delimiter-face |
| 76 | +;font-lock-misc-punctuation-face |
| 77 | + |
| 78 | +(setq antlrv4-mode--font-lock-defaults |
| 79 | + '( |
| 80 | + ("grammar\\|annotations" . 'font-lock-keyword-face) |
| 81 | + ("separator\\|description\\|dublication\\|substitute_count\\|auto_substitute" . 'font-lock-constant-face) |
| 82 | + ("^\\([[:word:]_-]+\\)\s*$" . (1 'font-lock-variable-name-face)) |
| 83 | + ("\s+\\([[:word:]_-]+\\)" . (1 'font-lock-type-face)) |
| 84 | + ) |
| 85 | +) |
| 86 | + |
| 87 | +;;;###autoload |
| 88 | +(define-derived-mode antlrv4-mode prog-mode "AntlrV4" |
| 89 | + :syntax-table antlrv4-mode-syntax-table |
| 90 | + :abbrev-table antlrv4-mode-abbrev-table |
| 91 | + (setq font-lock-defaults '(antlrv4-mode--font-lock-defaults)) |
| 92 | +) |
| 93 | + |
| 94 | +;;;###autoload |
| 95 | +(add-to-list 'auto-mode-alist '("\\.g4\\'" . antlrv4-mode)) |
| 96 | + |
| 97 | +(provide 'antlrv4-mode) |
| 98 | + |
| 99 | +;;; antlr-mode.el ends here |
0 commit comments