diff options
| author | Tom Tromey <tom@tromey.com> | 2015-05-27 09:02:50 -0600 |
|---|---|---|
| committer | Tom Tromey <tom@tromey.com> | 2015-08-20 09:39:40 -0600 |
| commit | 012537b6c915afedaa458642bd23b0937b11d6b1 (patch) | |
| tree | 03d70de6531fba92e7ebcfcc218c8502b70cd1eb /rust-mode.el | |
| parent | 5e51aaa7cdea3d80d4beecfb2cded91185214519 (diff) | |
| download | rust-mode-012537b6c915afedaa458642bd23b0937b11d6b1.tar.gz | |
remove byte-compiler warnings and prevent future ones
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 138 |
1 files changed, 72 insertions, 66 deletions
diff --git a/rust-mode.el b/rust-mode.el index 2a0ad19..ff6814b 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -11,7 +11,10 @@ ;;; Code: (eval-when-compile (require 'misc) - (require 'rx)) + (require 'rx) + (require 'compile)) + +(defvar electric-pair-inhibit-predicate) ;; for GNU Emacs < 24.3 (eval-when-compile @@ -20,6 +23,70 @@ "Set variable VAR to value VAL in current buffer." (list 'set (list 'make-local-variable (list 'quote var)) val)))) +(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*") + +(defconst rust-re-non-standard-string + (rx + (or + ;; Raw string: if it matches, it ends up with the starting character + ;; of the string as group 1, any ending backslashes as group 4, and + ;; the ending character as either group 5 or group 6. + (seq + ;; The "r" starts the raw string. Capture it as group 1 to mark it as such syntactically: + (group "r") + + ;; Then either: + (or + ;; a sequence at least one "#" (followed by quote). Capture all + ;; but the last "#" as group 2 for this case. + (seq (group (* "#")) "#\"") + + ;; ...or a quote without any "#". Capture it as group 3. This is + ;; used later to match the opposite quote only if this capture + ;; occurred + (group "\"")) + + ;; The contents of the string: + (*? anything) + + ;; If there are any backslashes at the end of the string, capture + ;; them as group 4 so we can suppress the normal escape syntax + ;; parsing: + (group (* "\\")) + + ;; Then the end of the string--the backreferences ensure that we + ;; only match the kind of ending that corresponds to the beginning + ;; we had: + (or + ;; There were "#"s - capture the last one as group 5 to mark it as + ;; the end of the string: + (seq "\"" (backref 2) (group "#")) + + ;; No "#"s - capture the ending quote (using a backref to group 3, + ;; so that we can't match a quote if we had "#"s) as group 6 + (group (backref 3)) + + ;; If the raw string wasn't actually closed, go all the way to the end + string-end)) + + ;; Character literal: match the beginning ' of a character literal + ;; as group 7, and the ending one as group 8 + (seq + (group "'") + (or + (seq + "\\" + (or + (: "U" (= 8 xdigit)) + (: "u" (= 4 xdigit)) + (: "x" (= 2 xdigit)) + (any "'nrt0\"\\"))) + (not (any "'\\")) + ) + (group "'")) + ) + )) + (defun rust-looking-back-str (str) "Like `looking-back' but for fixed strings rather than regexps (so that it's not so slow)" (let ((len (length str))) @@ -145,8 +212,6 @@ (backward-up-list) (back-to-indentation)))) -(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*") - (defun rust-align-to-method-chain () (save-excursion ;; for method-chain alignment to apply, we must be looking at @@ -420,6 +485,9 @@ ("fn" . font-lock-function-name-face) ("static" . font-lock-constant-face))))) +(defvar font-lock-beg) +(defvar font-lock-end) + (defun rust-font-lock-extend-region () "Extend the region given by `font-lock-beg' and `font-lock-end' to include the beginning of a string or comment if it includes @@ -490,68 +558,6 @@ (set-match-data (nth 1 ret-list)) (nth 0 ret-list)))) -(defconst rust-re-non-standard-string - (rx - (or - ;; Raw string: if it matches, it ends up with the starting character - ;; of the string as group 1, any ending backslashes as group 4, and - ;; the ending character as either group 5 or group 6. - (seq - ;; The "r" starts the raw string. Capture it as group 1 to mark it as such syntactically: - (group "r") - - ;; Then either: - (or - ;; a sequence at least one "#" (followed by quote). Capture all - ;; but the last "#" as group 2 for this case. - (seq (group (* "#")) "#\"") - - ;; ...or a quote without any "#". Capture it as group 3. This is - ;; used later to match the opposite quote only if this capture - ;; occurred - (group "\"")) - - ;; The contents of the string: - (*? anything) - - ;; If there are any backslashes at the end of the string, capture - ;; them as group 4 so we can suppress the normal escape syntax - ;; parsing: - (group (* "\\")) - - ;; Then the end of the string--the backreferences ensure that we - ;; only match the kind of ending that corresponds to the beginning - ;; we had: - (or - ;; There were "#"s - capture the last one as group 5 to mark it as - ;; the end of the string: - (seq "\"" (backref 2) (group "#")) - - ;; No "#"s - capture the ending quote (using a backref to group 3, - ;; so that we can't match a quote if we had "#"s) as group 6 - (group (backref 3)) - - ;; If the raw string wasn't actually closed, go all the way to the end - string-end)) - - ;; Character literal: match the beginning ' of a character literal - ;; as group 7, and the ending one as group 8 - (seq - (group "'") - (or - (seq - "\\" - (or - (: "U" (= 8 xdigit)) - (: "u" (= 4 xdigit)) - (: "x" (= 2 xdigit)) - (any "'nrt0\"\\"))) - (not (any "'\\")) - ) - (group "'")) - ) - )) - (defun rust-look-for-non-standard-string (bound) ;; Find a raw string or character literal, but only if it's not in the middle ;; of another string or a comment. @@ -769,7 +775,7 @@ ;; Otherwise, if the ident: appeared with anything other than , or { ;; before it, it can't be part of a struct initializer and therefore ;; must be denoting a type. - nil + (t nil) )) )) |
