Skip to content

Commit

Permalink
Q: Fixed comments + added explanation, renamed date to datetime, opti…
Browse files Browse the repository at this point in the history
…mized operators
  • Loading branch information
Golmote committed Sep 8, 2015
1 parent d1f90a1 commit addc971
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
26 changes: 22 additions & 4 deletions components/prism-q.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
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 ])\/.+/m,

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.]*)/,
'date': {
'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]:|<>|[<>]=?|:|[+\-*%,!?_~=|$&#@^']):?/,
pattern: /(?:\B\.\B|\b[01]:|<[=>]?|>=?|[:+\-*%,!?_~=|$&#@^]):?/,
alias: 'operator'
},
'punctuation': /[(){}\[\];.]/
Expand Down
2 changes: 1 addition & 1 deletion components/prism-q.min.js

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

13 changes: 12 additions & 1 deletion examples/prism-q.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ <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</code></pre>
<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"
Expand Down

0 comments on commit addc971

Please sign in to comment.