A qualified destructor-id in an explicit destructor call via `->`/`.`, e.g.
`p->std::vector<int>::~vector()` or `p->A::~A()`, produced an ERROR node.
`qualified_identifier` already accepts a trailing `destructor_name`, but
`qualified_field_identifier` (the member-access path) did not; mirror it there.
The destructor-id in an explicit destructor call may name a class template
specialization, e.g. `p->~vector<int>()` or `p->~shared_ptr<const T>()`.
`destructor_name` only allowed `~ identifier`, so any template-id after `~`
produced an ERROR node. Allow an optional `template_argument_list` and add a
GLR conflict for `destructor_name` to resolve the `<` (template-args vs
less-than) ambiguity. A plain `~Name` is unchanged.
This change allows operators (not just fields/member functions) as dependent
template expressions.
```cpp
auto x = y.template operator()<int>();
```
This syntax is used e.g. to call C++20 lambda expressions with a template head
where the template arguments are not function arguments and therefore cannot be
deduced.
```cpp
[]<typename> () {}.template operator()<int>();
```
This change allows commas inside subscripts.
```cpp
auto x = a[1, 2, 3];
```
From C++23, array subscripts work like arguments to `operator[]` as an n-ary
function.
Before C++23, `operator[]` must be a unary function, but before C++20, it's
possible to use the comma operator inside subscript expressions - and this is
done in libraries that use expression templates to achieve multidimensional
array syntax.
Use of the comma operator in subscript expressions was deprecated in C++20 to
make way for the C++23 change to n-ary `operator[]`.
Include rawstring delimiters in the tree, use for injections
In raw-strings, the delimiter can be used to indicate embedded language:
R"css( body { background: red; } )css"
This patch adds the delimiter (if present) and raw-string content as
children of the raw_string_literal.
These can be used to parse the content with an injected grammar.
Fixes https://github.com/tree-sitter/tree-sitter-cpp/issues/159
!! Breaking change due to restructuring and renaming of scoped identifiers !!
Scoped identifier rules have been renamed to "qualified_x_identifier"
and all variants are aliased so they appear as simply
"qualified_identifier" in the syntax tree. This name better reflects the
c++ standard's language describing this concept.
Qualified identifier rules are now always the "parent" with a right
associative rule that lets them nest indefinitely. Each rule terminates
with some kind of non-scope identifier.
This commit also adds support for the 'template' keyword where required
to disambiguate dependent template names. Field accessors (., ->) can be
followed by keyword template before a template method. The scope
resolution operator can be immediately followed by the 'template'
keyword to indicate the following dependent name with '<' is actually a
template and shouldn't be parsed as a binary operator. These keywords
are required for dependent names in these contexts.
* Add user-defined literals
* Simplify operator rule
* Tweak operator tests
* Remove precedence for user-defined literanl
* Define a rule for ud-suffix
* Use a more readable name for ud-suffix
* Fix array assignment expressions so they don't parse as structured bindings
Array assignment expressions were broken in df7bc44 which added more
support for structured binding declarators. We need to add a dynamic
precedence that is lower than that of an assignment expression so that
code is parsed as an assignment expression before it's parsed as a
structured binding.
* Just use -1 for structured binding dynamic precedence
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
For information about parameter packs, see
https://en.cppreference.com/w/cpp/language/parameter_pack
Most expansion loci should work with this commit since it is implemented
as an expression, so anywhere an expression is valid, parameter pack
expansions will be parsed.
This commit also adds support for:
* The sizeof... operator (as an alternative to sizeof)
* Lambda captures can optionally start with a default capture along with
other captures
* Lambda function declarators (the parameter list) are optional
Tests added for the following parameter pack expansion loci:
* Function parameter and argument lists
* Template argument lists
* Brace-enclosed initializers
* Base class specifiers and member initializer lists
* Lambda captures