Skip to content

Commit

Permalink
Add support for the Jolie language (#1014)
Browse files Browse the repository at this point in the history
* Added component for the Jolie language

* Added Jolie among the supported components

* update for merge

- revised jolie component
- added tests
- added code example
- minified with `gulp`

* fixes

* fixes

* fixed Jolie html file example and highlight for punctuation

* fixed indentation in test html file and added comma as punctuation
  • Loading branch information
thesave authored and Golmote committed Nov 9, 2016
1 parent d75da8e commit dfc1941
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 3 deletions.
5 changes: 5 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ var components = {
"require": "clike",
"owner": "sherblot"
},
"jolie": {
"title": "Jolie",
"require": "clike",
"owner": "thesave"
},
"json": {
"title": "JSON",
"owner": "CupOfTea696"
Expand Down
56 changes: 56 additions & 0 deletions components/prism-jolie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Prism.languages.jolie = Prism.languages.extend('clike', {
'keyword': /\b(?:include|define|is_defined|undef|main|init|outputPort|inputPort|Location|Protocol|Interfaces|RequestResponse|OneWay|type|interface|extender|throws|cset|csets|forward|Aggregates|Redirects|embedded|courier|extender|execution|sequential|concurrent|single|scope|install|throw|comp|cH|default|global|linkIn|linkOut|synchronized|this|new|for|if|else|while|in|Jolie|Java|Javascript|nullProcess|spawn|constants|with|provide|until|exit|foreach|instanceof|over|service)\b/g,
'builtin': /\b(?:undefined|string|int|void|long|Byte|bool|double|float|char|any)\b/,
'number': /\b\d*\.?\d+(?:e[+-]?\d+)?l?\b/i,
'operator': /->|<<|[!+-<>=*]?=|[:<>!?*\/%^]|&&|\|\||--?|\+\+?/g,
'symbol': /[|;@]/,
'punctuation': /[,.]/,
'string': {
pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
greedy: true
},
});

delete Prism.languages.jolie['class-name'];
delete Prism.languages.jolie['function'];

Prism.languages.insertBefore( 'jolie', 'keyword', {
'function':
{
pattern: /((?:\b(?:outputPort|inputPort|in|service|courier)\b|@)\s*)\w+/,
lookbehind: true
},
'aggregates': {
pattern: /(\bAggregates\s*:\s*)(?:\w+(?:\s+with\s+\w+)?\s*,\s*)*\w+(?:\s+with\s+\w+)?/,
lookbehind: true,
inside: {
'withExtension': {
pattern: /\bwith\s+\w+/,
inside: {
'keyword' : /\bwith\b/
}
},
'function': {
pattern: /\w+/
},
'punctuation': {
pattern: /,/
}
}
},
'redirects': {
pattern: /(\bRedirects\s*:\s*)(?:\w+\s*=>\s*\w+\s*,\s*)*(?:\w+\s*=>\s*\w+)/,
lookbehind: true,
inside: {
'punctuation': {
pattern: /,/
},
'function': {
pattern: /\w+/g
},
'symbol': {
pattern: /=>/g
}
}
}
});
1 change: 1 addition & 0 deletions components/prism-jolie.min.js

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

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

<h2>Comments</h2>
<pre><code>// Single line comment
/* Multi-line
comment */</code></pre>

<h2>Strings</h2>
<pre><code>"foo \"bar\" baz";
'foo \'bar\' baz'</code></pre>

<h2>Numbers</h2>
<pre><code>42
42L
1.2e3
0.1E-4
0.2e+1
</code></pre>

<h2>Full example</h2>
<pre><code>include "console.iol"

type HubType: void {
.sid: undefined
.nodes[1,*] : NodeType
}

type NodeType: void {
.sid: string
.node: string
.load?: int
}

type NetType: HubType | NodeType

interface NetInterface {
OneWay: start( string ), addElement( NetType ), removeElement( NetType ), quit( void )
RequestResponse: showElements( void )( NetType ) throws SomeFault
}

type LogType: void {
.message: string
}

interface LoggerInterface {
RequestResponse: log( LogType )( void )
}

outputPort LoggerService {
Interfaces: LoggerInterface
}

embedded {
Jolie: "logger.ol" in LoggerService
}

type AuthenticationData: void {
.key:string
}

interface extender AuthInterfaceExtender {
OneWay: *(AuthenticationData)
}

service SubService
{
Interfaces: NetInterface

main
{
println@Console( "I do nothing" )()
}
}

inputPort ExtLogger {
Location: "socket://localhost:9000"
Protocol: sodep
Interfaces: LoggerInterface
Aggregates: LoggerService with AuthInterfaceExtender
}

courier ExtLogger {
[interface LoggerInterface( request )] {
if ( key == "secret" ){
forward ( request )
}
}
}

inputPort In {
Location: "socket://localhost:8000"
Protocol: http {
.debug = true;
.debug.showContent = true
}
Interfaces: NetInterface
Aggregates: SubService,
LoggerService
Redirects: A => SubService,
B => SubService
}

cset {
sid: HubType.sid NodeType.sid
}

execution{ concurrent }

define netmodule {
if( request.load == 0 || request.load < 1 &&
request.load <= 2 || request.load >= 3 &&
request.load > 4 || request.load%4 == 2
) {
scope( scopeName ) {
// inline comment
install( MyFault => println@Console( "Something \"Went\" Wrong" + ' but it\'s ok' )() );
/*
* Multi-line
* Comment
*/
install( this => cH; println@Console( "Something went wrong: " + ^load )() );
install( default => comp( scopeName ); println@Console( "Something went wrong" )() );
load -> request.( "load" );
{ ++load | load++ | --load | load-- };
throw( MyFault )
}
} else {
foreach ( node -> request.nodes ) {
with( node ){
while( .load != 100 ) {
.load++
}
}
}
}
}

main
{
start( sid );
synchronized( unneededSync ){
csets.sid = sid;
undef( sid )
};
provide
[ addElement( request ) ]{
if( request instanceof NodeType ) {
netmodule
}
}
[ removeElement() ]
[ showElements()( response ){
/*
* assemble response
*/
nullProcess
}]{
// log the request
log@LoggerService( new )();
log @ LoggerService( new )()
}
until
[ quit() ]{ exit }
}</code></pre>
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","fsharp":"clike","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","jade":"javascript","java":"clike","kotlin":"clike","less":"css","markdown":"markup","nginx":"clike","objectivec":"c","parser":"markup","php":"clike","php-extras":"php","processing":"clike","protobuf":"clike","qore":"clike","jsx":["markup","javascript"],"ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","wiki":"markup"}/*]*/;
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","fsharp":"clike","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","jade":"javascript","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","nginx":"clike","objectivec":"c","parser":"markup","php":"clike","php-extras":"php","processing":"clike","protobuf":"clike","qore":"clike","jsx":["markup","javascript"],"ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","wiki":"markup"}/*]*/;

var lang_data = {};

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.

12 changes: 11 additions & 1 deletion tests/helper/test-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,17 @@ module.exports = {
var compiledTokenStream = Prism.tokenize(testCase.testSource, mainLanguageGrammar);
var simplifiedTokenStream = TokenStreamTransformer.simplify(compiledTokenStream);

assert.deepEqual(simplifiedTokenStream, testCase.expectedTokenStream, testCase.comment);
var tzd = JSON.stringify( simplifiedTokenStream ); var exp = JSON.stringify( testCase.expectedTokenStream );
var i = 0;var j = 0;var diff = "";
while ( j < tzd.length ){ if (exp[i] != tzd[j] || i == exp.length) diff += tzd[j]; else i++; j++; }

// var message = "\nToken Stream: \n" + JSON.stringify( simplifiedTokenStream, null, " " ) +
var message = "\nToken Stream: \n" + tzd +
"\n-----------------------------------------\n" +
"Expected Token Stream: \n" + exp +
"\n-----------------------------------------\n" + diff;

var result = assert.deepEqual(simplifiedTokenStream, testCase.expectedTokenStream, testCase.comment + message);
},


Expand Down
43 changes: 43 additions & 0 deletions tests/languages/jolie/deployment_features.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Aggregates: First, Second with Third
Redirects: First => Second, Third => Fourth
Jolie: "logger.ol" in LoggerService
log@LoggerService( new )();
println @ Console( "none" )()
----------------------------------------------------
[
[ "keyword", "Aggregates" ],
[ "operator", ":" ],
[ "aggregates", [
[ "function", "First" ], [ "punctuation", ","],
[ "function", "Second" ],
[ "withExtension", [
[ "keyword", "with" ], " Third" ]
]
]
],
[ "keyword", "Redirects" ],
[ "operator", ":" ],
[ "redirects",
[
[ "function", "First" ],
[ "symbol", "=>" ],
[ "function", "Second" ], [ "punctuation", ","],
[ "function", "Third" ],
[ "symbol", "=>" ],
[ "function", "Fourth" ]
]
],
[ "keyword", "Jolie" ],
[ "operator", ":" ],
[ "string", "\"logger.ol\"" ],
[ "keyword", "in" ],
[ "function", "LoggerService" ],
"\nlog", [ "symbol", "@" ], [ "function", "LoggerService" ],
"( ", [ "keyword", "new" ], " )()", [ "symbol", ";" ],
"\nprintln ", [ "symbol", "@" ], [ "function", "Console" ],
"( ", [ "string", "\"none\"" ], " )()"
]

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

Checks for outputPorts and Aggregates and Redirect constructs.
Loading

0 comments on commit dfc1941

Please sign in to comment.