diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2023-05-20 13:16:00 -0400 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2023-05-20 13:16:00 -0400 |
commit | f0e0355589b9c731b5fa3b1e2fff1b5c9703620d (patch) | |
tree | bd001bdca0927523781d6f2a391ca58340c921f4 /plugins | |
parent | b68dad231632c9d425bc0528631d3f3c4e062878 (diff) | |
download | lite-xl-plugins-f0e0355589b9c731b5fa3b1e2fff1b5c9703620d.tar.gz lite-xl-plugins-f0e0355589b9c731b5fa3b1e2fff1b5c9703620d.zip |
Pulled language_nelua directly into the main repo, as the original repository that held this language plugin was deleted.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/language_nelua.lua | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/plugins/language_nelua.lua b/plugins/language_nelua.lua new file mode 100644 index 0000000..c29d969 --- /dev/null +++ b/plugins/language_nelua.lua @@ -0,0 +1,119 @@ +-- mod-version:3 + +-- to better understand these comments, see this section from rxi's article +-- https://rxi.github.io/lite_an_implementation_overview.html#syntax_highlighting + +-- first, we need to require the syntax module +local syntax = require "core.syntax" + +--[[ + then, we'll add a new syntax to the syntax module, lite-xl matches Lua patterns + against the source code in order to highlight the code. +]] +syntax.add { + -- the extension of source code + files = "%.nelua$", + -- this add support for shebang, is not rare to add #!/usr/local/bin/lua to make + -- lua scripts executable, here we add support for it for nelua + headers = "^#!.*[ /]nelua", + -- tells to lite how to toggle comments + comment = "--", + -- finally the patterns, is a table of tables, + -- each entry is a table with some fields, especially with "pattern" and "type" fields. + patterns = { + --[[ + ["pattern"] field: + Describes a syntax pattern, this is done with Lua Patterns + you can learn it works here: https://www.lua.org/manual/5.4/manual.html#6.4.1 + + The pattern can be a string or a table, when is a string, then is just a + pattern that match everything, when is a table, then it follows this + logic: + { range_start_pattern, range_end_pattern [, escape_character] } + + The matched range_start_pattern and range_end_pattern text will be highlighted, but the + text between them will not. + + ["syntax"] field: + Optional field, when set, the text between matched ranges will use syntax from another language, + a good common known example of this is using javascript syntax inside a `script` element: + https://github.com/lite-xl/lite-xl/blob/df667ad28e9995f8cb79dab64e6039f095c202f4/data/plugins/language_html.lua#L17-L23 + + ["type"] field: + Set the style that should be used, this is defined on the "style" file from + the lite-xl's source, at "data/core/style.lua". + ]] + { + pattern = {"##%[=*%[", "%]=*%]"}, + syntax = ".lua", + type = "function", + }, + { + pattern = {"#|", "|#"}, + syntax = ".lua", + type = "function", + }, + { + pattern = {"##", "\n"}, + syntax = ".lua", + type = "function", + }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = { "%[%[", "%]%]" }, type = "string" }, + { pattern = { "%-%-%[=*%[", "%]=*%]"}, type = "comment" }, + { pattern = "%-%-.-\n", type = "comment" }, + { pattern = "0x%x+%.%x*[pP][-+]?%d+", type = "number" }, + { pattern = "0x%x+%.%x*", type = "number" }, + { pattern = "0x%.%x+[pP][-+]?%d+", type = "number" }, + { pattern = "0x%.%x+", type = "number" }, + { pattern = "0x%x+[pP][-+]?%d+", type = "number" }, + { pattern = "0x%x+", type = "number" }, + { pattern = "%d%.%d*[eE][-+]?%d+", type = "number" }, + { pattern = "%d%.%d*", type = "number" }, + { pattern = "%.?%d*[eE][-+]?%d+", type = "number" }, + { pattern = "<%S[%w+%._,%s*'\"()<>]-%S>", type = "keyword2" }, + { pattern = "%.?%d+", type = "number" }, + { pattern = "%.%.%.?", type = "operator" }, + { pattern = "[<>~=]=", type = "operator" }, + { pattern = "[%+%-=/%*%^%%#<>]", type = "operator" }, + { pattern = "[%a_][%w_]*()%s*%f[(\"'{]", type = {"function", "normal"} }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + { pattern = "::[%a_][%w_]*::", type = "function" }, + }, + -- special symbols, like keywords + symbols = { + -- lua symbols + ["if"] = "keyword", + ["then"] = "keyword", + ["else"] = "keyword", + ["elseif"] = "keyword", + ["end"] = "keyword", + ["do"] = "keyword", + ["function"] = "keyword", + ["repeat"] = "keyword", + ["until"] = "keyword", + ["while"] = "keyword", + ["for"] = "keyword", + ["break"] = "keyword", + ["return"] = "keyword", + ["local"] = "keyword", + ["in"] = "keyword", + ["not"] = "keyword", + ["and"] = "keyword", + ["or"] = "keyword", + ["goto"] = "keyword", + ["self"] = "keyword2", + ["true"] = "literal", + ["false"] = "literal", + ["nil"] = "literal", + + -- nelua symbols + ["global"] = "keyword", + ["switch"] = "keyword", + ["case"] = "keyword", + ["defer"] = "keyword", + ["continue"] = "keyword", + ["nilptr"] = "keyword", + }, +} |