Function: ruby-syntax-propertize
ruby-syntax-propertize is a byte-compiled function defined in
ruby-mode.el.gz.
Signature
(ruby-syntax-propertize START END)
Documentation
Syntactic keywords for Ruby mode. See syntax-propertize-function.
Aliases
ruby-syntax-propertize-function (obsolete since 25.1)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/ruby-mode.el.gz
(defun ruby-syntax-propertize (start end)
"Syntactic keywords for Ruby mode. See `syntax-propertize-function'."
(let (case-fold-search)
(goto-char start)
(remove-text-properties start end '(ruby-expansion-match-data nil))
(ruby-syntax-propertize-heredoc end)
(ruby-syntax-enclosing-percent-literal end)
(funcall
(syntax-propertize-rules
;; $' $" $` .... are variables.
;; ?' ?" ?` are character literals (one-char strings in 1.9+).
("\\([?$]\\)[#\"'`:?]"
(1 (if (save-excursion
(nth 3 (syntax-ppss (match-beginning 0))))
;; Within a string, skip.
(ignore
(goto-char (match-end 1)))
(put-text-property (match-end 1) (match-end 0)
'syntax-table (string-to-syntax "_"))
(string-to-syntax "'"))))
;; Symbols with special characters.
(":\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)"
(1 (unless (or
(nth 8 (syntax-ppss (match-beginning 1)))
(eq (char-before (match-beginning 0)) ?:))
(goto-char (match-end 0))
(string-to-syntax "_"))))
;; Symbols ending with '=' (bug#42846).
(":[[:alpha:]][[:alnum:]_]*\\(=\\)"
(1 (unless (or (nth 8 (syntax-ppss))
(eq (char-before (match-beginning 0)) ?:)
(eq (char-after (match-end 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)))
(let (parse-sexp-lookup-properties)
(zerop (skip-syntax-backward "w_")))
(memq (preceding-char) '(?@ ?$))))
(string-to-syntax "_"))))
;; Backtick method redefinition.
("^[ \t]*def +\\(`\\)" (1 "_"))
;; Ternary operator colon followed by opening paren or bracket
;; (semi-important for indentation).
("\\(:\\)\\(?:[({]\\|\\[[^]]\\)"
(1 (string-to-syntax ".")))
;; Regular expressions.
("\\(/\\)"
(1
;; No unescaped slashes in front.
(when (save-excursion
(forward-char -1)
(cl-evenp (skip-chars-backward "\\\\")))
(let ((state (save-excursion (syntax-ppss (match-beginning 1)))))
(when (or
;; Beginning of a regexp.
(and (null (nth 8 state))
(or (not
;; Looks like division.
(or (eql (char-after) ?\s)
(eql (char-after) ?=)
(not (eql (char-before (1- (point))) ?\s))))
(save-excursion
(forward-char -1)
(looking-back ruby-syntax-before-regexp-re
(line-beginning-position)))))
;; End of regexp. We don't match the whole
;; regexp at once because it can have
;; string interpolation inside, or span
;; several lines.
(eq ?/ (nth 3 state)))
(string-to-syntax "\"/"))))))
;; Expression expansions in strings. We're handling them
;; here, so that the regexp rule never matches inside them.
(ruby-expression-expansion-re
(0 (ignore
(if (save-excursion
(goto-char (match-beginning 0))
;; The hash character is not escaped.
(cl-evenp (skip-chars-backward "\\\\")))
(ruby-syntax-propertize-expansion)
(goto-char (match-beginning 1))))))
("^=en\\(d\\)\\_>" (1 "!"))
("^\\(=\\)begin\\_>" (1 "!"))
;; Handle here documents.
((concat ruby-here-doc-beg-re ".*\\(\n\\)")
(7 (when (and (not (nth 8 (save-excursion
(syntax-ppss (match-beginning 0)))))
(ruby-verify-heredoc (match-beginning 0)))
(put-text-property (match-beginning 7) (match-end 7)
'syntax-table (string-to-syntax "\""))
(ruby-syntax-propertize-heredoc end))))
;; Handle percent literals: %w(), %q{}, etc.
((concat "\\(?:^\\|[[ \t\n<+(,=*]\\)" ruby-percent-literal-beg-re)
(1 (unless (nth 8 (save-excursion (syntax-ppss (match-beginning 1))))
;; Not inside a string, a comment, or a percent literal.
(ruby-syntax-propertize-percent-literal end)
(string-to-syntax "|")))))
(point) end)))