diff 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
line wrap: on
line diff
--- a/pygments_lexer_pseudocode2/bases.py	Sun Apr 26 15:38:28 2026 +0200
+++ b/pygments_lexer_pseudocode2/bases.py	Sun Apr 26 18:58:44 2026 +0200
@@ -8,6 +8,7 @@
 __all__ = ["LexBase"]
 
 
+from pygments import unistring
 from pygments.lexer import RegexLexer, combined, bygroups, include
 from pygments.token import Error, Name, Number, String, Comment
 
@@ -25,6 +26,9 @@
 # SPDX-License-Identifier: BSD-2-Clause
 # SPDX-SnippetCopyrightText: Copyright 2006-2023 by the Pygments team
 #
+
+    uni_name = "[%s][%s]*" % (unistring.xid_start, unistring.xid_continue)
+
     def py_innerstring_rules(ttype):
         return [
             # the old style '%s' % (...) string formatting (still valid in Py3)
@@ -119,6 +123,15 @@
         ],
         'py-strings-single': py_innerstring_rules(String.Single),
         'py-strings-double': py_innerstring_rules(String.Double),
+        'py-name': [
+            # We recognize decorator syntax here
+            (r'@' + uni_name, Name.Decorator),
+            #
+            # Python's new matrix multiplication operator:
+            # not used here in pseudocode
+            # (r'@', Operator),
+            (uni_name, Name),
+        ],
 # SPDX-SnippetEnd
     # This snippet is from the Pygments' documentation "Write your own lexer"
     'multiline-nested-comment': [