Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
changeset 159:4ee0b1536ea6
Handle runs of dots in expressions (., .., ..., ...., ...)
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 08 May 2026 17:13:26 +0200 |
| parents | f08d77b8cbf7 |
| children | b4028838e0c8 |
| files | docs/details-algpseudocode.rst docs/intro.rst pygments_lexer_pseudocode2/algpseudocode.py tests/test_algpseudo.py |
| diffstat | 4 files changed, 39 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/details-algpseudocode.rst Fri May 08 16:44:30 2026 +0200 +++ b/docs/details-algpseudocode.rst Fri May 08 17:13:26 2026 +0200 @@ -137,6 +137,14 @@ and highlighted accordingly. +Punctuation +=========== + +Runs of dots ``.``, ``..``, ``...``, ``....``, ... are handled +properly in expressions and yield a punctuation token. +They are not replaced by corresponding Unicode symbols. + + Keywords ========
--- a/docs/intro.rst Fri May 08 16:44:30 2026 +0200 +++ b/docs/intro.rst Fri May 08 17:13:26 2026 +0200 @@ -112,7 +112,8 @@ :lines: 2- This is Wikipedia's pseudocode of the *Edmonds–Karp Algorithm* -(see https://en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm): +(see https://en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm) +with a custom lexer that skip all ``ENDxxx`` keywords: .. literalinclude:: examples/algorithm-edmonds-karp.pseudocode :language: NoEndAlgPseudocode
--- a/pygments_lexer_pseudocode2/algpseudocode.py Fri May 08 16:44:30 2026 +0200 +++ b/pygments_lexer_pseudocode2/algpseudocode.py Fri May 08 17:13:26 2026 +0200 @@ -461,6 +461,7 @@ Keyword.Constant), ], "ascii-punctuation": [ + (r"\.+", Punctuation), (r"[{}:(),;[\]?@]", Punctuation), ], "ascii-punctuation-in-braces": [
--- a/tests/test_algpseudo.py Fri May 08 16:44:30 2026 +0200 +++ b/tests/test_algpseudo.py Fri May 08 17:13:26 2026 +0200 @@ -1003,6 +1003,34 @@ pygments.lex(r"(* word1 * word2 ( word3 ) word4 () word5 *)", self.lexer)) + def test_dots_one(self): + self.assertTokenStreamEqualComplete( + [("Punctuation", "."), + ("Text.Whitespace", "\n"), + ], + pygments.lex(r".", self.lexer)) + + def test_dots_two(self): + self.assertTokenStreamEqualComplete( + [("Punctuation", ".."), + ("Text.Whitespace", "\n"), + ], + pygments.lex(r"..", self.lexer)) + + def test_dots_three(self): + self.assertTokenStreamEqualComplete( + [("Punctuation", "..."), + ("Text.Whitespace", "\n"), + ], + pygments.lex(r"...", self.lexer)) + + def test_dots_four(self): + self.assertTokenStreamEqualComplete( + [("Punctuation", "...."), + ("Text.Whitespace", "\n"), + ], + pygments.lex(r"....", self.lexer)) + class PygmentizeCompletely(unittest.TestCase):
