# HG changeset patch # User Franz Glasner # Date 1779271801 -7200 # Node ID 397ed930a5baadb41b4f7e9438996a7ea2d41e06 # Parent f365d9d2c0add40f73ffb2c043f852d1d396605e Allow more separator characters for explicit token types. Extensive tests including a special test when using the backslash. diff -r f365d9d2c0ad -r 397ed930a5ba docs/lexer-algpseudocode.rst --- 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**. diff -r f365d9d2c0ad -r 397ed930a5ba pygments_lexer_pseudocode2/lexers/algpseudocode.py --- 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[a-zA-Z0-9_-]+?)(?P[/:|=*+!\\$~])" - r"(?P(.|\n)+?)(?P=sep)", + (r"""\\ttx\-(?P[a-zA-Z0-9_-]+?)""" + r"""(?P[/?.,:;%|=*+!\\$~"'#@_-])""" + r"""(?P(.|\n)+?)(?P=sep)""", op_explicit_tokentype), (r"\\ttx\-(?P[a-zA-Z0-9_-]+?)\{(?P[^}]+?)\}", op_explicit_tokentype), diff -r f365d9d2c0ad -r 397ed930a5ba tests/test_algpseudo.py --- 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]"""),