3 * Description: Standard ML programming language
.
4 * Author: Matthew Fluet <mfluet@acm
.org>
9 comment_face
--- comments
10 function_name_face
--- modules keywords
12 keyword_face
--- core keywords
13 reference_face
--- special constants
(nums
)
14 string_face
--- strings
15 type_face
--- type bindings
16 variable_name_face
--- constructor bindings
19 require_state
(sml_verbose
);
25 sml_typctxt_expected_eqs
= -1;
26 SML_DATBIND_UNKNOWN = 1;
41 SML_AND_WHERETYPE = 8;
42 sml_andbind
= list
(SML_AND_NUL);
45 SML_MODULES_LEVEL = 1;
47 sml_endmatch
= list
(SML_MODULES_LEVEL);
49 sml_last_keyword
= "";
50 sub sml_keyword
(s, lvl
) {
52 if
(lvl
== SML_CORE_LEVEL)
54 else if
(lvl
= SML_MODULES_LEVEL)
55 function_name_face
(true);
57 if
(lvl
== SML_CORE_LEVEL)
59 else if
(lvl
= SML_MODULES_LEVEL)
60 function_name_face
(false);
63 sml_scopes
= list
(list
("",
SML_MODULES_LEVEL));
65 sub sml_enter_scope
(s, lvl
) {
66 sml_andbind
= list
(SML_AND_NUL, sml_andbind
);
67 sml_endmatch
= list
(-1, sml_endmatch
);
68 sml_scopes
= list
(list
(s,lvl
), sml_scopes
);
72 sub sml_leave_scope
() {
74 sml_scopes
= sml_scopes
[1];
75 sml_endmatch
= sml_endmatch
[1];
76 sml_andbind
= sml_andbind
[1];
79 sub sml_let_level
() {
80 local scopes
= sml_scopes
;
81 if
(sml_andbind
[0] == SML_AND_STRBIND ||
82 sml_andbind
[0] == SML_AND_FUNBIND) {
85 if
((strcmp
(scopes
[0][0],
"let") == 0 ||
86 strcmp
(scopes
[0][0],
"(") == 0) &&
87 scopes
[0][1] == SML_MODULES_LEVEL)
91 sub sml_local_level
() {
92 local scopes
= sml_scopes
;
94 if
((strcmp
(scopes
[0][0],
"let") == 0 ||
95 strcmp
(scopes
[0][0],
"(") == 0) &&
96 scopes
[0][1] == SML_MODULES_LEVEL)
98 while
(length
(scopes
) == 2) {
99 if
(strcmp
(scopes
[0][0],
"local") == 0 &&
100 scopes
[0][1] == SML_MODULES_LEVEL)
102 else if
(strcmp
(scopes
[0][0],
"let") == 0 &&
103 scopes
[0][1] == SML_MODULES_LEVEL)
111 sub sml_start_typctxt
(eqs
) {
113 sml_typctxt
= sml_scope
;
114 sml_typctxt_expected_eqs
= eqs
;
117 sub sml_start_typbind
() {
118 sml_start_typctxt
(1);
123 sub sml_start_eqtyp
() {
124 sml_start_typctxt
(0);
129 sub sml_start_wheretyp
() {
130 sml_start_typctxt
(1);
135 sub sml_start_sharingtyp
() {
136 sml_start_typctxt
(-1);
141 sub sml_start_datbind
() {
142 sml_start_typctxt
(1);
143 sml_datbind
= SML_DATBIND_UNKNOWN;
147 sub sml_start_exbind
() {
148 sml_start_typctxt
(1);
153 sub sml_finish_typctxt
() {
154 if
(sml_typctxt
== sml_scope
) {
156 sml_typctxt_expected_eqs
= -1;
157 if
(sml_datbind
) {sml_datbind
= FALSE; sml_conbind
= FALSE;}
158 if
(sml_exbind
) {sml_exbind
= FALSE; sml_conbind
= FALSE;}
164 state sml_fancy extends sml_verbose
167 sml_finish_typctxt
();
177 sml_enter_scope
($0,sml_scopes
[0][1]);
181 sml_finish_typctxt
();
186 sml_finish_typctxt
();
187 sml_andbind
[0] = SML_AND_NUL;
191 if
(sml_datbind
== SML_DATBIND_DECL) {
201 if
(sml_typctxt
!= -1) {
205 if
(sml_typctxt_expected_eqs
== 0) {
206 sml_finish_typctxt
();
208 sml_typctxt_expected_eqs
--;
209 if
(sml_datbind
== SML_DATBIND_UNKNOWN) {
224 sml_finish_typctxt
();
225 sml_enter_scope
($0,
SML_CORE_LEVEL);
226 sml_keyword
($0,
SML_CORE_LEVEL);
227 sml_andbind
[0] = SML_AND_DATBIND;
228 sml_endmatch
[0] = SML_CORE_LEVEL;
229 sml_start_datbind
();
232 sml_finish_typctxt
();
233 if
(sml_andbind
[0] == SML_AND_VALBIND) {
234 sml_keyword
($0,
SML_CORE_LEVEL);
235 } else if
(sml_andbind
[0] == SML_AND_TYPBIND) {
236 sml_keyword
($0,
SML_CORE_LEVEL);
237 sml_start_typbind
();
238 } else if
(sml_andbind
[0] == SML_AND_DATBIND) {
239 sml_keyword
($0,
SML_CORE_LEVEL);
240 sml_start_datbind
();
241 } else if
(sml_andbind
[0] == SML_AND_EXBIND) {
242 sml_keyword
($0,
SML_CORE_LEVEL);
244 } else if
(sml_andbind
[0] == SML_AND_STRBIND) {
245 sml_keyword
($0,
SML_MODULES_LEVEL);
246 } else if
(sml_andbind
[0] == SML_AND_SIGBIND) {
247 sml_keyword
($0,
SML_MODULES_LEVEL);
248 } else if
(sml_andbind
[0] == SML_AND_FUNBIND) {
249 sml_keyword
($0,
SML_MODULES_LEVEL);
250 } else if
(sml_andbind
[0] == SML_AND_WHERETYPE) {
251 sml_keyword
($0,
SML_MODULES_LEVEL);
252 sml_last_keyword
= "where";
257 sml_keyword
($0,
SML_CORE_LEVEL);
260 sml_keyword
($0,
SML_CORE_LEVEL);
263 sml_keyword
($0,
SML_CORE_LEVEL);
266 if
(sml_datbind
== SML_DATBIND_UNKNOWN) {
267 sml_datbind
= SML_DATBIND_REPL;
269 sml_keyword
($0,
SML_CORE_LEVEL);
271 sml_finish_typctxt
();
272 sml_keyword
($0,
SML_CORE_LEVEL);
273 sml_andbind
[0] = SML_AND_DATBIND;
274 sml_start_datbind
();
278 sml_keyword
($0,
SML_CORE_LEVEL);
281 sml_keyword
($0,
SML_CORE_LEVEL);
284 sml_finish_typctxt
();
285 sml_keyword
($0, sml_endmatch
[0]);
289 sml_finish_typctxt
();
290 sml_keyword
($0,
SML_CORE_LEVEL);
294 sml_finish_typctxt
();
295 sml_keyword
($0,
SML_CORE_LEVEL);
296 sml_andbind
[0] = SML_AND_EXBIND;
300 sml_keyword
($0,
SML_CORE_LEVEL);
302 sml_fun_with_tyvar_re
{
303 sml_finish_typctxt
();
304 sml_keyword
($1,
SML_CORE_LEVEL);
309 sml_andbind
[0] = SML_AND_VALBIND;
311 sml_fun_with_tyvarseq_re
{
312 sml_finish_typctxt
();
313 sml_keyword
($1,
SML_CORE_LEVEL);
321 sml_andbind
[0] = SML_AND_VALBIND;
324 sml_finish_typctxt
();
325 sml_keyword
($0,
SML_CORE_LEVEL);
326 sml_andbind
[0] = SML_AND_VALBIND;
329 sml_finish_typctxt
();
330 sml_keyword
($0,
SML_MODULES_LEVEL);
331 sml_andbind
[0] = SML_AND_FUNBIND;
334 sml_keyword
($0,
SML_CORE_LEVEL);
337 sml_keyword
($0,
SML_CORE_LEVEL);
340 sml_finish_typctxt
();
341 sml_andbind
[0] = SML_AND_NUL;
342 sml_keyword
($0, sml_endmatch
[0]);
345 sml_finish_typctxt
();
346 sml_keyword
($0,
SML_MODULES_LEVEL);
349 sml_finish_typctxt
();
350 sml_keyword
($1,
SML_CORE_LEVEL);
355 sml_finish_typctxt
();
356 if
(sml_let_level
()) {
357 sml_enter_scope
($0,
SML_MODULES_LEVEL);
358 sml_keyword
($0,
SML_MODULES_LEVEL);
359 sml_endmatch
[0] = SML_MODULES_LEVEL;
361 sml_enter_scope
($0,
SML_CORE_LEVEL);
362 sml_keyword
($0,
SML_CORE_LEVEL);
363 sml_endmatch
[0] = SML_CORE_LEVEL;
367 sml_finish_typctxt
();
368 if
(sml_local_level
()) {
369 sml_enter_scope
($0,
SML_MODULES_LEVEL);
370 sml_keyword
($0,
SML_MODULES_LEVEL);
371 sml_endmatch
[0] = SML_MODULES_LEVEL;
373 sml_enter_scope
($0,
SML_CORE_LEVEL);
374 sml_keyword
($0,
SML_CORE_LEVEL);
375 sml_endmatch
[0] = SML_CORE_LEVEL;
379 sml_finish_typctxt
();
380 sml_keyword
($0,
SML_CORE_LEVEL);
383 sml_keyword
($0,
SML_CORE_LEVEL);
386 sml_keyword
($0,
SML_CORE_LEVEL);
389 sml_finish_typctxt
();
390 sml_keyword
($0,
SML_MODULES_LEVEL);
393 sml_keyword
($0,
SML_CORE_LEVEL);
396 sml_keyword
($0,
SML_CORE_LEVEL);
399 sml_keyword
($0,
SML_CORE_LEVEL);
402 sml_finish_typctxt
();
403 sml_keyword
($0,
SML_MODULES_LEVEL);
406 sml_enter_scope
($0,
SML_CORE_LEVEL);
407 sml_keyword
($0,
SML_MODULES_LEVEL);
408 sml_endmatch
[0] = SML_MODULES_LEVEL;
411 sml_finish_typctxt
();
412 sml_keyword
($0,
SML_MODULES_LEVEL);
413 sml_andbind
[0] = SML_AND_SIGBIND;
416 sml_enter_scope
($0,
SML_CORE_LEVEL);
417 sml_keyword
($0,
SML_MODULES_LEVEL);
418 sml_endmatch
[0] = SML_MODULES_LEVEL;
421 sml_finish_typctxt
();
422 sml_keyword
($0,
SML_MODULES_LEVEL);
423 sml_andbind
[0] = SML_AND_STRBIND;
426 sml_keyword
($0,
SML_CORE_LEVEL);
429 if
(strcmp
(sml_last_keyword,
"where") == 0) {
430 sml_keyword
($0,
SML_MODULES_LEVEL);
431 sml_last_keyword
= "where type";
432 sml_andbind
[0] = SML_AND_WHERETYPE;
433 sml_start_wheretyp
();
434 } else if
(strcmp
(sml_last_keyword,
"sharing") == 0) {
435 sml_keyword
($0,
SML_MODULES_LEVEL);
436 sml_last_keyword
= "sharing type";
437 sml_andbind
[0] = SML_AND_NUL;
438 sml_start_sharingtyp
();
440 sml_finish_typctxt
();
441 sml_keyword
($0,
SML_CORE_LEVEL);
442 sml_andbind
[0] = SML_AND_TYPBIND;
443 sml_start_typbind
();
446 sml_val_with_tyvar_re
{
447 sml_finish_typctxt
();
448 sml_keyword
($1,
SML_CORE_LEVEL);
453 sml_andbind
[0] = SML_AND_VALBIND;
455 sml_val_with_tyvarseq_re
{
456 sml_finish_typctxt
();
457 sml_keyword
($1,
SML_CORE_LEVEL);
465 sml_andbind
[0] = SML_AND_VALBIND;
468 sml_finish_typctxt
();
469 sml_keyword
($0,
SML_CORE_LEVEL);
470 sml_andbind
[0] = SML_AND_VALBIND;
473 sml_finish_typctxt
();
474 sml_keyword
($0,
SML_MODULES_LEVEL);
477 sml_keyword
($0,
SML_CORE_LEVEL);
480 sml_finish_typctxt
();
481 sml_keyword
($0,
SML_CORE_LEVEL);
484 sml_finish_typctxt
();
485 sml_keyword
($0,
SML_CORE_LEVEL);
486 sml_andbind
[0] = SML_AND_TYPBIND;
487 sml_start_typbind
();
492 variable_name_face
(true);
494 variable_name_face
(false);
501 if
(sml_datbind
== SML_DATBIND_UNKNOWN)
502 sml_datbind
= SML_DATBIND_DECL;
504 variable_name_face
(true);
506 variable_name_face
(false);
517 state sml_tyvarseq extends
Highlight