diff pygments_lexer_pseudocode2/algpseudocode.py @ 94:dc17b778a52b

Refactor \END variants
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 03 May 2026 15:13:43 +0200
parents 84c0f761c836
children 98cd0787f62f
line wrap: on
line diff
--- a/pygments_lexer_pseudocode2/algpseudocode.py	Sun May 03 15:10:52 2026 +0200
+++ b/pygments_lexer_pseudocode2/algpseudocode.py	Sun May 03 15:13:43 2026 +0200
@@ -203,20 +203,21 @@
              bygroups(op_translate(Keyword),
                       LexBase.op_fixed(Whitespace, " ")),
              "entity-name"),
-            # ENDxxx keywords with optional entity name
-            #   with name
-            (r"(?i)\\end(?:_|-)?("
+            # ENDxxx keywords with optional entity name in two parts:
+            #   1. with name
+            (r"(?i)\\end(?:[_\-]|(?:[ \t]+))?("
              r"(?:prog(?:ram)?)"
              r"|(?:algo(?:rithm)?)"
              r"|(?:proc(?:edure)?)"
              r"|(?:func(?:tion)?)"
              r"|(?:class)"
-             r")(?:_|(?:[\t -]+))?(\{)",
+             r")(?:[_\-]|(?:[\t ]+))?(\{)",
              bygroups(op_opt_end_translate(Keyword),
                       op_opt_ignore_or_fixed(Whitespace, " ")),
              "entity-name-end"),
-            #   without name
-            (r"(?i)\\end(?:_|-)?("
+            #   2. without name
+            #   3. AND keywords that do not allow a param (e.g. endif)
+            (r"(?i)\\end(?:[_\-]|(?:[ \t]+))?("
              r"(?:prog(?:ram)?)"
              r"|(?:algo(?:rithm)?)"
              r"|(?:proc(?:edure)?)"