-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsamora.el
96 lines (77 loc) · 2.02 KB
/
samora.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
;;; samora.el --- mode for editing samora scripts
;; Copyright (C) 2023 Ismael GraHms
;; Author: Ismael GraHms <[email protected]>
;; Keywords: languages
;; Version: 1.0
;;; Commentary:
;; Provides support for editing samora scripts with full support for
;; font-locking, but no special keybindings, or indentation handling.
;;;; Enabling:
;; Add the following to your .emacs file
;; (require 'samora)
;; (setq auto-mode-alist (append '(("\\.mon$" . samora-mode)) auto-mode-alist)))
;;; Code:
(defvar samora-constants
'("true"
"false"))
(defvar samora-keywords
'(
"else"
"fn"
"for"
"foreach"
"function"
"if"
"in"
"let"
"return"
))
;; The language-core and functions from the standard-library.
(defvar samora-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 samora-font-lock-defaults
`((
("\"\\.\\*\\?" . font-lock-string-face)
(";\\|,\\|=" . font-lock-keyword-face)
( ,(regexp-opt samora-keywords 'words) . font-lock-builtin-face)
( ,(regexp-opt samora-constants 'words) . font-lock-constant-face)
( ,(regexp-opt samora-functions 'words) . font-lock-function-name-face)
)))
(define-derived-mode samora-mode fundamental-mode "samora script"
"samora-mode is a major mode for editing samora scripts"
(setq font-lock-defaults samora-font-lock-defaults)
;; Comment handler for single & multi-line modes
(modify-syntax-entry ?\/ ". 124b" samora-mode-syntax-table)
(modify-syntax-entry ?\* ". 23n" samora-mode-syntax-table)
;; Comment ender for single-line comments.
(modify-syntax-entry ?\n "> b" samora-mode-syntax-table)
(modify-syntax-entry ?\r "> b" samora-mode-syntax-table)
)
(provide 'samora)