Created
April 9, 2014 20:02
-
-
Save robstewart57/10308715 to your computer and use it in GitHub Desktop.
elisp generated from BNFC fork for deriving prog-mode from language grammar rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; define several class of keywords | |
(setq mylsl-keywords (quote (".*" "{" "}" "class" "extends" "implements" "interface" ";" "throws" "(" ")" ":" "=" "," "else" "finally" "while" "." "instanceof" "?" "||" "&&" "|" "^" "&" "==" "!=" "<" ">" "<=" ">=" "<<" ">>" ">>>" "+" "-" "*" "/" "%" "++" "--" "[" "]" ".this" ".class"))) | |
(setq mylsl-types (quote (";" "abstract" "final" "public" "protected" "private" "transient" "volatile" "native" "synchronized" "static" "char" "short" "int" "long" "float" "double" "byte" "boolean" "[]" "super" "this" "null" "true" "false" "+" "-" "~" "!" "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="))) | |
(setq mylsl-functions (quote ("package" "import" "final" "{" "case" "default" "if" "switch" "else if" "break" "continue" "return" "throw" "synchronized" "try" "catch" "while" "do" "for" "(" "++" "--" "new" "["))) | |
;; create the regex string for each class of keywords | |
(setq mylsl-keywords-regexp (regexp-opt mylsl-keywords (quote words))) | |
(setq mylsl-types-regexp (regexp-opt mylsl-types (quote words))) | |
(setq mylsl-functions-regexp (regexp-opt mylsl-functions (quote words))) | |
;; clear memory | |
(setq mylsl-keywords nil) | |
(setq mylsl-types nil) | |
(setq mylsl-functions nil) | |
;; create the list for font-lock. | |
;; each class of keyword is given a particular face | |
(setq mylsl-font-lock-keywords (list (cons mylsl-keywords-regexp (quote font-lock-keyword-face)) (cons mylsl-types-regexp (quote font-lock-type-face)) (cons mylsl-functions-regexp (quote font-lock-function-name-face)))) | |
;; define the mode | |
(define-derived-mode mylsl-mode prog-mode (setq font-lock-defaults (quote (mylsl-font-lock-keywords))) (setq mylsl-keywords-regexp nil) (setq mylsl-types-regexp nil) (setq mylsl-functions-regexp nil)) | |
;; povide mode to features list | |
(provide (quote mylsl-mode)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment