Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Ruby #132

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions Lua/Plugins/rb.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
-- Comments
highlight_region("#" , "", "comments", true)
highlight_region("=begin" , "=end", "comments", false)

-- Strings
highlight_region("\"", "\"", "string")
highlight_region("'", "'", "string")

-- Keywords
--- 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")
highlight("in" , "reserved")

-- Binary keywords
highlight("true" , "binary")
highlight("false" , "binary")

-- Binary Operator Keywords
highlight("or" , "reserved")
highlight("and" , "reserved")
highlight("not" , "reserved")

-- Normal operators
-- 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")

-- additional operators
highlight("{" , "binary")
highlight("}" , "binary")
highlight("[" , "binary")
highlight("]" , "binary")

-- Reserved words
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 = {}

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