-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
monkey.el
98 lines (79 loc) · 2.04 KB
/
monkey.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;;; monkey.el --- mode for editing monkey scripts
;; Copyright (C) 2018 Steve Kemp
;; Author: Steve Kemp <steve@steve.fi>
;; Keywords: languages
;; Version: 1.0
;;; Commentary:
;; Provides support for editing monkey scripts with full support for
;; font-locking, but no special keybindings, or indentation handling.
;;;; Enabling:
;; Add the following to your .emacs file
;; (require 'monkey)
;; (setq auto-mode-alist (append '(("\\.mon$" . monkey-mode)) auto-mode-alist)))
;;; Code:
(defvar monkey-constants
'("true"
"false"))
(defvar monkey-keywords
'(
"case"
"else"
"fn"
"for"
"foreach"
"function"
"if"
"in"
"let"
"return"
"switch"
))
;; The language-core and functions from the standard-library.
(defvar monkey-functions
'(
"args"
"exit"
"file.close"
"file.lines"
"file.open"
"first"
"int"
"last"
"len"
"math.abs"
"math.random"
"math.sqrt"
"push"
"puts"
"read"
"rest"
"set"
"string"
"string.interpolate"
"string.reverse"
"string.split"
"string.tolower"
"string.toupper"
"string.trim"
"type"
"version"
))
(defvar monkey-font-lock-defaults
`((
("\"\\.\\*\\?" . font-lock-string-face)
(";\\|,\\|=" . font-lock-keyword-face)
( ,(regexp-opt monkey-keywords 'words) . font-lock-builtin-face)
( ,(regexp-opt monkey-constants 'words) . font-lock-constant-face)
( ,(regexp-opt monkey-functions 'words) . font-lock-function-name-face)
)))
(define-derived-mode monkey-mode fundamental-mode "monkey script"
"monkey-mode is a major mode for editing monkey scripts"
(setq font-lock-defaults monkey-font-lock-defaults)
;; Comment handler for single & multi-line modes
(modify-syntax-entry ?\/ ". 124b" monkey-mode-syntax-table)
(modify-syntax-entry ?\* ". 23n" monkey-mode-syntax-table)
;; Comment ender for single-line comments.
(modify-syntax-entry ?\n "> b" monkey-mode-syntax-table)
(modify-syntax-entry ?\r "> b" monkey-mode-syntax-table)
)
(provide 'monkey)