Skip to content

Make regular expressions use character classes #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions haskell-align-imports.el
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
(concat "^\\(import[ ]+\\)"
"\\(qualified \\)?"
"[ ]*\\(\"[^\"]*\" \\)?"
"[ ]*\\([A-Za-z0-9_.']+\\)"
"[ ]*\\([ ]*as [A-Z][^ ]*\\)?"
"[ ]*\\([[:alnum:]_.']+\\)"
"[ ]*\\([ ]*as [:upper:][^ ]*\\)?"
"[ ]*\\((.*)\\)?"
"\\([ ]*hiding (.*)\\)?"
"\\( -- .*\\)?[ ]*$")
Expand Down
12 changes: 6 additions & 6 deletions haskell-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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))))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion haskell-complete-module.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))))
Expand Down
2 changes: 1 addition & 1 deletion haskell-debug.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
115 changes: 115 additions & 0 deletions haskell-lexeme.el
Original file line number Diff line number Diff line change
@@ -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 "\""))
2 changes: 1 addition & 1 deletion haskell-load.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion haskell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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) ".")))

Expand Down
4 changes: 2 additions & 2 deletions haskell-package.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion haskell-sort-imports.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
(concat "^import[ ]+"
"\\(qualified \\)?"
"[ ]*\\(\"[^\"]*\" \\)?"
"[ ]*\\([A-Za-z0-9_.']*.*\\)"))
"[ ]*\\([[:alnum:]_.']*.*\\)"))

;;;###autoload
(defun haskell-sort-imports ()
Expand Down
2 changes: 1 addition & 1 deletion haskell-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))


Expand Down