emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/csharp-mode 21c4b19 1/2: Add support for multiline stri


From: ELPA Syncer
Subject: [elpa] externals/csharp-mode 21c4b19 1/2: Add support for multiline strings (#251)
Date: Mon, 15 Nov 2021 16:57:15 -0500 (EST)

branch: externals/csharp-mode
commit 21c4b19d4875dc201e80b11143380a8d86c8852d
Author: Theodor Thornhill <theo@thornhill.no>
Commit: GitHub <noreply@github.com>

    Add support for multiline strings (#251)
    
    * Add support for multiline strings
    
    There is now a new type of support for multiline strings in CC Mode, and 
this is
    a first attempt to support this.  The regexes are supplied from Alan 
Mackenzie,
    the maintainer of CC Mode.  There are probably improvements to be made 
here, but
    it seems to fix some slowness with regards to string handling.  How does it
    work, you ask?
    
    It is left as an exercise to the reader.
---
 csharp-mode-tests.el             | 39 +++++++++++++++++++++++++--------------
 csharp-mode.el                   | 37 +++++++++++++++++++++++++++++++++++++
 test-files/fontification-test.cs |  2 +-
 test-files/multiline-strings.cs  |  6 ++++++
 4 files changed, 69 insertions(+), 15 deletions(-)

diff --git a/csharp-mode-tests.el b/csharp-mode-tests.el
index 8fe10a2..8c431c1 100644
--- a/csharp-mode-tests.el
+++ b/csharp-mode-tests.el
@@ -78,6 +78,16 @@
                         "true"       'font-lock-constant-face
                         ))
 
+(when (and (>= emacs-major-version 29)
+           (string-lessp "5.35.0" c-version))
+  (ert-deftest fontification-of-multiline-strings ()
+    (assess-face-in-file= "./test-files/multiline-strings.cs"
+                          "Literal0" 'font-lock-variable-name-face
+                          "Literal1" 'font-lock-variable-name-face
+                          "Literal2" 'font-lock-variable-name-face
+                          "Literal3" 'font-lock-variable-name-face
+                          "Literal4" 'font-lock-variable-name-face)))
+
 (ert-deftest fontification-of-constants ()
   (require 'assess)
   (assess-face-in-text=
@@ -108,20 +118,21 @@
    "var import = true;"
    "import" 'font-lock-variable-name-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
-           )))
+;; 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-compiler-directives ()
 ;;   ;; this replaces the manual test of
diff --git a/csharp-mode.el b/csharp-mode.el
index 7fd296c..9b88a60 100644
--- a/csharp-mode.el
+++ b/csharp-mode.el
@@ -95,6 +95,43 @@
 (c-lang-defconst c-multiline-string-start-char
   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))))
+
+(c-lang-defconst c-ml-string-max-opener-len
+  csharp 2)
+
+(c-lang-defconst c-ml-string-max-closer-len
+  csharp 2)
+
+(c-lang-defconst c-ml-string-any-closer-re
+  ;; "\\(?:\"\"\\)*\\(\\(\"\\)\\)\\(?:[^\"]\\|\\'\\)"
+  csharp
+  (rx
+   (seq
+    (zero-or-more "\"\"")
+    (group
+     (group "\""))
+    (or (not (any "\"")) eos))))
+
+(c-lang-defconst c-ml-string-back-closer-re
+  ;; "\\(:?\\`\\|[^\"]\\)\"*"
+  csharp
+  (rx
+   (seq
+    (group
+     (or (seq (opt ":") bos)
+         (not (any "\""))))
+    (zero-or-more "\""))))
+
 (c-lang-defconst c-type-prefix-kwds
   csharp '("class" "interface" "struct"))
 
diff --git a/test-files/fontification-test.cs b/test-files/fontification-test.cs
index e100796..177badf 100644
--- a/test-files/fontification-test.cs
+++ b/test-files/fontification-test.cs
@@ -1,6 +1,6 @@
+
 public const string Literal1 = @"literal without trailing slash";
 public const bool1 Reference = true;
-// public const string Literal2 = @"literal with trailing slash\"; 
 public const bool2 Reference = true;
 public static const string Literal3 = @"multi-line
 literal";
diff --git a/test-files/multiline-strings.cs b/test-files/multiline-strings.cs
new file mode 100644
index 0000000..7d87dd2
--- /dev/null
+++ b/test-files/multiline-strings.cs
@@ -0,0 +1,6 @@
+public const string Literal0 = @"\
+";
+public const string Literal1 = @"\";
+public const string Literal2 = @"\\";
+public const string Literal3 = @"\\\";
+public const string Literal4 = @"\\\\";



reply via email to

[Prev in Thread] Current Thread [Next in Thread]