-
Notifications
You must be signed in to change notification settings - Fork 1
/
uiua-ts-mode.el
105 lines (88 loc) · 2.57 KB
/
uiua-ts-mode.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
;;; uiua-ts-mode.el --- Uiua treesiter mode -*- lexical-binding:t -*-
;; SPDX-License-Identifier: GPL-3.0-or-later
;; URL: https://github.com/crmsnbleyd/uiua-ts-mode
;; Keywords: languages, uiua
;; Package-Requires: ((emacs "29.1") (uiua-mode "0.0.5"))
;; Version: 0.0.5
;;; Commentary:
;; A major mode for Uiua that uses treesitter for parsing
;;; Code:
(require 'uiua-mode)
(require 'treesit)
(defgroup uiua-ts nil
"Settings for ts-powered Uiua."
:prefix "uiua-ts-"
:prefix "uiua-"
:group 'uiua)
(defvar uiua-ts--indent-rules
`((uiua
((parent-is "program") parent-bol 0)
((query ((array (closeCurly)@curly :?
(closeBracket)@bracket :?)))
parent 0)
((query ((inlineFunction
(closeParen)@paren :?))
parent 0)
((parent-is "inlineFunction") parent 2)
((parent-is "array") parent 2)))))
(defvar uiua-ts--font-lock-rules
(treesit-font-lock-rules
:language 'uiua
:feature 'string
'([(character) (string) (multiLineString)]
@font-lock-string-face)
:language 'uiua
:feature 'number
'((number) @uiua-number)
:language 'uiua
:feature 'monadic-function
'((function _) @uiua-monadic-function)
;; :language 'uiua
;; :feature 'unadorned
;; :override t
;; '((function ["." "∘" "," ":" ";"
;; "duplicate"
;; "flip"
;; "pop"
;; "id" "identity"] @default))
:language 'uiua
:feature 'monadic-modifier
'((modifier1 _) @uiua-monadic-modifier)
:language 'uiua
:feature 'dyadic-modifier
'((modifier2 _) @uiua-dyadic-modifier)
:language 'uiua
:override t
:feature 'noadic
'((constant _) @uiua-noadic-or-constant)
:language 'uiua
:override t
:feature 'comment
'((comment) @font-lock-comment-face)))
(defun uiua-ts--setup ()
"Setup for uiua treesitter mode."
(setq-local treesit-font-lock-settings
uiua-ts--font-lock-rules)
(setq-local treesit-simple-indent-rules
uiua-ts--indent-rules)
(setq-local treesit-font-lock-feature-list
'((comment string)
(number)
(monadic-function
monadic-modifier dyadic-modifier
noadic)))
(treesit-major-mode-setup))
;;;###autoload
(define-derived-mode uiua-ts-mode uiua-base-mode "Uiua"
"Major mode for editing Uiua files.
Uses tree-sitter."
:group 'uiua
(add-to-list
'treesit-language-source-alist
'(uiua . ("https://github.com/shnarazk/tree-sitter-uiua.git")))
(setq-local font-lock-defaults nil) ; to let ts do the hard work
(when (treesit-ready-p 'uiua)
(treesit-parser-create 'uiua)
(uiua-ts--setup)))
(provide 'uiua-ts-mode)
;;; uiua-ts-mode.el ends here