Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison pygments_lexer_pseudocode2/bases.py @ 52:5bfa9113d3c4
First tests with "py-name": names from the Python lexer
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 26 Apr 2026 18:58:44 +0200 |
| parents | bbef0ac6cfcf |
| children | 661461fb4dfc |
comparison
equal
deleted
inserted
replaced
| 51:b4c255f8bdc4 | 52:5bfa9113d3c4 |
|---|---|
| 6 r"""Some common bases for the lexers.""" | 6 r"""Some common bases for the lexers.""" |
| 7 | 7 |
| 8 __all__ = ["LexBase"] | 8 __all__ = ["LexBase"] |
| 9 | 9 |
| 10 | 10 |
| 11 from pygments import unistring | |
| 11 from pygments.lexer import RegexLexer, combined, bygroups, include | 12 from pygments.lexer import RegexLexer, combined, bygroups, include |
| 12 from pygments.token import Error, Name, Number, String, Comment | 13 from pygments.token import Error, Name, Number, String, Comment |
| 13 | 14 |
| 14 | 15 |
| 15 class LexBase(RegexLexer): | 16 class LexBase(RegexLexer): |
| 23 # | 24 # |
| 24 # SPDX-SnippetBegin | 25 # SPDX-SnippetBegin |
| 25 # SPDX-License-Identifier: BSD-2-Clause | 26 # SPDX-License-Identifier: BSD-2-Clause |
| 26 # SPDX-SnippetCopyrightText: Copyright 2006-2023 by the Pygments team | 27 # SPDX-SnippetCopyrightText: Copyright 2006-2023 by the Pygments team |
| 27 # | 28 # |
| 29 | |
| 30 uni_name = "[%s][%s]*" % (unistring.xid_start, unistring.xid_continue) | |
| 31 | |
| 28 def py_innerstring_rules(ttype): | 32 def py_innerstring_rules(ttype): |
| 29 return [ | 33 return [ |
| 30 # the old style '%s' % (...) string formatting (still valid in Py3) | 34 # the old style '%s' % (...) string formatting (still valid in Py3) |
| 31 (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' | 35 (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' |
| 32 '[hlL]?[E-GXc-giorsaux%]', String.Interpol), | 36 '[hlL]?[E-GXc-giorsaux%]', String.Interpol), |
| 117 include('py-strings-single'), | 121 include('py-strings-single'), |
| 118 (r'\n', String.Single) | 122 (r'\n', String.Single) |
| 119 ], | 123 ], |
| 120 'py-strings-single': py_innerstring_rules(String.Single), | 124 'py-strings-single': py_innerstring_rules(String.Single), |
| 121 'py-strings-double': py_innerstring_rules(String.Double), | 125 'py-strings-double': py_innerstring_rules(String.Double), |
| 126 'py-name': [ | |
| 127 # We recognize decorator syntax here | |
| 128 (r'@' + uni_name, Name.Decorator), | |
| 129 # | |
| 130 # Python's new matrix multiplication operator: | |
| 131 # not used here in pseudocode | |
| 132 # (r'@', Operator), | |
| 133 (uni_name, Name), | |
| 134 ], | |
| 122 # SPDX-SnippetEnd | 135 # SPDX-SnippetEnd |
| 123 # This snippet is from the Pygments' documentation "Write your own lexer" | 136 # This snippet is from the Pygments' documentation "Write your own lexer" |
| 124 'multiline-nested-comment': [ | 137 'multiline-nested-comment': [ |
| 125 (r'[^*/]+', Comment.Multiline), | 138 (r'[^*/]+', Comment.Multiline), |
| 126 (r'/\*', Comment.Multiline, '#push'), | 139 (r'/\*', Comment.Multiline, '#push'), |
