From a37a6e9ac12796afcfc22a9c7ad7106a15d243a3 Mon Sep 17 00:00:00 2001 From: ecmel Date: Sun, 8 Oct 2023 20:28:40 +0300 Subject: [PATCH 1/5] rewrite syntax highlighting --- syntaxes/q.tmLanguage.json | 309 ++++++++++--------------------------- 1 file changed, 83 insertions(+), 226 deletions(-) diff --git a/syntaxes/q.tmLanguage.json b/syntaxes/q.tmLanguage.json index 3c506cc3..7274bea2 100644 --- a/syntaxes/q.tmLanguage.json +++ b/syntaxes/q.tmLanguage.json @@ -9,312 +9,158 @@ "include": "#strings" }, { - "include": "#constants" + "include": "#types" + }, + { + "include": "#numbers" }, { "include": "#keywords" }, { - "include": "#function" + "include": "#functions" }, { - "include": "#invalids" + "include": "#variables" } ], "repository": { "comments": { "patterns": [ { - "name": "comment.inline.q", - "match": "\\s/.*" - }, - { - "begin": "^(//?)(?:\\s*)(!.*)", - "end": "(?=^)", - "beginCaptures": { - "1": { - "name": "comment.line.slash.q" - }, - "2": { - "name": "comment.line.attention.q" - } - }, - "contentName": "comment.line.q" + "name": "comment.line.q", + "match": "(\\s+/|^/).*?\\S+.*" }, { "name": "comment.block.q", "begin": "^/\\s*$", "end": "^\\\\\\s*$" - }, - { - "begin": "(\\s//?)(?:\\s*)(!.*)", - "end": "(?=^)", - "beginCaptures": { - "1": { - "name": "comment.line.slash.q" - }, - "2": { - "name": "comment.line.attention.q" - } - }, - "contentName": "comment.line.q" - }, - { - "name": "comment.block.eof.q", - "begin": "^\\\\\\s*$", - "end": "\\z" - }, - { - "begin": "^(//?)(?:\\s*)(\\?.*)", - "end": "(?=^)", - "beginCaptures": { - "1": { - "name": "comment.line.slash.q" - }, - "2": { - "name": "comment.line.todo.q" - } - }, - "contentName": "comment.line.q" - }, - { - "begin": "(\\s//?)(?:\\s*)(\\?.*)", - "end": "(?=^)", - "beginCaptures": { - "1": { - "name": "comment.line.slash.q" - }, - "2": { - "name": "comment.line.todo.q" - } - }, - "contentName": "comment.line.q" - }, - { - "begin": "(^(//?)(?:\\s*)(?:(@\\w+)(?:[^.\\w]+([.\\w]+)(?:[^.\\w]+(\\w*))?)?)?)", - "beginCaptures": { - "2": { - "name": "comment.line.slash.q" - }, - "3": { - "name": "storage.type.class.q" - }, - "4": { - "name": "variable.parameter.q" - }, - "5": { - "name": "entity.name.type.q" - } - }, - "end": "(?=^)", - "contentName": "comment.line.q" } ] }, "strings": { "patterns": [ { + "name": "string.quoted.q", "begin": "\"", - "beginCaptures": { - "0": { - "name": "punctuation.definition.string.begin.q" - } - }, - "end": "\"", - "endCaptures": { - "0": { - "name": "punctuation.definition.string.end.q" - } - }, - "name": "string.quoted.double.q", - "patterns": [ - { - "name": "constant.character.escape.q", - "match": "\\\\(\\\\|n|t|r|\"|[0-7]{3})" - }, - { - "name": "invalid.illegal.newline.q", - "match": "^[^\\s]" - } - ] - } - ] - }, - "invalids": { - "patterns": [ - { - "name": "invalid.illegal.bracket.q", - "match": "^[}\\]\\)].*" + "end": "\"" } ] }, - "constants": { + "types": { "patterns": [ { - "name": "support.function.utility.q", - "match": "\\.Q\\.(a|A|addmonths|addr|b6|bt|btoa|bv|Cf|chk|cn|D|dd|def|dpft|dpfts|dsftg|en|ens|f|fc|ff|fk|fmt|fps|fs|fsn|ft|fu|gc|gz|hdpf|hg|host|hp|id|ind|j10|j12|k|l|M|MAP|nA|opt|P|par|pd|PD|pf|pn|pt|pv|PV|qp|qt|res|S|s|s1|sbt|sha1|trp|ts|ty|u|v|V|view|vp|w|x|x10|x12|Xf)\\b" - }, - { - "name": "support.function.json.q", - "match": "\\.j\\.(j|k|jd)\\b" - }, - { - "name": "support.function.callback.q", - "match": "\\.z\\.(ac|bm|exit|p[cdghiopqsw]|ts|vs|w[cos])\\b" - }, - { - "name": "support.constant.system.info.q", - "match": "\\.z\\.([a-fhiklno-qstuwxzDKNPTWXZ]|ex|ey|pm|zd)\\b" - }, - { - "name": "support.function.http.q", - "match": "\\.h\\.(br|c0|c1|cd|code|d|ed|edsn|fram|ha|hb|hc|he|hn|HOME|hp|hr|ht|hta|htac|htc|html|http|hu|hug|hy|iso8601|jx|logo|nbr|pre|sa|sb|sc|td|text|tx|ty|uh|val|xd|xmp|xs|xt)\\b" + "name": "constant.character.commands.q", + "match": "\\\\(a|b|B|cd?|C|d|e|E|f|g|l|L|o|p|P|q|r|s|S|ts?|T|u|v|w|W|x|z|1|2|_|\\\\)" }, { "name": "constant.language.null.q", - "match": "\\b0(N[ghijepmdznuvt]?|n)\\b" - }, - - { - "name": "support.function.internal.q", - "match": "\\-([1-9]|1[0-689]|2[0-79]|3[01368]|120)!" - }, - { - "name": "constant.language.boolean.q", - "match": "\\b[01]+b\\b" - }, - { - "name": "support.function.file.q", - "match": "\\b(0:|1:|2:)" + "match": "\\b0N[hjenpmdznuvt]\\b" }, { "name": "constant.language.infinity.q", - "match": "-?0(W[hijepdnutv]?|wz?)\\b" + "match": "\\b0[wnWN]\\b" }, { - "name": "constant.other.date", - "match": "\\b([12]\\d{3}\\.(0[1-9]|1[0-2])\\.(0[1-9]|[12]\\d|3[01]))\\b" + "name": "support.type.symbol.q", + "match": "`\\w*" }, { - "name": "constant.other.date.month", - "match": "\\b([12]\\d{3}\\.(0[1-9]|1[0-2])m)\\b" - }, + "name": "entity.name.function.q", + "match": "\\.\\w+" + } + ] + }, + "numbers": { + "patterns": [ { - "name": "constant.other.date.time.q", - "match": "\\b([01]\\d|2[0-3])(:([0-5]\\d)(:([0-5]\\d(\\.\\d{0,3})?))?)\\b" + "name": "constant.numeric.boolean.q", + "match": "[01]+b" }, { - "name": "constant.other.date.timespan.q", - "match": "\\b\\d+D(([01]\\d|2[0-3])(:([0-5]\\d)(:([0-5]\\d(\\.\\d{0,9})?))?)?)?n?\\b" + "name": "constant.numeric.byte.q", + "match": "0x[0-9A-Fa-f]+" }, { - "name": "constant.other.timestamp.q", - "match": "\\b([12]\\d{3}\\.(0[1-9]|1[0-2])\\.(0[1-9]|[12]\\d|3[01]))(p|D|Dp|D(([01]\\d|2[0-3])(:([0-5]\\d)(:([0-5]\\d(\\.\\d{0,9})?))?)?p?))\\b" - }, + "name": "constant.numeric.number.q", + "match": "([0-9]+([.][0-9]*)?|[.][0-9]+)(h|i|j|f|e)?" + } + ] + }, + "keywords": { + "patterns": [ { - "name": "constant.numeric.byte", - "match": "\\b0x[0-9a-fA-F]+\\b" + "name": "keyword.operator.q", + "match": "(=|<=?|>=?|~|<>|::?)" }, { - "name": "constant.numeric.guid.q", - "match": "\\b([\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12})\\b" + "name": "keyword.control.q", + "match": "\\b(do|exit|if|while)\\b" }, { - "name": "constant.other.timestamp.datetime.q", - "match": "\\b([12]\\d{3}\\.(0[1-9]|1[0-2])\\.(0[1-9]|[12]\\d|3[01]))(z|T|Tz|T(([01]\\d|2[0-3])(:([0-5]\\d)(:([0-5]\\d(\\.\\d{0,3})?))?)?z?))\\b" + "name": "keyword.other.env.q", + "match": "\\b(getenv|gtime|ltime|setenv)\\b" }, { - "name": "constant.numeric.decimal.q", - "match": "(?x)((?<=[^a-zA-Z0-9]|\\s|^)-)?(?:\n (?:\\b[0-9]+(\\.)[0-9]*e[+-]?[0-9]+[ef]?)| # 1.1e+3\n (?:\\b[0-9]+(\\.)e[+-]?[0-9]+[ef]?)| # 1.e+3\n (?:\\B(\\.)[0-9]+e[+-]?[0-9]+[ef]?)| # .1e+3\n (?:\\b[0-9]+e[+-]?[0-9]+[ef]?)| # 1e+3\n (?:\\b[0-9]+(\\.)[0-9]*[ef]?)| # 1.1\n (?:\\b[0-9]+(\\.)[ef]?)| # 1.\n (?:\\B(\\.)[0-9]+[ef]?)| # .1\n (?:\\b[0-9]+[efhij]?(?!\\.)) # 1efhij\n)" + "name": "keyword.other.interpret.q", + "match": "\\b(eval|parse|reval|show|system|value)\\b" }, { - "name": "support.type.q", - "match": "`(boolean|byte|short|int|long|real|float|char|symbol|timestamp|month|date|datetime|timespan|minute|second|time|year|mm|dd|hh|uu|ss)(?=\\$)" + "name": "keyword.other.io.q", + "match": "\\b(dsave|get|hclose|hcount|hdel|hopen|hsym|load|read0|read1|rload|rsave|save|set)\\b" }, { - "name": "support.attribute.q", - "match": "`[supg](?=#)" + "name": "keyword.other.iterate.q", + "match": "\\b(each|over|peach|prior|scan)\\b" }, { - "name": "constant.other.symbol.q", - "match": "`(:[a-zA-Z\\d_\\.:/]*|[a-zA-Z\\d_\\.:]*)" + "name": "keyword.other.join.q", + "match": "\\b(aj|aj0|ajf|ajf0|asof|ej|ij|ijf|lj|ljf|pj|uj|ujf|wj|wj1)\\b" }, { - "name": "constant.other.cmd.q", - "match": "^\\\\.+" + "name": "keyword.other.list.q", + "match": "\\b(count|cross|cut|enlist|except|fills|first|flip|group|in|inter|last|mcount|next|prev|raze|reverse|rotate|sublist|sv|til|union|vs|where|xprev)\\b" }, { - "name": "constant.other.namespace.q", - "match": "^[a-zA-Z]\\)" - } - ] - }, - "keywords": { - "patterns": [ - { - "include": "#variables" + "name": "keyword.other.logic.q", + "match": "\\b(all|and|any|not|or)\\b" }, { - "name": "keyword.control.q", - "match": "\\b(do|if|while)\\b" + "name": "keyword.other.math.q", + "match": "\\b(abs|acos|asin|atan|avg|avgs|ceiling|cor|cos|cov|deltas|dev|div|ema|exp|floor|inv|log|lsq|mavg|max|maxs|mdev|med|min|mins|mmax|mmin|mmu|mod|msum|neg|prd|prds|rand|ratios|reciprocal|scov|sdev|signum|sin|sqrt|sum|sums|svar|tan|var|wavg|within|wsum|xexp|xlog)\\b" }, { - "name": "keyword.operator.q", - "match": "(?<=\\b|_)(abs|acos|all|and|any|asc|asin|asof|atan|attr|avg|avgs|bin|binr|ceiling|cols|cor|cos|count|cov|cross|csv|cut|deltas|desc|dev|differ|distinct|div|dsave|each|ema|enlist|eval|except|exec|exit|exp|fills|first|fkeys|flip|floor|get|getenv|group|gtime|hclose|hcount|hdel|hopen|hsym|iasc|idesc|in|inter|inv|key|keys|last|like|load|log|lower|lsq|ltime|ltrim|mavg|max|maxs|mcount|md5|mdev|med|meta|min|mins|mmax|mmin|mmu|mod|msum|neg|next|not|null|or|over|parse|peach|pj|prd|prds|prev|prior|rand|rank|ratios|raze|read0|read1|reciprocal|reval|reverse|rload|rotate|rsave|rtrim|save|scan|scov|sdev|set|setenv|show|signum|sin|sqrt|ss|ssr|string|sublist|sum|sums|sv|svar|system|tables|tan|til|trim|type|ungroup|union|upper|value|var|view|views|vs|wavg|within|wsum|xasc|xbar|xcol|xcols|xdesc|xexp|xgroup|xkey|xlog|xprev|xrank)\\b" - }, - { - "name": "keyword.control.q", - "match": "\\$(?=\\[)" + "name": "keyword.other.meta.q", + "match": "\\b(attr|null|tables|type|view|views)\\b" }, { - "name": "keyword.iterator.q", - "match": "(':?|\\\\:?|/:?)" + "name": "keyword.other.query.q", + "match": "\\b(delete|exec|fby|from|select|update)\\b" }, { - "name": "keyword.other.DML.q", - "match": "\\b(select|update|delete|exec|from|by|fby|where|aj|aj0|ajf|ajf0|ej|ij|ijf|lj|ljf|uj|ujf|wj|wj1|upsert|insert)\\b" + "name": "keyword.other.sort.q", + "match": "\\b(asc|bin|binr|desc|differ|distinct|iasc|idesc|rank|xbar|xrank)\\b" }, { - "name": "keyword.operator.comparison.q", - "match": "(=|<=?|>=?|~|<>)" + "name": "keyword.other.table.q", + "match": "\\b(cols|csv|fkeys|insert|key|keys|meta|ungroup|upsert|xasc|xcol|xcols|xdesc|xgroup|xkey)\\b" }, { - "name": "keyword.operator.q", - "match": "[\\@\\.\\$!?+\\-\\*%|&#^,_]" - }, - { - "name": "keyword.assign.q", - "match": "::?" + "name": "keyword.other.text.q", + "match": "\\b(like|lower|ltrim|md5|rtrim|ss|ssr|string|trim|upper)\\b" } ] }, - "variables": { + "functions": { "patterns": [ { - "name": "variable.other.q", - "match": "[a-zA-Z][a-zA-Z\\d_]*" - }, - { - "name": "entity.name.function.q", - "match": "(? Date: Mon, 9 Oct 2023 05:46:44 +0300 Subject: [PATCH 2/5] remove category functions add category tests --- syntaxes/q.tmLanguage.json | 55 ++++++++------------------------------ 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/syntaxes/q.tmLanguage.json b/syntaxes/q.tmLanguage.json index 7274bea2..ae0232ad 100644 --- a/syntaxes/q.tmLanguage.json +++ b/syntaxes/q.tmLanguage.json @@ -9,7 +9,7 @@ "include": "#strings" }, { - "include": "#types" + "include": "#constants" }, { "include": "#numbers" @@ -18,7 +18,7 @@ "include": "#keywords" }, { - "include": "#functions" + "include": "#tests" }, { "include": "#variables" @@ -47,12 +47,8 @@ } ] }, - "types": { + "constants": { "patterns": [ - { - "name": "constant.character.commands.q", - "match": "\\\\(a|b|B|cd?|C|d|e|E|f|g|l|L|o|p|P|q|r|s|S|ts?|T|u|v|w|W|x|z|1|2|_|\\\\)" - }, { "name": "constant.language.null.q", "match": "\\b0N[hjenpmdznuvt]\\b" @@ -64,10 +60,6 @@ { "name": "support.type.symbol.q", "match": "`\\w*" - }, - { - "name": "entity.name.function.q", - "match": "\\.\\w+" } ] }, @@ -89,10 +81,6 @@ }, "keywords": { "patterns": [ - { - "name": "keyword.operator.q", - "match": "(=|<=?|>=?|~|<>|::?)" - }, { "name": "keyword.control.q", "match": "\\b(do|exit|if|while)\\b" @@ -151,39 +139,18 @@ } ] }, - "functions": { + "tests": { "patterns": [ { - "begin": "(\\w+)\\s*(:\\s*{|\\s*\\[)", - "beginCaptures": { - "0": { - "name": "entity.name.function.q" - } - }, - "end": "[}\\]]", - "patterns": [ - { - "include": "#comments" - }, - { - "include": "#strings" - }, - { - "include": "#types" - }, - { - "include": "#numbers" - }, - { - "include": "#keywords" - }, - { - "include": "#functions" + "match": "(feature|should|expect|before|after)\\s+(.*)", + "captures": { + "1": { + "name": "support.function.q" }, - { - "include": "#variables" + "2": { + "name": "string.quoted.q" } - ] + } } ] }, From 05f85d606acacade94cae7350b12015a0d58f3f3 Mon Sep 17 00:00:00 2001 From: ecmel Date: Mon, 9 Oct 2023 15:21:04 +0300 Subject: [PATCH 3/5] fixed escaped qoute --- syntaxes/q.tmLanguage.json | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/syntaxes/q.tmLanguage.json b/syntaxes/q.tmLanguage.json index ae0232ad..15cb636f 100644 --- a/syntaxes/q.tmLanguage.json +++ b/syntaxes/q.tmLanguage.json @@ -43,7 +43,13 @@ { "name": "string.quoted.q", "begin": "\"", - "end": "\"" + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape.q", + "match": "\\\\[\"\\\\]" + } + ] } ] }, @@ -142,7 +148,11 @@ "tests": { "patterns": [ { - "match": "(feature|should|expect|before|after)\\s+(.*)", + "name": "support.function.q", + "match": "(before|after)\\s+" + }, + { + "match": "(feature|should|expect)\\s+(.*)", "captures": { "1": { "name": "support.function.q" From a5929268d801367f8c5ce326a51cd41ec790bb62 Mon Sep 17 00:00:00 2001 From: ecmel Date: Tue, 10 Oct 2023 17:49:50 +0300 Subject: [PATCH 4/5] added terminator comment --- syntaxes/q.tmLanguage.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/syntaxes/q.tmLanguage.json b/syntaxes/q.tmLanguage.json index 15cb636f..dbdbb425 100644 --- a/syntaxes/q.tmLanguage.json +++ b/syntaxes/q.tmLanguage.json @@ -35,6 +35,10 @@ "name": "comment.block.q", "begin": "^/\\s*$", "end": "^\\\\\\s*$" + }, + { + "name": "comment.block.q", + "begin": "^\\\\\\s*$" } ] }, @@ -149,10 +153,10 @@ "patterns": [ { "name": "support.function.q", - "match": "(before|after)\\s+" + "match": "\\b(before|after)\\b\\s+" }, { - "match": "(feature|should|expect)\\s+(.*)", + "match": "\\b(feature|should|expect)\\b\\s+(.*)", "captures": { "1": { "name": "support.function.q" From 99cb4abb2295b9cb6d3fac094d873d487280f67a Mon Sep 17 00:00:00 2001 From: ecmel Date: Thu, 12 Oct 2023 13:46:37 +0300 Subject: [PATCH 5/5] added commands and operators --- language-configuration.json | 39 ++++++++++++++++++++++++++++++++++++ syntaxes/q.tmLanguage.json | 40 ++++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/language-configuration.json b/language-configuration.json index 77fac739..71c418fa 100644 --- a/language-configuration.json +++ b/language-configuration.json @@ -16,7 +16,46 @@ ["(", ")"], ["\"", "\""] ], + "onEnterRules": [ + { + "beforeText": "\\}", + "action": { + "indent": "outdent" + } + }, + { + "beforeText": "\\{", + "action": { + "indent": "indent" + } + }, + { + "beforeText": "\\)", + "action": { + "indent": "outdent" + } + }, + { + "beforeText": "\\(", + "action": { + "indent": "indent" + } + }, + { + "beforeText": "\\]", + "action": { + "indent": "outdent" + } + }, + { + "beforeText": "\\[", + "action": { + "indent": "indent" + } + } + ], "comments": { + "blockComment": ["/", "\\"], "lineComment": "/" }, "wordPattern": "(`:[a-zA-Z0-9._/]*)|(`[a-zA-Z0-9._]*)|(-?\\d*\\.\\d\\w*)|([^\\`\\~\\$\\!\\@\\#\\%\\^\\&\\*\\(\\)\\-\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\<\\>\\/\\?\\s]+)" diff --git a/syntaxes/q.tmLanguage.json b/syntaxes/q.tmLanguage.json index dbdbb425..87b50aac 100644 --- a/syntaxes/q.tmLanguage.json +++ b/syntaxes/q.tmLanguage.json @@ -8,6 +8,12 @@ { "include": "#strings" }, + { + "include": "#commands" + }, + { + "include": "#operators" + }, { "include": "#constants" }, @@ -28,7 +34,7 @@ "comments": { "patterns": [ { - "name": "comment.line.q", + "name": "comment.line.character.q", "match": "(\\s+/|^/).*?\\S+.*" }, { @@ -57,11 +63,39 @@ } ] }, + "commands": { + "patterns": [ + { + "name": "constant.character.q", + "match": "\\\\(cd|ts|[abBcCdeEfglLopPrsStTuvwWxz_])" + } + ] + }, + "operators": { + "patterns": [ + { + "name": "punctuation.terminator.statement.q", + "match": ";" + }, + { + "name": "keyword.operator.arithmetic.q", + "match": "[\\+\\-\\%\\*]" + }, + { + "name": "keyword.operator.logical.q", + "match": "(=|<>|~|<|<=|>=|>|\\|&)" + }, + { + "name": "keyword.operator.other.q", + "match": "(::|':|/:|\\\\:|[:@\\\\!$#?'/,\\^])" + } + ] + }, "constants": { "patterns": [ { "name": "constant.language.null.q", - "match": "\\b0N[hjenpmdznuvt]\\b" + "match": "\\b0N[hjenpmdznuvtg]\\b" }, { "name": "constant.language.infinity.q", @@ -85,7 +119,7 @@ }, { "name": "constant.numeric.number.q", - "match": "([0-9]+([.][0-9]*)?|[.][0-9]+)(h|i|j|f|e)?" + "match": "([0-9]+([.][0-9]*)?|[.][0-9]+)[hijfem]?" } ] },