(cpp) Add template generation, add optional params

This commit is contained in:
danymat
2021-11-08 21:13:32 +01:00
parent e87b4a20f3
commit fa472f6f29
2 changed files with 21 additions and 12 deletions

View File

@@ -175,7 +175,9 @@ There is a list of supported languages and fields, with their annotation style
| typescript | | | `func`, `class` | | typescript | | | `func`, `class` |
| | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `@param`, `@returns`, `@class`, `@classdesc`, `@type` | | | [JSDoc](https://jsdoc.app) (`"jsdoc"`) | `@param`, `@returns`, `@class`, `@classdesc`, `@type` |
| c | | | `func` | | c | | | `func` |
| | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@returns` | | | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@returns`, `@brief`|
| cpp | | | `func` |
| | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `@param`, `@returns`, `@tparam`, `@brief`|
| go | | | | | go | | | |
| | [Godoc](https://go.dev/blog/godoc) (`"godoc"`) | | | | [Godoc](https://go.dev/blog/godoc) (`"godoc"`) | |
| java | | | `class` | | java | | | `class` |

View File

@@ -4,15 +4,7 @@ local c_params = {
subtree = { subtree = {
{ {
retrieve = "all", retrieve = "all",
node_type = "parameter_declaration", node_type = "parameter_declaration|variadic_parameter_declaration|optional_parameter_declaration",
subtree = {
{ retrieve = "first", recursive = true, node_type = "identifier", extract = true },
},
},
-- This one is only used in cpp, considering moving it elsewhere to refactor
{
retrieve = "all",
node_type = "variadic_parameter_declaration",
subtree = { subtree = {
{ retrieve = "first", recursive = true, node_type = "identifier", extract = true }, { retrieve = "first", recursive = true, node_type = "identifier", extract = true },
}, },
@@ -21,6 +13,19 @@ local c_params = {
} }
local c_function_extractor = function(node) local c_function_extractor = function(node)
local tree = { local tree = {
{
retrieve = "first",
node_type = "template_parameter_list",
subtree = {
{
retrieve = "first",
node_type = "type_parameter_declaration",
subtree = {
{ retrieve = "all", node_type = "type_identifier", extract = true },
},
},
},
},
{ {
retrieve = "first", retrieve = "first",
node_type = "function_declarator", node_type = "function_declarator",
@@ -79,18 +84,19 @@ local c_function_extractor = function(node)
return { return {
parameters = res.identifier, parameters = res.identifier,
type_identifier = res.type_identifier,
return_statement = has_return_statement(), return_statement = has_return_statement(),
} }
end end
return { return {
parent = { parent = {
func = { "function_declaration", "function_definition", "declaration" }, func = { "function_declaration", "function_definition", "declaration", "template_declaration" },
}, },
data = { data = {
func = { func = {
["function_declaration|function_definition|declaration"] = { ["function_declaration|function_definition|declaration|template_declaration"] = {
["0"] = { ["0"] = {
extract = c_function_extractor, extract = c_function_extractor,
}, },
@@ -114,6 +120,7 @@ return {
{ nil, "/**" }, { nil, "/**" },
{ nil, " * @brief $1" }, { nil, " * @brief $1" },
{ nil, " *" }, { nil, " *" },
{ "type_identifier", " * @tparam %s $1" },
{ "parameters", " * @param %s $1" }, { "parameters", " * @param %s $1" },
{ "return_statement", " * @returns $1" }, { "return_statement", " * @returns $1" },
{ nil, " */" }, { nil, " */" },