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