comparison pygments_lexer_pseudocode2/bases.py @ 72:206017a08ed7

Refactor: Make the "op_space()" and related methods more flexible and allow a given fixed token type and value
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 28 Apr 2026 19:14:17 +0200
parents 2ea86269e84e
children a2a56d08b860
comparison
equal deleted inserted replaced
71:2ea86269e84e 72:206017a08ed7
8 __all__ = ["LexBase", "uni_name", "py_innerstring_rules", "py_name_rules"] 8 __all__ = ["LexBase", "uni_name", "py_innerstring_rules", "py_name_rules"]
9 9
10 10
11 from pygments import unistring 11 from pygments import unistring
12 from pygments.lexer import RegexLexer, combined, bygroups, include 12 from pygments.lexer import RegexLexer, combined, bygroups, include
13 from pygments.token import (Comment, Error, Name, Number, Other, String, 13 from pygments.token import (Comment, Error, Name, Number, Other, String)
14 Whitespace)
15 14
16 15
17 # 16 #
18 # SPDX-SnippetBegin 17 # SPDX-SnippetBegin
19 # SPDX-License-Identifier: BSD-2-Clause 18 # SPDX-License-Identifier: BSD-2-Clause
72 def op_ignore(lexer, match, ctx=None): 71 def op_ignore(lexer, match, ctx=None):
73 """Unconditionally ignore the match.""" 72 """Unconditionally ignore the match."""
74 if False: 73 if False:
75 yield match.start(), Other, "" 74 yield match.start(), Other, ""
76 75
77 def op_space(lexer, match, ctx=None): 76 def op_fixed(toktype, value):
78 """Unconditionally yield a single whitespace ' '.""" 77 """Unconditionally yield a given token type and value."""
79 yield match.start(), Whitespace, " " 78
79 def _op_fixed(lexer, match, ctx=None):
80 yield match.start(), toktype, value
81
82 return _op_fixed
80 83
81 tokens = { 84 tokens = {
82 # 85 #
83 # These states are borrowed from Pygment's Python lexer. 86 # These states are borrowed from Pygment's Python lexer.
84 # Their names have been prefixed with `py-'. 87 # Their names have been prefixed with `py-'.