-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrtcg.el
98 lines (74 loc) · 2.72 KB
/
rtcg.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
;;; rtcg.el --- Mode for the rtcg programming language -*- lexical-binding: t -*-
;; URL: /~https://github.com/AndrasKovacs/staged
;; Package-version: 1.0
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
;; Keywords: languages
;;; Commentary:
;; This package provides a major mode for editing proofs or programs
;; in rtcg, an implementation of a minimal dependently typed language
;; with runtime code generation.
(require 'comint)
(require 'cl-lib)
;;;; Customization options
(defgroup rtcg nil "Options for rtcg-mode"
:group 'languages
:prefix 'rtcg-
:tag "rtcg")
;;;; Syntax
(defvar rtcg-keywords
'("let" "do" "open")
"Keywords.")
(defvar rtcg-operations
'("U" "Code" "Ref" "Eff" "read" "write" "new" "return" "ℕ" "Nat" "zero" "suc" "NatElim" "ℕElim" "log" "printℕ"
"printNat" "readℕ" "readNat" )
"Operations.")
(defvar rtcg-special
'("undefined")
"Special operators.")
(defvar rtcg-keywords-regexp
(regexp-opt rtcg-keywords 'words)
"Regexp that recognizes keywords.")
(defvar rtcg-operations-regexp
(regexp-opt rtcg-operations 'words)
"Regexp that recognizes operations.")
(defvar rtcg-operators-regexp
(regexp-opt '(":" "->" "<-" "→" "←" "=" ":=" "=" "\\" "λ" "_" "." "<" ">" "~" "□" ";") t)
"Regexp that recognizes operators.")
(defvar rtcg-special-regexp
(regexp-opt rtcg-special 'words)
"Regexp that recognizes special operators.")
(defvar rtcg-def-regexp "^[[:word:]'-]+"
"Regexp that recognizes the beginning of a definition.")
(defvar rtcg-font-lock-keywords
`((,rtcg-keywords-regexp . font-lock-keyword-face)
(,rtcg-operations-regexp . font-lock-builtin-face)
(,rtcg-operators-regexp . font-lock-variable-name-face)
(,rtcg-special-regexp . font-lock-warning-face)
(,rtcg-def-regexp . font-lock-function-name-face))
"Font-lock information, assigning each class of keyword a face.")
(defvar rtcg-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?\{ "(}1nb" st)
(modify-syntax-entry ?\} "){4nb" st)
(modify-syntax-entry ?- "_ 123" st)
(modify-syntax-entry ?\n ">" st)
(modify-syntax-entry ?\\ "." st)
st)
"Syntax table with Haskell-style comments.")
;;;###autoload
(define-derived-mode rtcg-mode prog-mode
"rtcg"
"Major mode for editing rtcg files."
:syntax-table rtcg-syntax-table
;; Make comment-dwim do the right thing
(set (make-local-variable 'comment-start) "--")
(set (make-local-variable 'comment-end) "")
;; Code for syntax highlighting
(setq font-lock-defaults '(rtcg-font-lock-keywords))
;; Clear memory
(setq rtcg-keywords-regexp nil)
(setq rtcg-operators-regexp nil)
(setq rtcg-special-regexp nil))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.rtcg\\'" . rtcg-mode))
(provide 'rtcg)