comparison src/elisp/urweb-defs.el @ 350:3a1e36b14105

First sort-of-working run of urweb-mode
author Adam Chlipala <adamc@hcoop.net>
date Sun, 12 Oct 2008 10:04:17 -0400
parents
children d5148178a7be
comparison
equal deleted inserted replaced
349:beb72f8a7218 350:3a1e36b14105
1 ;;; urweb-defs.el --- Various definitions for urweb-mode
2
3 ;; Based on sml-mode:
4 ;; Copyright (C) 1999,2000,2003 Stefan Monnier <monnier@cs.yale.edu>
5 ;;
6 ;; Modified for urweb-mode:
7 ;; Copyright (C) 2008 Adam Chlipala <adamc@hcoop.net>
8 ;;
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2 of the License, or
12 ;; (at your option) any later version.
13 ;;
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18 ;;
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program; if not, write to the Free Software
21 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 ;;; Commentary:
24
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29 (require 'sml-util)
30
31
32 (defgroup urweb ()
33 "Editing Ur/Web code."
34 :group 'languages)
35
36 (defvar urweb-outline-regexp
37 ;; `st' and `si' are to match structure and signature.
38 " \\|s[ti]\\|[ \t]*\\(let[ \t]+\\)?\\(fun\\|and\\)\\>"
39 "Regexp matching a major heading.
40 This actually can't work without extending `outline-minor-mode' with the
41 notion of \"the end of an outline\".")
42
43 ;;;
44 ;;; Internal defines
45 ;;;
46
47 (defmap urweb-mode-map
48 ;; smarter cursor movement
49 '(("\C-c\C-i" . urweb-mode-info))
50 "The keymap used in `urweb-mode'."
51 ;; :inherit urweb-bindings
52 :group 'urweb)
53
54 (defsyntax urweb-mode-syntax-table
55 `((?\* . ,(if urweb-builtin-nested-comments-flag ". 23n" ". 23"))
56 (?\( . "()1")
57 (?\) . ")(4")
58 ("._'" . "_")
59 (",;" . ".")
60 ;; `!' is not really a prefix-char, oh well!
61 ("~#!" . "'")
62 ("%&$+-/:<=>?@`^|" . "."))
63 "The syntax table used in `urweb-mode'.")
64
65
66 (easy-menu-define urweb-mode-menu urweb-mode-map "Menu used in `urweb-mode'."
67 '("URWEB"
68 ["URWEB mode help (brief)" describe-mode t]
69 ["URWEB mode *info*" urweb-mode-info t]
70 ))
71
72 ;; Make's sure they appear in the menu bar when urweb-mode-map is active.
73 ;; On the hook for XEmacs only -- see easy-menu-add in auc-menu.el.
74 ;; (defun urweb-mode-menu-bar ()
75 ;; "Make sure menus appear in the menu bar as well as under mouse 3."
76 ;; (and (eq major-mode 'urweb-mode)
77 ;; (easy-menu-add urweb-mode-menu urweb-mode-map)))
78 ;; (add-hook 'urweb-mode-hook 'urweb-mode-menu-bar)
79
80 ;;
81 ;; regexps
82 ;;
83
84 (defun urweb-syms-re (&rest syms)
85 (concat "\\<" (regexp-opt (flatten syms) t) "\\>"))
86
87 ;;
88
89 (defconst urweb-module-head-syms
90 '("signature" "structure" "functor"))
91
92
93 (defconst urweb-begin-syms
94 '("struct" "sig")
95 "Symbols matching the `end' symbol.")
96
97 (defconst urweb-begin-syms-re
98 (urweb-syms-re urweb-begin-syms)
99 "Symbols matching the `end' symbol.")
100
101 ;; (defconst urweb-user-begin-symbols-re
102 ;; (urweb-syms-re "let" "abstype" "local" "struct" "sig" "in" "with")
103 ;; "Symbols matching (loosely) the `end' symbol.")
104
105 (defconst urweb-sexp-head-symbols-re
106 (urweb-syms-re "struct" "sig" "with"
107 "if" "then" "else" "case" "of" "fn" "fun" "val" "and"
108 "datatype" "type" "open" "include"
109 urweb-module-head-syms
110 "con" "fold" "where" "extern" "constraint" "constraints"
111 "table" "sequence" "class")
112 "Symbols starting an sexp.")
113
114 ;; (defconst urweb-not-arg-start-re
115 ;; (urweb-syms-re "in" "of" "end" "andalso")
116 ;; "Symbols that can't be found at the head of an arg.")
117
118 ;; (defconst urweb-not-arg-re
119 ;; (urweb-syms-re "in" "of" "end" "andalso")
120 ;; "Symbols that should not be confused with an arg.")
121
122 (defconst urweb-=-starter-syms
123 (list* "|" "val" "fun" "and" "datatype" "con" "type" "class"
124 urweb-module-head-syms)
125 "Symbols that can be followed by a `='.")
126 (defconst urweb-=-starter-re
127 (concat "\\S.|\\S.\\|" (urweb-syms-re (cdr urweb-=-starter-syms)))
128 "Symbols that can be followed by a `='.")
129
130 (defconst urweb-indent-rule
131 (urweb-preproc-alist
132 `((,urweb-module-head-syms "d=" 0)
133 ("if" "else" 0)
134 (,urweb-=-starter-syms nil)
135 (("case" "datatype" "if" "then" "else"
136 "open" "sig" "struct" "type" "val"
137 "con" "constraint" "table" "sequence" "class")))))
138
139 (defconst urweb-starters-indent-after
140 (urweb-syms-re "struct" "sig")
141 "Indent after these.")
142
143 (defconst urweb-delegate
144 (urweb-preproc-alist
145 `((("of" "else" "then" "with" "d=") . (not (urweb-bolp)))
146 ("in" . t)))
147 "Words which might delegate indentation to their parent.")
148
149 (defcustom urweb-symbol-indent
150 '(("fn" . -3)
151 ("of" . 1)
152 ("|" . -2)
153 ("," . -2)
154 (";" . -2)
155 ;;("in" . 1)
156 ("d=" . 2))
157 "Special indentation alist for some symbols.
158 An entry like (\"in\" . 1) indicates that a line starting with the
159 symbol `in' should be indented one char further to the right.
160 This is only used in a few specific cases, so it does not work
161 for all symbols and in all lines starting with the given symbol."
162 :group 'urweb
163 :type '(repeat (cons string integer)))
164
165 (defconst urweb-open-paren
166 (urweb-preproc-alist
167 `((,(list* urweb-begin-syms) ,urweb-begin-syms-re "\\<end\\>")))
168 "Symbols that should behave somewhat like opening parens.")
169
170 (defconst urweb-close-paren
171 `(("end" ,urweb-begin-syms-re)
172 ("then" "\\<if\\>")
173 ("else" "\\<if\\>" (urweb-bolp))
174 ("of" "\\<case\\>")
175 ("d=" nil))
176 "Symbols that should behave somewhat like close parens.")
177
178 (defconst urweb-agglomerate-re "\\<else[ \t]+if\\>"
179 "Regexp of compound symbols (pairs of symbols to be considered as one).")
180
181 (defconst urweb-non-nested-of-starter-re
182 (urweb-syms-re "datatype")
183 "Symbols that can introduce an `of' that shouldn't behave like a paren.")
184
185 (defconst urweb-starters-syms
186 (append urweb-module-head-syms
187 '("datatype" "fun"
188 "open" "type" "val" "and"
189 "con" "constraint" "table" "sequence" "class"))
190 "The starters of new expressions.")
191
192 (defconst urweb-exptrail-syms
193 '("if" "then" "else" "case" "of" "fn" "with" "fold"))
194
195 (defconst urweb-pipeheads
196 '("|" "of" "fun" "fn" "and" "datatype")
197 "A `|' corresponds to one of these.")
198
199
200 (provide 'urweb-defs)
201
202 ;;; urweb-defs.el ends here