comparison pygments_lexer_pseudocode2/__init__.py @ 19:2e67c4eae6d9

Use an alternate replace algorithm with a dict
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 20 Apr 2026 15:25:45 +0200
parents 81554feb6507
children 3db60b64abf6
comparison
equal deleted inserted replaced
18:859ab8abce0a 19:2e67c4eae6d9
34 aliases = ['pseudocode', 'pseudo', 'algorithm', 'algo'] 34 aliases = ['pseudocode', 'pseudo', 'algorithm', 'algo']
35 filenames = ['*.algo', '*.pseudocode'] 35 filenames = ['*.algo', '*.pseudocode']
36 mimetypes = [] 36 mimetypes = []
37 flags = re.IGNORECASE 37 flags = re.IGNORECASE
38 38
39 REPLACEMENTS = {
40 '<=': '≤',
41 '>=': '≥',
42 '<>': '≠',
43 '<-': '←',
44 '^': '↑',
45 }
46
39 def op_replace(lexer, match): 47 def op_replace(lexer, match):
40 op = match.group(0) 48 op = match.group(0)
41 49 opr = lexer.REPLACEMENTS.get(op)
42 S = ('<=', '>=', '<>', '<-', '^') 50 if opr is None:
43 R = ('≤', '≥', '≠', '←', '↑') 51 yield match.start(), Operator, op
44 52 else:
45 if op in S: 53 yield match.start(), Operator, opr
46 op = R[S.index(op)]
47
48 yield match.start(), Operator, op
49 54
50 def scomment(lexer, match): 55 def scomment(lexer, match):
51 s = match.group(1).lower().strip() 56 s = match.group(1).lower().strip()
52 c = Comment 57 c = Comment
53 58