changeset 94:dc17b778a52b

Refactor \END variants
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 03 May 2026 15:13:43 +0200
parents 84c0f761c836
children aed3204723ac
files pygments_lexer_pseudocode2/algpseudocode.py tests/test_algpseudo.py
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
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)?)"
--- a/tests/test_algpseudo.py	Sun May 03 15:10:52 2026 +0200
+++ b/tests/test_algpseudo.py	Sun May 03 15:13:43 2026 +0200
@@ -182,6 +182,15 @@
              ],
             pygments.lex("\\ENDPROCEDURE {the procedure name}", self.lexer))
 
+    def test_endproc_with_entityname_2(self):
+        self.assertTokenStreamEqualComplete(
+            [("Keyword", "END OF PROCEDURE"),
+             ("Text.Whitespace", " "),
+             ("Name.Entity", "the procedure name"),
+             ("Text.Whitespace", "\n"),
+             ],
+            pygments.lex("\\END-PROC {the procedure name}", self.lexer))
+
     def test_proc_de(self):
         lexer = pygments.lexers.load_lexer_from_file(
             ALGLEXERFILENAME, "AlgPseudocodeLexer_DE")