diff options
author | Christopher Di Bella <cjdb.ns@gmail.com> | 2023-04-26 00:39:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-26 09:39:19 +0200 |
commit | 8f6bc3ae436a4f04f71cd14c01a48266498f2f4d (patch) | |
tree | 0997ae3dbed7892e1bf5da137c7a5d006a299884 | |
parent | adc6a48a17fe7fb7bfa81edbbf550bb9796869b6 (diff) | |
download | pygments-git-8f6bc3ae436a4f04f71cd14c01a48266498f2f4d.tar.gz |
Updates C and C++ lexers (#2422)
* replaces `restrict` with `__restrict` in C++
`restrict` isn't a C++ keyword, but `__restrict` is recognised by Clang,
GCC, and MSVC as a language extension.
* adds `_BitInt` and `__int128` as C and C++ types
* `_BitInt` is a new C type and an extended integral type for C++.
* `__int128` is an extended integral type on both Clang and GCC.
-rw-r--r-- | pygments/lexers/c_cpp.py | 5 | ||||
-rw-r--r-- | tests/snippets/c/builtin_types.txt | 13 | ||||
-rw-r--r-- | tests/snippets/cpp/extension_keywords.txt | 17 |
3 files changed, 33 insertions, 2 deletions
diff --git a/pygments/lexers/c_cpp.py b/pygments/lexers/c_cpp.py index aed8b4a4..ba6702f5 100644 --- a/pygments/lexers/c_cpp.py +++ b/pygments/lexers/c_cpp.py @@ -107,7 +107,8 @@ class CFamilyLexer(RegexLexer): (words(('int8', 'int16', 'int32', 'int64', 'wchar_t'), prefix=r'__', suffix=r'\b'), Keyword.Reserved), (words(('bool', 'int', 'long', 'float', 'short', 'double', 'char', - 'unsigned', 'signed', 'void'), suffix=r'\b'), Keyword.Type) + 'unsigned', 'signed', 'void', '_BitInt', + '__int128'), suffix=r'\b'), Keyword.Type) ], 'keywords': [ (r'(struct|union)(\s+)', bygroups(Keyword, Whitespace), 'classname'), @@ -380,7 +381,7 @@ class CppLexer(CFamilyLexer): 'catch', 'const_cast', 'delete', 'dynamic_cast', 'explicit', 'export', 'friend', 'mutable', 'new', 'operator', 'private', 'protected', 'public', 'reinterpret_cast', 'class', - 'restrict', 'static_cast', 'template', 'this', 'throw', 'throws', + '__restrict', 'static_cast', 'template', 'this', 'throw', 'throws', 'try', 'typeid', 'using', 'virtual', 'constexpr', 'nullptr', 'concept', 'decltype', 'noexcept', 'override', 'final', 'constinit', 'consteval', 'co_await', 'co_return', 'co_yield', 'requires', 'import', 'module', diff --git a/tests/snippets/c/builtin_types.txt b/tests/snippets/c/builtin_types.txt new file mode 100644 index 00000000..86778593 --- /dev/null +++ b/tests/snippets/c/builtin_types.txt @@ -0,0 +1,13 @@ +---input--- +__int128 +_BitInt(2) + +---tokens--- +'__int128' Keyword.Type +'\n' Text.Whitespace + +'_BitInt' Keyword.Type +'(' Punctuation +'2' Literal.Number.Integer +')' Punctuation +'\n' Text.Whitespace diff --git a/tests/snippets/cpp/extension_keywords.txt b/tests/snippets/cpp/extension_keywords.txt new file mode 100644 index 00000000..e47eb339 --- /dev/null +++ b/tests/snippets/cpp/extension_keywords.txt @@ -0,0 +1,17 @@ +---input--- +__restrict +__int128 +_BitInt(2) + +---tokens--- +'__restrict' Keyword +'\n' Text.Whitespace + +'__int128' Keyword.Type +'\n' Text.Whitespace + +'_BitInt' Keyword.Type +'(' Punctuation +'2' Literal.Number.Integer +')' Punctuation +'\n' Text.Whitespace |