-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #624 from Golmote/prism-q
Add support for Q (kdb+ database)
- Loading branch information
Showing
12 changed files
with
716 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Prism.languages.q = { | ||
'string': /"(?:\\.|[^"\\\r\n])*"/, | ||
'comment': [ | ||
// From http://code.kx.com/wiki/Reference/Slash: | ||
// When / is following a space (or a right parenthesis, bracket, or brace), it is ignored with the rest of the line. | ||
{ | ||
|
||
pattern: /([\t )\]}])\/.*/, | ||
lookbehind: true | ||
}, | ||
// From http://code.kx.com/wiki/Reference/Slash: | ||
// A line which has / as its first character and contains at least one other non-whitespace character is a whole-line comment and is ignored entirely. | ||
// A / on a line by itself begins a multiline comment which is terminated by the next \ on a line by itself. | ||
// If a / is not matched by a \, the multiline comment is unterminated and continues to end of file. | ||
// The / and \ must be the first char on the line, but may be followed by any amount of whitespace. | ||
{ | ||
pattern: /(^|\r?\n|\r)\/[\t ]*(?:(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?(?:\\(?=[\t ]*(?:\r?\n|\r))|$)|\S.*)/, | ||
lookbehind: true | ||
}, | ||
// From http://code.kx.com/wiki/Reference/Slash: | ||
// A \ on a line by itself with no preceding matching / will comment to end of file. | ||
/^\\[\t ]*(?:\r?\n|\r)[\s\S]+/m, | ||
|
||
/^#!.+/m | ||
], | ||
'symbol': /`(?::\S+|[\w.]*)/, | ||
'datetime': { | ||
pattern: /0N[mdzuvt]|0W[dtz]|\d{4}\.\d\d(?:m|\.\d\d(?:T(?:\d\d(?::\d\d(?::\d\d(?:[.:]\d\d\d)?)?)?)?)?[dz]?)|\d\d:\d\d(?::\d\d(?:[.:]\d\d\d)?)?[uvt]?/, | ||
alias: 'number' | ||
}, | ||
// The negative look-ahead prevents bad highlighting | ||
// of verbs 0: and 1: | ||
'number': /\b-?(?![01]:)(?:0[wn]|0W[hj]?|0N[hje]?|0x[\da-fA-F]+|\d+\.?\d*(?:e[+-]?\d+)?[hjfeb]?)/, | ||
'keyword': /\\\w+\b|\b(?:abs|acos|aj0?|all|and|any|asc|asin|asof|atan|attr|avgs?|binr?|by|ceiling|cols|cor|cos|count|cov|cross|csv|cut|delete|deltas|desc|dev|differ|distinct|div|do|dsave|ej|enlist|eval|except|exec|exit|exp|fby|fills|first|fkeys|flip|floor|from|get|getenv|group|gtime|hclose|hcount|hdel|hopen|hsym|iasc|identity|idesc|if|ij|in|insert|inter|inv|keys?|last|like|list|ljf?|load|log|lower|lsq|ltime|ltrim|mavg|maxs?|mcount|md5|mdev|med|meta|mins?|mmax|mmin|mmu|mod|msum|neg|next|not|null|or|over|parse|peach|pj|plist|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|ssr?|string|sublist|sums?|sv|svar|system|tables|tan|til|trim|txf|type|uj|ungroup|union|update|upper|upsert|value|var|views?|vs|wavg|where|while|within|wj1?|wsum|ww|xasc|xbar|xcols?|xdesc|xexp|xgroup|xkey|xlog|xprev|xrank)\b/, | ||
'adverb': { | ||
pattern: /['\/\\]:?|\beach\b/, | ||
alias: 'function' | ||
}, | ||
'verb': { | ||
pattern: /(?:\B\.\B|\b[01]:|<[=>]?|>=?|[:+\-*%,!?_~=|$&#@^]):?/, | ||
alias: 'operator' | ||
}, | ||
'punctuation': /[(){}\[\];.]/ | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<h1>Q (kdb+ database)</h1> | ||
<p>To use this language, use the class "language-q".</p> | ||
|
||
<h2>Comments</h2> | ||
<pre><code>foo / This is a comment | ||
/ This is a comment too | ||
|
||
/ | ||
Some multi-line | ||
comment here | ||
\ | ||
|
||
\ | ||
This comment will | ||
continue until the | ||
end of code</code></pre> | ||
|
||
<h2>Character data and strings</h2> | ||
<pre><code>"q" | ||
"\"" | ||
"\\" | ||
"\142" | ||
"foo bar baz"</code></pre> | ||
|
||
<h2>Symbols</h2> | ||
<pre><code>` | ||
`q | ||
`zaphod | ||
`:198.162.0.2:5042 | ||
`:www.yourco.com:5042 | ||
`.new</code></pre> | ||
|
||
<h2>Numbers</h2> | ||
<pre><code>42 | ||
b:-123h | ||
c:1234567890j | ||
pi:3.14159265 | ||
float1:1f | ||
r:1.4142e | ||
2.0 | ||
4.00e | ||
f:1.23456789e-10 | ||
r:1.2345678e-10e | ||
bit:0b | ||
byte:0x2a | ||
a:42 | ||
bit:1b | ||
|
||
0w 0n 0W 0Wh 0Wj</code></pre> | ||
|
||
<h2>Dates</h2> | ||
<pre><code>d:2006.07.04 | ||
t:09:04:59.000 | ||
dt:2006.07.04T09:04:59.000 | ||
mon:2006.07m | ||
mm:09:04 | ||
sec:09:04:59 | ||
d:2006.07.04 | ||
|
||
0Nm 0Nd 0Nz 0Nu 0Nv 0Wd 0Wt 0Wz</code></pre> | ||
|
||
<h2>Verbs</h2> | ||
<pre><code>99+L | ||
x<42|x>98 | ||
(x<42)|x>98 | ||
42~(4 2;(1 0)) | ||
(4 2)~(4; 2*1)</code></pre> | ||
|
||
<h2>Adverbs</h2> | ||
<pre><code>" ," ,/: ("Now";"is";"the";"time") | ||
L1,/:\:L2 | ||
0+/10 20 30 | ||
(1#) each 1001 1002 1004 1003</code></pre> | ||
|
||
<h2>Built-in functions and q-sql</h2> | ||
<pre><code>string 42 | ||
L1 cross L2 | ||
type c | ||
select from t where price=(max;price) fby ([]sym;ex) | ||
ungroup `p xgroup sp | ||
`instrument insert (`g; `$"Google"; `$"Internet")</code></pre> | ||
|
||
<h2>Example</h2> | ||
<pre><code>/ Example from http://code.kx.com/wiki/Cookbook/CorporateActions | ||
getCAs:{[caTypes] | ||
/ handles multiplie corporate actions on one date | ||
t:0!select factor:prd factor by date-1,sym from ca where caType in caTypes; | ||
t,:update date:1901.01.01,factor:1.0 from ([]sym:distinct t`sym); | ||
t:`date xasc t; | ||
t:update factor:reverse prds reverse 1 rotate factor by sym from t; | ||
:update `g#sym from 0!t; | ||
}; | ||
|
||
adjust:{[t;caTypes] | ||
t:0!t; | ||
factors:enlist 1.0^aj[`sym`date;([] date:t`date;sym:t`sym);getCAs caTypes]`factor; | ||
mc:c where (lower c:cols t) like "*price"; / find columns to multiply | ||
dc:c where lower[c] like "*size"; / find columns to divide | ||
:![t;();0b;(mc,dc)!((*),/:mc,\:factors),((%),/:dc,\:factors)]; / multiply or divide out the columns | ||
}; | ||
|
||
/ get the adjustment factors considering all corporate actions | ||
getCAs exec distinct caType from ca | ||
|
||
adjust[t;`dividend] / adjust trades for dividends only</code></pre> | ||
|
||
<h2>Known failures</h2> | ||
<p>There are certain edge cases where Prism will fail. | ||
There are always such cases in every regex-based syntax highlighter. | ||
However, Prism dares to be open and honest about them. | ||
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug. | ||
</p> | ||
|
||
<h3>Two double quotes in a comment</h3> | ||
<pre><code>/ This "comment" is broken</code></pre> | ||
|
||
<h3>The global context is highlighted as a verb</h3> | ||
<pre><code>\d .</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
' ': | ||
+/ +/: | ||
\ \: | ||
each | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["adverb", "'"], ["adverb", "':"], | ||
["verb", "+"], ["adverb", "/"], ["verb", "+"], ["adverb", "/:"], | ||
["adverb", "\\"], ["adverb", "\\:"], | ||
["adverb", "each"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for adverbs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env q | ||
/ Foobar | ||
|
||
/ | ||
Foo | ||
bar | ||
\ | ||
|
||
\ | ||
Foo | ||
Bar | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "#!/usr/bin/env q"], | ||
["comment", "/ Foobar"], | ||
["comment", "/\r\nFoo\r\nbar\r\n\\"], | ||
["comment", "\\\r\nFoo\r\nBar"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
0Nm 0Nd 0Nz 0Nu 0Nv 0Nt | ||
0Wd 0Wt 0Wz | ||
|
||
2015.09m | ||
2015.09.08 | ||
2015.09.08d | ||
2015.09.08z | ||
2015.09.08T08:25:32 | ||
2015.09.08T08:25:32.000 | ||
08:25 | ||
08:25u | ||
08:25v | ||
08:25t | ||
08:25:32 | ||
08:25:32:000 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["datetime", "0Nm"], ["datetime", "0Nd"], ["datetime", "0Nz"], ["datetime", "0Nu"], ["datetime", "0Nv"], ["datetime", "0Nt"], | ||
["datetime", "0Wd"], ["datetime", "0Wt"], ["datetime", "0Wz"], | ||
|
||
["datetime", "2015.09m"], | ||
["datetime", "2015.09.08"], | ||
["datetime", "2015.09.08d"], | ||
["datetime", "2015.09.08z"], | ||
["datetime", "2015.09.08T08:25:32"], | ||
["datetime", "2015.09.08T08:25:32.000"], | ||
["datetime", "08:25"], | ||
["datetime", "08:25u"], | ||
["datetime", "08:25v"], | ||
["datetime", "08:25t"], | ||
["datetime", "08:25:32"], | ||
["datetime", "08:25:32:000"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for dates, times and datetimes. |
Oops, something went wrong.