diff options
| author | Dmitry Gutov | 2016-03-07 02:58:49 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2016-03-07 05:07:34 +0200 |
| commit | 6e63b3e997e1ac2fa9b58f0d2edeca3cd83628f2 (patch) | |
| tree | 80fe9ca13285f52d56c6c2a677001fe36d5ad884 /lisp | |
| parent | 066f3bc3f3d024b2e10ee11e09ae6aaa1003bbda (diff) | |
| download | emacs-6e63b3e997e1ac2fa9b58f0d2edeca3cd83628f2.tar.gz emacs-6e63b3e997e1ac2fa9b58f0d2edeca3cd83628f2.zip | |
Guard against nested percent literals
* lisp/progmodes/ruby-mode.el
(ruby-syntax-propertize-percent-literal):
Don't check the syntax status.
(ruby-syntax-propertize): Check it here. And also guard against
being in a larger percent literal.
* test/automated/ruby-mode-tests.el
(ruby-no-nested-percent-literals): New test.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index fa94992ab79..1395828cff9 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -1901,7 +1901,10 @@ It will be properly highlighted even when the call omits parens.") | |||
| 1901 | (ruby-syntax-propertize-heredoc end)))) | 1901 | (ruby-syntax-propertize-heredoc end)))) |
| 1902 | ;; Handle percent literals: %w(), %q{}, etc. | 1902 | ;; Handle percent literals: %w(), %q{}, etc. |
| 1903 | ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re) | 1903 | ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re) |
| 1904 | (1 (prog1 "|" (ruby-syntax-propertize-percent-literal end))))) | 1904 | (1 (unless (nth 8 (save-excursion (syntax-ppss (match-beginning 1)))) |
| 1905 | ;; Not inside a string, a comment, or a percent literal. | ||
| 1906 | (ruby-syntax-propertize-percent-literal end) | ||
| 1907 | (string-to-syntax "|"))))) | ||
| 1905 | (point) end))) | 1908 | (point) end))) |
| 1906 | 1909 | ||
| 1907 | (define-obsolete-function-alias | 1910 | (define-obsolete-function-alias |
| @@ -1944,35 +1947,33 @@ It will be properly highlighted even when the call omits parens.") | |||
| 1944 | 1947 | ||
| 1945 | (defun ruby-syntax-propertize-percent-literal (limit) | 1948 | (defun ruby-syntax-propertize-percent-literal (limit) |
| 1946 | (goto-char (match-beginning 2)) | 1949 | (goto-char (match-beginning 2)) |
| 1947 | ;; Not inside a simple string or comment. | 1950 | (let* ((op (char-after)) |
| 1948 | (when (eq t (nth 3 (syntax-ppss))) | 1951 | (ops (char-to-string op)) |
| 1949 | (let* ((op (char-after)) | 1952 | (cl (or (cdr (aref (syntax-table) op)) |
| 1950 | (ops (char-to-string op)) | 1953 | (cdr (assoc op '((?< . ?>)))))) |
| 1951 | (cl (or (cdr (aref (syntax-table) op)) | 1954 | parse-sexp-lookup-properties) |
| 1952 | (cdr (assoc op '((?< . ?>)))))) | 1955 | (save-excursion |
| 1953 | parse-sexp-lookup-properties) | 1956 | (condition-case nil |
| 1954 | (save-excursion | 1957 | (progn |
| 1955 | (condition-case nil | 1958 | (if cl ; Paired delimiters. |
| 1956 | (progn | 1959 | ;; Delimiter pairs of the same kind can be nested |
| 1957 | (if cl ; Paired delimiters. | 1960 | ;; inside the literal, as long as they are balanced. |
| 1958 | ;; Delimiter pairs of the same kind can be nested | 1961 | ;; Create syntax table that ignores other characters. |
| 1959 | ;; inside the literal, as long as they are balanced. | 1962 | (with-syntax-table (make-char-table 'syntax-table nil) |
| 1960 | ;; Create syntax table that ignores other characters. | 1963 | (modify-syntax-entry op (concat "(" (char-to-string cl))) |
| 1961 | (with-syntax-table (make-char-table 'syntax-table nil) | 1964 | (modify-syntax-entry cl (concat ")" ops)) |
| 1962 | (modify-syntax-entry op (concat "(" (char-to-string cl))) | 1965 | (modify-syntax-entry ?\\ "\\") |
| 1963 | (modify-syntax-entry cl (concat ")" ops)) | 1966 | (save-restriction |
| 1964 | (modify-syntax-entry ?\\ "\\") | 1967 | (narrow-to-region (point) limit) |
| 1965 | (save-restriction | 1968 | (forward-list))) ; skip to the paired character |
| 1966 | (narrow-to-region (point) limit) | 1969 | ;; Single character delimiter. |
| 1967 | (forward-list))) ; skip to the paired character | 1970 | (re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*" |
| 1968 | ;; Single character delimiter. | 1971 | (regexp-quote ops)) limit nil)) |
| 1969 | (re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*" | 1972 | ;; Found the closing delimiter. |
| 1970 | (regexp-quote ops)) limit nil)) | 1973 | (put-text-property (1- (point)) (point) 'syntax-table |
| 1971 | ;; Found the closing delimiter. | 1974 | (string-to-syntax "|"))) |
| 1972 | (put-text-property (1- (point)) (point) 'syntax-table | 1975 | ;; Unclosed literal, do nothing. |
| 1973 | (string-to-syntax "|"))) | 1976 | ((scan-error search-failed)))))) |
| 1974 | ;; Unclosed literal, do nothing. | ||
| 1975 | ((scan-error search-failed))))))) | ||
| 1976 | 1977 | ||
| 1977 | (defun ruby-syntax-propertize-expansion () | 1978 | (defun ruby-syntax-propertize-expansion () |
| 1978 | ;; Save the match data to a text property, for font-locking later. | 1979 | ;; Save the match data to a text property, for font-locking later. |