Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison pygments_lexer_pseudocode2/algpseudocode.py @ 83:cd79d2c76347
If a Pygments callback gets a "Context" it must set the new position explicitely.
This is **not** done automatically.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 30 Apr 2026 13:21:38 +0200 |
| parents | 36a0ef76a6d7 |
| children | 3ac1c4502ad0 |
comparison
equal
deleted
inserted
replaced
| 82:36a0ef76a6d7 | 83:cd79d2c76347 |
|---|---|
| 97 def op_translate(toktype): | 97 def op_translate(toktype): |
| 98 | 98 |
| 99 def _op_translate(lexer, match, ctx=None): | 99 def _op_translate(lexer, match, ctx=None): |
| 100 kw = match.group().upper() | 100 kw = match.group().upper() |
| 101 yield match.start(), toktype, lexer.TRANSLATIONS.get(kw, kw) | 101 yield match.start(), toktype, lexer.TRANSLATIONS.get(kw, kw) |
| 102 if ctx: | |
| 103 ctx.pos = match.end() | |
| 102 | 104 |
| 103 return _op_translate | 105 return _op_translate |
| 104 | 106 |
| 105 def op_opt_end_translate(toktype): | 107 def op_opt_end_translate(toktype): |
| 106 | 108 |
| 110 yield (match.start(), | 112 yield (match.start(), |
| 111 toktype, | 113 toktype, |
| 112 lexer.END_TRANSLATIONS.get( | 114 lexer.END_TRANSLATIONS.get( |
| 113 kw, | 115 kw, |
| 114 lexer.DEFAULT_END_PREFIX + kw)) | 116 lexer.DEFAULT_END_PREFIX + kw)) |
| 117 if ctx: | |
| 118 ctx.pos = match.end() | |
| 115 | 119 |
| 116 return _op_end_translate | 120 return _op_end_translate |
| 117 | 121 |
| 118 def op_opt_ignore(toktype): | 122 def op_opt_ignore(toktype): |
| 119 | 123 |
| 120 def _op_opt_ignore(lexer, match, ctx=None): | 124 def _op_opt_ignore(lexer, match, ctx=None): |
| 121 if not lexer.no_end: | 125 if not lexer.no_end: |
| 122 yield match.start(), toktype, match.group() | 126 yield match.start(), toktype, match.group() |
| 127 if ctx: | |
| 128 ctx.pos = match.end() | |
| 123 | 129 |
| 124 return _op_opt_ignore | 130 return _op_opt_ignore |
| 125 | 131 |
| 126 def op_opt_ignore_or_fixed(toktype, value): | 132 def op_opt_ignore_or_fixed(toktype, value): |
| 127 """Yield a fixed given token type and value or -- if the lexer's | 133 """Yield a fixed given token type and value or -- if the lexer's |
| 130 """ | 136 """ |
| 131 | 137 |
| 132 def _op_opt_ignore_or_fixed(lexer, match, ctx=None): | 138 def _op_opt_ignore_or_fixed(lexer, match, ctx=None): |
| 133 if not lexer.no_end: | 139 if not lexer.no_end: |
| 134 yield match.start(), toktype, value | 140 yield match.start(), toktype, value |
| 141 if ctx: | |
| 142 ctx.pos = match.end() | |
| 135 | 143 |
| 136 return _op_opt_ignore_or_fixed | 144 return _op_opt_ignore_or_fixed |
| 137 | 145 |
| 138 def op_symbol(toktype): | 146 def op_symbol(toktype): |
| 139 | 147 |
| 140 def _op_symbol(lexer, match, ctx=None): | 148 def _op_symbol(lexer, match, ctx=None): |
| 141 kw = match.group().upper() | 149 kw = match.group().upper() |
| 142 yield match.start(), toktype, lexer.SYMBOLS.get(kw, kw) | 150 yield match.start(), toktype, lexer.SYMBOLS.get(kw, kw) |
| 151 if ctx: | |
| 152 ctx.pos = match.end() | |
| 143 | 153 |
| 144 return _op_symbol | 154 return _op_symbol |
| 145 | 155 |
| 146 tokens = { | 156 tokens = { |
| 147 "root": [ | 157 "root": [ |
