-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwybe-font-lock.el
122 lines (89 loc) · 3.34 KB
/
wybe-font-lock.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
;;; wybe-mode --- Major mode for the wybe programming language
;; Copyright 2016 Ashutosh Rishi Ranjan
;; Author: Ashutosh Rishi Ranjan ([email protected])
;; Version: 1.0.0
;; Created: 20 Feb 2015
;; Keywords: languages
;;; Commentary:
;; Font locks for the Wybe Major mode to for writing Wybe modules.
;;; Code:
(require 'rx)
(require 'font-lock)
;; Faces for font-locking
(defgroup wybe-font-lock nil
"Font locking for Wybe code."
:group 'faces)
(defface wybe-font-lock-operators-face
'((((background light)) (:foreground "brown"))
(t (:foreground "khaki")))
"The default face used to highlight operators."
:group 'wybe-font-lock)
(defvar wybe-font-lock-operators-face
'wybe-font-lock-operators-face)
;; Font locking for various syntactical features of Wybe
;; Keywords
(defconst wybe--modifiers
'("public" "private")
"Special modifier keywords which act like syntactic labels.")
(defconst wybe--keywords
'("if" "then" "else" "proc" "end" "use"
"do" "until" "unless" "or" "test" "import" "while")
"Keywords of the Wybe language.")
(defconst wybe--keywords-regexp
(concat (regexp-opt wybe--keywords 'words) "[^']")
"The regular expression matching Wybe keywords.")
(defconst wybe--modifiers-regexp
(regexp-opt wybe--modifiers 'words)
"The regular expression matching Wybe modifiers.")
;; Primitive Types and user defined types
(defconst wybe--prim-types
'("int" "float" "string" "char" "bool")
"Wybe primitive types.")
(defconst wybe--prim-types-regexp
(regexp-opt wybe--prim-types 'words)
"The regular expression matching certain primitive Wybe types.")
(defconst wybe--custom-types-regexp
(rx (char ?:) (0+ space)
(group (1+ (any alnum))))
"Regex for custom type annotations.")
;; Constants
(defconst wybe--constant-regexp
(rx symbol-start (1+ digit) (opt ?.) (0+ digit) symbol-end)
"Regex for Wybe constants.")
;; Functions and Procedure names
(defconst wybe--func-regexp
(rx (group symbol-start (or "proc" "func" "type") (1+ space))
(group (1+ (any alnum ?+ ?- ?*)))
(any space ?\())
"The regular expression for matching function and proc names.")
;; Operators
(defconst wybe--operators-regexp
"[-@^!:*=<>&/%+~?#]"
"The regular expression for matching Wybe in-built operators.")
;; Syntax Table
(defvar wybe--syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?# "< b" st)
(modify-syntax-entry ?\n "> b" st)
st)
"Syntax table of the Wybe mode.")
;; Final Highlighting
(defvar wybe-font-lock-keywords
`(("\\<\\(false\\|true\\)\\>" . font-lock-constant-face)
(,wybe--modifiers-regexp . wybe-font-lock-operators-face)
(,wybe--func-regexp (1 font-lock-keyword-face)
(2 font-lock-function-name-face))
(,wybe--keywords-regexp . font-lock-keyword-face)
(,wybe--prim-types-regexp . font-lock-type-face)
(,wybe--custom-types-regexp 1 font-lock-type-face keep)
(,wybe--operators-regexp . wybe-font-lock-operators-face)
(,wybe--constant-regexp . font-lock-constant-face)
)
"Combined highlighting for various syntactical features of Wybe.")
(defun turn-on-wybe-font-lock ()
"Turn on Wybe-mode font lock."
(set-syntax-table wybe--syntax-table)
(setq-local font-lock-defaults '(wybe-font-lock-keywords
nil nil nil nil)))
(provide 'wybe-font-lock)
;;; wybe-font-lock.el ends here