Skip to content

Commit 0803525

Browse files
authored
Added support for DataWeave language (#2659)
1 parent 2457440 commit 0803525

18 files changed

+502
-2
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@
290290
"require": "clike",
291291
"owner": "Golmote"
292292
},
293+
"dataweave": {
294+
"title": "DataWeave",
295+
"owner": "machaval"
296+
},
293297
"dax": {
294298
"title": "DAX",
295299
"owner": "peterbud"

components/prism-dataweave.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
(function (Prism) {
2+
Prism.languages.dataweave = {
3+
'url': /\b[A-Za-z]+:\/\/[\w/:.?=&-]+|\burn:[\w:.?=&-]+/,
4+
'property': {
5+
pattern: /(?:\w+#)?(?:"(?:\\.|[^\\"\r\n])*"|\w+)(?=\s*[:@])/,
6+
greedy: true
7+
},
8+
'string': {
9+
pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
10+
greedy: true
11+
},
12+
'mime-type': /\b(?:text|audio|video|application|multipart|image)\/[\w+-]+/,
13+
'date': {
14+
pattern: /\|[\w:+-]+\|/,
15+
greedy: true
16+
},
17+
'comment': [
18+
{
19+
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
20+
lookbehind: true,
21+
greedy: true
22+
},
23+
{
24+
pattern: /(^|[^\\:])\/\/.*/,
25+
lookbehind: true,
26+
greedy: true
27+
}
28+
],
29+
'regex': {
30+
pattern: /\/(?:[^\\\/\r\n]|\\[^\r\n])+\//,
31+
greedy: true
32+
},
33+
'function': /\b[A-Za-z_]\w*(?=\s*\()/i,
34+
'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
35+
'punctuation': /[{}[\];(),.:@]/,
36+
'operator': /<<|>>|->|[<>~=]=?|!=|--?-?|\+\+?|\!|\?/,
37+
'boolean': /\b(?:true|false)\b/,
38+
'keyword': /\b(?:match|input|output|ns|type|update|null|if|else|using|unless|at|is|as|case|do|fun|var|not|and|or)\b/
39+
};
40+
41+
}(Prism));

components/prism-dataweave.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-dataweave.html

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2>Full example</h2>
2+
<pre><code>
3+
%dw 2.0
4+
input payalod application/json
5+
ns ns0 http://localhost.com
6+
var a = 123
7+
type T = String
8+
fun test(a: Number) = a + 123
9+
output application/json
10+
---
11+
{
12+
// This is a comment
13+
/**
14+
This is a multiline comment
15+
**/
16+
name: payload.name,
17+
string: "this",
18+
'another string': true,
19+
"regex": /123/,
20+
fc: test(1),
21+
"dates": |12-12-2020-T12:00:00|,
22+
number: 123,
23+
"null": null,
24+
25+
a: {} match {
26+
case is {} -> foo.name
27+
},
28+
b: {} update {
29+
case name at .user.name -> "123"
30+
},
31+
stringMultiLine: "This is a multiline
32+
string
33+
",
34+
a: if( !true > 2) a else 2,
35+
b: do {
36+
{}
37+
}
38+
}
39+
</code></pre>

plugins/show-language/prism-show-language.js

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"conc": "Concurnas",
5454
"csp": "Content-Security-Policy",
5555
"css-extras": "CSS Extras",
56+
"dataweave": "DataWeave",
5657
"dax": "DAX",
5758
"django": "Django/Jinja2",
5859
"jinja2": "Django/Jinja2",

plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
10+
11+
----------------------------------------------------
12+
Check for boolean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Line comment ""
2+
/* Block comment */
3+
/**
4+
* MultiLine Comment
5+
**/
6+
/* "" */
7+
8+
----------------------------------------------------
9+
10+
[
11+
["comment", "// Line comment \"\"\t"],
12+
["comment", "/* Block comment */"],
13+
["comment", "/**\r\n\t* MultiLine Comment\r\n\t**/"],
14+
["comment", "/* \"\" */"]
15+
]
16+
----------------------------------------------------
17+
Check for comments
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
|12-12-2001-T12:00:00|
2+
|12-12-2001-T12:00:00+03:00|
3+
|12-12-2001-T12:00:00Z|
4+
|12-12-2001|
5+
|12:00:00|
6+
|12:00:00Z|
7+
|12:00:00-03:00|
8+
|P1D|
9+
|P1Y1D|
10+
|P1Y1D2H3M5S|
11+
12+
----------------------------------------------------
13+
14+
[
15+
["date", "|12-12-2001-T12:00:00|"],
16+
["date", "|12-12-2001-T12:00:00+03:00|"],
17+
["date", "|12-12-2001-T12:00:00Z|"],
18+
["date", "|12-12-2001|"],
19+
["date", "|12:00:00|"],
20+
["date", "|12:00:00Z|"],
21+
["date", "|12:00:00-03:00|"],
22+
["date", "|P1D|"],
23+
["date", "|P1Y1D|"],
24+
["date", "|P1Y1D2H3M5S|"]
25+
]
26+
----------------------------------------------------
27+
Check for date
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
myfunction(a, b,123)
2+
payload.myFunction(1,2,3)
3+
4+
----------------------------------------------------
5+
6+
[
7+
["function", "myfunction"],
8+
["punctuation", "("],
9+
"a",
10+
["punctuation", ","],
11+
" b",
12+
["punctuation", ","],
13+
["number", "123"],
14+
["punctuation", ")"],
15+
16+
"\npayload",
17+
["punctuation", "."],
18+
["function", "myFunction"],
19+
["punctuation", "("],
20+
["number", "1"],
21+
["punctuation", ","],
22+
["number", "2"],
23+
["punctuation", ","],
24+
["number", "3"],
25+
["punctuation", ")"]
26+
]
27+
----------------------------------------------------
28+
Check for functions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
%dw 2.0
2+
input payalod application/json
3+
ns ns0 http://localhost.com
4+
var a = 123
5+
type T = String
6+
fun test(a: Number) = a + 123
7+
output application/json
8+
---
9+
{} match {
10+
case a is String -> x as String
11+
}
12+
update {
13+
case a at .name ->
14+
}
15+
if(true or false and not true) do {
16+
17+
}
18+
else
19+
payload match {
20+
case a is String -> x as String
21+
}
22+
23+
----------------------------------------------------
24+
25+
[
26+
"%dw ",
27+
["number", "2.0"],
28+
29+
["keyword", "input"],
30+
" payalod ",
31+
["mime-type", "application/json"],
32+
33+
["keyword", "ns"],
34+
" ns0 ",
35+
["url", "http://localhost.com"],
36+
37+
["keyword", "var"],
38+
" a ",
39+
["operator", "="],
40+
["number", "123"],
41+
42+
["keyword", "type"],
43+
" T ",
44+
["operator", "="],
45+
" String\n",
46+
47+
["keyword", "fun"],
48+
["function", "test"],
49+
["punctuation", "("],
50+
["property", "a"],
51+
["punctuation", ":"],
52+
" Number",
53+
["punctuation", ")"],
54+
["operator", "="],
55+
" a ",
56+
["operator", "+"],
57+
["number", "123"],
58+
59+
["keyword", "output"],
60+
["mime-type", "application/json"],
61+
62+
["operator", "---"],
63+
64+
["punctuation", "{"],
65+
["punctuation", "}"],
66+
["keyword", "match"],
67+
["punctuation", "{"],
68+
69+
["keyword", "case"],
70+
" a ",
71+
["keyword", "is"],
72+
" String ",
73+
["operator", "->"],
74+
" x ",
75+
["keyword", "as"],
76+
" String\n",
77+
78+
["punctuation", "}"],
79+
80+
["keyword", "update"],
81+
["punctuation", "{"],
82+
83+
["keyword", "case"],
84+
" a ",
85+
["keyword", "at"],
86+
["punctuation", "."],
87+
"name ",
88+
["operator", "->"],
89+
90+
["punctuation", "}"],
91+
92+
["function", "if"],
93+
["punctuation", "("],
94+
["boolean", "true"],
95+
["keyword", "or"],
96+
["boolean", "false"],
97+
["keyword", "and"],
98+
["keyword", "not"],
99+
["boolean", "true"],
100+
["punctuation", ")"],
101+
["keyword", "do"],
102+
["punctuation", "{"],
103+
104+
["punctuation", "}"],
105+
106+
["keyword", "else"],
107+
108+
" \npayload ",
109+
["keyword", "match"],
110+
["punctuation", "{"],
111+
112+
["keyword", "case"],
113+
" a ",
114+
["keyword", "is"],
115+
" String ",
116+
["operator", "->"],
117+
" x ",
118+
["keyword", "as"],
119+
" String\n",
120+
121+
["punctuation", "}"]
122+
]
123+
----------------------------------------------------
124+
Check for keywords
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
null
2+
3+
----------------------------------------------------
4+
5+
[
6+
["keyword", "null"]
7+
]
8+
----------------------------------------------------
9+
Check for null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
0
2+
123
3+
3.14159
4+
5.0e8
5+
0.2E+2
6+
47e-5
7+
-1.23
8+
-2.34E33
9+
-4.34E-33
10+
11+
----------------------------------------------------
12+
13+
[
14+
["number", "0"],
15+
["number", "123"],
16+
["number", "3.14159"],
17+
["number", "5.0e8"],
18+
["number", "0.2E+2"],
19+
["number", "47e-5"],
20+
["number", "-1.23"],
21+
["number", "-2.34E33"],
22+
["number", "-4.34E-33"]
23+
]
24+
----------------------------------------------------
25+
Check for number

0 commit comments

Comments
 (0)