branch: elpa/d-mode
commit e9278a992332e7e48465d71b294ff5856b1b54ee
Author: Vladimir Panteleev <[email protected]>
Commit: Vladimir Panteleev <[email protected]>
Reimplement compilation-mode error message detection for DMD
This addresses the following issues:
- Column numbers were not recognized in DMD error message when -vcolumns
is used. Error messages are now correctly detected with and without
column numbers.
- Continuation lines, such as when indicating the instantiation point of
a failed template instantiation, were not detected. They are now
detected as "information" level messages.
- The previous implementation was impossible to maintain, as it was
implemented as a single 235-character-long hand-optimized regular
expression. The new implementation uses the rx package to specify the
regular expression declaratively as lisp sexps.
- The previous implementation was not accompanied by any tests. A test
file has been added.
---
d-mode.el | 44 ++++++++++++++++++++++++++++++++------------
tests/I0069.txt | 7 +++++++
2 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/d-mode.el b/d-mode.el
index 6958637..4af9cec 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -75,6 +75,9 @@
;; The set-difference function is used from the Common Lisp extensions.
(require 'cl)
+;; Used to specify regular expressions in a sane way.
+(require 'rx)
+
;; These are only required at compile time to get the sources for the
;; language constants. (The cc-fonts require and the font-lock
;; related constants could additionally be put inside an
@@ -184,18 +187,35 @@ operators."
;;; Patterns to recognize the compiler generated messages
-;; The following regexp recognizes messages generated by the LDC and DMD
-;; compilers. Subexpression 1 is the filename, 2 is the line number, nil is
the
-;; column, because it's not present in the LDC error messages, and the
-;; subexpressions 3 and 4 are the message type -- error, warning, or info.
-
-;; GDC messages are recognized by gnu symbol already listed in
-;; compilation-error-regexp-alist.
-(add-to-list 'compilation-error-regexp-alist-alist
- '(ldc
- "^\\([^: \n]+\\)(\\([0-9]+\\)): \\(?:
*\\(?3:\\(?:W\\(?::\\|arning\\)\\|warning\\)\\)\\|
*\\(?4:[Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|\\[ skipping \\.+
]\\|instantiated from\\|required from\\|[Nn]ote\\)\\| *\\(?:[Ee]rror\\)\\|
*Deprecation\\)"
- 1 2 nil (3 . 4)))
-(add-to-list 'compilation-error-regexp-alist 'ldc)
+(defun d-mode-add-dmd-message-pattern (expr level symbol)
+ "Register DMD `compile' pattern for an error level.
+
+EXPR is the `rx' message sub-expression indicating the error level LEVEL.
+The expression is added to `compilation-error-regexp-alist' and
+`compilation-error-regexp-alist-alist' as SYMBOL."
+ (add-to-list
+ 'compilation-error-regexp-alist-alist
+ `(,symbol
+ ,(rx-form
+ `(and
+ line-start
+ (group-n 1 (one-or-more any)) ; File name
+ "("
+ (group-n 2 (one-or-more digit)) ; Line number
+ (zero-or-one
+ ","
+ (group-n 3 (one-or-more digit))) ; Column number
+ "): "
+ ,expr
+ (group-n 4 (one-or-more nonl)) ; Message
+ line-end))
+ 1 2 3 ,level 4))
+ (add-to-list 'compilation-error-regexp-alist symbol))
+
+(d-mode-add-dmd-message-pattern "Error: " 2 'dmd-error )
+(d-mode-add-dmd-message-pattern "Warning: " 1 'dmd-warning )
+(d-mode-add-dmd-message-pattern "Deprecation: " 1 'dmd-deprecation )
+(d-mode-add-dmd-message-pattern '(one-or-more " ") 0 'dmd-continuation)
;; The following regexp recognizes messages generated by the D runtime for
;; unhandled exceptions (e.g. assert failures).
diff --git a/tests/I0069.txt b/tests/I0069.txt
new file mode 100644
index 0000000..39cee45
--- /dev/null
+++ b/tests/I0069.txt
@@ -0,0 +1,7 @@
+-*-compilation-*-
+
+foo.d(1): Error: Test error
+foo.d(1,1): Error: Column number test
+baz.d(3,4): instantiated from here: Continuation test
+bar.d(2,1): Warning: Test warning
+quux.d(3): Deprecation: Test deprecation