diff --git a/haskell-align-imports.el b/haskell-align-imports.el index 2fbf51565..8d886ce69 100644 --- a/haskell-align-imports.el +++ b/haskell-align-imports.el @@ -101,8 +101,8 @@ (concat "^\\(import[ ]+\\)" "\\(qualified \\)?" "[ ]*\\(\"[^\"]*\" \\)?" - "[ ]*\\([A-Za-z0-9_.']+\\)" - "[ ]*\\([ ]*as [A-Z][^ ]*\\)?" + "[ ]*\\([[:alnum:]_.']+\\)" + "[ ]*\\([ ]*as [:upper:][^ ]*\\)?" "[ ]*\\((.*)\\)?" "\\([ ]*hiding (.*)\\)?" "\\( -- .*\\)?[ ]*$") diff --git a/haskell-commands.el b/haskell-commands.el index 40c6ea9a2..cf41a53b1 100644 --- a/haskell-commands.el +++ b/haskell-commands.el @@ -282,7 +282,7 @@ If PROMPT-VALUE is non-nil, request identifier via mini-buffer." (let ((at-point (haskell-ident-at-point))) (when (or prompt-value at-point) (let* ((ident (replace-regexp-in-string - "^!\\([A-Z_a-z]\\)" + "^!\\([[:alpha:]_]\\)" "\\1" (if prompt-value (read-from-minibuffer "Info: " at-point) @@ -294,7 +294,7 @@ If PROMPT-VALUE is non-nil, request identifier via mini-buffer." (format ":browse! %s" modname)) ((string= ident "") ; For the minibuffer input case nil) - (t (format (if (string-match "^[a-zA-Z_]" ident) + (t (format (if (string-match "^[[:alpha:]_]" ident) ":info %s" ":info (%s)") (or ident @@ -377,7 +377,7 @@ possible, using GHCi's :type." (let ((ident (haskell-ident-at-point))) (when ident (let ((process (haskell-interactive-process)) - (query (format (if (string-match "^[_[:lower:][:upper:]]" ident) + (query (format (if (string-match "^[[:alpha:]_]" ident) ":type %s" ":type (%s)") ident))) @@ -414,7 +414,7 @@ Returns: (when (stringp ident) (let ((reply (haskell-process-queue-sync-request (haskell-interactive-process) - (format (if (string-match "^[a-zA-Z_]" ident) + (format (if (string-match "^[[:alpha:]_]" ident) ":info %s" ":info (%s)") ident)))) @@ -589,7 +589,7 @@ command from GHCi." :go (lambda (state) (haskell-process-send-string (car state) - (if (string-match "^[A-Za-z_]" (cdr state)) + (if (string-match "^[[:alpha:]_]" (cdr state)) (format ":info %s" (cdr state)) (format ":info (%s)" (cdr state))))) :complete (lambda (state response) @@ -607,7 +607,7 @@ command from GHCi." :go (lambda (state) (haskell-process-send-string (car state) - (if (string-match "^[A-Za-z_]" (cdr state)) + (if (string-match "^[[:alpha:]_]" (cdr state)) (format ":type %s" (cdr state)) (format ":type (%s)" (cdr state))))) :complete (lambda (state response) diff --git a/haskell-complete-module.el b/haskell-complete-module.el index ff157a7cf..d088f0278 100644 --- a/haskell-complete-module.el +++ b/haskell-complete-module.el @@ -90,7 +90,7 @@ (append (cdr candidates) (list (car candidates))))) (t - (when (string-match "[A-Za-z0-9_'.]+" key) + (when (string-match "[[:alnum:]_'.]+" key) (push candidates stack) (setq pattern (concat pattern key)) (setq candidates (haskell-complete-module pattern candidates))))))) diff --git a/haskell-debug.el b/haskell-debug.el index aa017c9e4..635ee2426 100644 --- a/haskell-debug.el +++ b/haskell-debug.el @@ -693,7 +693,7 @@ variances in source span notation." (defun haskell-debug-parse-history-entry (string) "Parse a history entry." - (if (string-match "^\\([-0-9]+\\)[ ]+:[ ]+\\([A-Za-z0-9_':]+\\)[ ]+(\\([^:]+\\):\\(.+?\\))$" + (if (string-match "^\\([-0-9]+\\)[ ]+:[ ]+\\([[:alnum:]_':]+\\)[ ]+(\\([^:]+\\):\\(.+?\\))$" string) (list :index (string-to-number (match-string 1 string)) :name (match-string 2 string) diff --git a/haskell-lexeme.el b/haskell-lexeme.el new file mode 100644 index 000000000..5904ded73 --- /dev/null +++ b/haskell-lexeme.el @@ -0,0 +1,115 @@ + + +(eval-when-compile + (require 'rx)) + + +(defconst haskell-lexeme-varid + "[[:lower:]_][[:alnum:]'_]*") + +(defconst haskell-lexeme-conid + "[[:upper:]][[:alnum:]'_]*") + +(defconst haskell-lexeme-varid-or-conid + "[[:alpha:]_][[:alnum:]'_]*") + +(defconst haskell-lexeme-reservedid + (rx (| "case" + "class" + "data" + "default" + "deriving" + "do" + "else" + "foreign" + "if" + "import" + "in" + "infix" + "infixl" + "infixr" + "instance" + "let" + "module" + "newtype" + "of" + "then" + "type" + "where" + "_"))) + + +(defconst haskell-lexeme-varsym + "[!#$%&*+./<=>?@^|~\\-][!#$%&*+./:<=>?@^|~\\-]*") + +(defconst haskell-lexeme-consym + ":[!#$%&*+./:<=>?@^|~\\-]*") + +(defconst haskell-lexeme-varsym-or-consym + "[!#$%&*+./:<=>?@^|~\\-]+") + +(defconst haskell-lexeme-modid-opt-prefix + (concat "\\(?:" haskell-lexeme-conid "\\.\\)*")) + +(defconst haskell-lexeme-qvarid + (concat haskell-lexeme-modid-opt-prefix haskell-lexeme-varid)) + +(defconst haskell-lexeme-qconid + (concat haskell-lexeme-modid-opt-prefix haskell-lexeme-conid)) + +(defconst haskell-lexeme-qvarid-or-qconid + (concat haskell-lexeme-modid-opt-prefix haskell-lexeme-qvarid-or-qconid)) + + +(defconst haskell-lexeme-qvarsym + (concat haskell-lexeme-modid-opt-prefix haskell-lexeme-varsym)) + +(defconst haskell-lexeme-qconsym + (concat haskell-lexeme-modid-opt-prefix haskell-lexeme-consym)) + +(defconst haskell-lexeme-qvarsym-or-qconsym + (concat haskell-lexeme-modid-opt-prefix haskell-lexeme-varsym-or-consym)) + +(defconst haskell-lexeme-decimal + "[[:digit:]]+") + +(defconst haskell-lexeme-octal + "0[oO][0-7]+") + +(defconst haskell-lexeme-hexadecimal + "0[xX][[:xdigit:]]+") + +(defconst haskell-lexeme-float + (rx (| (regexp "[0-9]+\\." (opt (regexp "[eE][-+][0-9]+"))) + (regexp "[0-9]+[eE][-+][0-9]+")))) + +(defconst haskell-lexeme-char-literal-inside + (rx (| (regexp "[^\n'\\]") + (: "\\" + (| "a" "b" "f" "n" "r" "t" "v" "\\" "\"" "'" + "NUL" "SOH" "STX" "ETX" "EOT" "ENQ" "ACK" + "BEL" "BS" "HT" "LF" "VT" "FF" "CR" "SO" "SI" "DLE" + "DC1" "DC2" "DC3" "DC4" "NAK" "SYN" "ETB" "CAN" + "EM" "SUB" "ESC" "FS" "GS" "RS" "US" "SP" "DEL" + (regexp "^[A-Z@\\[\\]^_\\\\]") + + ))))) + +(defconst haskell-lexeme-char-literal + (concat "'" haskell-lexeme-char-literal-inside "'")) + +(defconst haskell-lexeme-string-literal-inside + (rx (* (| (regexp "[^\n\"\\]") + (: "\\" + (| "a" "b" "f" "n" "r" "t" "v" "\\" "\"" "'" "&" + "NUL" "SOH" "STX" "ETX" "EOT" "ENQ" "ACK" + "BEL" "BS" "HT" "LF" "VT" "FF" "CR" "SO" "SI" "DLE" + "DC1" "DC2" "DC3" "DC4" "NAK" "SYN" "ETB" "CAN" + "EM" "SUB" "ESC" "FS" "GS" "RS" "US" "SP" "DEL" + (regexp "^[A-Z@\\[\\]^_\\\\]") + (regexp "\\\\[[:space:]]*\\\\") + + )))))) + +(defconst haskell-lexeme-string-literal + (concat "\"" haskell-lexeme-string-literal-inside "\"")) diff --git a/haskell-load.el b/haskell-load.el index b41dfe9ae..32a2e635d 100644 --- a/haskell-load.el +++ b/haskell-load.el @@ -169,7 +169,7 @@ actual Emacs buffer of the module being loaded." (haskell-process-suggest-pragma session "LANGUAGE" "OverloadedStrings" file))) ((string-match "^Not in scope: .*[‘`‛]\\(.+\\)['’]$" msg) (let* ((match1 (match-string 1 msg)) - (ident (if (string-match "^[A-Za-z0-9_'.]+\\.\\(.+\\)$" match1) + (ident (if (string-match "^[[:alnum:]_'.]+\\.\\(.+\\)$" match1) ;; Skip qualification. (match-string 1 match1) match1))) diff --git a/haskell-mode.el b/haskell-mode.el index 497a0b9b5..0f8e2fc58 100644 --- a/haskell-mode.el +++ b/haskell-mode.el @@ -1001,7 +1001,7 @@ LOC = (list FILE LINE COL)" (let ((components (cl-loop for part in (reverse (split-string (buffer-file-name) "/")) while (let ((case-fold-search nil)) - (string-match "^[A-Z]+" part)) + (string-match "^[[:upper:]]+" part)) collect (replace-regexp-in-string "\\.l?hs$" "" part)))) (mapconcat 'identity (reverse components) "."))) diff --git a/haskell-package.el b/haskell-package.el index a7a36265b..1688beb01 100644 --- a/haskell-package.el +++ b/haskell-package.el @@ -128,11 +128,11 @@ (let* ((lines (split-string text "\n "))) (mapcar (lambda (line) - (string-match "^{?\\([a-zA-Z0-9-_]+\\)-\\([0-9.]+\\)}?$" line) + (string-match "^{?\\([[:alnum:]-_]+\\)-\\([0-9.]+\\)}?$" line) (cons (match-string 1 line) (match-string 2 line))) (cl-delete-if (lambda (line) - (not (string-match "^{?[a-zA-Z0-9-_]+-[0-9.]+}?$" line))) + (not (string-match "^{?[[:alnum:]-_]+-[0-9.]+}?$" line))) lines)))) (provide 'haskell-package) diff --git a/haskell-sort-imports.el b/haskell-sort-imports.el index 4d466322e..49cb71d36 100644 --- a/haskell-sort-imports.el +++ b/haskell-sort-imports.el @@ -34,7 +34,7 @@ (concat "^import[ ]+" "\\(qualified \\)?" "[ ]*\\(\"[^\"]*\" \\)?" - "[ ]*\\([A-Za-z0-9_.']*.*\\)")) + "[ ]*\\([[:alnum:]_.']*.*\\)")) ;;;###autoload (defun haskell-sort-imports () diff --git a/haskell-utils.el b/haskell-utils.el index fbf809426..43b245e2a 100644 --- a/haskell-utils.el +++ b/haskell-utils.el @@ -65,7 +65,7 @@ Note: doesn't detect if in {--}-style comment." "\\(?:safe[\t ]+\\)?" ;; SafeHaskell "\\(?:qualified[\t ]+\\)?" "\\(?:\"[^\"]*\"[\t ]+\\)?" ;; PackageImports - "\\([[:digit:][:upper:][:lower:]_.]+\\)")) + "\\([[:alnum:]_.]+\\)")) (match-string-no-properties 1))))