Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison pygments_lexer_pseudocode2/algpseudocode.py @ 65:3f4223a79d2b
Normalize whitespace handling for entity names
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 28 Apr 2026 13:05:15 +0200 |
| parents | 05c53e431c88 |
| children | 5517b0be67f0 |
comparison
equal
deleted
inserted
replaced
| 64:05c53e431c88 | 65:3f4223a79d2b |
|---|---|
| 110 def _op_opt_ignore(lexer, match, ctx=None): | 110 def _op_opt_ignore(lexer, match, ctx=None): |
| 111 if not lexer.no_end: | 111 if not lexer.no_end: |
| 112 yield match.start(), toktype, match.group() | 112 yield match.start(), toktype, match.group() |
| 113 | 113 |
| 114 return _op_opt_ignore | 114 return _op_opt_ignore |
| 115 | |
| 116 def op_opt_ignore_or_space(lexer, match, ctx=None): | |
| 117 """Yield a single whitespace ' ' or nothing -- depending on the lexer's | |
| 118 `no_end` setting. | |
| 119 | |
| 120 """ | |
| 121 if not lexer.no_end: | |
| 122 yield match.start(), Whitespace, " " | |
| 115 | 123 |
| 116 def op_symbol(toktype): | 124 def op_symbol(toktype): |
| 117 | 125 |
| 118 def _op_symbol(lexer, match, ctx=None): | 126 def _op_symbol(lexer, match, ctx=None): |
| 119 kw = match.group().upper() | 127 kw = match.group().upper() |
| 135 r"(?:prog(?:ram)?)" | 143 r"(?:prog(?:ram)?)" |
| 136 r"|(?:algo(?:rithm)?)" | 144 r"|(?:algo(?:rithm)?)" |
| 137 r"|(?:proc(?:edure)?)" | 145 r"|(?:proc(?:edure)?)" |
| 138 r"|(?:func(?:tion)?|(?:fn))" | 146 r"|(?:func(?:tion)?|(?:fn))" |
| 139 r"|(?:class)" | 147 r"|(?:class)" |
| 140 r")(\s*)(\{)", | 148 r")\s*(\{)", |
| 141 bygroups(op_translate(Keyword), Whitespace, LexBase.op_ignore), | 149 bygroups(op_translate(Keyword), LexBase.op_space), |
| 142 "entity-name"), | 150 "entity-name"), |
| 143 # ENDxxx keywords with optional entity name | 151 # ENDxxx keywords with optional entity name |
| 144 # with name | 152 # with name |
| 145 (r"(?i)\\end(?:_|-)?(" | 153 (r"(?i)\\end(?:_|-)?(" |
| 146 r"(?:prog(?:ram)?)" | 154 r"(?:prog(?:ram)?)" |
| 147 r"|(?:algo(?:rithm)?)" | 155 r"|(?:algo(?:rithm)?)" |
| 148 r"|(?:proc(?:edure)?)" | 156 r"|(?:proc(?:edure)?)" |
| 149 r"|(?:func(?:tion)?)" | 157 r"|(?:func(?:tion)?)" |
| 150 r"|(?:class)" | 158 r"|(?:class)" |
| 151 r")(\s*)(\{)", | 159 r")\s*(\{)", |
| 152 bygroups(op_opt_end_translate(Keyword), | 160 bygroups(op_opt_end_translate(Keyword), |
| 153 op_opt_ignore(Whitespace), | 161 op_opt_ignore_or_space), |
| 154 LexBase.op_ignore), | |
| 155 "entity-name-end"), | 162 "entity-name-end"), |
| 156 # without name | 163 # without name |
| 157 (r"(?i)\\end(?:_|-)?(" | 164 (r"(?i)\\end(?:_|-)?(" |
| 158 r"(?:prog(?:ram)?)" | 165 r"(?:prog(?:ram)?)" |
| 159 r"|(?:algo(?:rithm)?)" | 166 r"|(?:algo(?:rithm)?)" |
