branch: elpa/d-mode
commit 1e5c7c3510b19338eca3201c8e5f38805322df1e
Author: Vladimir Panteleev <[email protected]>
Commit: Vladimir Panteleev <[email protected]>
Fix parsing of declarations following protection group
Apparently, all that was missing was defining c-post-protection-token?
Replaces the last "hideous hack".
---
d-mode.el | 44 ++++---------------------------------------
tests/fonts_protection.d | 9 +++++++++
tests/fonts_protection.d.html | 9 +++++++++
3 files changed, 22 insertions(+), 40 deletions(-)
diff --git a/d-mode.el b/d-mode.el
index f2d4826..c2f5aae 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -7,7 +7,7 @@
;; Maintainer: Russel Winder <[email protected]>
;; Vladimir Panteleev <[email protected]>
;; Created: March 2007
-;; Version: 201909091656
+;; Version: 201909091759
;; Keywords: D programming language emacs cc-mode
;; Package-Requires: ((emacs "25.1"))
@@ -180,6 +180,9 @@ operators."
d (cl-set-difference (c-lang-const c-block-prefix-disallowed-chars)
'(?:)))
+(c-lang-defconst c-post-protection-token
+ d ":")
+
(defconst doxygen-font-lock-doc-comments
(let ((symbol "[a-zA-Z0-9_]+")
(header "^ \\* "))
@@ -1014,45 +1017,6 @@ Key bindings:
(cc-imenu-init d-imenu-generic-expression))
;;----------------------------------------------------------------------------
-;; "Hideous hacks" to support appropriate font-lock behaviour.
-;;
-;; * public/protected/private appear both in c-modifier-kwds and in
-;; c-protection-kwds. This causes cc-mode to fail parsing the first
-;; declaration after an access level label (because cc-mode trys to
-;; parse them as modifier but will fail due to the colon). But
-;; unfortunately we cannot remove them from either c-modifier-kwds
-;; or c-protection-kwds. Removing them from the former causes valid
-;; syntax like "private int foo() {}" to fail. Removing them from
-;; the latter cause indentation of the access level labels to
-;; fail. The solution used here is to use font-lock-add-keywords to
-;; add back the syntax highlight.
-
-(defconst d-var-decl-pattern "^[ \t]*\\(?:[_a-zA-Z0-9]+[
\t\n]+\\)*\\([_a-zA-Z0-9.!]+\\)\\(?:\\[[^]]*\\]\\|\\*\\)?[
\t\n]+\\([_a-zA-Z0-9]+\\)[ \t\n]*[;=]")
-(defconst d-fun-decl-pattern "^[ \t]*\\(?:[_a-zA-Z0-9]+[
\t\n]+\\)*\\([_a-zA-Z0-9.!]+\\)\\(?:\\[[^]]*\\]\\|\\*\\)?[
\t\n]+\\([_a-zA-Z0-9]+\\)[ \t\n]*(")
-(defmacro d-try-match-decl (regex)
- "Helper macro." ;; checkdoc-params: regex
- `(let ((pt))
- (setq pt (re-search-forward ,regex limit t))
- (while (let ((type (match-string 1)))
- (and pt type
- (save-match-data
- (string-match (c-lang-const c-regular-keywords-regexp)
type))))
- (setq pt (re-search-forward ,regex limit t)))
- pt))
-(defun d-match-var-decl (limit)
- "Helper function." ;; checkdoc-params: limit
- (d-try-match-decl d-var-decl-pattern))
-(defun d-match-fun-decl (limit)
- "Helper function." ;; checkdoc-params: limit
- (d-try-match-decl d-fun-decl-pattern))
-
-(font-lock-add-keywords
- 'd-mode
- '((d-match-var-decl (1 font-lock-type-face) (2 font-lock-variable-name-face))
- (d-match-fun-decl (1 font-lock-type-face) (2 font-lock-function-name-face)))
- t)
-
-;;----------------------------------------------------------------------------
(defun d--on-func-identifier ()
"Version of `c-on-identifier', but also match D constructors."
diff --git a/tests/fonts_protection.d b/tests/fonts_protection.d
new file mode 100644
index 0000000..7a3e237
--- /dev/null
+++ b/tests/fonts_protection.d
@@ -0,0 +1,9 @@
+// #min-version: 26.1
+// #run: (d-test-fontification)
+
+class C
+{
+ Type var1, var2;
+public:
+ Type var3, var4;
+}
diff --git a/tests/fonts_protection.d.html b/tests/fonts_protection.d.html
new file mode 100644
index 0000000..1908b70
--- /dev/null
+++ b/tests/fonts_protection.d.html
@@ -0,0 +1,9 @@
+<span class="comment-delimiter">// </span><span class="comment">#min-version:
26.1
+</span><span class="comment-delimiter">// </span><span class="comment">#run:
(d-test-fontification)
+</span>
+<span class="keyword">class</span> <span class="type">C</span>
+{
+ <span class="type">Type</span> <span class="variable-name">var1</span>,
<span class="variable-name">var2</span>;
+<span class="keyword">public</span>:
+ <span class="type">Type</span> <span class="variable-name">var3</span>,
<span class="variable-name">var4</span>;
+}