aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_psql.lua
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-04-23 20:49:37 +0100
committerrxi <rxi@users.noreply.github.com>2020-04-23 20:49:37 +0100
commit676f04945010aeb2ae71325bf2d1d6f336a5e162 (patch)
tree31b2e18df5e84fbc731840e5f1b28c974eea868a /plugins/language_psql.lua
parent9049e189d49440939192874d54af15a21eebbafb (diff)
downloadlite-xl-plugins-676f04945010aeb2ae71325bf2d1d6f336a5e162.tar.gz
lite-xl-plugins-676f04945010aeb2ae71325bf2d1d6f336a5e162.zip
Moved all plugins to `plugins` dir
Diffstat (limited to 'plugins/language_psql.lua')
-rw-r--r--plugins/language_psql.lua90
1 files changed, 90 insertions, 0 deletions
diff --git a/plugins/language_psql.lua b/plugins/language_psql.lua
new file mode 100644
index 0000000..7c6c4b7
--- /dev/null
+++ b/plugins/language_psql.lua
@@ -0,0 +1,90 @@
+local syntax = require "core.syntax"
+
+-- In sql symbols can be lower case and upper case
+local keywords = {
+ "CREATE", "SELECT", "INSERT", "INTO", "UPDATE",
+ "DELETE", "TABLE", "DROP", "VALUES", "NOT",
+ "NULL", "PRIMARY", "KEY", "REFERENCES",
+ "DEFAULT", "UNIQUE", "CONSTRAINT", "CHECK",
+ "ON", "EXCLUDE", "WITH", "USING", "WHERE",
+ "GROUP", "BY", "HAVING", "DISTINCT", "LIMIT",
+ "OFFSET", "ONLY", "CROSS", "JOIN", "INNER",
+ "LEFT", "RIGHT", "FULL", "OUTER", "NATURAL",
+ "AND", "OR", "AS", "ORDER", "ORDINALITY",
+ "UNNEST", "FROM", "VIEW", "RETURNS", "SETOF",
+ "LANGUAGE", "SQL", "LIKE", "LATERAL",
+ "INTERVAL", "PARTITION", "UNION", "INTERSECT",
+ "EXCEPT", "ALL", "ASC", "DESC", "NULLS",
+ "FIRST", "LAST", "IN", "RECURSIVE", "ARRAY",
+ "RETURNING", "SET", "ALSO", "INSTEAD",
+ "ALTER", "SEQUENCE", "OWNED", "AT", "ZONE",
+ "WITHOUT", "TO", "TIMEZONE", "TYPE", "ENUM",
+ "DOCUMENT", "XMLPARSE", "XMLSERIALIZE",
+ "CONTENT", "OPTION", "INDEX", "ANY",
+ "EXTENSION", "ISNULL", "NOTNULL", "UNKNOWN",
+ "CASE", "THEN", "WHEN", "ELSE", "END",
+ "ROWS", "BETWEEN", "UNBOUNDED", "PRECEDING",
+ "UNBOUNDED", "FOLLOWING", "EXISTS", "SOME",
+ "COLLATION", "FOR", "TRIGGER", "BEFORE",
+ "EACH", "ROW", "EXECUTE", "PROCEDURE",
+ "FUNCTION", "DECLARE", "BEGIN", "LOOP",
+ "RAISE", "NOTICE", "LOOP", "EVENT",
+ "OPERATOR", "DOMAIN", "VARIADIC", "FOREIGN"
+}
+
+local types = {
+ "BIGINT", "INT8", "BIGSERIAL", "SERIAL8",
+ "BIT", "VARBIT", "BOOLEAN", "BOOL", "BOX",
+ "BYTEA", "CHARACTER", "CHAR", "VARCHAR",
+ "CIDR", "CIRCLE", "DATE", "DOUBLE",
+ "PRECISION", "FLOAT8", "INET", "INTEGER",
+ "INT", "INT4", "INTERVAL", "JSON", "JSONB",
+ "LINE", "LSEG", "MACADDR", "MONEY", "NUMERIC",
+ "DECIMAL", "PATH", "POINT", "POLYGON", "REAL",
+ "FLOAT4", "INT2", "SMALLINT", "SMALLSERIAL",
+ "SERIAL2", "SERIAL", "SERIAL4", "TEXT",
+ "TIME", "TIMEZ", "TIMESTAMP", "TIMESTAMPZ",
+ "TSQUERY", "TSVECTOR", "TXID_SNAPSHOT",
+ "UUID", "XML", "INT4RANGE", "INT8RANGE",
+ "NUMRANGE", "TSRANGE", "TSTZRANGE",
+ "DATERANGE", "PG_LSN"
+}
+
+local literals = {
+ "FALSE", "TRUE", "CURRENT_TIMESTAMP",
+ "CURRENT_TIME", "CURRENT_DATE", "LOCALTIME",
+ "LOCALTIMESTAMP"
+}
+
+local symbols = {}
+for _, keyword in ipairs(keywords) do
+ symbols[keyword:lower()] = "keyword"
+ symbols[keyword] = "keyword"
+end
+
+for _, type in ipairs(types) do
+ symbols[type:lower()] = "keyword2"
+ symbols[type] = "keyword2"
+end
+
+for _, literal in ipairs(literals) do
+ symbols[literal:lower()] = "literal"
+ symbols[literal] = "literal"
+end
+
+syntax.add {
+ files = { "%.sql$", "%.psql$" },
+ comment = "--",
+ patterns = {
+ { pattern = "%-%-.-\n", type = "comment" },
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = "-?%d+[%d%.eE]*f?", type = "number" },
+ { pattern = "-?%.?%d+f?", type = "number" },
+ { pattern = "[%+%-=/%*%%<>!~|&@%?$#]", type = "operator" },
+ { pattern = "[%a_][%w_]*%f[(]", type = "function" },
+ { pattern = "[%a_][%w_]*", type = "symbol" },
+ },
+ symbols = symbols,
+}
+