| 1 |
;;; esml-util.el --- esml-util.el -*- lexical-binding: t; -*- |
| 2 |
;; Copyright (C) 2005 Vesa Karvonen |
| 3 |
;; |
| 4 |
;; MLton is released under a HPND-style license. |
| 5 |
;; See the file MLton-LICENSE for details. |
| 6 |
|
| 7 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 8 |
;; SML metadata |
| 9 |
|
| 10 |
(defconst esml-sml-symbolic-chars "-!%&$#+/:<=>?@~`^|*\\\\" |
| 11 |
"A string of all Standard ML symbolic characters as defined in section |
| 12 |
2.4 of the Definition.") |
| 13 |
|
| 14 |
(defconst esml-sml-alphanumeric-chars |
| 15 |
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'_" |
| 16 |
"A string of all Standard ML alphanumeric characters as defined in |
| 17 |
section 2.4 of the Definition.") |
| 18 |
|
| 19 |
(defconst esml-sml-symbolic-keywords '("#" "*" "->" ":" "::" ":>" "=" "=>" "|") |
| 20 |
"A list of symbolic keywords or reserved words as defined in sections |
| 21 |
2.1 and section 3.1 and including the special symbol * mentioned in 2.4 as |
| 22 |
well as the symbol :: mentioned in section 2.9 of the Definition.") |
| 23 |
|
| 24 |
(defconst esml-sml-alphanumeric-keywords |
| 25 |
'("_" "abstype" "and" "andalso" "as" "case" "datatype" "do" "else" "end" |
| 26 |
"eqtype" "exception" "false" "fn" "fun" "functor" "handle" "if" "in" |
| 27 |
"include" "infix" "infixr" "let" "local" "nil" "nonfix" "of" "op" "open" |
| 28 |
"orelse" "raise" "rec" "ref" "sharing" "sig" "signature" "struct" |
| 29 |
"structure" "then" "true" "type" "val" "where" "while" "with" "withtype") |
| 30 |
"A list of alphanumeric keywords or reserved words as well as |
| 31 |
non-bindable identifiers defined in various sections of the Definition") |
| 32 |
|
| 33 |
(defconst esml-sml-numeric-literal-regexp |
| 34 |
"\\(?:\\(?:0w\\)?[0-9]+\\|0w?x[0-9a-fA-F]+\\)" |
| 35 |
"Regexp matching the syntax of Standard ML numeric literals.") |
| 36 |
|
| 37 |
(defconst esml-sml-modes '(sml-mode sml-lex-mode sml-yacc-mode) |
| 38 |
"List of Emacs modes dealing with SML code.") |
| 39 |
|
| 40 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 41 |
;; Some general purpose Emacs Lisp utility functions |
| 42 |
|
| 43 |
(defun esml-point-preceded-by (regexp) |
| 44 |
"Determines whether point is immediately preceded by the given regexp. |
| 45 |
If the result is non-nil, the regexp match data will contain the |
| 46 |
corresponding match. As with `re-search-backward' the beginning of the |
| 47 |
match is as close to the starting point as possible. The end of the match |
| 48 |
is always the same as the starting point." |
| 49 |
(save-excursion |
| 50 |
(let ((limit (point)) |
| 51 |
(start (re-search-backward regexp 0 t))) |
| 52 |
(when start |
| 53 |
(re-search-forward regexp limit t) |
| 54 |
(= limit (match-end 0)))))) |
| 55 |
|
| 56 |
(defun esml-insert-or-skip-if-looking-at (str) |
| 57 |
"Inserts the specified string unless it already follows the point. The |
| 58 |
point is moved to the end of the string." |
| 59 |
(if (string= str |
| 60 |
(buffer-substring (point) |
| 61 |
(min (+ (point) (length str)) |
| 62 |
(point-max)))) |
| 63 |
(forward-char (length str)) |
| 64 |
(insert str))) |
| 65 |
|
| 66 |
(defun esml-split-string (string separator) |
| 67 |
(cl-remove "" (split-string string separator) :test 'equal)) |
| 68 |
|
| 69 |
(defun esml-string-matches-p (regexp str) |
| 70 |
"Non-nil iff the entire string matches the regexp." |
| 71 |
(and (string-match regexp str) |
| 72 |
(= 0 (match-beginning 0)) |
| 73 |
(= (length str) (match-end 0)))) |
| 74 |
|
| 75 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 76 |
|
| 77 |
(provide 'esml-util) |