FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cython lexer update by Spill-Tea · Pull Request #2933 · pygments/pygments · GitHub

43 changes: 22 additions & 21 deletions pygments/lexers/python.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ class CythonLexer(RegexLexer):
(r'(cp?def)(\s+)', bygroups(Keyword, Whitespace), 'cdef'),
# (should actually start a block with only cdefs)
(r'(cdef)(:)', bygroups(Keyword, Punctuation)),
(r'(class|struct)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
(r'(class|cppclass|struct)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
(r'(from)(\s+)', bygroups(Keyword, Whitespace), 'fromimport'),
(r'(c?import)(\s+)', bygroups(Keyword, Whitespace), 'import'),
include('builtins'),
Expand All @@ -879,37 +879,38 @@ class CythonLexer(RegexLexer):
],
'keywords': [
(words((
'assert', 'async', 'await', 'break', 'by', 'continue', 'ctypedef', 'del', 'elif',
'else', 'except', 'except?', 'exec', 'finally', 'for', 'fused', 'gil',
'global', 'if', 'include', 'lambda', 'nogil', 'pass', 'print',
'raise', 'return', 'try', 'while', 'yield', 'as', 'with'), suffix=r'\b'),
'assert', 'async', 'await', 'break', 'by', 'continue', 'ctypedef', 'del',
'elif', 'else', 'except', 'except?', 'exec', 'finally', 'for', 'fused', 'gil',
'global', 'if', 'include', 'lambda', 'namespace', 'new', 'noexcept','nogil',
'pass', 'print', 'raise', 'return', 'try', 'while', 'yield', 'as', 'with'),
suffix=r'\b'),
Keyword),
(words(('True', 'False', 'None', 'NULL'), suffix=r'\b'), Keyword.Constant),
(r'(DEF|IF|ELIF|ELSE)\b', Comment.Preproc),
],
'builtins': [
(words((
'__import__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bint',
'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr',
'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'char', 'chr',
'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'delattr',
'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit',
'dict', 'dir', 'divmod', 'double', 'enumerate', 'eval', 'execfile', 'exit',
'file', 'filter', 'float', 'frozenset', 'getattr', 'globals',
'hasattr', 'hash', 'hex', 'id', 'input', 'int', 'intern', 'isinstance',
'issubclass', 'iter', 'len', 'list', 'locals', 'long', 'map', 'max',
'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'Py_ssize_t',
'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed',
'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod',
'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'unsigned',
'vars', 'xrange', 'zip'), prefix=r'(?<!\.)', suffix=r'\b'),
'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'property',
'Py_ssize_t', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed',
'round', 'set', 'setattr', 'size_t', 'slice', 'sorted', 'staticmethod',
'ssize_t', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode',
'unsigned', 'vars', 'xrange', 'zip'), prefix=r'(?<!\.)', suffix=r'\b'),
Name.Builtin),
(r'(?<!\.)(self|None|Ellipsis|NotImplemented|False|True|NULL'
r')\b', Name.Builtin.Pseudo),
(r'(?<!\.)(self|cls|Ellipsis|NotImplemented)\b', Name.Builtin.Pseudo),
(words((
'ArithmeticError', 'AssertionError', 'AttributeError',
'BaseException', 'DeprecationWarning', 'EOFError', 'EnvironmentError',
'Exception', 'FloatingPointError', 'FutureWarning', 'GeneratorExit',
'IOError', 'ImportError', 'ImportWarning', 'IndentationError',
'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError',
'MemoryError', 'NameError', 'NotImplemented', 'NotImplementedError',
'MemoryError', 'NameError', 'NotImplementedError',
'OSError', 'OverflowError', 'OverflowWarning',
'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError',
'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError',
Expand Down Expand Up @@ -938,12 +939,12 @@ class CythonLexer(RegexLexer):
(r'[a-zA-Z_]\w*', Name.Function, '#pop')
],
'cdef': [
(r'(public|readonly|extern|api|inline)\b', Keyword.Reserved),
(r'(struct|enum|union|class)\b', Keyword),
(r'([a-zA-Z_]\w*)(\s*)(?=[(:#=]|$)',
bygroups(Name.Function, Whitespace), '#pop'),
(r'([a-zA-Z_]\w*)(\s*)(,)',
bygroups(Name.Function, Whitespace, Punctuation)),
(r"(public|readonly|extern|api|inline|packed)\b", Keyword.Reserved),
(r"(struct|enum|union|class|cppclass)\b(\s+)([a-zA-Z_]\w*)",
bygroups(Keyword, Whitespace, Name.Class), "#pop",),
(r"([a-zA-Z_]\w*)(\s*)(?=\()", bygroups(Name.Function, Whitespace), "#pop"),
(r"([a-zA-Z_]\w*)(\s*)(?=[:,=#\n]|$)", bygroups(Name.Variable, Whitespace), "#pop"),
(r"([a-zA-Z_]\w*)(\s*)(,)", bygroups(Name.Variable, Whitespace, Punctuation)),
(r'from\b', Keyword, '#pop'),
(r'as\b', Keyword),
(r':', Punctuation, '#pop'),
Expand Down
12 changes: 12 additions & 0 deletions tests/snippets/cython/test_builtin_pseudo.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---input---
self cls Ellipsis NotImplemented

---tokens---
'self' Name.Builtin.Pseudo
' ' Text
'cls' Name.Builtin.Pseudo
' ' Text
'Ellipsis' Name.Builtin.Pseudo
' ' Text
'NotImplemented' Name.Builtin.Pseudo
'\n' Text.Whitespace
Loading
Loading

Back | FazBrowse Home | New Git URL