highlights(cpp): add support for concepts

Requires https://github.com/tree-sitter/tree-sitter-cpp/pull/138
This commit is contained in:
Stephan Seitz 2021-11-28 18:05:18 +01:00
parent 4cf688ee68
commit db01c82b08
3 changed files with 28 additions and 2 deletions

View file

@ -27,13 +27,13 @@
"revision": "4fd115d3bb7046cd094f21bfe5766c302dbf64cd"
},
"cpp": {
"revision": "e8dcc9d2b404c542fd236ea5f7208f90be8a6e89"
"revision": "049c2a4edeb6c19bacefb4d40aa03c6fdc175575"
},
"css": {
"revision": "a03f1d2d1dfbf6f8e0fdca5f9ff030228241eb57"
},
"cuda": {
"revision": "bc20ed7a36031437a69a88ef368af4b9f1ecec70"
"revision": "61de33bc41231a2e7c1970542c505a42d62c98eb"
},
"d": {
"revision": "c2fbf21bd3aa45495fe13247e040ad5815250032"

View file

@ -30,6 +30,8 @@
(function_declarator
declarator: (field_identifier) @method)
(concept_definition
name: (identifier) @type)
(namespace_identifier) @namespace
((namespace_identifier) @type
@ -123,6 +125,8 @@
"using"
"virtual"
"co_await"
"concept"
"requires"
(auto)
] @keyword

View file

@ -0,0 +1,22 @@
template <class T, class U>
concept Derived = std::is_base_of<U, T>::value;
// ^ keyword
// ^ type
template<typename T>
concept Hashable = requires(T a) {
// ^ keyword
// ^ parameter
// ^ type
{ std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
typename CommonType<T, U>; // CommonType<T, U> is valid and names a type
{ CommonType<T, U>{std::forward<T>(t)} };
{ CommonType<T, U>{std::forward<U>(u)} };
};
template<typename T>
requires requires (T x) { x + x; } // ad-hoc constraint, note keyword used twice
// ^ keyword
T add(T a, T b) { return a + b; }