Skip to content

Commit

Permalink
Added support for Kusto (#3068)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Sep 15, 2021
1 parent 4433ccf commit e008ea0
Show file tree
Hide file tree
Showing 17 changed files with 555 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -731,6 +731,10 @@
"alias": "kum",
"owner": "edukisto"
},
"kusto": {
"title": "Kusto",
"owner": "RunDevelopment"
},
"latex": {
"title": "LaTeX",
"alias": ["tex", "context"],
Expand Down
44 changes: 44 additions & 0 deletions components/prism-kusto.js
@@ -0,0 +1,44 @@
Prism.languages.kusto = {
'comment': {
pattern: /\/\/.*/,
greedy: true
},
'string': {
pattern: /```[\s\S]*?```|[hH]?(?:"(?:[^\r\n\\"]|\\.)*"|'(?:[^\r\n\\']|\\.)*'|@(?:"[^\r\n"]*"|'[^\r\n']*'))/,
greedy: true
},

'verb': {
pattern: /(\|\s*)[a-z][\w-]*/i,
lookbehind: true,
alias: 'keyword'
},

'command': {
pattern: /\.[a-z][a-z\d-]*\b/,
alias: 'keyword'
},

'class-name': /\b(?:bool|datetime|decimal|dynamic|guid|int|long|real|string|timespan)\b/,
'keyword': /\b(?:access|alias|and|anti|as|asc|auto|between|by|database|declare|desc|external|from|fullouter|has_all|in|ingestion|inline|inner|innerunique|into|let|like|local|not|of|on|or|pattern|print|query_parameters|range|restrict|schema|set|step|table|tables|to|view|where|with|(?:has(?:perfix|suffix)?|contains|(?:starts|ends)with)(?:_cs)?|(?:left|right)(?:anti(?:semi)?|inner|outer|semi)?|matches\s+regex|nulls\s+(?:first|last))(?![\w-])/,
'boolean': /\b(?:true|false|null)\b/,

'function': /\b[a-z_]\w*(?=\s*\()/,

'datetime': [
{
// RFC 822 + RFC 850
pattern: /\b(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\s*,\s*)?\d{1,2}(?:\s+|-)(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(?:\s+|-)\d{2}\s+\d{2}:\d{2}(?::\d{2})?(?:\s*(?:\b(?:(?:U|GM|[ECMT][DS])T|[A-Z])|[+-]\d{4}))?\b/,
alias: 'number'
},
{
// ISO 8601
pattern: /[+-]?\b(?:\d{4}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?|\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)Z?/,
alias: 'number'
}
],
'number': /\b(?:0x[0-9A-Fa-f]+|\d+(?:\.\d+)?(?:[Ee][+-]?\d+)?)(?:(?:min|sec|[mnµ]s|tick|microsecond|[dhms])\b)?|[+-]?\binf\b/,

'operator': /=>|[!=]~|[!=<>]=?|[-+*/%|]|\.\./,
'punctuation': /[()\[\]{},;.:]/
};
1 change: 1 addition & 0 deletions components/prism-kusto.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions examples/prism-kusto.html
@@ -0,0 +1,8 @@
<h2>Full example</h2>
<pre><code>// Source: https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/tutorial?pivots=azuredataexplorer

StormEvents
| where StartTime > datetime(2007-02-01) and StartTime &lt; datetime(2007-03-01)
| where EventType == 'Flood' and State == 'CALIFORNIA'
| project StartTime, EndTime , State , EventType , EpisodeNarrative
</code></pre>
24 changes: 24 additions & 0 deletions tests/languages/kusto/boolean_feature.test
@@ -0,0 +1,24 @@
true bool(true)
false bool(false)
bool(null)

----------------------------------------------------

[
["boolean", "true"],
["class-name", "bool"],
["punctuation", "("],
["boolean", "true"],
["punctuation", ")"],

["boolean", "false"],
["class-name", "bool"],
["punctuation", "("],
["boolean", "false"],
["punctuation", ")"],

["class-name", "bool"],
["punctuation", "("],
["boolean", "null"],
["punctuation", ")"]
]
25 changes: 25 additions & 0 deletions tests/languages/kusto/class-name_feature.test
@@ -0,0 +1,25 @@
bool
datetime
decimal
dynamic
guid
int
long
real
string
timespan

----------------------------------------------------

[
["class-name", "bool"],
["class-name", "datetime"],
["class-name", "decimal"],
["class-name", "dynamic"],
["class-name", "guid"],
["class-name", "int"],
["class-name", "long"],
["class-name", "real"],
["class-name", "string"],
["class-name", "timespan"]
]
13 changes: 13 additions & 0 deletions tests/languages/kusto/command_feature.test
@@ -0,0 +1,13 @@
.show tables
| count

.set foo=234

----------------------------------------------------

[
["command", ".show"], ["keyword", "tables"],
["operator", "|"], ["verb", "count"],

["command", ".set"], " foo", ["operator", "="], ["number", "234"]
]
7 changes: 7 additions & 0 deletions tests/languages/kusto/comment_feature.test
@@ -0,0 +1,7 @@
// comment

----------------------------------------------------

[
["comment", "// comment"]
]
61 changes: 61 additions & 0 deletions tests/languages/kusto/datetime_feature.test
@@ -0,0 +1,61 @@
// ISO 8601
2014-05-25T08:20:03.123456Z
2014-05-25T08:20:03.123456
2014-05-25T08:20
2014-11-08 15:55:55.123456Z
2014-11-08 15:55:55
2014-11-08 15:55
2014-11-08

// RFC 822
Sat, 8 Nov 14 15:05:02 GMT
Sat, 8 Nov 14 15:05:02
Sat, 8 Nov 14 15:05
Sat, 8 Nov 14 15:05 GMT
8 Nov 14 15:05:02 GMT
8 Nov 14 15:05:02
8 Nov 14 15:05
8 Nov 14 15:05 GMT

// RFC 850
Saturday, 08-Nov-14 15:05:02 GMT
Saturday, 08-Nov-14 15:05:02
Saturday, 08-Nov-14 15:05 GMT
Saturday, 08-Nov-14 15:05
08-Nov-14 15:05:02 GMT
08-Nov-14 15:05:02
08-Nov-14 15:05 GMT
08-Nov-14 15:05

----------------------------------------------------

[
["comment", "// ISO 8601"],
["datetime", "2014-05-25T08:20:03.123456Z"],
["datetime", "2014-05-25T08:20:03.123456"],
["datetime", "2014-05-25T08:20"],
["datetime", "2014-11-08 15:55:55.123456Z"],
["datetime", "2014-11-08 15:55:55"],
["datetime", "2014-11-08 15:55"],
["datetime", "2014-11-08"],

["comment", "// RFC 822"],
["datetime", "Sat, 8 Nov 14 15:05:02 GMT"],
["datetime", "Sat, 8 Nov 14 15:05:02"],
["datetime", "Sat, 8 Nov 14 15:05"],
["datetime", "Sat, 8 Nov 14 15:05 GMT"],
["datetime", "8 Nov 14 15:05:02 GMT"],
["datetime", "8 Nov 14 15:05:02"],
["datetime", "8 Nov 14 15:05"],
["datetime", "8 Nov 14 15:05 GMT"],

["comment", "// RFC 850"],
["datetime", "Saturday, 08-Nov-14 15:05:02 GMT"],
["datetime", "Saturday, 08-Nov-14 15:05:02"],
["datetime", "Saturday, 08-Nov-14 15:05 GMT"],
["datetime", "Saturday, 08-Nov-14 15:05"],
["datetime", "08-Nov-14 15:05:02 GMT"],
["datetime", "08-Nov-14 15:05:02"],
["datetime", "08-Nov-14 15:05 GMT"],
["datetime", "08-Nov-14 15:05"]
]
9 changes: 9 additions & 0 deletions tests/languages/kusto/function_feature.test
@@ -0,0 +1,9 @@
min()

----------------------------------------------------

[
["function", "min"],
["punctuation", "("],
["punctuation", ")"]
]
145 changes: 145 additions & 0 deletions tests/languages/kusto/keyword_feature.test
@@ -0,0 +1,145 @@
access
alias
and
anti
as
asc
auto
between
by
contains
contains_cs
database
declare
desc
endswith
endswith_cs
external
from
fullouter
has
has_all
has_cs
hasperfix
hasperfix_cs
hassuffix
hassuffix_cs
in
ingestion
inline
inner
innerunique
into
left
leftanti
leftantisemi
leftinner
leftouter
leftsemi
let
like
local
matches regex
not
nulls first
nulls last
of
on
or
pattern
print
query_parameters
range
restrict
right
rightanti
rightantisemi
rightinner
rightouter
rightsemi
schema
set
startswith
startswith_cs
step
table
tables
to
view
where
with

----------------------------------------------------

[
["keyword", "access"],
["keyword", "alias"],
["keyword", "and"],
["keyword", "anti"],
["keyword", "as"],
["keyword", "asc"],
["keyword", "auto"],
["keyword", "between"],
["keyword", "by"],
["keyword", "contains"],
["keyword", "contains_cs"],
["keyword", "database"],
["keyword", "declare"],
["keyword", "desc"],
["keyword", "endswith"],
["keyword", "endswith_cs"],
["keyword", "external"],
["keyword", "from"],
["keyword", "fullouter"],
["keyword", "has"],
["keyword", "has_all"],
["keyword", "has_cs"],
["keyword", "hasperfix"],
["keyword", "hasperfix_cs"],
["keyword", "hassuffix"],
["keyword", "hassuffix_cs"],
["keyword", "in"],
["keyword", "ingestion"],
["keyword", "inline"],
["keyword", "inner"],
["keyword", "innerunique"],
["keyword", "into"],
["keyword", "left"],
["keyword", "leftanti"],
["keyword", "leftantisemi"],
["keyword", "leftinner"],
["keyword", "leftouter"],
["keyword", "leftsemi"],
["keyword", "let"],
["keyword", "like"],
["keyword", "local"],
["keyword", "matches regex"],
["keyword", "not"],
["keyword", "nulls first"],
["keyword", "nulls last"],
["keyword", "of"],
["keyword", "on"],
["keyword", "or"],
["keyword", "pattern"],
["keyword", "print"],
["keyword", "query_parameters"],
["keyword", "range"],
["keyword", "restrict"],
["keyword", "right"],
["keyword", "rightanti"],
["keyword", "rightantisemi"],
["keyword", "rightinner"],
["keyword", "rightouter"],
["keyword", "rightsemi"],
["keyword", "schema"],
["keyword", "set"],
["keyword", "startswith"],
["keyword", "startswith_cs"],
["keyword", "step"],
["keyword", "table"],
["keyword", "tables"],
["keyword", "to"],
["keyword", "view"],
["keyword", "where"],
["keyword", "with"]
]

0 comments on commit e008ea0

Please sign in to comment.