From 6baad702f6d87261b33814678381edcb9f5bbd1f Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Wed, 1 May 2024 22:43:15 +0200 Subject: [PATCH 01/16] Add Vala syntax highlighting. --- manifest.json | 11 +++++++++++ plugins/language_vala.lua | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 plugins/language_vala.lua diff --git a/manifest.json b/manifest.json index e51bb55a..d253136e 100644 --- a/manifest.json +++ b/manifest.json @@ -157,6 +157,7 @@ "language_typst": {}, "language_umka": {}, "language_v": {}, + "language_vala": {}, "language_wren": {}, "language_yaml": {}, "language_zig": {} @@ -1623,6 +1624,16 @@ ], "version": "0.1" }, + { + "description": "Syntax for the [Vala](https://vala.dev/) programming language", + "id": "language_vala", + "mod_version": "3", + "path": "plugins/language_vala.lua", + "tags": [ + "language" + ], + "version": "0.1" + }, { "description": "Syntax for the [Vale](https://vale.dev) programming language", "id": "language_vale", diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua new file mode 100644 index 00000000..1382f48f --- /dev/null +++ b/plugins/language_vala.lua @@ -0,0 +1,37 @@ +-- mod-version:3 +local syntax = require "core.syntax" + +syntax.add { + name = "Vala", + files = { "%.vala$" }, + comment = "//", + patterns = { + { pattern = "//.-\n", type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = "-?0x%x+", type = "number" }, + { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, + { pattern = "-?%.?%d+f?", type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + }, + symbols = { + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + [""] = "keyword", + }, +} From 10611ebf23e1e0e084b8c7a112511465776328cc Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Fri, 3 May 2024 11:04:17 +0200 Subject: [PATCH 02/16] Added some patterns and keywords. --- plugins/language_vala.lua | 136 ++++++++++++++++++++++++++++++-------- 1 file changed, 110 insertions(+), 26 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index 1382f48f..a359c47b 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -5,33 +5,117 @@ syntax.add { name = "Vala", files = { "%.vala$" }, comment = "//", + block_comment = { "/*", "*/" }, patterns = { - { pattern = "//.-\n", type = "comment" }, - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { pattern = "-?0x%x+", type = "number" }, - { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, - { pattern = "-?%.?%d+f?", type = "number" }, - { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, - { pattern = "[%a_][%w_]*%f[(]", type = "function" }, - { pattern = "[%a_][%w_]*", type = "symbol" }, + { pattern = "//.*", type = "comment" }, -- Single-string comment + { pattern = { "/%*", "%*/" }, type = "comment" }, -- Multi-line comment + { pattern = { '"', '"', '\\' }, type = "string" }, -- ? + { pattern = { "'", "'", '\\' }, type = "string" }, -- ? + { pattern = "-?0x%x+", type = "number" }, -- ? + { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- ? + { pattern = "-?%.?%d+f?", type = "number" }, -- ? + { regex = "\\w+(?=\\s+\\w++\\s+\\=\\s+)", type = "function" }, -- Class name in class instance + { regex = "\\<.+\\>", type = "keyword2" }, -- Generic Type + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- ? + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- ? + { pattern = "[%a_][%w_]*", type = "symbol" }, -- ? + { regex = "\\s?\\:\\s?(?:\\w+\\.?)+(?=\\s?[{])", type = "keyword2" }, -- Inheritance + { regex = "\\s?\\:\\s?(?:\\w+(?:\\<.+\\>)?\\s?\\,?\\s?)+(?=\\s?[{])", type = "keyword2" }, -- Inheritance + { regex = "class()\\s\\w+()\\<.+\\>(?=\\s?\\:)", type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type + { regex = "interface()\\s\\w+()\\<.+\\>(?=\\s?\\:)", type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type + { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda + { regex = "[A-Z][A-Z_]+", type = "keyword2" }, -- Constants + { regex = "\\[.+\\](?=\\w*)", type = "keyword2" }, -- Attribute + { regex = "\\#[if|elif|else|endif](?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive + { pattern = "[%a_][%w_]*", type = "symbol" }, -- Symbols }, symbols = { - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - [""] = "keyword", - }, + ["class"] = "keyword", + ["this"] = "keyword", + ["var"] = "keyword", + ["const"] = "keyword", + ["new"] = "keyword", + ["enum"] = "keyword", + ["namespace"] = "keyword", + ["interface"] = "keyword", + ["const"] = "keyword", + ["construct"] = "keyword", + ["virtual"] = "keyword", + ["get"] = "keyword", + ["set"] = "keyword", + ["default"] = "keyword", + ["signal"] = "keyword", + ["struct"] = "keyword", + ["Type"] = "keyword", + + ["public"] = "keyword", + ["private"] = "keyword", + ["protected"] = "keyword", + ["internal"] = "keyword", + ["static"] = "keyword", + ["void"] = "keyword", + ["override"] = "keyword", + ["abstract"] = "keyword", + + ["if"] = "keyword", + ["else"] = "keyword", + ["elseif"] = "keyword", + ["for"] = "keyword", + ["foreach"] = "keyword", + ["while"] = "keyword", + ["do"] = "keyword", + ["break"] = "keyword", + ["continue"] = "keyword", + ["return"] = "keyword", + + ["in"] = "keyword", + ["lock"] = "keyword", + ["unlock"] = "keyword", + ["with"] = "keyword", + ["using"] = "keyword", + ["ref"] = "keyword", + ["out"] = "keyword", + ["requires"] = "keyword", + ["ensures"] = "keyword", + ["delegate"] = "keyword", + + ["throw"] = "keyword", + ["throws"] = "keyword", + ["try"] = "keyword", + ["catch"] = "keyword", + ["finally"] = "keyword", + ["errordomain"] = "keyword", + + ["fundamental-struct-type"] = "keyword", + ["user-defined-struct-type"] = "keyword", + ["enumerated-type"] = "keyword", + ["integral-type"] = "keyword", + ["floating-point-type"] = "keyword", + ["bool"] = "keyword", + ["char"] = "keyword", + ["uchar"] = "keyword", + ["short"] = "keyword", + ["ushort"] = "keyword", + ["int"] = "keyword", + ["uint"] = "keyword", + ["long"] = "keyword", + ["ulong"] = "keyword", + ["size_t"] = "keyword", + ["ssize_t"] = "keyword", + ["int8"] = "keyword", + ["uint8"] = "keyword", + ["int16"] = "keyword", + ["uint16"] = "keyword", + ["int32"] = "keyword", + ["uint32"] = "keyword", + ["int64"] = "keyword", + ["uint64"] = "keyword", + ["unichar"] = "keyword", + ["float"] = "keyword", + ["double"] = "keyword", + + ["true"] = "literal", + ["false"] = "literal", + ["null"] = "literal" + } } From 0394bf390d4ca87ea70103338d669137206e323e Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Sat, 4 May 2024 17:47:03 +0200 Subject: [PATCH 03/16] Updated class patterns, removed redundant symbols pattern and fixed preprocessor pattern. --- plugins/language_vala.lua | 41 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index a359c47b..cb0a17c4 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -7,27 +7,26 @@ syntax.add { comment = "//", block_comment = { "/*", "*/" }, patterns = { - { pattern = "//.*", type = "comment" }, -- Single-string comment - { pattern = { "/%*", "%*/" }, type = "comment" }, -- Multi-line comment - { pattern = { '"', '"', '\\' }, type = "string" }, -- ? - { pattern = { "'", "'", '\\' }, type = "string" }, -- ? - { pattern = "-?0x%x+", type = "number" }, -- ? - { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- ? - { pattern = "-?%.?%d+f?", type = "number" }, -- ? - { regex = "\\w+(?=\\s+\\w++\\s+\\=\\s+)", type = "function" }, -- Class name in class instance - { regex = "\\<.+\\>", type = "keyword2" }, -- Generic Type - { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- ? - { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- ? - { pattern = "[%a_][%w_]*", type = "symbol" }, -- ? - { regex = "\\s?\\:\\s?(?:\\w+\\.?)+(?=\\s?[{])", type = "keyword2" }, -- Inheritance - { regex = "\\s?\\:\\s?(?:\\w+(?:\\<.+\\>)?\\s?\\,?\\s?)+(?=\\s?[{])", type = "keyword2" }, -- Inheritance - { regex = "class()\\s\\w+()\\<.+\\>(?=\\s?\\:)", type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type - { regex = "interface()\\s\\w+()\\<.+\\>(?=\\s?\\:)", type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type - { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda - { regex = "[A-Z][A-Z_]+", type = "keyword2" }, -- Constants - { regex = "\\[.+\\](?=\\w*)", type = "keyword2" }, -- Attribute - { regex = "\\#[if|elif|else|endif](?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive - { pattern = "[%a_][%w_]*", type = "symbol" }, -- Symbols + { pattern = "//.*", type = "comment" }, -- Single-line comment + { pattern = { "/%*", "%*/" }, type = "comment" }, -- Multi-line comment + { pattern = { '"', '"', '\\' }, type = "string" }, -- ? + { pattern = { "'", "'", '\\' }, type = "string" }, -- ? + { pattern = "-?0x%x+", type = "number" }, -- ? + { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- ? + { pattern = "-?%.?%d+f?", type = "number" }, -- ? + { regex = "\\w+(?=\\s+\\w++\\s+\\=\\s+)", type = "function" }, -- Class name in class instance + { regex = "\\<.+\\>", type = "keyword2" }, -- Generic Type + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- ? + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- ? + { regex = [[\s?\:\s?(?:\w+\.?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance + { regex = [[\s?\:\s?(?:\w+(?:\<.+\>)?\s?\,?\s?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance + { regex = [[class()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type + { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type + { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda + { regex = "[A-Z][A-Z_]+", type = "keyword2" }, -- Constants + { regex = "\\[.+\\](?=\\w*)", type = "literal" }, -- Attribute + { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive + { pattern = "[%a_][%w_]*", type = "symbol" }, -- ? }, symbols = { ["class"] = "keyword", From 3bd60578d53968cdb45d4a8704e8fa5aae562173 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Wed, 7 Aug 2024 22:18:48 +0200 Subject: [PATCH 04/16] WIP: fixing some mistakes. --- plugins/language_vala.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index cb0a17c4..b80c04d7 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -1,6 +1,8 @@ -- mod-version:3 local syntax = require "core.syntax" +-- https://docs.vala.dev/tutorials/programming-language/main/02-00-basics/02-03-comments.html + syntax.add { name = "Vala", files = { "%.vala$" }, @@ -27,6 +29,15 @@ syntax.add { { regex = "\\[.+\\](?=\\w*)", type = "literal" }, -- Attribute { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive { pattern = "[%a_][%w_]*", type = "symbol" }, -- ? + -- FIX: @"$a * $b = $(a * b)" should be fully string-colored + -- FIX: 21.to_string(); the . should be symbol-colored + -- FIX: int[] a = new int[10] and int[] c = b[1:3]; + -- FIX: var l = new List(); // same as: List l = new List(); + -- FIX: MyFoo> foo = new MyFoo>(); + -- FIX: : GLib.List + -- FIX: <> and <<>> operators + -- FIX: int method_name(int arg1, Object arg2) { Object is not colored properly + -- }, symbols = { ["class"] = "keyword", @@ -46,6 +57,8 @@ syntax.add { ["signal"] = "keyword", ["struct"] = "keyword", ["Type"] = "keyword", + ["string"] = "keyword", + ["unowned"] = "keyword", ["public"] = "keyword", ["private"] = "keyword", @@ -66,6 +79,8 @@ syntax.add { ["break"] = "keyword", ["continue"] = "keyword", ["return"] = "keyword", + ["switch"] = "keyword", + ["case"] = "keyword", ["in"] = "keyword", ["lock"] = "keyword", From 95c02021c6abaa280a4336994ea74eb79f4d41e4 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Wed, 14 Aug 2024 11:50:51 +0200 Subject: [PATCH 05/16] WIP: finished review. --- plugins/language_vala.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index b80c04d7..c5190293 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -25,7 +25,7 @@ syntax.add { { regex = [[class()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda - { regex = "[A-Z][A-Z_]+", type = "keyword2" }, -- Constants + { regex = "[A-Z][A-Z_]+(?=\\s*[)]|[\\;]|[\\,]|[\\s\\=])", type = "keyword2" }, -- Constants { regex = "\\[.+\\](?=\\w*)", type = "literal" }, -- Attribute { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive { pattern = "[%a_][%w_]*", type = "symbol" }, -- ? @@ -37,18 +37,19 @@ syntax.add { -- FIX: : GLib.List -- FIX: <> and <<>> operators -- FIX: int method_name(int arg1, Object arg2) { Object is not colored properly - -- + -- FIX: proper coloring for: public class ListClass : GLib.Object, Collection, List }, symbols = { ["class"] = "keyword", ["this"] = "keyword", + ["is"] = "keyword", + ["as"] = "keyword", ["var"] = "keyword", ["const"] = "keyword", ["new"] = "keyword", ["enum"] = "keyword", ["namespace"] = "keyword", ["interface"] = "keyword", - ["const"] = "keyword", ["construct"] = "keyword", ["virtual"] = "keyword", ["get"] = "keyword", @@ -58,7 +59,10 @@ syntax.add { ["struct"] = "keyword", ["Type"] = "keyword", ["string"] = "keyword", + ["yield"] = "keyword", + ["owned"] = "keyword", ["unowned"] = "keyword", + ["weak"] = "keyword", ["public"] = "keyword", ["private"] = "keyword", From 7d4752cda40019720656e713b0a6205b03295365 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Mon, 23 Sep 2024 22:46:22 +0200 Subject: [PATCH 06/16] Last commit before final review. --- plugins/language_vala.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index cb0a17c4..e219b374 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -1,6 +1,9 @@ -- mod-version:3 local syntax = require "core.syntax" +-- Language syntax reference +-- https://gnome.pages.gitlab.gnome.org/vala/manual/overview.html + syntax.add { name = "Vala", files = { "%.vala$" }, From d81a19184e03b87ff1bef2b48fdd5597df745d87 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Tue, 24 Sep 2024 14:17:34 +0200 Subject: [PATCH 07/16] Updated meta_languages version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index d253136e..c4c441be 100644 --- a/manifest.json +++ b/manifest.json @@ -166,7 +166,7 @@ "id": "meta_languages", "mod_version": "3", "type": "meta", - "version": "0.1.15" + "version": "0.1.20" }, { "description": "Align multiple carets and selections *([clip](https://user-images.githubusercontent.com/2798487/165631951-532f8d24-d596-4dd0-9d21-ff53c71ed32f.mp4))*", From 82961bdaede6c86f157a051b0e6e925d309a037a Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Wed, 2 Oct 2024 19:13:20 +0200 Subject: [PATCH 08/16] WIP: ... --- plugins/language_vala.lua | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index 6a797f56..a06df02b 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -12,33 +12,32 @@ syntax.add { patterns = { { pattern = "//.*", type = "comment" }, -- Single-line comment { pattern = { "/%*", "%*/" }, type = "comment" }, -- Multi-line comment - { pattern = { '"', '"', '\\' }, type = "string" }, -- ? - { pattern = { "'", "'", '\\' }, type = "string" }, -- ? + --{ pattern = { '"', '"', '\\' }, type = "string" }, -- String, double apices + { regex = { '\\@?\\"', '\\"', '\\' }, type = "string" }, -- Special string + { pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices { pattern = "-?0x%x+", type = "number" }, -- ? { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- ? - { pattern = "-?%.?%d+f?", type = "number" }, -- ? + --{ pattern = "-?%.?%d+f?", type = "number" }, -- ? { regex = "\\w+(?=\\s+\\w++\\s+\\=\\s+)", type = "function" }, -- Class name in class instance { regex = "\\<.+\\>", type = "keyword2" }, -- Generic Type { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- ? { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- ? { regex = [[\s?\:\s?(?:\w+\.?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance - { regex = [[\s?\:\s?(?:\w+(?:\<.+\>)?\s?\,?\s?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance + { regex = [[\s?\:\s?(?:\w+(?:\<\w+\.\>)?\s?\,?\s?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance { regex = [[class()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda { regex = "[A-Z][A-Z_]+(?=\\s*[)]|[\\;]|[\\,]|[\\s\\=])", type = "keyword2" }, -- Constants - { regex = "\\[.+\\](?=\\w*)", type = "literal" }, -- Attribute + { regex = "^\\[.+\\]", type = "literal" }, -- Attribute { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive { pattern = "[%a_][%w_]*", type = "symbol" }, -- Symbols - -- FIX: @"$a * $b = $(a * b)" should be fully string-colored - -- FIX: 21.to_string(); the . should be symbol-colored - -- FIX: int[] a = new int[10] and int[] c = b[1:3]; + -- FIX: 21.to_string(); -- FIX: var l = new List(); // same as: List l = new List(); -- FIX: MyFoo> foo = new MyFoo>(); -- FIX: : GLib.List + -- FIX: public class ListClass : GLib.Object, Collection, List -- FIX: <> and <<>> operators -- FIX: int method_name(int arg1, Object arg2) { Object is not colored properly - -- FIX: proper coloring for: public class ListClass : GLib.Object, Collection, List }, symbols = { ["class"] = "keyword", From 736219955fe1efd4e059e23e693bf8e180a73d63 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Wed, 2 Oct 2024 21:36:53 +0200 Subject: [PATCH 09/16] Fixing patterns. --- plugins/language_vala.lua | 47 +++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index a06df02b..ccc5aa0e 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -10,34 +10,27 @@ syntax.add { comment = "//", block_comment = { "/*", "*/" }, patterns = { - { pattern = "//.*", type = "comment" }, -- Single-line comment - { pattern = { "/%*", "%*/" }, type = "comment" }, -- Multi-line comment - --{ pattern = { '"', '"', '\\' }, type = "string" }, -- String, double apices - { regex = { '\\@?\\"', '\\"', '\\' }, type = "string" }, -- Special string - { pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices - { pattern = "-?0x%x+", type = "number" }, -- ? - { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- ? - --{ pattern = "-?%.?%d+f?", type = "number" }, -- ? - { regex = "\\w+(?=\\s+\\w++\\s+\\=\\s+)", type = "function" }, -- Class name in class instance - { regex = "\\<.+\\>", type = "keyword2" }, -- Generic Type - { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- ? - { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- ? - { regex = [[\s?\:\s?(?:\w+\.?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance - { regex = [[\s?\:\s?(?:\w+(?:\<\w+\.\>)?\s?\,?\s?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance - { regex = [[class()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type - { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type - { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda - { regex = "[A-Z][A-Z_]+(?=\\s*[)]|[\\;]|[\\,]|[\\s\\=])", type = "keyword2" }, -- Constants - { regex = "^\\[.+\\]", type = "literal" }, -- Attribute - { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive - { pattern = "[%a_][%w_]*", type = "symbol" }, -- Symbols + { pattern = "//.*", type = "comment" }, -- Single-line comment + { pattern = { "/%*", "%*/" }, type = "comment" }, -- Multi-line comment + { pattern = { '"', '"', '\\' }, type = "string" }, -- String, double apices + { regex = { '\\@?\\"', '\\"', '\\' }, type = "string" }, -- Special string + { pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices + { pattern = "-?0x%x+", type = "number" }, -- ? + { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- ? + { regex = "\\w+(?=(?:\\s+\\w++\\s+\\=\\s+)|(?:\\s+\\w+\\s*[)]))", type = "function" }, -- Class name in class instance + { regex = "\\<(?:[\\w+][\\<\\w+\\>]\\,?\\s*)+\\>(?=[(]?[)]?[\\;\\s*])", type = "keyword2" }, -- Generic Type + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- Operators + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- Function + { regex = [[\s?\:\s?(?:\w+\.?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance + { regex = [[\s?\:\s?(?:\w+(?:\.\w+)?(?:\<\w+\.\w+\>)?\s?\,?\s?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance + { regex = [[class()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type + { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type + { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda + { regex = "[A-Z][A-Z_]+(?=\\s*[)]|[\\;]|[\\,]|[\\s\\=])", type = "keyword2" }, -- Constants + { regex = "^\\[.+\\]", type = "literal" }, -- Attribute + { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive + { pattern = "[%a_][%w_]*", type = "symbol" }, -- Symbols -- FIX: 21.to_string(); - -- FIX: var l = new List(); // same as: List l = new List(); - -- FIX: MyFoo> foo = new MyFoo>(); - -- FIX: : GLib.List - -- FIX: public class ListClass : GLib.Object, Collection, List - -- FIX: <> and <<>> operators - -- FIX: int method_name(int arg1, Object arg2) { Object is not colored properly }, symbols = { ["class"] = "keyword", From a3dc2de431761dcdd265459b9144178f4ad767fd Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Thu, 3 Oct 2024 13:47:01 +0200 Subject: [PATCH 10/16] Fixed last pattern. --- plugins/language_vala.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index ccc5aa0e..67088ab9 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -15,8 +15,8 @@ syntax.add { { pattern = { '"', '"', '\\' }, type = "string" }, -- String, double apices { regex = { '\\@?\\"', '\\"', '\\' }, type = "string" }, -- Special string { pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices - { pattern = "-?0x%x+", type = "number" }, -- ? - { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- ? + { pattern = "-?0x%x+", type = "number" }, -- Numbers + { regex = "-?(?:\\d_?)+(?:.\\d+[eE]?)?f?", type = "number" }, -- Numbers { regex = "\\w+(?=(?:\\s+\\w++\\s+\\=\\s+)|(?:\\s+\\w+\\s*[)]))", type = "function" }, -- Class name in class instance { regex = "\\<(?:[\\w+][\\<\\w+\\>]\\,?\\s*)+\\>(?=[(]?[)]?[\\;\\s*])", type = "keyword2" }, -- Generic Type { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- Operators @@ -30,7 +30,6 @@ syntax.add { { regex = "^\\[.+\\]", type = "literal" }, -- Attribute { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive { pattern = "[%a_][%w_]*", type = "symbol" }, -- Symbols - -- FIX: 21.to_string(); }, symbols = { ["class"] = "keyword", From 92ec4a822a3ce6b67d5fb8e2eec259389c7ff694 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Fri, 25 Oct 2024 22:46:36 +0200 Subject: [PATCH 11/16] WIP: fixing regex patterns vulnerable to REDOs. --- plugins/language_vala.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index 67088ab9..767457bd 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -4,6 +4,9 @@ local syntax = require "core.syntax" -- Language syntax reference -- https://gnome.pages.gitlab.gnome.org/vala/manual/overview.html +-- https://devina.io/redos-checker +-- https://redosdetector.com/?pattern=%5C%40%3F%5C%22&caseInsensitive=false&unicode=false + syntax.add { name = "Vala", files = { "%.vala$" }, @@ -16,16 +19,24 @@ syntax.add { { regex = { '\\@?\\"', '\\"', '\\' }, type = "string" }, -- Special string { pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices { pattern = "-?0x%x+", type = "number" }, -- Numbers + -- FIX: Vulnerable to REDO { regex = "-?(?:\\d_?)+(?:.\\d+[eE]?)?f?", type = "number" }, -- Numbers + -- ? { regex = "\\w+(?=(?:\\s+\\w++\\s+\\=\\s+)|(?:\\s+\\w+\\s*[)]))", type = "function" }, -- Class name in class instance + -- FIX: Vulnerable to REDO { regex = "\\<(?:[\\w+][\\<\\w+\\>]\\,?\\s*)+\\>(?=[(]?[)]?[\\;\\s*])", type = "keyword2" }, -- Generic Type { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- Operators { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- Function + -- FIX: Vulnerable to REDO { regex = [[\s?\:\s?(?:\w+\.?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance + -- FIX: Vulnerable to REDO { regex = [[\s?\:\s?(?:\w+(?:\.\w+)?(?:\<\w+\.\w+\>)?\s?\,?\s?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance + -- FIX: Vulnerable to REDO { regex = [[class()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type + -- FIX: Vulnerable to REDO { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda + -- FIX: Vulnerable to REDO { regex = "[A-Z][A-Z_]+(?=\\s*[)]|[\\;]|[\\,]|[\\s\\=])", type = "keyword2" }, -- Constants { regex = "^\\[.+\\]", type = "literal" }, -- Attribute { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive From cd6830ccca8a7d2a64f92ed1dcfd1558467a114e Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Sat, 26 Oct 2024 09:37:32 +0200 Subject: [PATCH 12/16] Fixed name. --- plugins/language_vala.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index 767457bd..0beda7ac 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -19,24 +19,24 @@ syntax.add { { regex = { '\\@?\\"', '\\"', '\\' }, type = "string" }, -- Special string { pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices { pattern = "-?0x%x+", type = "number" }, -- Numbers - -- FIX: Vulnerable to REDO + -- FIX: Vulnerable to REDOs { regex = "-?(?:\\d_?)+(?:.\\d+[eE]?)?f?", type = "number" }, -- Numbers -- ? { regex = "\\w+(?=(?:\\s+\\w++\\s+\\=\\s+)|(?:\\s+\\w+\\s*[)]))", type = "function" }, -- Class name in class instance - -- FIX: Vulnerable to REDO + -- FIX: Vulnerable to REDOs { regex = "\\<(?:[\\w+][\\<\\w+\\>]\\,?\\s*)+\\>(?=[(]?[)]?[\\;\\s*])", type = "keyword2" }, -- Generic Type { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- Operators { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- Function - -- FIX: Vulnerable to REDO + -- FIX: Vulnerable to REDOs { regex = [[\s?\:\s?(?:\w+\.?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance - -- FIX: Vulnerable to REDO + -- FIX: Vulnerable to REDOs { regex = [[\s?\:\s?(?:\w+(?:\.\w+)?(?:\<\w+\.\w+\>)?\s?\,?\s?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance - -- FIX: Vulnerable to REDO + -- FIX: Vulnerable to REDOs { regex = [[class()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type - -- FIX: Vulnerable to REDO + -- FIX: Vulnerable to REDOs { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda - -- FIX: Vulnerable to REDO + -- FIX: Vulnerable to REDOs { regex = "[A-Z][A-Z_]+(?=\\s*[)]|[\\;]|[\\,]|[\\s\\=])", type = "keyword2" }, -- Constants { regex = "^\\[.+\\]", type = "literal" }, -- Attribute { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive From 0d80176d517ce9d018f9e0cf246c7dbf16c9f7a9 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Sun, 15 Dec 2024 12:03:47 +0100 Subject: [PATCH 13/16] WIP: fixing patterns. --- plugins/language_vala.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index 0beda7ac..a897d701 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -16,13 +16,15 @@ syntax.add { { pattern = "//.*", type = "comment" }, -- Single-line comment { pattern = { "/%*", "%*/" }, type = "comment" }, -- Multi-line comment { pattern = { '"', '"', '\\' }, type = "string" }, -- String, double apices - { regex = { '\\@?\\"', '\\"', '\\' }, type = "string" }, -- Special string + { pattern = { '@?"', '"', '\\' }, type = "string" }, -- Special string { pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices { pattern = "-?0x%x+", type = "number" }, -- Numbers - -- FIX: Vulnerable to REDOs - { regex = "-?(?:\\d_?)+(?:.\\d+[eE]?)?f?", type = "number" }, -- Numbers - -- ? - { regex = "\\w+(?=(?:\\s+\\w++\\s+\\=\\s+)|(?:\\s+\\w+\\s*[)]))", type = "function" }, -- Class name in class instance + { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- Numbers + { pattern = "-?%.?%d+f?", type = "number" }, -- Numbers + { regex = "(?>\\w+\\.?)+\\<.+?\\>(?=\\s+\\w+\\s*)?", type = "function" }, -- Generic class name reference + { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)", type = "function" }, -- Class name reference + { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)?(?=\\s*\\{)", type = "function" }, -- Class name + { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)?(?=\\s*\\:)", type = "function" }, -- Class name -- FIX: Vulnerable to REDOs { regex = "\\<(?:[\\w+][\\<\\w+\\>]\\,?\\s*)+\\>(?=[(]?[)]?[\\;\\s*])", type = "keyword2" }, -- Generic Type { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- Operators @@ -36,9 +38,8 @@ syntax.add { -- FIX: Vulnerable to REDOs { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda - -- FIX: Vulnerable to REDOs - { regex = "[A-Z][A-Z_]+(?=\\s*[)]|[\\;]|[\\,]|[\\s\\=])", type = "keyword2" }, -- Constants - { regex = "^\\[.+\\]", type = "literal" }, -- Attribute + { regex = "[A-Z](?:[A-Z_][\\d]*)+", type = "keyword2" }, -- Constants + { pattern = "^%s*%[.*%]", type = "literal" }, -- Attribute { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive { pattern = "[%a_][%w_]*", type = "symbol" }, -- Symbols }, From fa66cb217cc0f4eb47954b4d64b81d1efdf4bf33 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Sun, 15 Dec 2024 12:46:52 +0100 Subject: [PATCH 14/16] WIP: fixing patterns... --- plugins/language_vala.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index a897d701..142eba70 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -21,22 +21,17 @@ syntax.add { { pattern = "-?0x%x+", type = "number" }, -- Numbers { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, -- Numbers { pattern = "-?%.?%d+f?", type = "number" }, -- Numbers - { regex = "(?>\\w+\\.?)+\\<.+?\\>(?=\\s+\\w+\\s*)?", type = "function" }, -- Generic class name reference - { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)", type = "function" }, -- Class name reference + -- FIX: Vulnerable to REDOs + { regex = "\\<(?:[\\w+][\\<\\w+\\>]\\,?\\s*)+\\>\\>*(?=[(]?[)]?[\\;\\s*])", type = "keyword2" }, -- Generic Type + { regex = "(?>\\w+\\.?)+\\,?\\<.+?\\>\\>*(?=\\s+\\w+\\s*)?", type = "function" }, -- Generic class name reference + -- FIX: it also matches var names with a following , + { regex = "(?>\\w+\\.?)+\\,?(?=\\s+\\w+\\s*)", type = "function" }, -- Class name reference + -- FIX: it also matches var names with a following , { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)?(?=\\s*\\{)", type = "function" }, -- Class name { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)?(?=\\s*\\:)", type = "function" }, -- Class name - -- FIX: Vulnerable to REDOs - { regex = "\\<(?:[\\w+][\\<\\w+\\>]\\,?\\s*)+\\>(?=[(]?[)]?[\\;\\s*])", type = "keyword2" }, -- Generic Type { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- Operators { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- Function - -- FIX: Vulnerable to REDOs - { regex = [[\s?\:\s?(?:\w+\.?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance - -- FIX: Vulnerable to REDOs - { regex = [[\s?\:\s?(?:\w+(?:\.\w+)?(?:\<\w+\.\w+\>)?\s?\,?\s?)+(?=\s?[{])]], type = "keyword2" }, -- Inheritance - -- FIX: Vulnerable to REDOs - { regex = [[class()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Class Type - -- FIX: Vulnerable to REDOs - { regex = [[interface()\s+\w+()\<.+\>(?=\s?\:)]], type = { "keyword", "normal", "keyword2" } }, -- Generic Interface Type + { pattern = "%s*%:%s*", type = "keyword" }, -- Inheritance { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda { regex = "[A-Z](?:[A-Z_][\\d]*)+", type = "keyword2" }, -- Constants { pattern = "^%s*%[.*%]", type = "literal" }, -- Attribute From 7664795be3143a84b8eafeccb95c28dd1d09cd12 Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Sun, 5 Jan 2025 11:14:43 +0100 Subject: [PATCH 15/16] Fixed constants pattern. --- plugins/language_vala.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index 142eba70..1eb8e899 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -33,7 +33,7 @@ syntax.add { { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- Function { pattern = "%s*%:%s*", type = "keyword" }, -- Inheritance { regex = "\\=\\>(?=[{])", type = "keyword" }, -- Lambda - { regex = "[A-Z](?:[A-Z_][\\d]*)+", type = "keyword2" }, -- Constants + { regex = "[A-Z](?:[A-Z_][\\d]*)+(?!\\w)", type = "keyword2" }, -- Constants { pattern = "^%s*%[.*%]", type = "literal" }, -- Attribute { regex = "\\#\\w+(?=\\s?\\w*)", type = "keyword" }, -- Preprocessor directive { pattern = "[%a_][%w_]*", type = "symbol" }, -- Symbols From 8edaf19ff064cdd1db362311fc51dbf95cb0eddc Mon Sep 17 00:00:00 2001 From: PerilousBooklet Date: Sun, 5 Jan 2025 11:24:51 +0100 Subject: [PATCH 16/16] WIP: fixinf patterns... --- plugins/language_vala.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/language_vala.lua b/plugins/language_vala.lua index 1eb8e899..d0271d6f 100644 --- a/plugins/language_vala.lua +++ b/plugins/language_vala.lua @@ -23,12 +23,14 @@ syntax.add { { pattern = "-?%.?%d+f?", type = "number" }, -- Numbers -- FIX: Vulnerable to REDOs { regex = "\\<(?:[\\w+][\\<\\w+\\>]\\,?\\s*)+\\>\\>*(?=[(]?[)]?[\\;\\s*])", type = "keyword2" }, -- Generic Type + -- FIX: it also matches var names with a following , + -- es. void my_sorting_algorithm(int[] data, Comparator compare) { { regex = "(?>\\w+\\.?)+\\,?\\<.+?\\>\\>*(?=\\s+\\w+\\s*)?", type = "function" }, -- Generic class name reference -- FIX: it also matches var names with a following , + -- es. es. void my_sorting_algorithm(int[] data, Comparator compare) { + -- es. delegate int Comparator(int a, int b); { regex = "(?>\\w+\\.?)+\\,?(?=\\s+\\w+\\s*)", type = "function" }, -- Class name reference - -- FIX: it also matches var names with a following , - { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)?(?=\\s*\\{)", type = "function" }, -- Class name - { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)?(?=\\s*\\:)", type = "function" }, -- Class name + { regex = "(?>\\w+\\.?)+(?=\\s+\\w+\\s*)?(?=\\s*\\{|\\:)", type = "function" }, -- Class name { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, -- Operators { pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- Function { pattern = "%s*%:%s*", type = "keyword" }, -- Inheritance