From ac897462f89b1c1cb3e51df01063f1191e9d2a72 Mon Sep 17 00:00:00 2001 From: devrandom Date: Fri, 10 Nov 2023 18:08:49 +0000 Subject: Added syntax support for JSON files (#331) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create language_json.lua * Update manifest.json * Update manifest.json * Update plugins/language_json.lua Co-authored-by: Jefferson González * removed invalid literals and numeric keys * updated key pattern to include spaces and hyphens, and updated value pattern to not match multiline strings * added priority again, changed value back to string and updated formatting a bit * actually added priority this time god it's hard working with 2 different files * patterns now match everything but newlines, and allow for whitespace to prefix the colon, and priority is now fixed aswell * added cjson comment support * Update plugins/language_json.lua Co-authored-by: Guldoman * Update plugins/language_json.lua Co-authored-by: Guldoman * Update plugins/language_json.lua Co-authored-by: Guldoman * avoid highlighting colon * updated pattern * Add ".jsonc" extension --------- Co-authored-by: Jefferson González Co-authored-by: Guldoman --- manifest.json | 9 +++++++++ plugins/language_json.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 plugins/language_json.lua diff --git a/manifest.json b/manifest.json index 40b118a..40f993f 100644 --- a/manifest.json +++ b/manifest.json @@ -106,6 +106,7 @@ "language_java": {}, "language_jiyu": {}, "language_jsx": {}, + "language_json": {}, "language_julia": {}, "language_ksy": {}, "language_lilypond": {}, @@ -872,6 +873,14 @@ "mod_version": "3", "tags": ["language"] }, + { + "description": "Syntax for the [JSON](https://www.json.org/json-en.html) language", + "version": "0.1", + "path": "plugins/language_json.lua", + "id": "language_json", + "mod_version": "3", + "tags": ["language"] + }, { "description": "Syntax for the [Julia](https://julialang.org/) programming language", "version": "0.1", diff --git a/plugins/language_json.lua b/plugins/language_json.lua new file mode 100644 index 0000000..eae97d4 --- /dev/null +++ b/plugins/language_json.lua @@ -0,0 +1,27 @@ +-- mod-version:3 priority:110 + +local syntax = require "core.syntax" + +syntax.add { + name = "JSON", + files = { "%.json$", "%.cjson$", "%.jsonc$" }, + comment = "//", + block_comment = {"/*", "*/"}, + patterns = { + + -- cjson support + { pattern = "//.*", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + + { regex = [["(?:[^"\\]|\\.)*"()\s*:]], type = { "keyword", "normal" } }, -- key + { regex = [["(?:[^"\\]|\\.)*"]], type = "string" }, -- value + { pattern = "0x[%da-fA-F]+", type = "number" }, + { pattern = "-?%d+[%d%.eE]*", type = "number" }, + { pattern = "-?%.?%d+", type = "number" }, + { pattern = "null", type = "literal" }, + { pattern = "true", type = "literal" }, + { pattern = "false", type = "literal" } + }, + symbols = { } +} + -- cgit v1.2.3