diff options
| author | amitkummer <49096391+amitkummer@users.noreply.github.com> | 2021-02-27 18:32:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-27 17:32:41 +0100 |
| commit | c1a0d82acbe6fa026a1f6843fee00cc1df626549 (patch) | |
| tree | 2f62310c9f3e6b674c2d8a39f700dbfa921181fb /tests/examplefiles/cpp | |
| parent | ad55974ce83b85dbb333ab57764415ab84169461 (diff) | |
| download | pygments-git-c1a0d82acbe6fa026a1f6843fee00cc1df626549.tar.gz | |
Fixes for C and C++ functions and namespaces (#1722)
* 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
Diffstat (limited to 'tests/examplefiles/cpp')
| -rw-r--r-- | tests/examplefiles/cpp/example.cpp.output | 54 | ||||
| -rw-r--r-- | tests/examplefiles/cpp/functions.cpp | 87 | ||||
| -rw-r--r-- | tests/examplefiles/cpp/functions.cpp.output | 1405 | ||||
| -rw-r--r-- | tests/examplefiles/cpp/namespace.cpp | 35 | ||||
| -rw-r--r-- | tests/examplefiles/cpp/namespace.cpp.output | 276 |
5 files changed, 1827 insertions, 30 deletions
diff --git a/tests/examplefiles/cpp/example.cpp.output b/tests/examplefiles/cpp/example.cpp.output index 2d6615f3..aea47bec 100644 --- a/tests/examplefiles/cpp/example.cpp.output +++ b/tests/examplefiles/cpp/example.cpp.output @@ -20,7 +20,7 @@ ' ' Text 'namespace' Keyword ' ' Text -'std' Name +'std' Name.Namespace ';' Punctuation '\n' Text @@ -28,7 +28,7 @@ 'namespace' Keyword ' ' Text -'highlight' Name +'highlight' Name.Namespace ' ' Text '{' Punctuation '\n' Text @@ -39,10 +39,7 @@ 'string' Name ' ' Text -'AnsiGenerator' Name -':' Operator -':' Operator -'getOpenTag' Name +'AnsiGenerator::getOpenTag' Name.Function '(' Punctuation 'const' Keyword ' ' Text @@ -519,7 +516,7 @@ ' ' Text 'return' Keyword ' ' Text -'string' Name.Function +'string' Name '(' Punctuation ')' Punctuation ';' Punctuation @@ -569,7 +566,7 @@ ' ' Text 'return' Keyword ' ' Text -'string' Name.Function +'string' Name '(' Punctuation ')' Punctuation ';' Punctuation @@ -786,7 +783,7 @@ 'namespace' Keyword ' ' Text -'highlight' Name +'highlight' Name.Namespace ' ' Text '{' Punctuation '\n' Text @@ -1096,7 +1093,7 @@ ' ' Text 'namespace' Keyword ' ' Text -'std' Name +'std' Name.Namespace ';' Punctuation '\n' Text @@ -1118,7 +1115,7 @@ 'namespace' Keyword ' ' Text -'astyle' Name +'astyle' Name.Namespace '\n' Text ' ' Text @@ -1236,10 +1233,7 @@ ' ' Text 'void' Keyword.Type ' ' Text -'ASBeautifier' Name -':' Operator -':' Operator -'initStatic' Name +'ASBeautifier::initStatic' Name.Function '(' Punctuation ')' Punctuation '\n' Text @@ -4875,7 +4869,7 @@ ' ' Text 'return' Keyword ' ' Text -'beautify' Name.Function +'beautify' Name '(' Punctuation 'sourceIterator' Name '-' Operator @@ -7038,7 +7032,7 @@ ' ' Text 'else' Keyword ' ' Text -'if' Name.Function +'if' Keyword ' ' Text '(' Punctuation '!' Operator @@ -8678,7 +8672,7 @@ '\n' Text ' ' Text -'registerInStatementIndent' Name.Function +'registerInStatementIndent' Name '(' Punctuation 'line' Name ',' Punctuation @@ -13779,7 +13773,7 @@ ' ' Text 'else' Keyword ' ' Text -'if' Name.Function +'if' Keyword ' ' Text '(' Punctuation '!' Operator @@ -13838,7 +13832,7 @@ ' ' Text 'else' Keyword ' ' Text -'if' Name.Function +'if' Keyword ' ' Text '(' Punctuation '!' Operator @@ -15080,7 +15074,7 @@ ' ' Text 'else' Keyword ' ' Text -'if' Name.Function +'if' Keyword ' ' Text '(' Punctuation 'ch' Name @@ -16225,7 +16219,7 @@ ' ' Text 'namespace' Keyword ' ' Text -'std' Name +'std' Name.Namespace ';' Punctuation '\n' Text @@ -16233,7 +16227,7 @@ 'namespace' Keyword ' ' Text -'astyle' Name +'astyle' Name.Namespace '\n' Text ' ' Text @@ -16363,7 +16357,7 @@ ' ' Text 'void' Keyword.Type ' ' Text -'init' Name +'init' Name.Function '(' Punctuation 'ASSourceIterator' Name '*' Operator @@ -16379,7 +16373,7 @@ ' ' Text 'void' Keyword.Type ' ' Text -'init' Name +'init' Name.Function '(' Punctuation ')' Punctuation ';' Punctuation @@ -16390,7 +16384,7 @@ ' ' Text 'bool' Keyword.Type ' ' Text -'hasMoreLines' Name +'hasMoreLines' Name.Function '(' Punctuation ')' Punctuation ' ' Text @@ -16403,7 +16397,7 @@ ' ' Text 'string' Name ' ' Text -'nextLine' Name +'nextLine' Name.Function '(' Punctuation ')' Punctuation ';' Punctuation @@ -16414,7 +16408,7 @@ ' ' Text 'string' Name ' ' Text -'beautify' Name +'beautify' Name.Function '(' Punctuation 'const' Keyword ' ' Text @@ -16680,7 +16674,7 @@ 'string' Name ' ' Text '*' Operator -'findHeader' Name +'findHeader' Name.Function '(' Punctuation 'const' Keyword ' ' Text @@ -17566,6 +17560,6 @@ ' ' Text 'namespace' Keyword ' ' Text -'std' Name +'std' Name.Namespace ';' Punctuation '\n' Text diff --git a/tests/examplefiles/cpp/functions.cpp b/tests/examplefiles/cpp/functions.cpp new file mode 100644 index 00000000..662e0d2c --- /dev/null +++ b/tests/examplefiles/cpp/functions.cpp @@ -0,0 +1,87 @@ +using std::numerical; +string contains(const char str); +string contains(const char str) {} +string* contains(const char str); +string* contains(const char str) {} +string * contains(const char str); +string * contains(const char str) {} +string * contains(const char str); +string * contains(const char str) {} +string *contains(const char str); +string *contains(const char str) {} +string **contains(const char str); +string **contains(const char str) {} +string** contains(const char str); +string** contains(const char str) {} +string ** contains(const char str); +string ** contains(const char str) {} +string & contains(const char str); +string & contains(const char str) {} +string& contains(const char str); +string& contains(const char str) {} +string &contains(const char str); +string &contains(const char str) {} +string &&contains(const char str); +string &&contains(const char str) {} +string && contains(const char str); +string && contains(const char str) {} +string&& contains(const char str); +string&& contains(const char str) {} +const string contains(const char str); +const string contains(const char str) {} +explicit const string contains(const char str); +explicit const string contains(const char str) {} +explicit const string contains(const char str) noexcept; +explicit const string contains(const char str) noexcept {} +explicit const string contains(const char str) noexcept const; +explicit const string contains(const char str) noexcept const {} + + +explicit const string contains(const char&str); +explicit const string contains(const char&str) {} +explicit const string contains(const char& str); +explicit const string contains(const char& str) {} +explicit const string contains(const char str); +explicit const string contains(const char str) {} +explicit const string contains(const char&& str); +explicit const string contains(const char&& str) {} +explicit const string contains(const char&& str); +explicit const string contains(const char&& str) {} +explicit const string contains(const char &&str); +explicit const string contains(const char &&str) {} +explicit const string contains(const char ***** str); +explicit const string contains(const char ***** str) {} +explicit const string contains(const char *****str); +explicit const string contains(const char *****str) {} +explicit const string contains(const char***** str); +explicit const string contains(const char***** str) {} +explicit const string contains(const char *str); +explicit const string contains(const char *str) {} +explicit const string contains(const char* str); +explicit const string contains(const char* str) {} +explicit const string contains(const char * str); +explicit const string contains(const char * str) {} + +// Names with namespaces + +string Type::contains(char c) const noexcept; +string Type::contains(char c) const noexcept {} +std::string contains(char c) const noexcept; +std::string contains(char c) const noexcept {} +std::string contains(std::vector<char> chars) const noexcept; +std::string contains(std::vector<char> chars) const noexcept {} +std::string std::vector::contains(std::vector<char> chars) const; +std::string std::vector::contains(std::vector<char> chars) const {} +const inline explicit std::string std::vector::contains(std::vector<char> chars) const {} +const inline explicit std::string std::vector::contains(std::vector<char> chars) const; + +// inside classes + +class raz { + const virtual std::string contains(const std::string str); +} + +// Make sure these are not functions: +else if(flag && func_call()) {} +new T(); +const operator int() const {} // so int is lexed as type and not function.name
\ No newline at end of file diff --git a/tests/examplefiles/cpp/functions.cpp.output b/tests/examplefiles/cpp/functions.cpp.output new file mode 100644 index 00000000..cec14f10 --- /dev/null +++ b/tests/examplefiles/cpp/functions.cpp.output @@ -0,0 +1,1405 @@ +'using' Keyword +' ' Text +'std' Name +':' Operator +':' Operator +'numerical' Name +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +'*' Operator +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +'*' Operator +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +'*' Operator +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +'*' Operator +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'*' Operator +'*' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'&' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'&' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +'&' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +'&' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'&' Operator +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'&' Operator +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'&' Operator +'&' Operator +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'&' Operator +'&' Operator +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +' ' Text +'&' Operator +'&' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'&' Operator +'&' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'string' Name +'&' Operator +'&' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'string' Name +'&' Operator +'&' Operator +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'noexcept' Keyword +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'noexcept' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'noexcept' Keyword +' ' Text +'const' Keyword +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'noexcept' Keyword +' ' Text +'const' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'\n' Text + +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'&' Operator +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'&' Operator +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'&' Operator +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'&' Operator +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'&' Operator +'&' Operator +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'&' Operator +'&' Operator +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'&' Operator +'&' Operator +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'&' Operator +'&' Operator +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'&' Operator +'&' Operator +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'&' Operator +'&' Operator +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'*' Operator +'*' Operator +'*' Operator +'*' Operator +'*' Operator +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'*' Operator +'*' Operator +'*' Operator +'*' Operator +'*' Operator +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'*' Operator +'*' Operator +'*' Operator +'*' Operator +'*' Operator +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'*' Operator +'*' Operator +'*' Operator +'*' Operator +'*' Operator +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'*' Operator +'*' Operator +'*' Operator +'*' Operator +'*' Operator +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'*' Operator +'*' Operator +'*' Operator +'*' Operator +'*' Operator +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'*' Operator +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'*' Operator +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'*' Operator +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +'*' Operator +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'*' Operator +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'explicit' Keyword +' ' Text +'const' Keyword +' ' Text +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'char' Keyword.Type +' ' Text +'*' Operator +' ' Text +'str' Name +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'\n' Text + +'// Names with namespaces\n' Comment.Single + +'\n' Text + +'string' Name +' ' Text +'Type::contains' Name.Function +'(' Punctuation +'char' Keyword.Type +' ' Text +'c' Name +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'noexcept' Keyword +';' Punctuation +'\n' Text + +'string' Name +' ' Text +'Type::contains' Name.Function +'(' Punctuation +'char' Keyword.Type +' ' Text +'c' Name +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'noexcept' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'char' Keyword.Type +' ' Text +'c' Name +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'noexcept' Keyword +';' Punctuation +'\n' Text + +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'char' Keyword.Type +' ' Text +'c' Name +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'noexcept' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'std' Name +':' Operator +':' Operator +'vector' Name +'<' Operator +'char' Keyword.Type +'>' Operator +' ' Text +'chars' Name +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'noexcept' Keyword +';' Punctuation +'\n' Text + +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'std' Name +':' Operator +':' Operator +'vector' Name +'<' Operator +'char' Keyword.Type +'>' Operator +' ' Text +'chars' Name +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'noexcept' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'std::vector::contains' Name.Function +'(' Punctuation +'std' Name +':' Operator +':' Operator +'vector' Name +'<' Operator +'char' Keyword.Type +'>' Operator +' ' Text +'chars' Name +')' Punctuation +' ' Text +'const' Keyword +';' Punctuation +'\n' Text + +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'std::vector::contains' Name.Function +'(' Punctuation +'std' Name +':' Operator +':' Operator +'vector' Name +'<' Operator +'char' Keyword.Type +'>' Operator +' ' Text +'chars' Name +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'const' Keyword +' ' Text +'inline' Keyword.Reserved +' ' Text +'explicit' Keyword +' ' Text +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'std::vector::contains' Name.Function +'(' Punctuation +'std' Name +':' Operator +':' Operator +'vector' Name +'<' Operator +'char' Keyword.Type +'>' Operator +' ' Text +'chars' Name +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'const' Keyword +' ' Text +'inline' Keyword.Reserved +' ' Text +'explicit' Keyword +' ' Text +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'std::vector::contains' Name.Function +'(' Punctuation +'std' Name +':' Operator +':' Operator +'vector' Name +'<' Operator +'char' Keyword.Type +'>' Operator +' ' Text +'chars' Name +')' Punctuation +' ' Text +'const' Keyword +';' Punctuation +'\n' Text + +'\n' Text + +'// inside classes\n' Comment.Single + +'\n' Text + +'class' Keyword +' ' Text +'raz' Name.Class +' ' Text +'{' Punctuation +'\n' Text + +' ' Text +'const' Keyword +' ' Text +'virtual' Keyword +' ' Text +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'contains' Name.Function +'(' Punctuation +'const' Keyword +' ' Text +'std' Name +':' Operator +':' Operator +'string' Name +' ' Text +'str' Name +')' Punctuation +';' Punctuation +'\n' Text + +'}' Punctuation +'\n' Text + +'\n' Text + +'// Make sure these are not functions:\n' Comment.Single + +'else' Keyword +' ' Text +'if' Keyword +'(' Punctuation +'flag' Name +' ' Text +'&' Operator +'&' Operator +' ' Text +'func_call' Name +'(' Punctuation +')' Punctuation +')' Punctuation +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'new' Keyword +' ' Text +'T' Name +'(' Punctuation +')' Punctuation +';' Punctuation +'\n' Text + +'const' Keyword +' ' Text +'operator' Keyword +' ' Text +'int' Keyword.Type +'(' Punctuation +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +' ' Text +'// so int is lexed as type and not function.name\n' Comment.Single diff --git a/tests/examplefiles/cpp/namespace.cpp b/tests/examplefiles/cpp/namespace.cpp new file mode 100644 index 00000000..45d95405 --- /dev/null +++ b/tests/examplefiles/cpp/namespace.cpp @@ -0,0 +1,35 @@ +namespace std {} +namespace std::exprimental::inner {} +namespace {} +namespace std::exprimental::inline innner {} +namespace std::inline exprimental::innner {} +namespace other = std; +namespace other = std::exprimental; + +namespace std::exprimental::inner { +class QualifiedName { +public: + QualifiedName(const FlyString& local_name) + { + } + const FlyString& local_name() const { return m_local_name; } + +private: + FlyString m_local_name; +}; +} + +namespace ns::inner::inline pygments { + using namespace outer; + int has_value() { + namespace other = std; + } + namespace { + namespace user { + int has_value() { + using namespace inner; + return 4; + } + } + } +}
\ No newline at end of file diff --git a/tests/examplefiles/cpp/namespace.cpp.output b/tests/examplefiles/cpp/namespace.cpp.output new file mode 100644 index 00000000..c6d8f9d2 --- /dev/null +++ b/tests/examplefiles/cpp/namespace.cpp.output @@ -0,0 +1,276 @@ +'namespace' Keyword +' ' Text +'std' Name.Namespace +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'namespace' Keyword +' ' Text +'std' Name.Namespace +':' Operator +':' Operator +'exprimental' Name.Namespace +':' Operator +':' Operator +'inner' Name.Namespace +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'namespace' Keyword +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'namespace' Keyword +' ' Text +'std' Name.Namespace +':' Operator +':' Operator +'exprimental' Name.Namespace +':' Operator +':' Operator +'inline' Keyword +' ' Text +'innner' Name.Namespace +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'namespace' Keyword +' ' Text +'std' Name.Namespace +':' Operator +':' Operator +'inline' Keyword +' ' Text +'exprimental' Name.Namespace +':' Operator +':' Operator +'innner' Name.Namespace +' ' Text +'{' Punctuation +'}' Punctuation +'\n' Text + +'namespace' Keyword +' ' Text +'other' Name.Namespace +' ' Text +'=' Operator +' ' Text +'std' Name.Namespace +';' Punctuation +'\n' Text + +'namespace' Keyword +' ' Text +'other' Name.Namespace +' ' Text +'=' Operator +' ' Text +'std' Name.Namespace +':' Operator +':' Operator +'exprimental' Name.Namespace +';' Punctuation +'\n' Text + +'\n' Text + +'namespace' Keyword +' ' Text +'std' Name.Namespace +':' Operator +':' Operator +'exprimental' Name.Namespace +':' Operator +':' Operator +'inner' Name.Namespace +' ' Text +'{' Punctuation +'\n' Text + +'class' Keyword +' ' Text +'QualifiedName' Name.Class +' ' Text +'{' Punctuation +'\n' Text + +'public' Keyword +':' Operator +'\n' Text + +' ' Text +'QualifiedName' Name +'(' Punctuation +'const' Keyword +' ' Text +'FlyString' Name +'&' Operator +' ' Text +'local_name' Name +')' Punctuation +'\n' Text + +' ' Text +'{' Punctuation +'\n' Text + +' ' Text +'}' Punctuation +'\n' Text + +' ' Text +'const' Keyword +' ' Text +'FlyString' Name +'&' Operator +' ' Text +'local_name' Name +'(' Punctuation +')' Punctuation +' ' Text +'const' Keyword +' ' Text +'{' Punctuation +' ' Text +'return' Keyword +' ' Text +'m_local_name' Name +';' Punctuation +' ' Text +'}' Punctuation +'\n' Text + +'\n' Text + +'private' Keyword +':' Operator +'\n' Text + +' ' Text +'FlyString' Name +' ' Text +'m_local_name' Name +';' Punctuation +'\n' Text + +'}' Punctuation +';' Punctuation +' \n' Text + +'}' Punctuation +'\n' Text + +'\n' Text + +'namespace' Keyword +' ' Text +'ns' Name.Namespace +':' Operator +':' Operator +'inner' Name.Namespace +':' Operator +':' Operator +'inline' Keyword +' ' Text +'pygments' Name.Namespace +' ' Text +'{' Punctuation +'\n' Text + +' ' Text +'using' Keyword +' ' Text +'namespace' Keyword +' ' Text +'outer' Name.Namespace +';' Punctuation +'\n' Text + +' ' Text +'int' Keyword.Type +' ' Text +'has_value' Name.Function +'(' Punctuation +')' Punctuation +' ' Text +'{' Punctuation +'\n' Text + +' ' Text +'namespace' Keyword +' ' Text +'other' Name.Namespace +' ' Text +'=' Operator +' ' Text +'std' Name.Namespace +';' Punctuation +'\n' Text + +' ' Text +'}' Punctuation +'\n' Text + +' ' Text +'namespace' Keyword +' ' Text +'{' Punctuation +'\n' Text + +' ' Text +'namespace' Keyword +' ' Text +'user' Name.Namespace +' ' Text +'{' Punctuation +'\n' Text + +' ' Text +'int' Keyword.Type +' ' Text +'has_value' Name.Function +'(' Punctuation +')' Punctuation +' ' Text +'{' Punctuation +'\n' Text + +' ' Text +'using' Keyword +' ' Text +'namespace' Keyword +' ' Text +'inner' Name.Namespace +';' Punctuation +'\n' Text + +' ' Text +'return' Keyword +' ' Text +'4' Literal.Number.Integer +';' Punctuation +'\n' Text + +' ' Text +'}' Punctuation +'\n' Text + +' ' Text +'}' Punctuation +'\n' Text + +' ' Text +'}' Punctuation +'\n' Text + +'}' Punctuation +'\n' Text |
