aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_typst.lua
diff options
context:
space:
mode:
authorGaspartcho <93390411+Gaspartcho@users.noreply.github.com>2024-02-10 23:24:33 +0100
committerGitHub <noreply@github.com>2024-02-10 23:24:33 +0100
commit0eef56fa95d32f190fab990340f14e29815a73af (patch)
treef3388916b039bfa89c0b2881fea651dd6e8db76a /plugins/language_typst.lua
parent46681653fdd152b0dc33d91d2d70c97e8f0adf84 (diff)
downloadlite-xl-plugins-0eef56fa95d32f190fab990340f14e29815a73af.tar.gz
lite-xl-plugins-0eef56fa95d32f190fab990340f14e29815a73af.zip
Add support for Typst syntax (#361)
* Update manifest.json * Create language_typst.lua * Bumped the version of meta_languages from 0.1.5 to 0.1.6 * Update language_typst.lua passed the sub-syntax in local Commented out the code that would not work for now * Update language_typst.lua Deleted the part where it created new token types (not going to be used anyway) Commented out any part where it said "bold" or "italic". * Update language_typst.lua * Update language_typst.lua * Update plugins/language_typst.lua Allows also tabs
Diffstat (limited to 'plugins/language_typst.lua')
-rw-r--r--plugins/language_typst.lua156
1 files changed, 156 insertions, 0 deletions
diff --git a/plugins/language_typst.lua b/plugins/language_typst.lua
new file mode 100644
index 0000000..c5bd943
--- /dev/null
+++ b/plugins/language_typst.lua
@@ -0,0 +1,156 @@
+-- mod-version:3
+local syntax = require "core.syntax"
+
+
+local typst_math = {
+
+ patterns = {
+
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+ { pattern = "//.*", type = "comment" },
+
+ { pattern = { '"', '"', '\\' }, type = "string" },
+
+ { pattern = "[%a_][%w_%-]*%f[(]", type = "function" },
+ { pattern = "%a%a+", type = "function"},
+
+
+ { pattern = "0x[%dabcdef]+", type = "number" },
+ { pattern = "0b[01]+", type = "number" },
+ { pattern = "0o[01234567]+", type = "number" },
+ { pattern = "%d+[.e]%d+", type = "number" },
+ { pattern = "%d", type = "number" },
+
+ {pattern = "&", type = "literal"},
+ { pattern = "[%+%-=/%*%^%%<>~|#_^\\]", type = "operator" },
+
+ },
+
+ symbols = {
+ ["alpha"] = "keyword2",
+ ["beta"] = "keyword2",
+ ["gamma"] = "keyword2",
+ ["delta"] = "keyword2",
+ ["epsilon"] = "keyword2",
+ ["zeta"] = "keyword2",
+ ["eta"] = "keyword2",
+ ["theta"] = "keyword2",
+ ["iota"] = "keyword2",
+ ["kappa"] = "keyword2",
+ ["lambda"] = "keyword2",
+ ["mu"] = "keyword2",
+ ["nu"] = "keyword2",
+ ["xi"] = "keyword2",
+ ["omicron"] = "keyword2",
+ ["pi"] = "keyword2",
+ ["rho"] = "keyword2",
+ ["sigma"] = "keyword2",
+ ["tau"] = "keyword2",
+ ["upsilon"] = "keyword2",
+ ["phi"] = "keyword2",
+ ["chi"] = "keyword2",
+ ["psi"] = "keyword2",
+ ["omega"] = "keyword2",
+
+ ["Alpha"] = "keyword2",
+ ["Beta"] = "keyword2",
+ ["Gamma"] = "keyword2",
+ ["Delta"] = "keyword2",
+ ["Epsilon"] = "keyword2",
+ ["Zeta"] = "keyword2",
+ ["Eta"] = "keyword2",
+ ["Theta"] = "keyword2",
+ ["Iota"] = "keyword2",
+ ["Kappa"] = "keyword2",
+ ["Lambda"] = "keyword2",
+ ["Mu"] = "keyword2",
+ ["Nu"] = "keyword2",
+ ["Xi"] = "keyword2",
+ ["Omicron"] = "keyword2",
+ ["Pi"] = "keyword2",
+ ["Rho"] = "keyword2",
+ ["Sigma"] = "keyword2",
+ ["Tau"] = "keyword2",
+ ["Upsilon"] = "keyword2",
+ ["Phi"] = "keyword2",
+ ["Chi"] = "keyword2",
+ ["Psi"] = "keyword2",
+ ["Omega"] = "keyword2",
+ }
+}
+
+
+local typst_script = {
+
+ patterns = {
+
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+ { pattern = "//.*", type = "comment" },
+
+ { pattern = { '"', '"', '\\' }, type = "string" },
+ { pattern = {"%[", "%]"}, type = "normal", syntax = ".typ" },
+
+ { pattern = "[%a_][%w_%-]*%f[(]", type = "function" },
+
+ { pattern = "0x[%dabcdef]+", type = "number" },
+ { pattern = "0b[01]+", type = "number" },
+ { pattern = "0o[01234567]+", type = "number" },
+ { pattern = "%d+[.e]%d+()[%a%%]+", type = {"number", "keyword2"}},
+ { pattern = "%d+[.e]%d+", type = "number" },
+ { pattern = "%d+()[%a%%]+", type = {"number", "keyword2"}},
+ { pattern = "%d", type = "number" },
+
+
+ { pattern = "[%+%-=/%*%^%%<>~|&#_^\\]", type = "operator" },
+
+ },
+
+
+ symbols = {
+ ["set"] = "keyword",
+ ["let"] = "keyword",
+ ["include"] = "keyword",
+ }
+}
+
+
+syntax.add {
+ name = "Typst",
+ files = { "%.typ$" },
+ comment = "//",
+ block_comment = { "/*", "*/" },
+
+ patterns = {
+
+
+ { pattern = {"%$", "%$", "\\"}, type = "literal", syntax = typst_math },
+ { pattern = {"```js", "```", "\\"}, type = "literal", syntax = ".js" },
+ { pattern = {"#", "[^,%(%[{]\n"}, type = "literal", syntax = typst_script },
+ { pattern = {"`", "`", "\\"}, type = "normal"},
+
+ { pattern = { '"', '"', '\\' }, type = "string" },
+
+
+ { pattern = "//.*", type = "comment" },
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+
+ -- { pattern = {"link"}, type = "typst_underline"}, -- add underline text later
+
+ { pattern = "^%s*=+ ().+%f[\n]", type ={"operator", "literal"}}, -- Supposed to be bold
+
+ -- Finish later
+ { pattern = {"%*_", "_%*[%s,%.]"}, type = "keyword2"}, -- Bold Italic
+ { pattern = {"_%*", "%*_[%s,%.]"}, type = "keyword2"}, -- Bold Italic
+ { pattern = {"_", "_[%s,%.]"}, type = "keyword"}, -- Italic
+ { pattern = {"%*[^%/]", "%*[%s,%.]"}, type = "literal"}, -- Bold
+
+ { pattern = "[%+%-\\]", type = "operator" },
+
+ },
+
+
+
+ symbols = {
+
+ }
+}