forked from museoa/bqn-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bqn-syntax.el
98 lines (82 loc) · 3.6 KB
/
bqn-syntax.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
;;; -*- lexical-binding: t -*-
(require 'cl-lib)
(require 'bqn-symbols)
(defface bqn-block-face
'((t (:inherit font-lock-function-name-face)))
"Face used for BQN curly braces."
:group 'bqn)
(defface bqn-paren-face
'((t (:inherit default)))
"Face used for BQN parentheses."
:group 'bqn)
(defface bqn-header-face
'((t (:inherit default)))
"Face used for BQN header delimiters : and ; ."
:group 'bqn)
(defface bqn-list-face
'((t (:inherit font-lock-builtin-face)))
"Face used for BQN list characters: angle brackets and ligature."
:group 'bqn)
(defface bqn-separator-face
'((t (:inherit font-lock-builtin-face)))
"Face used for BQN expression separators."
:group 'bqn)
(defface bqn-arrow-face
'((t (:inherit 'default)))
"Face used for BQN assignment and return arrows."
:group 'bqn)
(defface bqn-function-face
'((t (:inherit font-lock-type-face)))
"Face used for BQN functions."
:group 'bqn)
(defface bqn-one-modifier-face
'((t (:inherit font-lock-preprocessor-face)))
"Face used for BQN 1-modifiers."
:group 'bqn)
(defface bqn-two-modifier-face
'((t (:inherit font-lock-keyword-face)))
"Face used for BQN 2-modifiers."
:group 'bqn)
(defface bqn-subject-face
'((t (:inherit font-lock-variable-name-face)))
"Face used for BQN subjects."
:group 'bqn)
(defface bqn-nothing-face
'((t (:inherit font-lock-constant-face)))
"Face used for BQN Nothing (·)."
:group 'bqn)
(defface bqn-number-face
'((t (:inherit font-lock-constant-face)))
"Face used for BQN numeric literals."
:group 'bqn)
(defvar bqn--token-syntax-types '((("'.'\\|@" . font-lock-string-face)
("[{}]" . 'bqn-block-face)
("[()]" . 'bqn-paren-face)
("[:;?]" . 'bqn-header-face)
("[⟨⟩‿]" . 'bqn-list-face)
("[⋄,]" . 'bqn-separator-face)
("[←⇐↩→]" . 'bqn-arrow-face)
("[𝔽𝔾𝕎𝕏𝕊+×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!⍕⍎-]\\|•?\\_<[A-Z][A-Z_a-z0-9π∞¯]*\\_>" . 'bqn-function-face)
("[˙˜˘¨⌜⁼´˝`]\\|•?\\_<_[A-Za-z][A-Z_a-z0-9π∞¯]*\\|_𝕣\\_>" . 'bqn-one-modifier-face)
("[∘○⊸⟜⌾⊘◶⎉⚇⍟⎊]\\|_𝕣_\\|•?\\_<_[A-Za-z][A-Z_a-z0-9π∞¯]*_\\_>" . 'bqn-two-modifier-face)
("[𝕗𝕘𝕨𝕩𝕤𝕣]\\|•\\|•?\\_<[a-z][A-Z_a-z0-9π∞¯]*\\_>" . 'bqn-subject-face)
("·" . 'bqn-nothing-face)
("\\_<¯?\\(\\([0-9]+\\.\\)?[0-9]+\\(e¯?[0-9]+\\)?\\|π\\|∞\\)\\(i¯?\\(\\([0-9]+\\.\\)?[0-9]+\\(e¯?[0-9]+\\)?\\|π\\|∞\\)\\)?\\_>" . 'bqn-number-face)
("[^ \r\n]" . 'error))
nil nil nil))
(defvar bqn--syntax-table
(let ((table (make-syntax-table)))
(cl-loop for s in bqn--symbols
do (modify-syntax-entry (aref (cl-second s) 0) "." table))
(cl-loop for s in (append "$%&*+-/<=>|" nil)
do (modify-syntax-entry s "." table))
(modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?\n ">" table)
(modify-syntax-entry ?⟨ "(⟩" table)
(modify-syntax-entry ?⟩ ")⟨" table)
(modify-syntax-entry ?¯ "_" table)
(modify-syntax-entry ?π "_" table)
(modify-syntax-entry ?∞ "_" table)
table)
"Syntax table for ‘bqn-mode’.")
(provide 'bqn-syntax)