summaryrefslogtreecommitdiff
path: root/pygments/lexers/c_cpp.py
Commit message (Collapse)AuthorAgeFilesLines
* Updates C and C++ lexers (#2422)Christopher Di Bella2023-04-261-2/+3
| | | | | | | | | | | * 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.
* adds C++ alternative tokens as keywords (#2421)Christopher Di Bella2023-04-261-1/+2
|
* Update copyright year to 2023.Matthäus G. Chajdas2023-03-291-1/+1
|
* all: style fixesGeorg Brandl2022-10-271-19/+31
|
* CFamilyLexer: Fix matching of function parameters (#2210)amitkummer2022-08-181-8/+8
| | | | | | | | | | | | | | This fixes an issue where in code like this: ``` int foo(float bar) // hello() {} ``` The lexer would match `(float bar) // hello()` as the parameters of the function `foo`, instead of just `(float bar)`. In addition, a similar test case to what was originally reported in #2208 is added.
* CFamilyLexer: refuse quotes between parentheses for function definitions and ↵Jean Abou-Samra2022-08-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | declarations (#2208) Something like id id2("){ ... }"); is no longer wrongly recognized as a "function" id id2(") { ... } "); As the difference in the tests shows, this has the unfortunate side effect that we no longer highlight something like int f(param="default"); as a function declaration, but it is hard to imagine another way to fix this (cf. “most vexing parse” problem). Fixes #2207
* Fix comments within function declarations in C (#1891) (#2140)lambda-karlculus2022-05-301-12/+29
| | | Co-authored-by: Jean Abou Samra <jean@abou-samra.fr>
* Rework URL information in lexers.Matthäus G. Chajdas2022-03-201-0/+1
| | | | | | | | This commit adds a new url field to a lexer, which can be used to link to the language website, instead of relying on having the link in either languages.rst or the docstring of the lexer. Additionally, it changes the languages.rst file to auto-generate the list of lexers from the actual source code, using the provided URL.
* CFamily: Lex identifiers after `case` as constants (#2084)amitkummer2022-03-121-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Lex identifiers after `case` as constants Add a state for marking identifiers preceded by a `case` keyword as constants. Additionally, refactor the `label` rule to no longer permit a `case` keyword before a label. Consequentially, identifiers after a `case` keyword (like `foo` in `case foo:`) are no longer wrongly lexed as `Name.Label`, but as `Name.Constant`. In addition, this fixes #2076, as multiple `case` keywords in one line are lexed the same. * Add test for multiple `case` keywords in one line * Fix existing tests * Lex `::` as Operator and not Name.Constant After a `case`, when lexing a namespaced name, like `foo::bar`, lex the namespace operator `::` as Operator, and not Name.Constant. * Regenerate tokens
* Happy new year.Georg Brandl2022-01-251-1/+1
|
* Fix typos (#2030)Kian-Meng Ang2022-01-181-1/+1
|
* Add .tpp as a c++ lexer file extension (#2031)HampusMat2022-01-111-1/+1
|
* CFamily: improve label detection (#2022)amitkummer2022-01-061-6/+4
| | | | | | | | | | | | | | | | * Remove unused variable This variable is unused since the first commit to this file in the commit history, so it's probably safe to remove it. * Lex identifier as label only if it's at line start * Stop matching identifiers that begin with a digit This is so we don't match numbers as labels with the new labels rule. * Add label tests * Fix existing tests
* CFamily: improve function detection (#2008)amitkummer2021-12-301-2/+3
| | | | Detect function with return types of more than a single word length (like `unsigned int` or `long long`).
* feat(lexers): associate XBM and XPM with C code (#1802)Ville Skyttä2021-12-281-2/+2
|
* Refactor identifiers regex to match unicode characters (#1848)amitkummer2021-10-151-2/+2
|
* Fix #1237 cpp whitespace token usage expanded (#1904)Sebastian Engel2021-10-021-4/+4
| | | | | * Fix #1237 cpp whitespace token usage expanded * Adapt tests change to 3eff56f5
* Use the correct whitespace token for the C family.Matthäus G. Chajdas2021-06-201-3/+3
| | | | The CFamilyLexer was matching whitespace as Text instead of Whitespace.
* Fix CFamilyLexer preprocessor tokenization errors (#1830)Henrik Lievonen2021-06-201-1/+1
| | | | | | | | | | | | CFamilyLexer failed to tokenize preprocessor macros when they were preceded by line break surrounded by spaces. This was the case because prerpocessor regex rule expected to start at the beginning of the line, but the space regex rule matched also the whitespace after the line break. Now the space rule has been refined not to match the line break. Because of this, the preprocessor regex rule correctly matches prerpocessor tokens even when they are preceded by white spaces, at the cost of adding some more tokens in the token stream in some cases. This change preserves the behavior of invalid preprocessor usage failing to tokenize.
* Support for OMG IDL (#1595)Fred Hornsey2021-05-021-2/+4
| | | | | | | | | | | | | | | | | | * Support for OMG IDL Lexer for [Object Management Group Interface Definition Language](https://www.omg.org/spec/IDL/About-IDL/). * Allow Whitespace Before include in C Preprocessor It wasn't highlighting the included filename the same as if there was no space before the include, but now it is. * Update omg-idl Tests to Latest Requirements * Update omg-idl versionadded to 2.9 Since I just realized this missed the 2.8 release. * Add Missing Operators to omg-idl
* Refactor CFamilyLexer (#1746)amitkummer2021-03-141-10/+7
| | | | | | | | | | | | | | * Remove duplicate lines in state * Refactor ident regex for readability Refactor ident regex changed in c1a0d82 to improve readability. Refactor namespaced_ident regex added in c1a0d82 to improve readability. * Fix inline keword lexing * Fix indentation * Refactor CLexer keywords to 'keywords' state
* Fixes for C and C++ functions and namespaces (#1722)amitkummer2021-02-271-28/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix lexing of function names This fixes #1561. Add a keywords state that matches inside and outside functions for keywords. Before this, when a keyword would appear the lexer would go to the statements state, in which functions were not matched. * Add tests for lexing of function names * Unbreak previous tests * Allow namespaced names in function statements Add a second identifiers regex that matces all the previous identifiers and also '::'. I took the decision to create a second identifiers regex with '::' inside, simply because using the old identifiers regex would hurt performance massively on every solution I tried to craft. * Add tests for namespaced names in functions * Unbreak previous tests * Add support for namespaces in namespace declarations Add a namespace state that is entered each time the namespace keyword is matched and lexes all name matches as namespaces. Cases this approach doesn't cover: * Namespaces in using declarations. * Namespaces that prefix names in random code. Unfortunately, in both of these cases the names before and after '::' are not always namespaces. * Add tests for namespace declartions * Unbreak previous tests * Tidy functions regex Remove group nesting that became unneeded after fc56ab8 (the last big refactor). * Remove f string usage I introduced by mistake
* Fix mishandling '*/' in C/C++ and related (fixes #1695)Georg Brandl2021-01-291-2/+1
|
* Run pyupgrade across codebase to modernize syntax and patterns (#1622)Jon Dufresne2021-01-171-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | pyupgrade is a tool to automatically upgrade syntax for newer versions of the Python language. The project has been Python 3 only since 35544e2fc6eed0ce4a27ec7285aac71ff0ddc473, allowing for several cleanups: - Remove unnecessary "-*- coding: utf-8 -*-" cookie. Python 3 reads all source files as utf-8 by default. - Replace IOError/EnvironmentError with OSError. Python 3 unified these exceptions. The old names are aliases only. - Use the Python 3 shorter super() syntax. - Remove "utf8" argument form encode/decode. In Python 3, this value is the default. - Remove "r" from open() calls. In Python 3, this value is the default. - Remove u prefix from Unicode strings. In Python 3, all strings are Unicode. - Replace io.open() with builtin open(). In Python 3, these functions are functionally equivalent. Co-authored-by: Matthäus G. Chajdas <Anteru@users.noreply.github.com>
* Bump copyright year.Matthäus G. Chajdas2021-01-031-1/+1
|
* Update copyright year (fixes #1514.)Matthäus G. Chajdas2020-08-221-1/+1
|
* General improvement to the C/C++ lexer (#1350)Hubert Gruniaux2020-05-221-35/+126
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * General improvement to the C/C++ lexer * Add missing C11 keywords Add '_Imaginary', '_Static_assert', '_Atomic' keywords. * Highlight C11 std atomic types (#906) Add support for C11 atomic types `atomic_*`. * Extended character literals prefixes for C/C++ Add support for `u'a'`, `U'a'` (C++11, C11), and `u8'a'` (C++17, C2x). [Reference](https://en.cppreference.com/w/cpp/language/character_literal). [Reference](https://en.cppreference.com/w/c/language/character_constant). * Fix bad floating point highlighting in C lexer Fix bad highlighting for `5.`, where `.` was not highlighted. * Fix hex floating literal highlighting in C Hexadecimal floating point literals needs an exponent (`0x5p8`). Before this commit, event floating-point literals without an exponent were accepted (e.g. `0x5.5`). * Support '$' in identifiers, C/C++ Some old C/C++ compilers have supported `$` (dollar sign) in identifiers, and some news continue to support this for legacy reasons. That is, some codes may use them, and it is therefore preferable to color them correctly. * Cleaning and fixing some bugs in C/C++ lexer - Add '_Pragma' keyword - Recognize the identifier following 'typename' as Name.Class - Do not tokenize 'class' or 'struct' following 'enum' as Name.Class, but instead as Keyword (C++ lexer) - Move some C++ keywords to the generic lexer (`alignas`, `alignof`, etc...) - Add some C keywords (`noreturn`, `imaginary`, `complex`) - And others things... * Fix building errors in C/C++ lexer * Fix bug in C/C++ Now `class`, `struct`, `enum`, `union`, etc... can be used alone. Previously, the lexer do not recognizes them if they are not followed by an identifier. This regression was introduced in https://github.com/pygments/pygments/pull/1350/commits/013bf6af2777f6ba444e2c8e3a8ca3ad1bb1e674 by me. * Reuse old states names for C/C++ Some lexers depends on the old states names (e.g. `classname` state) to works. This commit, reintroduce these old names. * Improve C/C++ lexer documentation * Correct english errors in C lexer documentation * Cleaning and Unicode literals for C * Move Unicode literals from C++ to generic C * Remove useless 'classname' state in ECLexer * Revert "Remove useless 'classname' state in ECLexer" This reverts commit 89a0c138fbcc70883d8035b0585b7e94e49f73cc. * Revert "Revert "Remove useless 'classname' state in ECLexer"" This reverts commit 2d4734308a813abec6a17ea7fa6eb3a0b6f57939. * Add support for UCNs in C and C++ * Apply correction from #1162 Solves #1162 * Correctly highlights negatives numbers in C++ * Revert some changes from 8fe8ed6 * Add unicode suffixes to C++ raw string literals * Solves #1166 * Fix previous regression in C like lexer * Fix invalid regex in C like lexer * Fix #1396 and now are identifiers support UCNs in C and C++ lexer * Update AUTHORS * Add missing Python raw string prefix Co-authored-by: Hubert Gruniaux <42495291+HubertGruniaux@users.noreply.github.com>
* Update c_cpp.py to adds support for C++20 keywordsHubert Gruniaux2020-01-051-2/+3
| | | The soon C++20 newcomer standard will introduce lots of new keywords like `constinit`, `co_yield` (for courotines), `import` or`module` (for modules, however these are special identifiers instead of real keywords), etc...
* Update project to use modern Python features and idiomsJon Dufresne2019-11-251-6/+6
| | | | | | | | | | Run the pyupgrade tool across the project to use modern language features. - Use set literals - Use dict comprehension - Remove unnecessary numeric indexes in format string - Remove unnecessary extra parentheses
* Fixup all headers and some more minor problems.2.4.2Georg Brandl2019-05-281-1/+1
|
* Fix more instances of invalid string escapesGeorg Brandl2018-11-281-4/+4
| | | | Also, raise on warnings from Pygments only.
* Copyright update.Georg Brandl2017-01-221-1/+1
|
* Add support for partials and path segments for Handlebars.Christian Hammond2016-11-041-0/+252
This introduces support for some missing features to the Handlebars lexer: Partials and path segments. Partials mostly appeared to work before, but the `>` in `{{> ... }}` would appear as a syntax error, as could other components of the partial. This change introduces support for: * Standard partials: `{{> partialName}}` * Partials with parameters: `{{> partialName varname="value"}}` * Ddynamic partials: `{{> (partialFunc)}}` * Ddynamic partials with lookups: `{{> (lookup ../path "partialName")}}` * Partial blocks: `{{> @partial-block}}` * Inline partials: `{{#*inline}}..{{/inline}}` It also introduces support for path segments, which can reference content in the current context or in a parent context. For instance, `this.name`, `this/name`, `./name`, `../name`, `this/name`, etc. These are all now tracked as variables.