From aed2a0a5fdc089adf31986ad93aa4e7927d94db4 Mon Sep 17 00:00:00 2001 From: atf1206 Date: Wed, 1 Jan 2020 15:31:44 -0500 Subject: [PATCH 1/2] First commit of new q syntax from atf1206's q-kdb-syntax --- syntax/q.tmLanguage | 416 ++++++++++++++++++++++++++++++++------------ 1 file changed, 307 insertions(+), 109 deletions(-) diff --git a/syntax/q.tmLanguage b/syntax/q.tmLanguage index 800f6ec..2aecef7 100644 --- a/syntax/q.tmLanguage +++ b/syntax/q.tmLanguage @@ -7,120 +7,254 @@ q name - q + q/kdb + patterns + - begin - / - comment - comment block + block comment + name + comment.block.q + begin + ^\s*/\s*$\n end - \\ - + ^\s*\\\s*$\n + + + comment + end of script block comment name - comment.block.source.q + comment.block.q + begin + ^\\\s*\n + end + 'As far as I know, there is no way to exit this kind of block comment' comment - comment exit - match - \s/.*|^/.* + single line comment name - comment.line.source.q + comment.line.q + match + \s/.+$\n?|^/.+$\n + + - begin - \\ - comment string + name + string.quoted.string.source.q + begin + " end - \\ - + " + patterns + + + + name + constant.numeric.complex.source.q + match + \\[trn\\\"] + + + + name + constant.numeric.complex.source.q + match + \\[0-9]{3} + + + + name + message.error.q + match + \\[0-9]{1,2} + + + + + + + comment + symbol name - comment.block.source.q + string.interpolated.symbol.q + match + (`:[:/a-zA-Z0-9_.]*)|(`[:a-zA-Z0-9_.]*) + + - captures + comment + dict_assign + begin + (?=(\W|\b))(\.[a-zA-Z]+[a-zA-Z0-9_]*)(\.[a-zA-Z0-9_]*)*\s*\[(?=.*\]\s*([,+\-*%@$!?<>=~|&\#]?)(::|:)) + beginCaptures 2 name - support.function.q + variable.parameter.complex.namespace_dict_assign.q + + 3 + + name + variable.parameter.complex.namespace_dict_assign.q + + + patterns + + + + include + $self + + + end + \]([,+\-*%@$!?<>=~|&\#]?)(::|:) + endCaptures + + 1 + + name + support.function.assignment.q + + 2 + + name + support.function.assignment.q + + + + comment - q Reserved Functions - match - (?=(\W|\b))((\.Q\.\w+)|(\.z\.\w+)|(\\\w+))(?=(\W|\b)) + namespace assignment name - other.source.q + variable.parameter.complex.namespace_assignment.q + match + (?=(\W|\b))(\.[a-zA-Z]+[a-zA-Z0-9_]*)(\.[a-zA-Z0-9_]*)*\s*([,+\-*%@$!?<>=~|&\#]?)(::|:) + captures + + 4 + + name + support.function.assignment.q + + 5 + + name + support.function.assignment.q + + + + comment - string - match - ".*?" + Built-in namespaces name - string.quoted.string.source.q + support.function.namespace.q + match + \.[qQhkozj]\.\w+ + + comment - string - match - `[:/a-zA-Z0-9_.]+ + other namespaces name - string.interpolated.symbol.source.q + source.other_namespaces.q + match + (?=(\W|\b))(\.[a-zA-Z]+[a-zA-Z0-9_]*)(\.[a-zA-Z0-9_]*)*(?=(\W|\b)) + + + comment + variable assignment + name + other.assignment.q + match + (?=([^a-zA-Z0-9]|\b))([a-zA-Z]+[a-zA-Z0-9_]*)\s*([,+\-*%@$!?<>=~|&\#]?)(::|:) + captures 2 name - variable.parameter.complex.source.q + variable.parameter.complex.assignment.q 3 name support.function.q + 4 + + name + support.function.q + - comment - Variable Definition - match - (?=([^a-zA-Z0-9]|\b))(\.?[a-zA-Z]+[a-zA-Z0-9_\.]*\s*)(:)\s* - name - other.source.q - - - comment - q adverbs and shortcut - match - [!$@\\/_#?|',`(\\:)] - name - support.function.q + + comment - dot notation - match - \.(?=\W) - name - support.function.q + dict_assign + begin + (?=([^a-zA-Z0-9]|\b))([a-zA-Z]+[a-zA-Z0-9_]*)\s*\[(?=.*\]\s*([,+\-*%@$!?<>=~|&\#]?)(::|:)) + beginCaptures + + 2 + + name + variable.parameter.complex.dict_assign.q + + + patterns + + + + include + $self + + + end + \]([,+\-*%@$!?<>=~|&\#]?)(::|:) + endCaptures + + 1 + + name + support.function.assignment.q + + 2 + + name + support.function.assignment.q + + + + - begin - (\{\s*\[) contentName meta.function.parameters.q + begin + (\{\s*\[) end - (?=\]\s*) + ] patterns + match + \b([a-zA-Z_][a-zA-Z0-9_]*)\s*(?:(;)|(?=[\]\)])) captures 1 @@ -134,95 +268,159 @@ punctuation.separator.parameters.q - match - \b([a-zA-Z_][a-zA-Z_0-9]*)\s*(?:(;)|(?=[\]\)])) + + - captures - - 2 - - name - keyword.other.complex.source.q - - comment q keywords + name + keyword.other.complex.keyword.q match - (?=(\W|\b))(prd|while|wavg|delete|min|like|exp|abs|insert|wsum|last|log|div|cos|sin|sqrt|max|in|exec|within|xexp|avg|second|hour|minute|update|sum|by|from|select|neg|not|null|string|reciprocal|floor|ceiling|signum|mod|xbar|xlog|and|or|each|scan|over|prior|mmu|lsq|inv|md5|ltime|gtime|count|first|var|dev|med|cov|cor|all|any|rand|sums|prds|mins|maxs|fills|deltas|ratios|avgs|differ|prev|next|rank|reverse|iasc|idesc|asc|desc|msum|mcount|mavg|mdev|xrank|mmin|mmax|xprev|rotate|distinct|group|where|flip|type|key|til|get|value|attr|cut|set|upsert|raze|union|inter|except|cross|sv|vs|sublist|enlist|read0|read1|hopen|hclose|hdel|hsym|hcount|peach|system|ltrim|rtrim|trim|lower|upper|ssr|view|tables|views|cols|xcols|keys|xkey|xcol|xasc|xdesc|fkeys|meta|lj|aj|aj0|ij|pj|asof|uj|ww|wj|wj1|fby|xgroup|ungroup|ej|save|load|rsave|rload|show|csv|parse|eval)(?=(\W|\b)) + (?=(\W|\b))(abs|acos|aj|aj0|all|and|any|asc|asin|asof|atan|attr|avg|avgs|bin|binr|by|ceiling|cols|cor|cos|count|cov|cross|csv|cut|delete|deltas|desc|dev|differ|distinct|div|do|dsave|each|ej|ema|enlist|eval|except|exec|exit|exp|fby|fills|first|fkeys|flip|floor|from|get|getenv|group|gtime|hclose|hcount|hdel|hopen|hsym|iasc|idesc|if|ij|ijf|in|insert|inter|inv|key|keys|last|like|lj|ljf|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|select|set|setenv|show|signum|sin|sqrt|ss|ssr|string|sublist|sum|sums|sv|svar|system|tables|tan|til|trim|type|uj|ujf|ungroup|union|update|upper|upsert|value|var|view|views|vs|wavg|where|while|within|wj|wj1|wsum|xasc|xbar|xcol|xcols|xdesc|xexp|xgroup|xkey|xlog|xprev|xrank)(?=(\W|\b)) + + + + + comment + timestamp name - other.source.q + constant.numeric.complex.timestamp.q + match + + (?=(\W|\b))([0-9]{4}\.[0-9]{2}\.[0-9]{2}D[0-9]{2}(:[0-5][0-9]){0,2}(\.[0-9]{3}([a-zA-CE-SU-Z0-9]*[ABCEFGHIJKLMNOPQRSUVWXYZagklnopqrtuvwxy0-9])?|\.[0-9]*|:)?)(?=(\W|\b)) + + - captures - - 2 - - name - constant.numeric.complex.source.q - - comment datetime + name + constant.numeric.complex.datetime.q match - (?=(\W|\b))([0-9]{4}\.[0-9]{2}\.[0-9]{2}[TD]?[0-9]{2}:[0-9]{2}:[0-9]{2}(:[0-9]{2})?(\.[0-9]{3,6})?)(?=(\W|\b)) + + (?=(\W|\b))([0-9]{4}\.[0-9]{2}\.[0-9]{2}T[0-9]{2}(:[0-5][0-9]){0,2}(\.[0-9]{3}([a-zA-CE-Z0-9]*[ABCEFGHIJKLMNOPQRSUVWXYZagklnopqrtuvwxy0-9])?|\.[0-9]*|:)?)(?=(\W|\b)) + + + + + comment + datetime and timespan name - other.source.q + constant.numeric.complex.timespan.q + match + + (?=(\W|\b))(([0-9]{1,6}D([0-9]{1,2})((:[0-5][0-9]){0,2}|:)(\.[0-9]{0,9}[a-zA-Z0-9]*[A-Zacgklnopqrtuvwxy0-9])?)|([0-9]{2}:[0-5][0-9](:[0-5][0-9]\.[0-9]{4,}|:[0-5][0-9]\.[0-9]{9,}[a-zA-Z0-9]*[ABCEFGHIJKLMNOPQRSUVWXYZagklnopqrtuvwxy0-9])|\.[0-9]{8,}))(?=(\W|\b)) + + - captures - - 2 - - name - constant.numeric.complex.source.q - - comment time + name + constant.numeric.complex.time.q match - (?=(\W|\b))([0-9]{4}\.[0-9]{2}\.[0-9]{2}[TD]?)(?=(\W|\b)) + + (?=(\W|\b))([0-9]{2}:[0-5][0-9]((:[0-9]{2}(((([ABCEFGHIJKLMNOPQRSUVWXYZacgklnopqrtuvwxy0-9:]){1,2})?([0-5][0-9]){1,2})|\.[0-9]{3}[ABCEFGHIJKLMNOPQRSUVWXYZacgklnopqrtuvwxy0-9]?|\.[0-9]{0,3}))|\.[0-9]{4,7}))(?=(\W|\b)) + + + + + comment + second name - other.source.q + constant.numeric.complex.second.q + match + (?=(\W|\b))([0-9]{2}:[0-5][0-9]([0-5][0-9]([0-5][0-9])?|\.[0-9]{2}|:[0-9]{2}|([a-zA-Z]){0,2}[0-5][0-9]))(?=(\W|\b)) + + + + comment + minute + name + constant.numeric.complex.minute.q + match + + (?=(\W|\b))([0-9]{2}:([0-5][0-9]([ABCEFGHIJKLMNOPQRSUVWXYZacgklnopqrtuvwxy0-9:])?)?)(?=(\W|\b)) + + + - captures - - 2 - - name - constant.numeric.complex.source.q - - comment date + name + constant.numeric.complex.date.q match - (?=(\W|\b))([0-9]{2}:[0-9]{2}:[0-9]{2}(:[0-9]{2})?(\.[0-9]{3,6})?)(?=(\W|\b)) + (?=(\W|\b))([0-9]{4}\.[0-9]{2}\.[0-9]{2})(?=(\W|\b)) + + + + + comment + month name - other.source.q + constant.numeric.complex.month.q + match + (?=(\W|\b))([0-9]{4,}\.([0][1-9]|[1][0-2])m)(?=(\W|\b)) + + - captures - - 2 - - name - constant.numeric.complex.source.q - - comment - boolean,short,integer,long + special I/O functions + name + support.function.io.q match - (?=(\W|\b))([-]?[0-9]+[bhijef]{0,1}(\.[0-9]+[m]?)?|0x[a-f0-9]+)(?=(\W|\b)) + 0:|1:|2: + + + + + comment + boolean, byte, short, int, long, float name - other.source.q + constant.numeric.complex.q + match + (?=(\W|\b))([-]?[0-9]+[bhijf]?(\.[0-9]+[m]?)?|0x[a-fA-F0-9]+)(?=(\W|\b)|_) + + + + + comment + real + name + constant.numeric.complex.real.q + match + (?=(\W|\b))([-]?[0-9]+e[-]?[0-9]+)(?=(\W|\b)) + + + + + comment + nulls + name + constant.numeric.complex.null.q + match + (?=(\W|\b))(0n|0N[ghijepmdznuvt]?)(?=(\W|\b)) + + + + + comment + infinities + name + constant.numeric.complex.inf.q + match + (?=(\W|\b))(0w|0W[hijepdznuvt]?)(?=(\W|\b)) + scopeName source.q uuid - ef19f88f-c8f2-4877-a39b-68259fdd0ded + 6b28adea-f9ea-36f3-e98e-87a5599f915d From 2166734415efaf918bfcefa6f23fae60d26a99cb Mon Sep 17 00:00:00 2001 From: atf1206 Date: Mon, 8 Jun 2020 22:16:17 -0400 Subject: [PATCH 2/2] Re-add highlighting for some operators --- syntax/q.tmLanguage | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/syntax/q.tmLanguage b/syntax/q.tmLanguage index 2aecef7..fd126c9 100644 --- a/syntax/q.tmLanguage +++ b/syntax/q.tmLanguage @@ -416,6 +416,25 @@ match (?=(\W|\b))(0w|0W[hijepdznuvt]?)(?=(\W|\b)) + + + + comment + q adverbs and shortcut + name + support.function.q + match + [!$@\\/_#?|',`\\:] + + + comment + dot notation + name + support.function.q + match + \.(?=\W) + + scopeName