Skip to content

Commit

Permalink
Add Concurnas support (#2206)
Browse files Browse the repository at this point in the history
Concurnas is an open-source JVM programming language designed for building reliable, scalable, high performance concurrent, distributed and parallel systems. For more information please see: https://concurnas.com/
  • Loading branch information
jasontatton authored Feb 14, 2020
1 parent 238f116 commit b24f734
Show file tree
Hide file tree
Showing 16 changed files with 471 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@
"require": "clike",
"owner": "zeitgeist87"
},
"concurnas": {
"title": "Concurnas",
"alias": "conc",
"owner": "jasontatton"
},
"csharp": {
"title": "C#",
"require": "clike",
Expand Down
48 changes: 48 additions & 0 deletions components/prism-concurnas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Prism.languages.concurnas = {
'comment': [
{
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
lookbehind: true
},
{
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true
}
],
'langext': {
pattern: /\w+\s*\|\|[\s\S]+?\|\|/,
greedy: true,
alias: 'string'
},
'function': {
pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/,
lookbehind: true
},
'keyword': /\b(?:abstract|actor|also|annotation|assert|async|await|bool|boolean|break|byte|case|catch|changed|char|class|closed|constant|continue|def|default|del|double|elif|else|enum|every|extends|false|finally|float|for|from|global|gpudef|gpukernel|if|import|in|init|inject|int|lambda|local|long|loop|match|new|nodefault|null|of|onchange|open|out|override|package|parfor|parforsync|post|pre|private|protected|provide|provider|public|return|shared|short|single|size_t|sizeof|super|sync|this|throw|trait|trans|transient|true|try|typedef|unchecked|using|val|var|void|while|with)\b/,
'boolean': /\b(?:false|true)\b/,
'number': /\b0b[01][01_]*L?\b|\b0x[\da-f_]*\.?[\da-f_p+-]+\b|(?:\b\d[\d_]*\.?[\d_]*|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfls]?/i,
'punctuation': /[{}[\];(),.:]/,
'operator': /<==|>==|=>|->|<-|<>|\^|&==|&<>|!|\?|\?:|\.\?|\+\+|--|[-+*/=<>]=?|\b(?:and|as|band|bor|bxor|comp|is|isnot|mod|or)\b=?/,
'annotation': {
pattern: /@(?:\w+:)?(?:\w*|\[[^\]]+\])/,
alias: 'builtin'
}
};

Prism.languages.insertBefore('concurnas', 'langext', {
'string': {
pattern: /[rs]?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
greedy: true,
inside: {
'interpolation': {
pattern: /((?:^|[^\\])(?:\\{2})*){(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
lookbehind: true,
inside: Prism.languages.concurnas
},
'string': /[\s\S]+/
}
}
});

Prism.languages.conc = Prism.languages.concurnas;
1 change: 1 addition & 0 deletions components/prism-concurnas.min.js

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

89 changes: 89 additions & 0 deletions examples/prism-concurnas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<h2>Comments</h2>
<pre><code>// This is a comment
/* This is a comment
on multiple lines */</code></pre>

<h2>Numbers</h2>
<pre><code>12
12e5
12.f
12f
12d
12.d
12.0
12.0f
12.0d</code></pre>

<h2>strings and language extensions</h2>
<pre><code>"hi"
'hi'
'c'
'what "yach"'
s'c'
"c"
r"[a-z|A-Z]+"</code></pre>

<h2>Functions</h2>
<pre><code>def add(a int, b int) => a + b</code></pre>

<h2>Language Extensions</h2>
<pre><code>dcalc = mylisp||(+ 1 2 (* 2 3))|| // == 9

myFortran || program hello
print *, "Hello World!"
end program hello|| //prints "Hello World!"

lotto = myAPL || x[⍋x←6?40] || //6 unique random numbers from 1 to 40</code></pre>

<h2>Full example</h2>
<pre><code>//an overloaded function
def adder(a int, b int) => a + b
def adder(a int, b float) => adder(a, b as int)
def adder(a int) => adder(a, 10)

//a default value
def powerPlus(a int, raiseTo = 2, c int) => a ** raiseTo + c

//call our function with a default value
res1 = powerPlus(4, 10)//second argument defaults to '2'
res2 = powerPlus(4, 3, 10)//second argument provided

//calling a function with named parameters:
def powerAdder(a int, raiseATo = 2, b int, raiseBTo = 2) => a**raiseATo + b**raiseBTo
res3 = powerAdder(2, 4, raiseATo=3)//equivalent to: powerAdder(2, 3, 4, 2)

//varargs:
def sum(elms int...) int {
res = 0
for(elm in elms){
res += elm
}
res
}

//call our function with a vararg
thesum = sum(1, 2, 3, 4, 5)

//partially defined typedef
typedef NameMap<X> = java.util.ArrayList<java.util.HashMap<String, java.util.HashSet<X>>>

//using typedefs...
nm NameMap<String>= new NameMap<String>()

@Annotation
class MyClass(a int, b int, c String){
override toString() => 'MyClass({a}, {b}, "{c}")'
}

mc1 = MyClass(12, 14, "hi there")
mc2 = mc1@ //copy mc1

assert mc1 == mc2//same values!
assert mc1 &<> mc2//different objects!

mc3 = mc1@(a = 100)//copy mc1 but overwrite value of a
assert 'MyClass(100, 14, "hi there")' == mc3.toString()

mc4 = mc1@(<a, b>)//copy mc1 but exclude a and b
assert 'MyClass(0, 0, "hi there")' == mc3.toString()
</code></pre>
12 changes: 6 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"adoc": "asciidoc",
"shell": "bash",
"rbnf": "bnf",
"conc": "concurnas",
"cs": "csharp",
"dotnet": "csharp",
"coffee": "coffeescript",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

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

1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"bbcode": "BBcode",
"bnf": "Backus–Naur form",
"rbnf": "Routing Backus–Naur form",
"conc": "Concurnas",
"csharp": "C#",
"cs": "C#",
"dotnet": "C#",
Expand Down
Loading

0 comments on commit b24f734

Please sign in to comment.