changeset 276:397ed930a5ba

Allow more separator characters for explicit token types. Extensive tests including a special test when using the backslash.
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 20 May 2026 12:10:01 +0200
parents f365d9d2c0ad
children a5c96fdd1cb3
files docs/lexer-algpseudocode.rst pygments_lexer_pseudocode2/lexers/algpseudocode.py tests/test_algpseudo.py
diffstat 3 files changed, 27 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/docs/lexer-algpseudocode.rst	Wed May 20 10:16:58 2026 +0200
+++ b/docs/lexer-algpseudocode.rst	Wed May 20 12:10:01 2026 +0200
@@ -477,7 +477,7 @@
 
   No escaping possible! There are enough alternatives available!
 
-  `SEP` is one of ``/:|=*+!\$~``.
+  `SEP` is exactly one character of ``/?.,:;%|=*+!\$~"'_-#@``.
 
 
 Examples:
@@ -502,10 +502,19 @@
       */
    \text{• \\ttx-nd[∈_∌](p1, p2)}                \ttx-nd[∈_∌](p1, p2)
      /*
-      * This is a non-existing token type: you get some generic error marking
+      * Normal emphasis ("strong")
+      */
+   \text{• \\ttx-gs$this is strong$}             \ttx-gs$this is strong$
+     /*
+      * A strong emphasis.
+      * Note that the backslash is a valid delimiter!
+      */
+   \text{• \\ttx-ges\\strong emphasis!\\}          \ttx-ges\strong emphasis!\
+     /*
+      * This is a non-existing token type: you get some generic error markup
       * with a Generic.Error token and no expansion.
       */
-   \text{• \\ttx-NON-EXISTING[∈_∌](p1, p2)}      \ttx-NON_EXISTING[∈_∌](p1, p2)
+   \text{• \\ttx-NON-EXISTING?∈_∌?(p1, p2)}      \ttx-NON_EXISTING?∈_∌?(p1, p2)
 
 .. note:: Explicit token types are **case-sensitive**.
 
--- a/pygments_lexer_pseudocode2/lexers/algpseudocode.py	Wed May 20 10:16:58 2026 +0200
+++ b/pygments_lexer_pseudocode2/lexers/algpseudocode.py	Wed May 20 12:10:01 2026 +0200
@@ -491,8 +491,9 @@
             # All these REs are CASE-SENSITIVE!
 
             # Multiple characters possible, but no escaping!
-            (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)(?P<sep>[/:|=*+!\\$~])"
-             r"(?P<character>(.|\n)+?)(?P=sep)",
+            (r"""\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)"""
+             r"""(?P<sep>[/?.,:;%|=*+!\\$~"'#@_-])"""
+             r"""(?P<character>(.|\n)+?)(?P=sep)""",
              op_explicit_tokentype),
             (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)\{(?P<character>[^}]+?)\}",
              op_explicit_tokentype),
--- a/tests/test_algpseudo.py	Wed May 20 10:16:58 2026 +0200
+++ b/tests/test_algpseudo.py	Wed May 20 12:10:01 2026 +0200
@@ -700,15 +700,25 @@
                 self.lexer))
 
     def test_explicit_tokentype_all_seps(self):
-        for sep in r"/:|=*+!\$~":
+        for sep in r"""/?.,:;%|=*+!$"'~_-#@""":
             self.assertTokenStreamEqualComplete(
                 [("Name.Decorator", "word"),
+                 ("Text", sep),
                  ("Text.Whitespace", "\n"),
                  ],
                 pygments.lex(
-                    r"\ttx-nd%sword%s" % (sep, sep,),
+                    r"\text{\ttx-nd%sword%s%s}" % (sep, sep, sep),
                     self.lexer))
 
+    def test_explicit_tokentype_backslash(self):
+        self.assertTokenStreamEqualComplete(
+            [("Name.Decorator", "word"),
+             ("Text", "\\"),
+             ("Text", " "),
+             ("Text.Whitespace", "\n"),
+             ],
+            pygments.lex(r"\text{\ttx-nd\word\\ }", self.lexer))
+
     def test_explicit_tokentype_error(self):
         self.assertTokenStreamEqualComplete(
             [("Generic.Error", r"""\ttx-non-existing[a_Decorator]"""),