aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrmargarido <drmargarido@gmail.com>2020-04-11 01:13:35 +0100
committerdrmargarido <drmargarido@gmail.com>2020-04-11 01:13:35 +0100
commit4f582035026914605f448f3a22a2af61c0ebd2c7 (patch)
tree0be61c06699c9b6c1c75b0c2f7e6db33a8b9de05
parentbb07bc7022edab4f9ff67f7e1fb8d1e2c64b4fc0 (diff)
downloadlite-xl-plugins-4f582035026914605f448f3a22a2af61c0ebd2c7.tar.gz
lite-xl-plugins-4f582035026914605f448f3a22a2af61c0ebd2c7.zip
Added support for the psql syntax.
-rw-r--r--README.md1
-rw-r--r--language_psql.lua90
2 files changed, 91 insertions, 0 deletions
diff --git a/README.md b/README.md
index 38454d5..f1be5f0 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ Plugin | Description
[`language_go`](language_go.lua?raw=1) | Syntax for the [Go](https://golang.org/) programming language
[`language_jiyu`](language_jiyu.lua?raw=1) | Syntax for the [jiyu](https://github.com/machinamentum/jiyu) programming language
[`language_odin`](language_odin.lua?raw=1) | Syntax for the [Odin](https://github.com/odin-lang/Odin) programming language
+[`language_psql`](language_psql.lua?raw=1) | Syntax for the postgresql database access language
[`language_wren`](language_wren.lua?raw=1) | Syntax for the [Wren](http://wren.io/) programming language
[`macmodkeys`](macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt`
[`sort`](sort.lua?raw=1) | Sorts selected lines
diff --git a/language_psql.lua b/language_psql.lua
new file mode 100644
index 0000000..7c6c4b7
--- /dev/null
+++ b/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,
+}
+