-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunison-ts-font-lock.el
128 lines (107 loc) · 4.48 KB
/
unison-ts-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
123
124
125
126
127
128
;;; unison-ts-font-lock.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 Filipe Guerreiro
;;
;; Author: Filipe Guerreiro <[email protected]>
;; Maintainer: Filipe Guerreiro <[email protected]>
;; Created: November 11, 2023
;; Modified: November 11, 2023
;; Version: 0.0.1
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
;; Homepage: https://github.com/fmguerreiro/font-lock
;; Package-Requires: ((emacs "24.3"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; Description
;;
;;; Code:
(require 'treesit)
(declare-function treesit-query-compile "treesit.c")
(declare-function treesit-query-validate "treesit.c")
;; @ref https://www.unison-lang.org/learn/language-reference/identifiers/#reserved-words
(defvar unison-ts-font-lock--keywords
'("use" "!" "structural" "unique" "if" "then" "else"
(ability) (namespace) (cases) (where) (do) (handle)
(kw_let) (match) (with) (kw_typelink) (kw_termlink)
(kw_forall) (type_kw)))
(defvar unison-ts-font-lock--constants
'((nat) (int) (float) (literal_boolean) (literal_byte)
(literal_hex) (hash_qualifier)))
(defvar unison-ts-font-lock-operators
'((or) (and) (pipe) (operator) (kw_equals)
(type_signature_colon) (arrow_symbol)))
(defvar unison-ts-font-lock)
;; possible faces
;; @ref: https://www.gnu.org/software/emacs/manual/html_node/elisp/Faces-for-Font-Lock.html
;; syntax
;; @ref: https://www.gnu.org/software/emacs/manual/html_node/elisp/Pattern-Matching.html
(setq unison-ts-font-lock
`(:feature error
:override t
:language unison
((ERROR) @font-lock-warning-face)
:feature comment
:override t
:language unison
((comment) @font-lock-comment-face)
:feature doc
:override t
:language unison
((doc_block) @font-lock-doc-face)
:feature declaration
:override t
:language unison
([(constructor :anchor (wordy_id) @font-lock-function-name-face)
;; declarations with no args are highlighted as variable declarations
(term_definition :anchor (path) :? (wordy_id) @font-lock-variable-name-face :anchor (kw_equals))
;; by default, declarations are highlighted as function declarations
(term_definition :anchor (path) :? (wordy_id) @font-lock-function-name-face)
(type_signature (wordy_id) @font-lock-function-name-face)])
:feature keyword
:language unison
([,@unison-ts-font-lock--keywords] @font-lock-keyword-face)
:feature constant
:override t
:language unison
([,@unison-ts-font-lock--constants] @font-lock-constant-face)
:feature variable
:language unison
([((path) @font-lock-type-face :*)
((wordy_id) @font-lock-variable-use-face)
((type_argument) @font-lock-variable-use-face)
(type_name (wordy_id) @font-lock-variable-name-face)])
:feature preprocessor
:language unison
((watch_expression) @font-lock-preprocessor-face)
:feature type
:override t
:language unison
([((namespace) @font-lock-type-face)
((wordy_id) @font-lock-type-face (:match "^[A-Z][a-zA-Z_\\d]+" @font-lock-type-face))])
:feature function-call
:override t
:language unison
([;; TODO arguments should be highlighted as variables as much as possible, but slow down the font-lock too much
;; ((wordy_id) @font-lock-variable-use-face :anchor (operator))
;; ((operator) :anchor (wordy_id) @font-lock-variable-use-face)
;; function name should be highlighted as a function
(function_application :anchor (path) :? (wordy_id) @font-lock-function-call-face)])
:feature bracket
:language unison
([(tuple_or_parenthesized) (literal_list) (effect)] @font-lock-bracket-face)
:feature operator
:language unison
([,@unison-ts-font-lock-operators] @font-lock-operator-face)
:feature delimiter
:override t
:language unison
([","] @font-lock-delimiter-face)
:feature string
:override t
:language unison
([(literal_char) (literal_text)] @font-lock-string-face)))
(provide 'unison-ts-font-lock)
;;; unison-ts-font-lock.el ends here