comparison pygments_lexer_pseudocode2/lexers/algpseudocode.py @ 288:298841bc4dee

Allow "normal" Pygments token names in "\ttX" ("Error", "Text.Whitespace", ...)
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 22 May 2026 12:32:38 +0200
parents 051c8877ee22
children 6fc7f9c1d89d
comparison
equal deleted inserted replaced
287:f506d752e801 288:298841bc4dee
24 # 24 #
25 # Relative imports do not work with pygments.lexers.load_lexer_from_file() 25 # Relative imports do not work with pygments.lexers.load_lexer_from_file()
26 # in all of our supported Python releases. 26 # in all of our supported Python releases.
27 # 27 #
28 from pygments_lexer_pseudocode2.lexers.bases import LexBase 28 from pygments_lexer_pseudocode2.lexers.bases import LexBase
29 from pygments_lexer_pseudocode2.utils import REVERSED_STANDARD_TYPES 29 from pygments_lexer_pseudocode2.utils import (
30 REVERSED_STANDARD_TYPES, string_to_defined_tokentype)
30 from pygments_lexer_pseudocode2 import uniprops 31 from pygments_lexer_pseudocode2 import uniprops
31 32
32 # 33 #
33 # As in the local imports: use an explicit name because __name__ is 34 # As in the local imports: use an explicit name because __name__ is
34 # __builtins__ 35 # __builtins__
238 239
239 def op_explicit_tokentype_ex_start(lexer, match, ctx): 240 def op_explicit_tokentype_ex_start(lexer, match, ctx):
240 needed_css = match.group("type") 241 needed_css = match.group("type")
241 toktype = REVERSED_STANDARD_TYPES.get(needed_css, None) 242 toktype = REVERSED_STANDARD_TYPES.get(needed_css, None)
242 if toktype is None: 243 if toktype is None:
243 if not lexer.strict_tokentype: 244 if lexer.strict_tokentype:
245 toktype = string_to_defined_tokentype(needed_css)
246 if toktype is None:
247 _logger.warning(
248 "Unhandled explicit token type: %s", needed_css)
249 else:
244 toktype = string_to_tokentype(needed_css) 250 toktype = string_to_tokentype(needed_css)
245 if toktype is None: 251 if toktype is None:
246 _logger.warning( 252 _logger.warning(
247 "Unhandled explicit token type: %s", needed_css) 253 "Unhandled explicit token type: %s", needed_css)
248 else: 254 else:
249 _logger.debug( 255 _logger.debug(
250 "Synthesized new token type: %s", needed_css) 256 "New token type may have been synthesized: %s",
251 else: 257 needed_css)
252 _logger.warning(
253 "Unhandled explicit token type: %s", needed_css)
254 if toktype is None: 258 if toktype is None:
255 # Be more error friendly 259 # Be more error friendly
256 ctx.explicit_token_type = Generic.Error 260 ctx.explicit_token_type = Generic.Error
257 yield match.start(), ctx.explicit_token_type, match.group() 261 yield match.start(), ctx.explicit_token_type, match.group()
258 else: 262 else:
530 # All these REs are CASE-SENSITIVE! 534 # All these REs are CASE-SENSITIVE!
531 535
532 # 536 #
533 # New extended (more flexible, allows escaping) 537 # New extended (more flexible, allows escaping)
534 # 538 #
535 (r"""\\ttX[ \t]*\{(?P<type>[^}]+)\}[ \t]*\{""", 539 (r"""\\ttX[ \t]*\{(?P<type>[^}]*)\}[ \t]*\{""",
536 op_explicit_tokentype_ex_start, 540 op_explicit_tokentype_ex_start,
537 "extended-explicit-tokentype"), 541 "extended-explicit-tokentype"),
538 542
539 # 543 #
540 # Old variants 544 # Old variants