summaryrefslogtreecommitdiffstats
path: root/george-mode.el
blob: 4c929dedc0c2437912fc72cef782ae4b59640484 (plain) (blame)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
;;; george-mode.el --- George mode  -*- lexical-binding: t; -*-

;; Copyright (C) 2019 Amin Bandali

;; Author: Amin Bandali <bandali@gnu.org>
;; Keywords: languages, george
;; URL: https://git.sr.ht/~bandali/george-mode
;; Version: 0.1.0

;; This file is not part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; This is an Emacs major mode for editing George files.

;;; Code:

(defvar george-mode-map
   (let ((map (make-sparse-keymap)))
     map)
   "Keymap for `george-mode'.")

(defvar george-mode-directives
  (let ((methods (regexp-opt
                  '("NONE" "PROP" "PRED" "TP" "ND" "ST" "Z" "PC")
                  'words)))
    (format "#\\(\\(u\\|a\\|q\\).*\\|check\\s-*%s\\)" methods))
  "Regexp matching George's directives.")

(defvar george-mode-symbols
  '(";" ":" "," "." "!" "="
    ":=" "==" "!="
    "+" "-" "*" "/"
    "^"
    ">" "<" ">=" "<="
    "{" "}" "[" "]"
    "&" "|"
    "=>" "<=>" "<==>"
    "|-"
    "||"
    "<|" "<-|" "|>" "|->"
    "(+)" "(|" "|)"
    "'" "~"
    "::="
    "<->" "-->" ">-->" "-->>" ">-->>"
    "-|->" ">-|->" "-|->>" ">-|->>"))

(defvar george-mode-keywords
  '(;; === PROP ===
    ;; "false" "true" ; will be constants

    ;; === PRED ===
    "forall" "exists"

    ;; === TP ===
    "by"
    ;; prop rules
    "comm"   "assoc"      "contr"  "lem"
    "impl"   "contrapos"  "simp1"  "simp2"
    "distr"  "dm"         "neg"    "equiv"
    "idemp"
    ;; pred rules
    "forall_over_and" "exists_over_or" "swap_vars" "move_exists"
    "move_forall" ;; "dm" ; (same name as for prop logic)

    ;; === ND ===
    "premise"
    "and_i"        "and_e"
    "or_i"         "or_e"
    ;; "lem" ; same name as for TP
                   "imp_e"
                   "not_e"
    "not_not_i"    "not_not_e"
    "iff_i"        "iff_e"
    "trans"        "iff_mp"
    "exists_i"
                   "forall_e"
    ;; "true" ; will be a constant
    "eq_i"         "eq_e"

    "disprove"     "raa"
    "case"         "cases"
    "assume"       "imp_i"
    "for" "every"  "forall_i"
          "some"   "exists_e"
    "magic"

    ;; === ST ===
    "closed"
    "on"
    "and_nb"     "not_and_br"
    "or_br"      "not_or_nb"
    "imp_br"     "not_imp_br"
                 "not_not_nb"
    "iff_br"     "not_iff_br"
    "forall_nb"  "not_forall_nb"
    "exists_nb"  "not_exists_nb"

    ;; === arith ===
    "arith"
    "induction"

    ;; === sets ===
    "empty" "univ"
    "in" "sub" "sube"
    "pow"
    "union" "inter"
    "card"
    "gen_U" "gen_I"
    "dom" "ran"
    "id"
    "iter"

    ;; === Z ===
    "schema" "begin"
    "pred" "end"
    "seq"

    ;; === PC ===
    "proc" "fun"
    "if" "then" "else"
    "while" "for" "until" "do"
    "assert"))

(defvar george-mode-constants
  '("false"
    "true"))

(defconst george-mode-syntax-table
  (let ((st (make-syntax-table)))
    ;; % is a comment starter
    (modify-syntax-entry ?% "<" st)
    ;; \n is a comment ender
    (modify-syntax-entry ?\n ">" st)

    ;; return our modified syntax table
    st))

(defvar george-mode-font-lock-defaults
  `((("\"\\.\\*\\?" . font-lock-string-face)
     (,george-mode-directives                    . font-lock-builtin-face)
     (,(regexp-opt george-mode-symbols 'symbols) . font-lock-keyword-face)
     (,(regexp-opt george-mode-keywords 'words)  . font-lock-keyword-face)
     (,(regexp-opt george-mode-constants 'words) . font-lock-constant-face))))

;;;###autoload
(define-derived-mode george-mode prog-mode "George"
  "Major mode for editing George files."
  :syntax-table george-mode-syntax-table

  (setq-local font-lock-defaults george-mode-font-lock-defaults)
  (setq-local comment-start "%")
  (setq-local comment-end "")
  (font-lock-ensure))

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.grg\\'" . george-mode))

(provide 'george-mode)
;;; george-mode.el ends here