branch: externals/csharp-mode commit a28999cde0990ff438c24df4854c64edc7a6a193 Author: Theodor Thornhill <t...@thornhill.no> Commit: Theodor Thornhill <t...@thornhill.no>
Tweak multiline strings regexes --- csharp-mode-tests.el | 34 ++++++++++++++++++---------------- csharp-mode.el | 20 ++++++++------------ test-files/multiline-strings.cs | 6 +++++- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/csharp-mode-tests.el b/csharp-mode-tests.el index 8c431c1..f86b2d0 100644 --- a/csharp-mode-tests.el +++ b/csharp-mode-tests.el @@ -86,7 +86,10 @@ "Literal1" 'font-lock-variable-name-face "Literal2" 'font-lock-variable-name-face "Literal3" 'font-lock-variable-name-face - "Literal4" 'font-lock-variable-name-face))) + "Literal4" 'font-lock-variable-name-face + "Literal5" 'font-lock-variable-name-face + "Literal6" 'font-lock-variable-name-face + "Literal7" 'font-lock-variable-name-face))) (ert-deftest fontification-of-constants () (require 'assess) @@ -118,21 +121,20 @@ "var import = true;" "import" 'font-lock-variable-name-face)) -;; TODO: Should we really behave like this? The new CC Mode multiline strings doesn't -;; (ert-deftest fontification-of-literals-allows-multi-line-strings () -;; (require 'assess) -;; (should (assess-face-at= -;; "string Literal = \"multi-line\nstring\";" -;; 'csharp-mode -;; ;; should be interpreted as error -;; 18 'font-lock-warning-face -;; )) -;; (should (assess-face-at= -;; "string Literal = @\"multi-line\nstring\";" -;; 'csharp-mode -;; ;; should not be interpreted as error because of @ -;; 19 'font-lock-string-face -;; ))) +(ert-deftest fontification-of-literals-allows-multi-line-strings () + (require 'assess) + (should (assess-face-at= + "string Literal = \"multi-line\nstring\";" + 'csharp-mode + ;; should be interpreted as error + 18 'font-lock-warning-face + )) + (should (assess-face-at= + "string Literal = @\"multi-line\nstring\";" + 'csharp-mode + ;; should not be interpreted as error because of @ + 19 'font-lock-string-face + ))) ;; (ert-deftest fontification-of-compiler-directives () ;; ;; this replaces the manual test of diff --git a/csharp-mode.el b/csharp-mode.el index eee8f29..400a8d2 100644 --- a/csharp-mode.el +++ b/csharp-mode.el @@ -96,18 +96,15 @@ csharp ?@) (c-lang-defconst c-ml-string-opener-re - ;; "\\(?:\\=\\|[^\"]\\)\\(?:\"\"\\)*\\(\\(\"\\)\\)\\(?:[^\"]\\|\\'\\)" + ;; "\\(\\(?:@\\$?\\)\\(\"\\)\\)" csharp (rx - (seq - (or point (not (any "\""))) - (zero-or-more "\"\"") - (group - (group "\"")) - (or (not (any "\"")) eos)))) + (group + (or "@" "@$") + (group "\"")))) (c-lang-defconst c-ml-string-max-opener-len - csharp 2) + csharp 3) (c-lang-defconst c-ml-string-max-closer-len csharp 2) @@ -123,13 +120,12 @@ (or (not (any "\"")) eos)))) (c-lang-defconst c-ml-string-back-closer-re - ;; "\\(:?\\`\\|[^\"]\\)\"*" + ;; "\\(?:\\`\\|[^\"]\\)\"*" csharp (rx (seq - (group - (or (seq (opt ":") bos) - (not (any "\"")))) + (or bos + (not (any "\""))) (zero-or-more "\"")))) (c-lang-defconst c-type-prefix-kwds diff --git a/test-files/multiline-strings.cs b/test-files/multiline-strings.cs index 7d87dd2..cd7ee5c 100644 --- a/test-files/multiline-strings.cs +++ b/test-files/multiline-strings.cs @@ -3,4 +3,8 @@ public const string Literal0 = @"\ public const string Literal1 = @"\"; public const string Literal2 = @"\\"; public const string Literal3 = @"\\\"; -public const string Literal4 = @"\\\\"; +public const string Literal4 = @$"\\\\"; +public const string Literal5 = $@"\\\\ +"; +public const string Literal6 = "\t\t/* We need to ensure that \"{0}\"comes first in this list. */"; +public const string Literal7 = "";