Skip to content

Instantly share code, notes, and snippets.

@robstewart57
Created April 9, 2014 20:02
Show Gist options
  • Save robstewart57/10308715 to your computer and use it in GitHub Desktop.
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
;; 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