comparison pygments_lexer_pseudocode2/lexers/algpseudocode.py @ 289:6fc7f9c1d89d

Remove the old implementation of explicit token types completely
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 22 May 2026 12:41:08 +0200
parents 298841bc4dee
children
comparison
equal deleted inserted replaced
288:298841bc4dee 289:6fc7f9c1d89d
220 yield match.start(), toktype, lexer.SYMBOLS.get(kw, kw) 220 yield match.start(), toktype, lexer.SYMBOLS.get(kw, kw)
221 if ctx: 221 if ctx:
222 ctx.pos = match.end() 222 ctx.pos = match.end()
223 223
224 return _op_symbol 224 return _op_symbol
225
226 def op_explicit_tokentype(lexer, match, ctx=None):
227 needed_css = match.group("type")
228 toktype = REVERSED_STANDARD_TYPES.get(needed_css, None)
229 if toktype is None:
230 # Be more error friendly
231 toktype = Generic.Error
232 val = match.group()
233 _logger.warning("Unhandled explicit token type: %s", val)
234 else:
235 val = match.group("characters")
236 yield match.start(), toktype, val
237 if ctx:
238 ctx.pos = match.end()
239 225
240 def op_explicit_tokentype_ex_start(lexer, match, ctx): 226 def op_explicit_tokentype_ex_start(lexer, match, ctx):
241 needed_css = match.group("type") 227 needed_css = match.group("type")
242 toktype = REVERSED_STANDARD_TYPES.get(needed_css, None) 228 toktype = REVERSED_STANDARD_TYPES.get(needed_css, None)
243 if toktype is None: 229 if toktype is None:
537 # New extended (more flexible, allows escaping) 523 # New extended (more flexible, allows escaping)
538 # 524 #
539 (r"""\\ttX[ \t]*\{(?P<type>[^}]*)\}[ \t]*\{""", 525 (r"""\\ttX[ \t]*\{(?P<type>[^}]*)\}[ \t]*\{""",
540 op_explicit_tokentype_ex_start, 526 op_explicit_tokentype_ex_start,
541 "extended-explicit-tokentype"), 527 "extended-explicit-tokentype"),
542
543 #
544 # Old variants
545 #
546
547 # Multiple characters possible, but no escaping!
548 (r"""\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)"""
549 r"""(?P<sep>[/?.,:;%|=*+!\\$~"'#@_-])"""
550 r"""(?P<characters>(.|\n)+?)(?P=sep)""",
551 op_explicit_tokentype),
552 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)\{(?P<characters>[^}]+?)\}",
553 op_explicit_tokentype),
554 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)\((?P<characters>[^)]+?)\)",
555 op_explicit_tokentype),
556 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)<(?P<characters>[^>]+?)>",
557 op_explicit_tokentype),
558 (r"\\ttx\-(?P<type>[a-zA-Z0-9_-]+?)\[(?P<characters>[^\]]+?)\]",
559 op_explicit_tokentype),
560
561 # Every character is possible: no escaping needed!
562 (r"\\tt-(?P<type>[^/]+?)/(?P<characters>(?:.|\n))",
563 op_explicit_tokentype),
564 ], 528 ],
565 "extended-explicit-tokentype": [ 529 "extended-explicit-tokentype": [
566 (r"([^\\}]+)", op_explicit_tokentype_ex_value), 530 (r"([^\\}]+)", op_explicit_tokentype_ex_value),
567 (r"\}", op_explicit_tokentype_ex_end, "#pop"), 531 (r"\}", op_explicit_tokentype_ex_end, "#pop"),
568 (r"\\(\})", op_explicit_tokentype_ex_value), 532 (r"\\(\})", op_explicit_tokentype_ex_value),