Propertize operator symbol names with symbol syntax class

* lisp/progmodes/ruby-mode.el (ruby-syntax-propertize):
Do it here.
(ruby-font-lock-keywords): Instead of handling them here.  Leave
highlighting them to the "normal" matcher, because now we can.
(ruby-smie--forward-token, ruby-smie--backward-token):
Likewise, don't special-case operator symbols anymore.
(ruby-smie--args-separator-p): Simplify the regexp, match operator
names with \s_.
(ruby-smie--implicit-semi-p): Handle the special cases of ? and =
at EOL the same way: check if the character has been assigned the
symbol syntax class by syntax-propertize.
This commit is contained in:
Dmitry Gutov 2016-03-09 16:43:51 +02:00
parent 9b16bc2a01
commit 1b9d6163b0
2 changed files with 17 additions and 22 deletions

View file

@ -431,17 +431,11 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
(not (or (bolp)
(memq (char-before) '(?\[ ?\())
(and (memq (char-before)
'(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\\ ?& ?> ?< ?% ?~ ?^))
;; Not a binary operator symbol.
(not (eq (char-before (1- (point))) ?:))
;; Not the end of a regexp or a percent literal.
(not (memq (car (syntax-after (1- (point)))) '(7 15))))
(and (eq (char-before) ?\?)
(equal (save-excursion (ruby-smie--backward-token)) "?"))
(and (eq (char-before) ?=)
;; Not a symbol :==, :!=, or a foo= method.
(string-match "\\`\\s." (save-excursion
(ruby-smie--backward-token))))
'(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\\ ?& ?> ?< ?% ?~ ?^ ?= ??))
;; Not a binary operator symbol like :+ or :[]=.
;; Or a (method or symbol) name ending with ?.
;; Or the end of a regexp or a percent literal.
(not (memq (car (syntax-after (1- (point)))) '(3 7 15))))
(and (eq (char-before) ?|)
(member (save-excursion (ruby-smie--backward-token))
'("|" "||")))
@ -485,7 +479,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
"else" "elsif" "do" "end" "and")
'symbols))))
(memq (car (syntax-after pos)) '(7 15))
(looking-at "[([]\\|[-+!~]\\sw\\|:\\(?:\\sw\\|\\s.\\)")))))
(looking-at "[([]\\|[-+!~:]\\(?:\\sw\\|\\s_\\)")))))
(defun ruby-smie--at-dot-call ()
(and (eq ?w (char-syntax (following-char)))
@ -511,8 +505,6 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
(save-excursion
(ruby-smie--args-separator-p (prog1 (point) (goto-char pos)))))
" @ ")
((looking-at ":\\s.+")
(goto-char (match-end 0)) (match-string 0)) ;bug#15208.
((looking-at "\\s\"") "") ;A string.
(t
(let ((dot (ruby-smie--at-dot-call))
@ -562,8 +554,6 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
(dot (ruby-smie--at-dot-call)))
(when dot
(setq tok (concat "." tok)))
(when (and (eq ?: (char-before)) (string-match "\\`\\s." tok))
(forward-char -1) (setq tok (concat ":" tok))) ;; bug#15208.
(cond
((member tok '("unless" "if" "while" "until"))
(if (ruby-smie--bosp)
@ -1861,11 +1851,13 @@ It will be properly highlighted even when the call omits parens.")
(ignore
(goto-char (match-end 1)))
(string-to-syntax "\\"))))
;; Part of symbol when at the end of a method name.
;; Symbols with special characters.
("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)"
(3 (string-to-syntax "_")))
;; Part of method name when at the end of it.
("[!?]"
(0 (unless (save-excursion
(or (nth 8 (syntax-ppss (match-beginning 0)))
(eq (char-before) ?:)
(let (parse-sexp-lookup-properties)
(zerop (skip-syntax-backward "w_")))
(memq (preceding-char) '(?@ ?$))))
@ -2183,7 +2175,7 @@ See `font-lock-syntax-table'.")
;; Keywords that evaluate to certain values.
("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>"
(0 font-lock-builtin-face))
;; Symbols with symbol characters.
;; Symbols.
("\\(^\\|[^:]\\)\\(:@?\\(?:\\w\\|_\\)+\\)\\([!?=]\\)?"
(2 font-lock-constant-face)
(3 (unless (and (eq (char-before (match-end 3)) ?=)
@ -2191,9 +2183,6 @@ See `font-lock-syntax-table'.")
;; bug#18644
font-lock-constant-face)
nil t))
;; Symbols with special characters.
("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)"
2 font-lock-constant-face)
;; Special globals.
(,(concat "\\$\\(?:[:\"!@;,/\\._><\\$?~=*&`'+0-9]\\|-[0adFiIlpvw]\\|"
(regexp-opt '("LOAD_PATH" "LOADED_FEATURES" "PROGRAM_NAME"

View file

@ -168,6 +168,12 @@ def test2 (arg)
something
end
qux :+,
bar,
:[]=,
bar,
:a
# Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
d = 4 + 5 + # no '\' needed
6 + 7