Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
changeset 97:dd4eb937485c
A couple of new keywords
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 03 May 2026 15:18:35 +0200 |
| parents | 98cd0787f62f |
| children | c1f93e109798 |
| files | pygments_lexer_pseudocode2/algpseudocode.py tests/test_algpseudo.py |
| diffstat | 2 files changed, 70 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/pygments_lexer_pseudocode2/algpseudocode.py Sun May 03 15:15:34 2026 +0200 +++ b/pygments_lexer_pseudocode2/algpseudocode.py Sun May 03 15:18:35 2026 +0200 @@ -64,6 +64,22 @@ "CLASS": "CLASS", "IS": "IS", "WITH": "WITH", + "IF": "IF", + "THEN": "THEN", + "ELSE": "ELSE", + "ELSEIF": "ELSE IF", + "ELSIF": "ELSE IF", + "ELIF": "ELSE IF", + "DO": "DO", + "WHILE": "WHILE", + "FOR": "FOR", + "FORALL": "FOR ALL", + "STEP": "STEP", + "LOOP": "LOOP", + "REPEAT": "REPEAT", + "UNTIL": "UNTIL", + "BEGIN": "BEGIN", + "END": "END", # not in END_TRANSLATIONS } END_TRANSLATIONS = { "PROG": "END OF PROGRAM", @@ -76,6 +92,11 @@ "FUNCTION": "END OF FUNCTION", "FN": "END OF FUNCTION", "CLASS": "END OF CLASS", + "IF": "END IF", + "WHILE": "END WHILE", + "FOR": "END FOR", + "FORALL": "END FOR ALL", + "LOOP": "END LOOP", } DEFAULT_END_PREFIX = "END OF " SYMBOL_REMARK = "▷" # U+25B7: Unicode 1.0 (Geometric Shapes) @@ -192,6 +213,21 @@ r")[ \t]*(\{)", bygroups(op_symbol(Text), LexBase.op_fixed(Whitespace, " ")), "text-statement"), + (r"(?i)\\(" + r"(?:if)" + r"|(?:then)" + r"|(?:else)" + r"|(?:el(?:s(?:e)?)?if)" + r"|(?:do)" + r"|(?:while)" + r"|(?:forall)" + r"|(?:for)" + r"|(?:step)" + r"|(?:loop)" + r"|(?:repeat)" + r"|(?:until)" + r")\b", + bygroups(op_translate(Keyword))), (r"\\\n", Text), (r"(?i)\\(" r"(?:prog(?:ram)?)" @@ -225,8 +261,19 @@ r"|(?:func(?:tion)?)" r"|(?:fn)" r"|(?:class)" + r"|(?:if)" + r"|(?:while)" + r"|(?:for)" + r"|(?:forall)" + r"|(?:loop)" r")\b", bygroups(op_opt_end_translate(Keyword))), + # + # A single begin or end that is never suppressed because + # it is supposed to be paired with begin + # + (r"(?i)\\(begin|end)\b", + bygroups(op_translate(Keyword))), # Keywords (r"(?i)\\(" r"(?:is)"
--- a/tests/test_algpseudo.py Sun May 03 15:15:34 2026 +0200 +++ b/tests/test_algpseudo.py Sun May 03 15:18:35 2026 +0200 @@ -636,6 +636,29 @@ r"""\ttx-non-existing[a_Decorator]""", self.lexer)) + def test_end_combinations(self): + self.assertTokenStreamEqualComplete( + [("Keyword", "BEGIN"), + ("Text", " "), + ("Keyword", "END"), + ("Text", " "), + ("Keyword", "END OF FUNCTION"), + ("Text", " "), + ("Keyword", "END OF FUNCTION"), + ("Text.Whitespace", " "), + ("Name.Entity", "An End of a Function"), + ("Text", " "), + ("Keyword", "END OF FUNCTION"), + ("Text.Whitespace", " "), + ("Name.Entity", "The End of the Next Function"), + ("Text", " "), + ("Text.Whitespace", "\n"), + ], + pygments.lex( + r"""\begin \end \end-fn \end-fn {An End of a Function}""" + r""" \end fn {The End of the Next Function} """, + self.lexer)) + class PygmentizeCompletely(unittest.TestCase):
