Skip to content

Commit dfbb202

Browse files
Jolie: Improved tokenization (#3221)
1 parent 563cd73 commit dfbb202

9 files changed

+355
-210
lines changed

components/prism-jolie.js

+20-34
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,41 @@
11
Prism.languages.jolie = Prism.languages.extend('clike', {
22
'string': {
3-
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
3+
pattern: /(^|[^\\])"(?:\\[\s\S]|[^"\\])*"/,
4+
lookbehind: true,
45
greedy: true
56
},
6-
'keyword': /\b(?:Aggregates|Interfaces|Java|Javascript|Jolie|Location|OneWay|Protocol|Redirects|RequestResponse|cH|comp|concurrent|constants|courier|cset|csets|default|define|else|embedded|execution|exit|extender|for|foreach|forward|global|if|in|include|init|inputPort|install|instanceof|interface|is_defined|linkIn|linkOut|main|new|nullProcess|outputPort|over|provide|scope|sequential|service|single|spawn|synchronized|this|throw|throws|type|undef|until|while|with)\b/,
7+
'class-name': {
8+
pattern: /((?:\b(?:as|courier|embed|in|inputPort|outputPort|service)\b|@)[ \t]*)\w+/,
9+
lookbehind: true
10+
},
11+
'keyword': /\b(?:as|cH|comp|concurrent|constants|courier|cset|csets|default|define|else|embed|embedded|execution|exit|extender|for|foreach|forward|from|global|if|import|in|include|init|inputPort|install|instanceof|interface|is_defined|linkIn|linkOut|main|new|nullProcess|outputPort|over|private|provide|public|scope|sequential|service|single|spawn|synchronized|this|throw|throws|type|undef|until|while|with)\b/,
12+
'function': /\b[a-z_]\w*(?=[ \t]*[@(])/i,
713
'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?l?/i,
8-
'operator': /-[-=>]?|\+[+=]?|<[<=]?|[>=*!]=?|&&|\|\||[:?\/%^]/,
9-
'punctuation': /[,.]/,
10-
'builtin': /\b(?:Byte|any|bool|char|double|float|int|long|string|undefined|void)\b/,
11-
'symbol': /[|;@]/
14+
'operator': /-[-=>]?|\+[+=]?|<[<=]?|[>=*!]=?|&&|\|\||[?\/%^@|]/,
15+
'punctuation': /[()[\]{},;.:]/,
16+
'builtin': /\b(?:Byte|any|bool|char|double|enum|float|int|length|long|ranges|regex|string|undefined|void)\b/
1217
});
1318

14-
delete Prism.languages.jolie['class-name'];
15-
1619
Prism.languages.insertBefore('jolie', 'keyword', {
17-
'function':
18-
{
19-
pattern: /((?:\b(?:courier|in|inputPort|outputPort|service)\b|@)\s*)\w+/,
20-
lookbehind: true
21-
},
2220
'aggregates': {
2321
pattern: /(\bAggregates\s*:\s*)(?:\w+(?:\s+with\s+\w+)?\s*,\s*)*\w+(?:\s+with\s+\w+)?/,
2422
lookbehind: true,
2523
inside: {
26-
'with-extension': {
27-
pattern: /\bwith\s+\w+/,
28-
inside: {
29-
'keyword': /\bwith\b/
30-
}
31-
},
32-
'function': {
33-
pattern: /\w+/
34-
},
35-
'punctuation': {
36-
pattern: /,/
37-
}
24+
'keyword': /\bwith\b/,
25+
'class-name': /\w+/,
26+
'punctuation': /,/
3827
}
3928
},
4029
'redirects': {
4130
pattern: /(\bRedirects\s*:\s*)(?:\w+\s*=>\s*\w+\s*,\s*)*(?:\w+\s*=>\s*\w+)/,
4231
lookbehind: true,
4332
inside: {
44-
'punctuation': {
45-
pattern: /,/
46-
},
47-
'function': {
48-
pattern: /\w+/
49-
},
50-
'symbol': {
51-
pattern: /=>/
52-
}
33+
'punctuation': /,/,
34+
'class-name': /\w+/,
35+
'operator': /=>/
5336
}
37+
},
38+
'property': {
39+
pattern: /\b(?:Aggregates|[Ii]nterfaces|Java|Javascript|Jolie|[Ll]ocation|OneWay|[Pp]rotocol|Redirects|RequestResponse)\b(?=[ \t]*:)/
5440
}
5541
});

components/prism-jolie.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+22-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
undefined
2-
string
3-
int
4-
void
5-
long
61
Byte
2+
any
73
bool
4+
char
85
double
6+
enum
97
float
10-
char
11-
any
8+
int
9+
length
10+
long
11+
ranges
12+
regex
13+
string
14+
undefined
15+
void
1216

1317
----------------------------------------------------
1418

1519
[
16-
["builtin", "undefined"],
17-
["builtin", "string"],
18-
["builtin", "int"],
19-
["builtin", "void"],
20-
["builtin", "long"],
2120
["builtin", "Byte"],
21+
["builtin", "any"],
2222
["builtin", "bool"],
23+
["builtin", "char"],
2324
["builtin", "double"],
25+
["builtin", "enum"],
2426
["builtin", "float"],
25-
["builtin", "char"],
26-
["builtin", "any"]
27+
["builtin", "int"],
28+
["builtin", "length"],
29+
["builtin", "long"],
30+
["builtin", "ranges"],
31+
["builtin", "regex"],
32+
["builtin", "string"],
33+
["builtin", "undefined"],
34+
["builtin", "void"]
2735
]
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// single line
2+
3+
/*
4+
multiple
5+
lines
6+
*/
7+
8+
----------------------------------------------------
9+
10+
[
11+
["comment", "// single line"],
12+
13+
["comment", "/*\r\nmultiple\r\nlines\r\n*/"]
14+
]

tests/languages/jolie/deployment_features.test

+126-30
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,152 @@
11
Aggregates: First, Second with Third
2+
23
Redirects: First => Second, Third => Fourth
4+
35
Jolie: "logger.ol" in LoggerService
6+
47
log@LoggerService( new )();
58
println @ Console( "none" )()
69

10+
outputPort OutputPort3 {
11+
location: "socket://localhost:9002/"
12+
protocol: sodep
13+
interfaces: Interface3
14+
}
15+
16+
interface MyInterface {
17+
OneWay:
18+
myOW( string )
19+
RequestResponse:
20+
myRR( string )( string )
21+
}
22+
23+
private service MainService {
24+
embed ConfigurationService( ) as Conf
25+
main {
26+
getDBConn@Conf( )( res )
27+
}
28+
}
29+
730
----------------------------------------------------
831

932
[
10-
["keyword", "Aggregates"],
11-
["operator", ":"],
33+
["property", "Aggregates"],
34+
["punctuation", ":"],
1235
["aggregates", [
13-
["function", "First"],
36+
["class-name", "First"],
1437
["punctuation", ","],
15-
["function", "Second"],
16-
["with-extension", [
17-
["keyword", "with"],
18-
" Third"
19-
]]
38+
["class-name", "Second"],
39+
["keyword", "with"],
40+
["class-name", "Third"]
2041
]],
2142

22-
["keyword", "Redirects"],
23-
["operator", ":"],
43+
["property", "Redirects"],
44+
["punctuation", ":"],
2445
["redirects", [
25-
["function", "First"],
26-
["symbol", "=>"],
27-
["function", "Second"],
46+
["class-name", "First"],
47+
["operator", "=>"],
48+
["class-name", "Second"],
2849
["punctuation", ","],
29-
["function", "Third"],
30-
["symbol", "=>"],
31-
["function", "Fourth"]
50+
["class-name", "Third"],
51+
["operator", "=>"],
52+
["class-name", "Fourth"]
3253
]],
3354

34-
["keyword", "Jolie"],
35-
["operator", ":"],
55+
["property", "Jolie"],
56+
["punctuation", ":"],
3657
["string", "\"logger.ol\""],
3758
["keyword", "in"],
38-
["function", "LoggerService"],
59+
["class-name", "LoggerService"],
3960

40-
"\r\nlog",
41-
["symbol", "@"],
42-
["function", "LoggerService"],
43-
"( ",
61+
["function", "log"],
62+
["operator", "@"],
63+
["class-name", "LoggerService"],
64+
["punctuation", "("],
4465
["keyword", "new"],
45-
" )()",
46-
["symbol", ";"],
66+
["punctuation", ")"],
67+
["punctuation", "("],
68+
["punctuation", ")"],
69+
["punctuation", ";"],
4770

48-
"\r\nprintln ",
49-
["symbol", "@"],
50-
["function", "Console"],
51-
"( ",
71+
["function", "println"],
72+
["operator", "@"],
73+
["class-name", "Console"],
74+
["punctuation", "("],
5275
["string", "\"none\""],
53-
" )()"
76+
["punctuation", ")"],
77+
["punctuation", "("],
78+
["punctuation", ")"],
79+
80+
["keyword", "outputPort"],
81+
["class-name", "OutputPort3"],
82+
["punctuation", "{"],
83+
84+
["property", "location"],
85+
["punctuation", ":"],
86+
["string", "\"socket://localhost:9002/\""],
87+
88+
["property", "protocol"],
89+
["punctuation", ":"],
90+
" sodep\r\n ",
91+
92+
["property", "interfaces"],
93+
["punctuation", ":"],
94+
" Interface3\r\n",
95+
96+
["punctuation", "}"],
97+
98+
["keyword", "interface"],
99+
" MyInterface ",
100+
["punctuation", "{"],
101+
102+
["property", "OneWay"],
103+
["punctuation", ":"],
104+
105+
["function", "myOW"],
106+
["punctuation", "("],
107+
["builtin", "string"],
108+
["punctuation", ")"],
109+
110+
["property", "RequestResponse"],
111+
["punctuation", ":"],
112+
113+
["function", "myRR"],
114+
["punctuation", "("],
115+
["builtin", "string"],
116+
["punctuation", ")"],
117+
["punctuation", "("],
118+
["builtin", "string"],
119+
["punctuation", ")"],
120+
121+
["punctuation", "}"],
122+
123+
["keyword", "private"],
124+
["keyword", "service"],
125+
["class-name", "MainService"],
126+
["punctuation", "{"],
127+
128+
["keyword", "embed"],
129+
["class-name", "ConfigurationService"],
130+
["punctuation", "("],
131+
["punctuation", ")"],
132+
["keyword", "as"],
133+
["class-name", "Conf"],
134+
135+
["keyword", "main"],
136+
["punctuation", "{"],
137+
138+
["function", "getDBConn"],
139+
["operator", "@"],
140+
["class-name", "Conf"],
141+
["punctuation", "("],
142+
["punctuation", ")"],
143+
["punctuation", "("],
144+
" res ",
145+
["punctuation", ")"],
146+
147+
["punctuation", "}"],
148+
149+
["punctuation", "}"]
54150
]
55151

56152
----------------------------------------------------

0 commit comments

Comments
 (0)