diff options
| author | Jefferson González <jgmdev@gmail.com> | 2024-08-09 17:17:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-09 17:17:04 -0400 |
| commit | 1260d8dee30c7aa637ef5d085b2dadfd3ce4d79b (patch) | |
| tree | fa9e7d1a700dbf3f920c534eae5e910bec6b0f18 /data/plugins/language_cpp.lua | |
| parent | 60829aee2332fcd4170d0f09e1f9df54e15a17fd (diff) | |
| download | pragtical-1260d8dee30c7aa637ef5d085b2dadfd3ce4d79b.tar.gz pragtical-1260d8dee30c7aa637ef5d085b2dadfd3ce4d79b.zip | |
Improvements to c/c++ language plugins (#128)
* Match enum names same as with structs and unions
* Match single line type declarations to better match code like:
```c
custome_type*
function_name (type *param_name)
{
/*...*/
}
```
* Added matching of single line param declaration without modifiers
* Allow spaces between function name and parameters list
* Also distinguish upper case constants when used as function calls
* Added matching of generic type declarations
Diffstat (limited to 'data/plugins/language_cpp.lua')
| -rw-r--r-- | data/plugins/language_cpp.lua | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/data/plugins/language_cpp.lua b/data/plugins/language_cpp.lua index 1a7e9830..8fe74095 100644 --- a/data/plugins/language_cpp.lua +++ b/data/plugins/language_cpp.lua @@ -34,6 +34,7 @@ syntax.add { { pattern = "##", type = "operator" }, { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, { pattern = "class%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "enum%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, { pattern = "namespace%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, -- static declarations @@ -62,15 +63,47 @@ syntax.add { "literal", "normal", "operator" } }, + -- match single line type declarations (exclude keywords) + { pattern = "^%s*_?%u[%u_][%u%d_]*%s*\n", -- skip uppercase constants + type = "number" + }, + { pattern = "^%s*()[%a_][%w_]*()%s*&()%s*\n", -- reference + type = { "normal", "literal", "operator", "normal" } + }, + { pattern = "^%s*()[%a_][%w_]*()%s*%*+()%s*\n", -- pointer + type = { "normal", "literal", "operator", "normal" } + }, + { pattern = "^%s*()[%a_][%w_]*()%s*\n", -- non-pointer + type = { "normal", "literal", "normal" } + }, -- match function type declarations - { pattern = "[%a_][%w_]*()%*+()%s+()[%a_][%w_]*%f[%(]", - type = { "literal", "operator", "normal", "function" } + { pattern = "[%a_][%w_]*()%*+()%s+()[%a_][%w_]*()%s*%f[%(]", + type = { "literal", "operator", "normal", "function", "normal" } + }, + { pattern = "[%a_][%w_]*()%s+()%*+()[%a_][%w_]*()%s*%f[%(]", + type = { "literal", "normal", "operator", "function", "normal" } + }, + { pattern = "[%a_][%w_]*()%s+()[%a_][%w_]*()%s*%f[%(]", + type = { "literal", "normal", "function", "normal" } }, - { pattern = "[%a_][%w_]*()%s+()%*+()[%a_][%w_]*%f[%(]", - type = { "literal", "normal", "operator", "function" } + -- match generic variable type declarations (eg: vector<int> myvector) + { regex = "^\\s*[\\p{L}_][\\p{L}\\d_]*(?=(?:<.*>\\s*[\\*&]*\\s*\n))", + type = "literal" }, - { pattern = "[%a_][%w_]*()%s+()[%a_][%w_]*%f[%(]", - type = { "literal", "normal", "function" } + { regex = "[\\p{L}_][\\p{L}\\d_]*(?=(?:<.*>\\s*\\*+\\s+[\\p{L}_][\\p{L}\\d_]*))", + type = "literal" + }, + { regex = "[\\p{L}_][\\p{L}\\d_]*(?=(?:<.*>\\s*&\\s+[\\p{L}_][\\p{L}\\d_]*))", + type = "literal" + }, + { regex = "[\\p{L}_][\\p{L}\\d_]*(?=(?:<.*>\\s+\\*+\\s*[\\p{L}_][\\p{L}\\d_]*))", + type = "literal" + }, + { regex = "[\\p{L}_][\\p{L}\\d_]*(?=(?:<.*>\\s+&\\s*[\\p{L}_][\\p{L}\\d_]*))", + type = "literal" + }, + { regex = "[\\p{L}_][\\p{L}\\d_]*(?=(?:<.*>\\s+[\\p{L}_][\\p{L}\\d_]*))", + type = "literal" }, -- match variable type declarations { pattern = "[%a_][%w_]*()%*+()%s+()[%a_][%w_]*", @@ -82,6 +115,9 @@ syntax.add { { pattern = "[%a_][%w_]*()%s+()[%a_][%w_]*()%s*()[;,%[%)]", type = { "literal", "normal", "normal", "normal", "normal" } }, + { pattern = "^%s*()[%a_][%w_]*()%s+[%a_][%w_]*()%s*\n", + type = { "normal", "literal", "normal", "normal" } + }, { pattern = "[%a_][%w_]*()%s+()[%a_][%w_]*()%s*()=", type = { "literal", "normal", "normal", "normal", "operator" } }, @@ -96,13 +132,16 @@ syntax.add { type = { "literal", "normal", "operator" } }, -- Uppercase constants of at least 2 chars in len + { pattern = "_?%u[%u_][%u%d_]*%s*%f[%(]", -- when used as function + type = "number" + }, { pattern = "_?%u[%u_][%u%d_]*%f[%s%+%*%-%.%)%]}%?%^%%=/<>~|&;:,!]", type = "number" }, -- Magic constants { pattern = "__[%u%l]+__", type = "number" }, -- all other functions - { pattern = "[%a_][%w_]*%f[(]", type = "function" }, + { pattern = "[%a_][%w_]*()%s*%f[(]", type = {"function", "normal"} }, -- Macros { pattern = "^%s*#%s*define%s+()[%a_][%a%d_]*", type = { "keyword", "symbol" } |
