Editor eric7

Tue, 23 Aug 2022 19:14:35 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 23 Aug 2022 19:14:35 +0200
branch
eric7
changeset 9293
7d9d916a9a9f
parent 9292
a5c8a0213fe3
child 9294
3c12aacd98d8

Editor
- extended the Pygments based lexer to support the various comment variants (see Issue 439)

docs/changelog file | annotate | diff | comparison | revisions
src/eric7/QScintilla/Lexers/Lexer.py file | annotate | diff | comparison | revisions
src/eric7/QScintilla/Lexers/LexerPygments.py file | annotate | diff | comparison | revisions
--- a/docs/changelog	Tue Aug 23 16:21:07 2022 +0200
+++ b/docs/changelog	Tue Aug 23 19:14:35 2022 +0200
@@ -9,6 +9,8 @@
   -- updated the simplifications checker to support more cases
 - Debugger
   -- added capability to suppress reporting of unhandled exceptions
+- Editor
+  -- extended the Pygments based lexer to support the various comment variants
 - MicroPython
   -- added capability to connect to devices for which only the serial port name
      is available
--- a/src/eric7/QScintilla/Lexers/Lexer.py	Tue Aug 23 16:21:07 2022 +0200
+++ b/src/eric7/QScintilla/Lexers/Lexer.py	Tue Aug 23 19:14:35 2022 +0200
@@ -44,7 +44,8 @@
         """
         Public method to return the comment string.
 
-        @return comment string (string)
+        @return comment string
+        @type str
         """
         return self.commentString
 
@@ -53,7 +54,8 @@
         Public method to determine, whether the lexer language supports a
         block comment.
 
-        @return flag (boolean)
+        @return flag indicating block comment is available
+        @rtype bool
         """
         return self.commentString != ""
 
@@ -61,7 +63,8 @@
         """
         Public method to return the stream comment strings.
 
-        @return stream comment strings (dictionary with two strings)
+        @return dictionary containing the start and end stream comment strings
+        @type dict of {"start": str, "end": str}
         """
         return self.streamCommentString
 
@@ -70,7 +73,8 @@
         Public method to determine, whether the lexer language supports a
         stream comment.
 
-        @return flag (boolean)
+        @return flag indicating stream comment is available
+        @type bool
         """
         return (
             self.streamCommentString["start"] != ""
@@ -81,7 +85,8 @@
         """
         Public method to return the box comment strings.
 
-        @return box comment strings (dictionary with three QStrings)
+        @return dictionary containing the start, middle and end box comment strings
+        @type dict of {"start": str, "middle": str, "end": str}
         """
         return self.boxCommentString
 
@@ -90,7 +95,8 @@
         Public method to determine, whether the lexer language supports a
         box comment.
 
-        @return flag (boolean)
+        @return flag box comment is available
+        @type bool
         """
         return (
             (self.boxCommentString["start"] != "")
--- a/src/eric7/QScintilla/Lexers/LexerPygments.py	Tue Aug 23 16:21:07 2022 +0200
+++ b/src/eric7/QScintilla/Lexers/LexerPygments.py	Tue Aug 23 19:14:35 2022 +0200
@@ -303,6 +303,69 @@
             PYGMENTS_BACKTICKSTRING: True,
         }
 
+        self.__commentString = {
+            "Bash": "#",
+            "Batchfile": "REM ",
+            "C": "//",
+            "C++": "//",
+            "C#": "//",
+            "CMake": "#",
+            "CoffeScript": "#",
+            "CSS": "#",
+            "D": "//",
+            "Fortran": "c ",
+            "Gettext Catalog": "#",
+            "IDL": "//",
+            "INI": "#",
+            "Java": "//",
+            "JavaScript": "//",
+            "JSON": "//",
+            "Lua": "--",
+            "Makefile": "#",
+            "Matlab": "%~",
+            "Octave": "#",
+            "Perl": "#",
+            "PostScript": "%",
+            "POVRay": "//",
+            "Properties": "#",
+            "Python": "#",
+            "RPMSpec": "#",
+            "Ruby": "#",
+            "SQL": "--",
+            "Tcl": "#",
+            "TeX": "%",
+            "TOML": "#",
+            "YAML": "#",
+        }
+
+        self.__streamCommentString = {
+            "CoffeScript": {"start": "###\n", "end": "\n###"},
+            "C": {"start": "/* ", "end": " */"},
+            "C++": {"start": "/* ", "end": " */"},
+            "C#": {"start": "/* ", "end": " */"},
+            "CSS": {"start": "/* ", "end": " */"},
+            "D": {"start": "/+ ", "end": " +/"},
+            "HTML": {"start": "<!-- ", "end": " -->"},
+            "IDL": {"start": "/* ", "end": " */"},
+            "Java": {"start": "/* ", "end": " */"},
+            "JavaScript": {"start": "/* ", "end": " */"},
+            "JSON": {"start": "/* ", "end": " */"},
+            "Lua": {"start": "--[[ ", "end": " ]]--"},
+            "POVRay": {"start": "/* ", "end": " */"},
+            "XML": {"start": "<!-- ", "end": " -->"},
+        }
+
+        self.__boxCommentString = {
+            "C": {"start": "/* ", "middle": " * ", "end": " */"},
+            "C++": {"start": "/* ", "middle": " * ", "end": " */"},
+            "C#": {"start": "/* ", "middle": " * ", "end": " */"},
+            "D": {"start": "/* ", "middle": " * ", "end": " */"},
+            "IDL": {"start": "/* ", "middle": " * ", "end": " */"},
+            "Java": {"start": "/* ", "middle": " * ", "end": " */"},
+            "JavaScript": {"start": "/* ", "middle": " * ", "end": " */"},
+            "POVRay": {"start": "/* ", "middle": " * ", "end": " */"},
+        }
+
     def readSettings(self, qs, prefix="/Scintilla"):
         """
         Public method to read the lexer settings.
@@ -564,3 +627,69 @@
         @return string giving the keywords (string) or None
         """
         return None  # __IGNORE_WARNING_M831__
+
+    def commentStr(self):
+        """
+        Public method to return the comment string.
+
+        @return comment string
+        @rtype str
+        """
+        try:
+            return self.__commentString[self.name()]
+        except KeyError:
+            return ""
+
+    def canBlockComment(self):
+        """
+        Public method to determine, whether the lexer language supports a
+        block comment.
+
+        @return flag indicating block comment is available
+        @rtype bool
+        """
+        return self.name() in self.__commentString
+
+    def streamCommentStr(self):
+        """
+        Public method to return the stream comment strings.
+
+        @return dictionary containing the start and end stream comment strings
+        @type dict of {"start": str, "end": str}
+        """
+        try:
+            return self.__streamCommentString
+        except KeyError:
+            return {"start": "", "end": ""}
+
+    def canStreamComment(self):
+        """
+        Public method to determine, whether the lexer language supports a
+        stream comment.
+
+        @return flag indicating stream comment is available
+        @type bool
+        """
+        return self.name() in self.__streamCommentString
+
+    def boxCommentStr(self):
+        """
+        Public method to return the box comment strings.
+
+        @return dictionary containing the start, middle and end box comment strings
+        @type dict of {"start": str, "middle": str, "end": str}
+        """
+        try:
+            return self.__boxCommentString
+        except KeyError:
+            return {"start": "", "middle": "", "end": ""}
+
+    def canBoxComment(self):
+        """
+        Public method to determine, whether the lexer language supports a
+        box comment.
+
+        @return flag box comment is available
+        @type bool
+        """
+        return self.name() in self.__boxCommentString

eric ide

mercurial