Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
diff pygments_lexer_pseudocode2/algpseudocode.py @ 85:ae5e741d2a9b
Optimize op_explicit_tokentype(): use a pref-computed reversed pygments.token.STANDARD_TYPES
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 30 Apr 2026 19:56:39 +0200 |
| parents | 3ac1c4502ad0 |
| children | d8ca835c74ea |
line wrap: on
line diff
--- a/pygments_lexer_pseudocode2/algpseudocode.py Thu Apr 30 19:37:24 2026 +0200 +++ b/pygments_lexer_pseudocode2/algpseudocode.py Thu Apr 30 19:56:39 2026 +0200 @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # :- # SPDX-FileCopyrightText: © 2026 Franz Glasner @@ -18,14 +17,14 @@ import pygments.util from pygments.lexer import bygroups, include, words from pygments.token import (Comment, Keyword, Name, Operator, Punctuation, - Text, Whitespace, - STANDARD_TYPES) + Text, Whitespace) # # Relative imports do not work with pygments.lexers.load_lexer_from_file() # in all of our supported Python releases. # from pygments_lexer_pseudocode2.bases import LexBase +from pygments_lexer_pseudocode2.utils import REVERSED_STANDARD_TYPES class AlgPseudocodeLexer(LexBase): @@ -156,12 +155,7 @@ def op_explicit_tokentype(lexer, match, ctx=None): needed_css = match.group("type") - for ttype, css in STANDARD_TYPES.items(): - if css == needed_css: - toktype = ttype - break - else: - toktype = Text + toktype = REVERSED_STANDARD_TYPES.get(needed_css, Text) yield match.start(), toktype, match.group("character") if ctx: ctx.pos = match.end()
