Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
diff pygments_lexer_pseudocode2/pseudocode.py @ 35:d9a3551a1038
Basics of translating some keywords
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 22 Apr 2026 16:23:09 +0200 |
| parents | 1f741934205e |
| children | 69522d4cafac |
line wrap: on
line diff
--- a/pygments_lexer_pseudocode2/pseudocode.py Tue Apr 21 19:40:08 2026 +0200 +++ b/pygments_lexer_pseudocode2/pseudocode.py Wed Apr 22 16:23:09 2026 +0200 @@ -8,13 +8,13 @@ """ -__all__ = ["PseudocodeLexer"] +__all__ = ["PseudocodeLexer", "PseudocodeLexer_DE"] import re from pygments.lexer import include -from pygments.token import (Text, Whitespace) +from pygments.token import (Keyword, Text, Whitespace) # # Relative imports do not work with pygments.lexers.load_lexer_from_file() @@ -38,10 +38,41 @@ mimetypes = [] flags = re.MULTILINE + LANG = "en" + TRANSLATIONS = { + "PROG": "PROGRAM", + "PROGRAM": "PROGRAM", + "ALGO": "ALGORITHM", + "ALGORITHM": "ALGORITHM", + "PROC": "PROCEDURE", + "PROCEDURE": "PROCEDURE", + "FUNC": "FUNCTION", + "FUNCTION": "FUNCTION", + "FN": "FUNCTION", + "CLASS": "CLASS", + } + + def op_translate(toktype): + + def _op_translate(lexer, match): + kw = match.group(1).upper() + kwtrans = lexer.TRANSLATIONS.get(kw, kw) + yield match.start(), toktype, kwtrans + + return _op_translate + tokens = { "root": [ (r"\n", Whitespace), (r"\\\n", Text), + (r"(?i)\\(" + r"(?:prog(?:ram)?)" + r"|(?:algo(?:rithm)?)" + r"|(?:proc(?:edure)?)" + r"|(?:func(?:tion)?|(?:fn))" + r"|(?:class)" + r")\b", + op_translate(Keyword)), include("expr"), ], "expr": [ @@ -49,3 +80,45 @@ include("py-numbers"), ] } + + +class PseudocodeLexer_DE(PseudocodeLexer): + + name = "PseudocodeDE" + aliases = ["pseudocode-de", "pseudo-de", "algorithm-de", "algo-de"] + filenames = ["*.algo-de", "*.pseudocode-de"] + + LANG = "de" + TRANSLATIONS = { + "PROG": "PROGRAMM", + "PROGRAM": "PROGRAMM", + "ALGO": "ALGORITHMUS", + "ALGORITHM": "ALGORITHM", + "PROC": "PROZEDUR", + "PROCEDURE": "PROZEDUR", + "FUNC": "FUNKTION", + "FUNCTION": "FUNKTION", + "FN": "FUNKTION", + "CLASS": "KLASSE", + } + + +class PseudocodeLexer_FR(PseudocodeLexer): + + name = "PseudocodeFR" + aliases = ["pseudocode-fr", "pseudo-fr", "algorithm-fr", "algo-fr"] + filenames = ["*.algo-fr", "*.pseudocode-fr"] + + LANG = "de" + TRANSLATIONS = { + "PROG": "PROGRAMME", + "PROGRAM": "PROGRAMME", + "ALGO": "ALGORITHME", + "ALGORITHM": "ALGORITHME", + "PROC": "PROCÉDURE", + "PROCEDURE": "PROCÉDURE", + "FUNC": "FONCTION", + "FUNCTION": "FOUNCTION", + "FN": "FONCTION", + "CLASS": "CLASSE", + }
