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

Create c.lua #116

Merged
merged 2 commits into from
May 9, 2024
Merged
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
138 changes: 138 additions & 0 deletions Lua/Plugins/c.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
-- Highlight Keywords
highlight("auto", "reserved")
highlight("break", "reserved")
highlight("case", "reserved")
highlight("char", "reserved")
highlight("const", "reserved")
highlight("continue", "reserved")
highlight("default", "reserved")
highlight("do", "reserved")
highlight("double", "reserved")
highlight("else", "reserved")
highlight("enum", "reserved")
highlight("extern", "reserved")
highlight("float", "reserved")
highlight("for", "reserved")
highlight("goto", "reserved")
highlight("if", "reserved")
highlight("inline", "reserved")
highlight("int", "reserved")
highlight("long", "reserved")
highlight("register", "reserved")
highlight("restrict", "reserved")
highlight("return", "reserved")
highlight("short", "reserved")
highlight("signed", "reserved")
highlight("sizeof", "reserved")
highlight("static", "reserved")
highlight("struct", "reserved")
highlight("switch", "reserved")
highlight("typedef", "reserved")
highlight("union", "reserved")
highlight("unsigned", "reserved")
highlight("void", "reserved")
highlight("volatile", "reserved")
highlight("while", "reserved")
highlight("_Alignas", "reserved")
highlight("_Alignof", "reserved")
highlight("_Atomic", "reserved")
highlight("_Bool", "reserved")
highlight("_Complex", "reserved")
highlight("_Generic", "reserved")
highlight("_Imaginary", "reserved")
highlight("_Noreturn", "reserved")
highlight("_Static_assert", "reserved")
highlight("_Thread_local", "reserved")

-- Arithmetic Operators
highlight("+", "operator")
highlight("-", "operator")
highlight("*", "operator")
highlight("/", "operator")
highlight("%", "operator")
highlight("++", "operator")
highlight("--", "operator")

-- Assignment Operators
highlight("=", "operator")
highlight("+=", "operator")
highlight("-=", "operator")
highlight("*=", "operator")
highlight("/=", "operator")
highlight("%=", "operator")
highlight("&=", "operator")
highlight("^=", "operator")
highlight("|=", "operator")
highlight("<<=", "operator")
highlight(">>=", "operator")

-- Comparison Operators
highlight("==", "operator")
highlight("!=", "operator")
highlight(">", "operator")
highlight("<", "operator")
highlight(">=", "operator")
highlight("<=", "operator")

-- Logical Operators
highlight("&&", "operator")
highlight("||", "operator")
highlight("!", "operator")

-- Bitwise Operators
highlight("&", "operator")
highlight("|", "operator")
highlight("^", "operator")
highlight("~", "operator")
highlight("<<", "operator")
highlight(">>", "operator")

-- Special Characters
highlight("{", "binary")
highlight("}", "binary")
highlight("[", "binary")
highlight("]", "binary")
highlight("(", "binary")
highlight(")", "binary")
highlight(";", "binary")
highlight(",", "binary")

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

-- Comments
highlight_region("//", "", "comments", true)
highlight_region("/*", "*/", "comments", false)

-- Autocomplete

function detect_functions(content)
local functionNames = {}

for line in content:gmatch("[^\r\n]+") do
-- Match function declarations
local functionName = line:match("%s*([%w_]+)%s*%([^%)]*%)%s*%{?")
if functionName then
table.insert(functionNames, functionName)
end
end

return functionNames
end

function detect_variables(content)
local variable_names = {}
local lines = content:gmatch("[^\r\n]+")

for line in lines do
-- Match variable declarations
local variable = line:match("%s*([%w_]+)%s+[%w_]+%s*[=;%(%),]")

if variable then
table.insert(variable_names, variable)
end
end

return variable_names
end