This repository has been archived on 2024-06-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
coffee.pygments/tests/examplefiles/cpp/namespace.cpp
amitkummer c1a0d82acb
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
2021-02-27 17:32:41 +01:00

35 lines
No EOL
745 B
C++

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;
}
}
}
}