Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for J #623

Merged
merged 4 commits into from
Sep 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ var components = {
"title": "Ini",
"owner": "aviaryan"
},
"j": {
"title": "J",
"owner": "Golmote"
},
"jade": {
"title": "Jade",
"require": "javascript",
Expand Down
22 changes: 22 additions & 0 deletions components/prism-j.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Prism.languages.j = {
'comment': /\bNB\..*/,
'string': /'(?:''|[^'\r\n])*'/,
'keyword': /\b(?:(?:adverb|conjunction|CR|def|define|dyad|LF|monad|noun|verb)\b|(?:assert|break|case|catch[dt]?|continue|do|else|elseif|end|fcase|for|for_\w+|goto_\w+|if|label_\w+|return|select|throw|try|while|whilst)\.)/,
'verb': {
// Negative look-ahead prevents bad highlighting
// of ^: ;. =. =: !. !:
pattern: /(?!\^:|;\.|[=!][.:])(?:\{(?:\.|::?)?|p(?:\.\.?|:)|[=!\]]|[<>+*\-%$|,#][.:]?|[\^?]\.?|[;\[]:?|[~}"i][.:]|[ACeEIjLor]\.|(?:[_\/\\qsux]|_?\d):)/,
alias: 'keyword'
},
'number': /\b_?(?:(?!\d:)\d+(?:\.\d+)?(?:(?:[ejpx]|ad|ar)_?\d+(?:\.\d+)?)*(?:b_?[\da-z]+(?:\.[\da-z]+)?)?|_(?!\.))/,
'adverb': {
pattern: /[~}]|[\/\\]\.?|[bfM]\.|t[.:]/,
alias: 'builtin'
},
'operator': /[=a][.:]|_\./,
'conjunction': {
pattern: /&(?:\.:?|:)?|[.:@][.:]?|[!D][.:]|[;dHT]\.|`:?|[\^LS]:|"/,
alias: 'variable'
},
'punctuation': /[()]/
};
1 change: 1 addition & 0 deletions components/prism-j.min.js

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

72 changes: 72 additions & 0 deletions examples/prism-j.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<h1>J</h1>
<p>To use this language, use the class "language-j".</p>

<h2>Comments</h2>
<pre><code>NB. This is a comment</code></pre>

<h2>Strings</h2>
<pre><code>'This is a string.'
'This is a string with ''quotes'' in it.'</code></pre>

<h2>Numbers</h2>
<pre><code>2.3e2 2.3e_2 2j3
2p1 1p_1
1x2 2x1 1x_1
2e2j_2e2 2e2j2p1 2ad45 2ar0.785398
16b1f 10b23 _10b23 1e2b23 2b111.111</code></pre>

<h2>Verbs</h2>
<pre><code>%4
3%4
,b
'I';'was';'here'
3 5$'wake read lamp '</code></pre>

<h2>Adverbs</h2>
<pre><code>1 2 3 */ 4 5 6 7
'%*'(1 3;2 _1)} y</code></pre>

<h2>Conjunctions</h2>
<pre><code>10&^. 2 3 10 100 200
+`*
+:@*: +/ -:@%:</code></pre>

<h2>Examples</h2>
<pre><code>NB. The following functions E1, E2 and E3
NB. interchange two rows of a matrix,
NB. multiply a row by a constant,
NB. and add a multiple of one row to another:

E1=: <@] C. [
E2=: f`g`[}
E3=: F`g`[}
f=: {:@] * {.@] { [
F=: [: +/ (1:,{:@]) * (}:@] { [)
g=: {.@]
M=: i. 4 5
M;(M E1 1 3);(M E2 1 10);(M E3 1 3 10)</code></pre>

<pre><code>NB. Implementation of quicksort

sel=: adverb def 'u # ['

quicksort=: verb define
if. 1 >: #y do. y
else.
(quicksort y &lt;sel e),(y =sel e),quicksort y >sel e=.y{~?#y
end.
)</code></pre>

<pre><code>NB. Implementation of quicksort (tacit programming)

quicksort=: (($:@(&lt;#[), (=#[), $:@(>#[)) ({~ ?@#)) ^: (1&lt;#)</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>Comment-like substrings</h3>
<pre><code>'This string is NB. broken'</code></pre>
19 changes: 19 additions & 0 deletions tests/languages/j/adverb_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
~ }
/ /.
\ \.
b. f. M.
t. t:

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

[
["adverb", "~"], ["adverb", "}"],
["adverb", "/"], ["adverb", "/."],
["adverb", "\\"], ["adverb", "\\."],
["adverb", "b."], ["adverb", "f."], ["adverb", "M."],
["adverb", "t."], ["adverb", "t:"]
]

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

Checks for adverbs.
13 changes: 13 additions & 0 deletions tests/languages/j/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
NB.
NB. Foo bar

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

[
["comment", "NB."],
["comment", "NB. Foo bar"]
]

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

Checks for comments.
41 changes: 41 additions & 0 deletions tests/languages/j/conjunction_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
& &. &.: &:

. .. .:
: :. ::
@ @. @:

!. !:
D. D:

;. d. H. T.

` `:

^: L: S:

"

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

[
["conjunction", "&"], ["conjunction", "&."], ["conjunction", "&.:"], ["conjunction", "&:"],

["conjunction", "."], ["conjunction", ".."], ["conjunction", ".:"],
["conjunction", ":"], ["conjunction", ":."], ["conjunction", "::"],
["conjunction", "@"], ["conjunction", "@."], ["conjunction", "@:"],

["conjunction", "!."], ["conjunction", "!:"],
["conjunction", "D."], ["conjunction", "D:"],

["conjunction", ";."], ["conjunction", "d."], ["conjunction", "H."], ["conjunction", "T."],

["conjunction", "`"], ["conjunction", "`:"],

["conjunction", "^:"], ["conjunction", "L:"], ["conjunction", "S:"],

["conjunction", "\""]
]

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

Checks for conjunctions.
77 changes: 77 additions & 0 deletions tests/languages/j/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
adverb
conjunction
CR
def
define
dyad
LF
monad
noun
verb

assert.
break.
case.
catch.
catchd.
catcht.
continue.
do.
else.
elseif.
end.
fcase.
for.
for_foobar.
goto_foobar.
if.
label_foobar.
return.
select.
throw.
try.
while.
whilst.

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

[
["keyword", "adverb"],
["keyword", "conjunction"],
["keyword", "CR"],
["keyword", "def"],
["keyword", "define"],
["keyword", "dyad"],
["keyword", "LF"],
["keyword", "monad"],
["keyword", "noun"],
["keyword", "verb"],

["keyword", "assert."],
["keyword", "break."],
["keyword", "case."],
["keyword", "catch."],
["keyword", "catchd."],
["keyword", "catcht."],
["keyword", "continue."],
["keyword", "do."],
["keyword", "else."],
["keyword", "elseif."],
["keyword", "end."],
["keyword", "fcase."],
["keyword", "for."],
["keyword", "for_foobar."],
["keyword", "goto_foobar."],
["keyword", "if."],
["keyword", "label_foobar."],
["keyword", "return."],
["keyword", "select."],
["keyword", "throw."],
["keyword", "try."],
["keyword", "while."],
["keyword", "whilst."]
]

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

Checks for all keywords.
41 changes: 41 additions & 0 deletions tests/languages/j/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
2.3e2 2.3e_2 2j3
230 0.023 2j3

2p1 1p_1
6.28319 0.31831

1x2 2x1 1x_1
7.38906 5.43656 0.367879

2e2j_2e2 2e2j2p1 2ad45 2ar0.785398
200j_200 628.319j6.28319 1.41421j1.41421 1.41421j1.41421

16b1f 10b23 _10b23 1e2b23 2b111.111
31 23 _17 203 7.875

_ __

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

[
["number", "2.3e2"], ["number", "2.3e_2"], ["number", "2j3"],
["number", "230"], ["number", "0.023"], ["number", "2j3"],

["number", "2p1"], ["number", "1p_1"],
["number", "6.28319"], ["number", "0.31831"],

["number", "1x2"], ["number", "2x1"], ["number", "1x_1"],
["number", "7.38906"], ["number", "5.43656"], ["number", "0.367879"],

["number", "2e2j_2e2"], ["number", "2e2j2p1"], ["number", "2ad45"], ["number", "2ar0.785398"],
["number", "200j_200"], ["number", "628.319j6.28319"], ["number", "1.41421j1.41421"], ["number", "1.41421j1.41421"],

["number", "16b1f"], ["number", "10b23"], ["number", "_10b23"], ["number", "1e2b23"], ["number", "2b111.111"],
["number", "31"], ["number", "23"], ["number", "_17"], ["number", "203"], ["number", "7.875"],

["number", "_"], ["number", "__"]
]

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

Checks for numbers.
13 changes: 13 additions & 0 deletions tests/languages/j/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
''
'fo''obar'

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

[
["string", "''"],
["string", "'fo''obar'"]
]

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

Checks for strings.
Loading