Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison pygments_lexer_pseudocode2/algpseudocode.py @ 89:7414eed7b275
Introduce logging for unhandled explicit token types
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 02 May 2026 13:21:45 +0200 |
| parents | d8ca835c74ea |
| children | 2af4684c8e78 |
comparison
equal
deleted
inserted
replaced
| 88:03e9031b5eca | 89:7414eed7b275 |
|---|---|
| 10 | 10 |
| 11 __all__ = ["AlgPseudocodeLexer", | 11 __all__ = ["AlgPseudocodeLexer", |
| 12 "AlgPseudocodeLexer_DE", "AlgPseudocodeLexer_FR"] | 12 "AlgPseudocodeLexer_DE", "AlgPseudocodeLexer_FR"] |
| 13 | 13 |
| 14 | 14 |
| 15 import logging | |
| 15 import re | 16 import re |
| 16 | 17 |
| 17 import pygments.util | 18 import pygments.util |
| 18 from pygments.lexer import bygroups, include, words | 19 from pygments.lexer import bygroups, include, words |
| 19 from pygments.token import (Comment, Generic, Keyword, Name, Operator, | 20 from pygments.token import (Comment, Generic, Keyword, Name, Operator, |
| 23 # Relative imports do not work with pygments.lexers.load_lexer_from_file() | 24 # Relative imports do not work with pygments.lexers.load_lexer_from_file() |
| 24 # in all of our supported Python releases. | 25 # in all of our supported Python releases. |
| 25 # | 26 # |
| 26 from pygments_lexer_pseudocode2.bases import LexBase | 27 from pygments_lexer_pseudocode2.bases import LexBase |
| 27 from pygments_lexer_pseudocode2.utils import REVERSED_STANDARD_TYPES | 28 from pygments_lexer_pseudocode2.utils import REVERSED_STANDARD_TYPES |
| 29 | |
| 30 | |
| 31 # | |
| 32 # As in the local imports: use an explicit name because __name__ is | |
| 33 # __builtins__ | |
| 34 # | |
| 35 _logger = logging.getLogger("pygments_lexer_pseudocode2.algpseudocode") | |
| 28 | 36 |
| 29 | 37 |
| 30 class AlgPseudocodeLexer(LexBase): | 38 class AlgPseudocodeLexer(LexBase): |
| 31 | 39 |
| 32 """A pseudocode lexer along the lines of CTAN's algpseudocode or | 40 """A pseudocode lexer along the lines of CTAN's algpseudocode or |
| 158 toktype = REVERSED_STANDARD_TYPES.get(needed_css, None) | 166 toktype = REVERSED_STANDARD_TYPES.get(needed_css, None) |
| 159 if toktype is None: | 167 if toktype is None: |
| 160 # Be more error friendly | 168 # Be more error friendly |
| 161 toktype = Generic.Error | 169 toktype = Generic.Error |
| 162 val = match.group() | 170 val = match.group() |
| 171 _logger.warning("Unhandled explicit token type: %s", val) | |
| 163 else: | 172 else: |
| 164 val = match.group("character") | 173 val = match.group("character") |
| 165 yield match.start(), toktype, val | 174 yield match.start(), toktype, val |
| 166 if ctx: | 175 if ctx: |
| 167 ctx.pos = match.end() | 176 ctx.pos = match.end() |
