Skip to content

Instantly share code, notes, and snippets.

@elliotpotts
Created November 15, 2016 22:52
Show Gist options
  • Save elliotpotts/152111f2298a958b07ecfadd43d5d72b to your computer and use it in GitHub Desktop.
Save elliotpotts/152111f2298a958b07ecfadd43d5d72b to your computer and use it in GitHub Desktop.
(defvar wren-mode-hook nil)
(defvar wren-mode-map
(let ((map (make-sparse-keymap))))
"Keymap for Wren major mode")
;;; Autoload
(add-to-list 'auto-mode-alist '("\\.wren\\'" . wren-mode))
(defconst wren-keyword-regex
(regexp-opt '("break" "class" "construct" "else" "for" "foreign" "if" "import"
"in" "is" "null" "return" "static" "super" "this" "var" "while")
'words)
"Regex matching all wren keywords")
(defconst wren-constant-regex "true\|false\|[0-9]*\.[0-9]+"
"Regex matching wren boolean and numeric literals")
(defconst wren-string-regex "\"\\(\\(?:\\\\\\(?:[\"%abfnrtv0\\\\]\\|u[0-9a-fA-F]{4}\\|U[0-9a-fA-F]{8}\\|x[0-9a-fA-F]{2}\\)\\|[^\"]\\)*\\)\""
"Regex matching wren strings")
(defconst wren-comment-regex "\\.*$\|"
"Regex matching wren comments")
(defconst wren-field-regex "_[a-zA-Z0-9]*"
"Regex matching wren field identifiers")
(defconst wren-type-regex "[A-Z][a-zA-Z0-9]*"
"Regex matching wren type identifiers")
(defconst wren-identifier-regex "[a-z0-9][a-zA-Z0-9]*"
"Regex matching other wren identifiers")
(defconst wren-operator-regex
(regexp-opt '("=" "?" ":" "||" "&&" "!=" "==" "is" ">=" ">" "<=" "<" "|" "&" ">>" "<<"
"..." ".." "-" "+" "%" "/" "*" "~" "!" "[" "]")
'symbols)
"Regex matching wren operators")
(defconst wren-font-lock
'(list
(wren-keyword-regex . font-lock-builtin-face)
(wren-type-regex . font-lock-variable-face)))
(define-derived-mode wren-mode fundamental-mode "Wren"
"Major mode for editing Wren files"
(set (make-local-variable 'font-locks-defaults) '(wren-font-lock))
(run-hooks 'wren-mode-hook))
(provide 'wren-mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment