From c1bb563921b9d2610afecadb5760d2ac6189c1d8 Mon Sep 17 00:00:00 2001 From: Samuel <36420837+Samueru-sama@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:43:30 -0400 Subject: Add `language_awk` (#461) * Add `language_awk` * Update manifest.json to include language awk * Remove "case" from `language_awk.lua` I forgot to delete this when copying the symbols, I left it in place because it was used as reference for how the "=" should be spaced. * Update `language_awk`, remove new line from pattern * Update manifest.json, fix id for `language_awk` * Simplify sheabang pattern in `language_awk` * Update pattern in `language_awk` * Update pattern in `language_awk` * Update pattern in `language_awk` * Update pattern in `language_awk` * Update pattern in `language_awk` * Add more symbols to `language_awk` --- manifest.json | 13 +++++- plugins/language_awk.lua | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 plugins/language_awk.lua diff --git a/manifest.json b/manifest.json index fb9e543..68a69ee 100644 --- a/manifest.json +++ b/manifest.json @@ -64,6 +64,7 @@ "language_assembly_riscv": {}, "language_assembly_x86": {}, "language_autohotkey_v1": {}, + "language_awk": {}, "language_batch": {}, "language_bazel": {}, "language_bend": {}, @@ -166,7 +167,7 @@ "id": "meta_languages", "mod_version": "3", "type": "meta", - "version": "0.1.16" + "version": "0.1.17" }, { "description": "Align multiple carets and selections *([clip](https://user-images.githubusercontent.com/2798487/165631951-532f8d24-d596-4dd0-9d21-ff53c71ed32f.mp4))*", @@ -670,6 +671,16 @@ ], "version": "0.1" }, + { + "description": "Syntax for the [Awk](https://en.wikipedia.org/wiki/AWK)(v1) programming language", + "id": "language_awk", + "mod_version": "3", + "path": "plugins/language_awk.lua", + "tags": [ + "language" + ], + "version": "0.1" + }, { "description": "Syntax for Windows [Batch Files](https://en.wikipedia.org/wiki/Batch_file)", "id": "language_batch", diff --git a/plugins/language_awk.lua b/plugins/language_awk.lua new file mode 100644 index 0000000..cc56335 --- /dev/null +++ b/plugins/language_awk.lua @@ -0,0 +1,110 @@ +-- mod-version:3 +local syntax = require "core.syntax" + +syntax.add { + name = "Awk script", + files = "%.awk$", + headers = "^#!.*bin.*awk", + comment = "#", + patterns = { + -- $# is a awk special variable and the '#' shouldn't be interpreted + -- as a comment. + { pattern = "%$[%a_@*#][%w_]*", type = "keyword2" }, + -- Comments + { pattern = "#.*", type = "comment" }, + -- Strings + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = { '`', '`', '\\' }, type = "string" }, + -- Ignore numbers that start with dots or slashes + { pattern = "%f[%w_%.%/]%d[%d%.]*%f[^%w_%.]", type = "number" }, + -- Operators + { pattern = "[!<>|&%[%]:=*]", type = "operator" }, + -- Match parameters + { pattern = "%f[%S][%+%-][%w%-_:]+", type = "function" }, + { pattern = "%f[%S][%+%-][%w%-_]+%f[=]", type = "function" }, + -- Prevent parameters with assignments from been matched as variables + { + pattern = "%s%-%a[%w_%-]*()%s+()%d[%d%.]+", + type = { "function", "normal", "number" } + }, + { + pattern = "%s%-%a[%w_%-]*()%s+()%a[%a%-_:=]+", + type = { "function", "normal", "symbol" } + }, + -- Match variable assignments + { pattern = "[_%a][%w_]+%f[%+=]", type = "keyword2" }, + -- Match variable expansions + { pattern = "%${.-}", type = "keyword2" }, + { pattern = "%$[%d%$%a_@*][%w_]*", type = "keyword2" }, + -- Functions + { pattern = "[%a_%-][%w_%-]*()%s*%f[(]", type = { "function", "normal" } }, + -- Everything else + { pattern = "[%a_][%w_]*", type = "symbol" }, + }, + symbols = { + ["break"] = "keyword", + ["continue"] = "keyword", + ["do"] = "keyword", + ["delete"] = "keyword", + ["else"] = "keyword", + ["exit"] = "keyword", + ["for"] = "keyword", + ["function"] = "keyword", + ["getline"] = "keyword", + ["if"] = "keyword", + ["next"] = "keyword", + ["nextfile"] = "keyword", + ["print"] = "keyword", + ["printf"] = "keyword", + ["return"] = "keyword", + ["while"] = "keyword", + ["gsub"] = "keyword", + ["index"] = "keyword", + ["length"] = "keyword", + ["match"] = "keyword", + ["split"] = "keyword", + ["sprintf"] = "keyword", + ["sub"] = "keyword", + ["substr"] = "keyword", + ["tolower"] = "keyword", + ["toupper"] = "keyword", + ["atan2"] = "keyword", + ["cos"] = "keyword", + ["exp"] = "keyword", + ["int"] = "keyword", + ["log"] = "keyword", + ["rand"] = "keyword", + ["sin"] = "keyword", + ["sqrt"] = "keyword", + ["srand"] = "keyword", + ["BEGIN"] = "keyword", + ["END"] = "keyword", + ["ARGC"] = "keyword", + ["ARGV"] = "keyword", + ["FILENAME"] = "keyword", + ["FNR"] = "keyword", + ["FS"] = "keyword", + ["NF"] = "keyword", + ["NR"] = "keyword", + ["OFMT"] = "keyword", + ["OFS"] = "keyword", + ["ORS"] = "keyword", + ["RLENGTH"] = "keyword", + ["RS"] = "keyword", + ["RSTART"] = "keyword", + ["SUBSEP"] = "keyword", + ["ARGIND"] = "keyword", + ["BINMODE"] = "keyword", + ["CONVFMT"] = "keyword", + ["ENVIRON"] = "keyword", + ["ERRNO"] = "keyword", + ["FIELDWIDTHS"] = "keyword", + ["IGNORECASE"] = "keyword", + ["LINT"] = "keyword", + ["PROCINFO"] = "keyword", + ["RT"] = "keyword", + ["RLENGTH"] = "keyword", + ["TEXTDOMAIN"] = "keyword" + } +} -- cgit v1.2.3