From 4a71dd7a4ecc10a692054001b4be7d49f85fda74 Mon Sep 17 00:00:00 2001 From: Shannarra Date: Sat, 11 May 2024 17:43:31 +0300 Subject: [PATCH 1/4] Added basic Ruby mode --- Lua/Plugins/rb.lua | 132 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 Lua/Plugins/rb.lua diff --git a/Lua/Plugins/rb.lua b/Lua/Plugins/rb.lua new file mode 100644 index 0000000..d69e636 --- /dev/null +++ b/Lua/Plugins/rb.lua @@ -0,0 +1,132 @@ +-- Comments +highlight_region("#", "", "comments", true) +highlight_region("=begin", "=end", "comments", false) + +-- Keywords +highlight("BEGIN" , "reserved") +highlight("END" , "reserved") +highlight("alias" , "reserved") +highlight("begin" , "reserved") +highlight("break" , "reserved") +highlight("case" , "reserved") +highlight("class" , "reserved") +highlight("def" , "reserved") +highlight("module" , "reserved") +highlight("next" , "reserved") +highlight("nil" , "reserved") +highlight("redo" , "reserved") +highlight("rescue" , "reserved") +highlight("retry" , "reserved") +highlight("return" , "reserved") +highlight("elsif" , "reserved") +highlight("end" , "reserved") +highlight("ensure" , "reserved") +highlight("for" , "reserved") +highlight("if" , "reserved") +highlight("undef" , "reserved") +highlight("unless" , "reserved") +highlight("do" , "reserved") +highlight("else" , "reserved") +highlight("super" , "reserved") +highlight("then" , "reserved") +highlight("until" , "reserved") +highlight("when" , "reserved") +highlight("while" , "reserved") +highlight("defined?" , "reserved") +highlight("self" , "reserved") +highlight("loop" , "reserved") +highlight("require" , "reserved") +highlight("require_relative" , "reserved") + +-- Binary keywords +highlight("true" , "binary") +highlight("false" , "binary") + +-- Binary Operator Keywords +highlight("or" , "reserved") +highlight("and" , "reserved") +highlight("not" , "reserved") + +-- Normal operators +highlight("+", "operator") +highlight("-", "operator") +highlight("*", "operator") +highlight("/", "operator") +highlight("%", "operator") +highlight("&", "operator") +highlight("|", "operator") +highlight("^", "operator") +highlight("**", "operator") +highlight("<<", "operator") +highlight(">>", "operator") +highlight("&&", "operator") +highlight("||", "operator") + +-- Assignment (abbreviated) operators +highlight("+=", "operator") +highlight("-=", "operator") +highlight("*=", "operator") +highlight("/=", "operator") +highlight("%=", "operator") +highlight("&=", "operator") +highlight("|=", "operator") +highlight("^=", "operator") +highlight("&&=", "operator") +highlight("**=", "operator") +highlight("||=", "operator") +highlight("<=", "operator") +highlight(">=", "operator") +highlight("==", "operator") +highlight("===", "operator") +highlight("!=", "operator") +highlight("!==", "operator") + +highlight("{", "binary") +highlight("}", "binary") +highlight("[", "binary") +highlight("]", "binary") + +-- Reserved words +highlight("block_given?", "reserved") +highlight("&block", "reserved") + +function detect_functions(content) + local functionNames = {} + + for line in content:gmatch("[^\r\n]+") do + -- Match the "def" keyword for regular functions + -- note that Ruby allows the ! and ? symbols at the end + -- of function definitions. + + local functionName = line:match("def%s+([%w_(%?%!)]+)/?%s*%(") + or line:match(".%s+([%w_(%?%!)]+)/?%s*%(") + + -- Although detected properly, AND being a part of the function name as a string, + -- the base editor does not detect functions with names ending in ! and ? properly for now. + -- Will open an issue. + -- - Shannarra + if functionName then + table.insert(functionNames, functionName) + end + end + + return functionNames +end + +function detect_variables(content) + local variable_names = { + -- TODO: add variables here if you think of any.. Hmmge + "self", + } + local lines = content:gmatch("[^\r\n]+") + + for line in lines do + local assignment = line:match("(%w+)%s*=%s*.+") + if assignment then + local variable_name = assignment:match("(%w+)") + table.insert(variable_names, variable_name) + end + end + + return variable_names +end From 508ce5d22f635cd0281cf1daab910a4f98de05a2 Mon Sep 17 00:00:00 2001 From: Shannarra Date: Sun, 12 May 2024 11:57:31 +0300 Subject: [PATCH 2/4] Added comments and formatted file --- Lua/Plugins/rb.lua | 184 +++++++++++++++++++++++++-------------------- 1 file changed, 101 insertions(+), 83 deletions(-) diff --git a/Lua/Plugins/rb.lua b/Lua/Plugins/rb.lua index d69e636..2694322 100644 --- a/Lua/Plugins/rb.lua +++ b/Lua/Plugins/rb.lua @@ -1,94 +1,112 @@ -- Comments -highlight_region("#", "", "comments", true) -highlight_region("=begin", "=end", "comments", false) +highlight_region("#" , "", "comments", true) +highlight_region("=begin" , "=end", "comments", false) -- Keywords -highlight("BEGIN" , "reserved") -highlight("END" , "reserved") -highlight("alias" , "reserved") -highlight("begin" , "reserved") -highlight("break" , "reserved") -highlight("case" , "reserved") -highlight("class" , "reserved") -highlight("def" , "reserved") -highlight("module" , "reserved") -highlight("next" , "reserved") -highlight("nil" , "reserved") -highlight("redo" , "reserved") -highlight("rescue" , "reserved") -highlight("retry" , "reserved") -highlight("return" , "reserved") -highlight("elsif" , "reserved") -highlight("end" , "reserved") -highlight("ensure" , "reserved") -highlight("for" , "reserved") -highlight("if" , "reserved") -highlight("undef" , "reserved") -highlight("unless" , "reserved") -highlight("do" , "reserved") -highlight("else" , "reserved") -highlight("super" , "reserved") -highlight("then" , "reserved") -highlight("until" , "reserved") -highlight("when" , "reserved") -highlight("while" , "reserved") -highlight("defined?" , "reserved") -highlight("self" , "reserved") -highlight("loop" , "reserved") -highlight("require" , "reserved") -highlight("require_relative" , "reserved") +--- basic +highlight("BEGIN" , "reserved") +highlight("END" , "reserved") +highlight("alias" , "reserved") +highlight("begin" , "reserved") +highlight("class" , "reserved") +highlight("module" , "reserved") +highlight("redo" , "reserved") +highlight("rescue" , "reserved") +highlight("retry" , "reserved") +highlight("return" , "reserved") +highlight("end" , "reserved") +highlight("defined?" , "reserved") +highlight("self" , "reserved") +highlight("require" , "reserved") +highlight("require_relative" , "reserved") +highlight("def" , "reserved") +highlight("nil" , "reserved") +highlight("ensure" , "reserved") +highlight("super" , "reserved") + +-- branching +highlight("if" , "reserved") +highlight("elsif" , "reserved") +highlight("unless" , "reserved") +highlight("else" , "reserved") +highlight("case" , "reserved") +highlight("when" , "reserved") +highlight("then" , "reserved") + +-- loops +highlight("break" , "reserved") +highlight("next" , "reserved") +highlight("for" , "reserved") +highlight("undef" , "reserved") +highlight("do" , "reserved") +highlight("until" , "reserved") +highlight("while" , "reserved") +highlight("loop" , "reserved") -- Binary keywords -highlight("true" , "binary") -highlight("false" , "binary") +highlight("true" , "binary") +highlight("false" , "binary") -- Binary Operator Keywords -highlight("or" , "reserved") -highlight("and" , "reserved") -highlight("not" , "reserved") +highlight("or" , "reserved") +highlight("and" , "reserved") +highlight("not" , "reserved") -- Normal operators -highlight("+", "operator") -highlight("-", "operator") -highlight("*", "operator") -highlight("/", "operator") -highlight("%", "operator") -highlight("&", "operator") -highlight("|", "operator") -highlight("^", "operator") -highlight("**", "operator") -highlight("<<", "operator") -highlight(">>", "operator") -highlight("&&", "operator") -highlight("||", "operator") +-- binary singular +highlight("+" , "operator") +highlight("-" , "operator") +highlight("*" , "operator") +highlight("/" , "operator") +highlight("%" , "operator") +highlight("&" , "operator") +highlight("|" , "operator") +highlight("^" , "operator") + +-- binary multiple +highlight("**" , "operator") +highlight("<<" , "operator") +highlight(">>" , "operator") +highlight("&&" , "operator") +highlight("||" , "operator") -- Assignment (abbreviated) operators -highlight("+=", "operator") -highlight("-=", "operator") -highlight("*=", "operator") -highlight("/=", "operator") -highlight("%=", "operator") -highlight("&=", "operator") -highlight("|=", "operator") -highlight("^=", "operator") -highlight("&&=", "operator") -highlight("**=", "operator") -highlight("||=", "operator") -highlight("<=", "operator") -highlight(">=", "operator") -highlight("==", "operator") -highlight("===", "operator") -highlight("!=", "operator") -highlight("!==", "operator") - -highlight("{", "binary") -highlight("}", "binary") -highlight("[", "binary") -highlight("]", "binary") +highlight("+=" , "operator") +highlight("-=" , "operator") +highlight("*=" , "operator") +highlight("/=" , "operator") +highlight("%=" , "operator") +highlight("&=" , "operator") +highlight("|=" , "operator") +highlight("^=" , "operator") +highlight("&&=" , "operator") +highlight("**=" , "operator") +highlight("||=" , "operator") +highlight("<=" , "operator") +highlight(">=" , "operator") +highlight("==" , "operator") +highlight("===" , "operator") +highlight("!=" , "operator") +highlight("!==" , "operator") + +-- additional operators +highlight("{" , "binary") +highlight("}" , "binary") +highlight("[" , "binary") +highlight("]" , "binary") -- Reserved words -highlight("block_given?", "reserved") -highlight("&block", "reserved") +highlight("block_given?" , "reserved") +highlight("&block" , "reserved") + +-- Comments +add_comment("Fuck. You. - DHH") +add_comment("Smart people underestimate the ordinarity of ordinary people. - Yukihiro Matsumoto ") +add_comment("Plant a memory, plant a tree, do it today for tomorrow.") +add_comment("Ruby’s original heresy was indeed to place the happiness of the programmer on a pedestal") +add_comment("Don't forget to run Rubocop before pushing 🤖🚓💨") +add_comment("Too weird for you? How about you shut up") +add_comment("IDK what am I doing, but at least in Ruby it looks nice") function detect_functions(content) local functionNames = {} @@ -101,12 +119,12 @@ function detect_functions(content) local functionName = line:match("def%s+([%w_(%?%!)]+)/?%s*%(") or line:match(".%s+([%w_(%?%!)]+)/?%s*%(") - -- Although detected properly, AND being a part of the function name as a string, + -- Although detected properly , AND being a part of the function name as a string, -- the base editor does not detect functions with names ending in ! and ? properly for now. -- Will open an issue. -- - Shannarra if functionName then - table.insert(functionNames, functionName) + table.insert(functionNames , functionName) end end @@ -116,15 +134,15 @@ end function detect_variables(content) local variable_names = { -- TODO: add variables here if you think of any.. Hmmge - "self", + "self" , } local lines = content:gmatch("[^\r\n]+") for line in lines do - local assignment = line:match("(%w+)%s*=%s*.+") + local assignment = line:match("(%w+)%s*=%s*+") if assignment then local variable_name = assignment:match("(%w+)") - table.insert(variable_names, variable_name) + table.insert(variable_names , variable_name) end end From 8cd11cb34ea652c27edd7d41400e4740f084dba7 Mon Sep 17 00:00:00 2001 From: Shannarra Date: Sun, 12 May 2024 12:50:52 +0300 Subject: [PATCH 3/4] Added strings support --- Lua/Plugins/rb.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lua/Plugins/rb.lua b/Lua/Plugins/rb.lua index 2694322..9f2df84 100644 --- a/Lua/Plugins/rb.lua +++ b/Lua/Plugins/rb.lua @@ -2,6 +2,10 @@ highlight_region("#" , "", "comments", true) highlight_region("=begin" , "=end", "comments", false) +-- Strings +highlight_region("\"", "\"", "string") +highlight_region("'", "'", "string") + -- Keywords --- basic highlight("BEGIN" , "reserved") From 37ae0ae76e977c1af6b5507233718cc69bb7d948 Mon Sep 17 00:00:00 2001 From: Shannarra Date: Sun, 12 May 2024 13:12:19 +0300 Subject: [PATCH 4/4] Added 'in' keyword --- Lua/Plugins/rb.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/Lua/Plugins/rb.lua b/Lua/Plugins/rb.lua index 9f2df84..8d151e0 100644 --- a/Lua/Plugins/rb.lua +++ b/Lua/Plugins/rb.lua @@ -46,6 +46,7 @@ highlight("do" , "reserved") highlight("until" , "reserved") highlight("while" , "reserved") highlight("loop" , "reserved") +highlight("in" , "reserved") -- Binary keywords highlight("true" , "binary")