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

DataWeave: Adding support for DataWeave language #2659

Merged
merged 14 commits into from Nov 27, 2020
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -290,6 +290,10 @@
"require": "clike",
"owner": "Golmote"
},
"dataweave": {
"title": "DataWeave",
"owner": "machaval"
},
"dax": {
"title": "DAX",
"owner": "peterbud"
Expand Down
45 changes: 45 additions & 0 deletions components/prism-dataweave.js
@@ -0,0 +1,45 @@
(function (Prism) {
Prism.languages.dataweave = {
'url': {
pattern:/\b[A-Za-z]+:\/\/[\w/:.?=&-]+|\burn:[\w:.?=&-]+/
},
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
'property': {
pattern: /(?:\w+#)?(?:"(?:\\.|[^\\"\r\n])*"|\w+)(?=\s*[:@])/,
greedy: true
},
'string': {
pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
greedy: true
},
'mime-type': {
pattern: /\b(?:text|audio|video|application|multipart|image)\/[\w+-]+/
},
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
'date': {
pattern: /\|[\w\-:+-]+\|/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
greedy: true
},
'comment': [
{
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
lookbehind: true,
greedy: true
},
{
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true
}
],
'regex': {
pattern: /\/(?:[^\\\/\r\n]|\\[^\r\n])+\//,
greedy: true
},
'function': /\b[A-Za-z_]\w*(?=\s*\()/i,
'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
'punctuation': /[{}[\];(),.:@]/,
'operator': /<<|>>|->|[<>~=]=?|!=|--?-?|\+\+?|\!|\?/,
'boolean': /\b(?:true|false)\b/,
'keyword': /\b(?:match|input|output|ns|type|update|null|if|else|using|unless|at|is|as|case|do|fun|var|not|and|or)\b/
};

}(Prism));
1 change: 1 addition & 0 deletions components/prism-dataweave.min.js

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

39 changes: 39 additions & 0 deletions examples/prism-dataweave.html
@@ -0,0 +1,39 @@
<h2>Full example</h2>
<pre><code>
%dw 2.0
input payalod application/json
ns ns0 http://localhost.com
var a = 123
type T = String
fun test(a: Number) = a + 123
output application/json
---
{
// This is a comment
/**
This is a multiline comment
**/
name: payload.name,
string: "this",
'another string': true,
"regex": /123/,
fc: test(1),
"dates": |12-12-2020-T12:00:00|,
number: 123,
"null": null,

a: {} match {
case is {} -> foo.name
},
b: {} update {
case name at .user.name -> "123"
},
stringMultiLine: "This is a multiline
string
",
a: if( !true > 2) a else 2,
b: do {
{}
}
}
</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -53,6 +53,7 @@
"conc": "Concurnas",
"csp": "Content-Security-Policy",
"css-extras": "CSS Extras",
"dataweave": "DataWeave",
"dax": "DAX",
"django": "Django/Jinja2",
"jinja2": "Django/Jinja2",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

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

12 changes: 12 additions & 0 deletions tests/languages/dataweave/boolean_feature.test
@@ -0,0 +1,12 @@
true
false

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

[
["boolean", "true"],
["boolean", "false"]
]

----------------------------------------------------
Check for boolean
17 changes: 17 additions & 0 deletions tests/languages/dataweave/comment_feature.test
@@ -0,0 +1,17 @@
// Line comment ""
/* Block comment */
/**
* MultiLine Comment
**/
/* "" */

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

[
["comment", "// Line comment \"\"\t"],
["comment", "/* Block comment */"],
["comment", "/**\r\n\t* MultiLine Comment\r\n\t**/"],
["comment", "/* \"\" */"]
]
----------------------------------------------------
Check for comments
27 changes: 27 additions & 0 deletions tests/languages/dataweave/dates_feature.test
@@ -0,0 +1,27 @@
|12-12-2001-T12:00:00|
|12-12-2001-T12:00:00+03:00|
|12-12-2001-T12:00:00Z|
|12-12-2001|
|12:00:00|
|12:00:00Z|
|12:00:00-03:00|
|P1D|
|P1Y1D|
|P1Y1D2H3M5S|

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

[
["date", "|12-12-2001-T12:00:00|"],
["date", "|12-12-2001-T12:00:00+03:00|"],
["date", "|12-12-2001-T12:00:00Z|"],
["date", "|12-12-2001|"],
["date", "|12:00:00|"],
["date", "|12:00:00Z|"],
["date", "|12:00:00-03:00|"],
["date", "|P1D|"],
["date", "|P1Y1D|"],
["date", "|P1Y1D2H3M5S|"]
]
----------------------------------------------------
Check for date
28 changes: 28 additions & 0 deletions tests/languages/dataweave/functions_feature.test
@@ -0,0 +1,28 @@
myfunction(a, b,123)
payload.myFunction(1,2,3)

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

[
["function", "myfunction"],
["punctuation", "("],
"a",
["punctuation", ","],
" b",
["punctuation", ","],
["number", "123"],
["punctuation", ")"],

"\npayload",
["punctuation", "."],
["function", "myFunction"],
["punctuation", "("],
["number", "1"],
["punctuation", ","],
["number", "2"],
["punctuation", ","],
["number", "3"],
["punctuation", ")"]
]
----------------------------------------------------
Check for functions
124 changes: 124 additions & 0 deletions tests/languages/dataweave/keywords_feature.test
@@ -0,0 +1,124 @@
%dw 2.0
input payalod application/json
ns ns0 http://localhost.com
var a = 123
type T = String
fun test(a: Number) = a + 123
output application/json
---
{} match {
case a is String -> x as String
}
update {
case a at .name ->
}
if(true or false and not true) do {

}
else
payload match {
case a is String -> x as String
}

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

[
"%dw ",
["number", "2.0"],

["keyword", "input"],
" payalod ",
["mime-type", "application/json"],

["keyword", "ns"],
" ns0 ",
["url", "http://localhost.com"],

["keyword", "var"],
" a ",
["operator", "="],
["number", "123"],

["keyword", "type"],
" T ",
["operator", "="],
" String\n",

["keyword", "fun"],
["function", "test"],
["punctuation", "("],
["property", "a"],
["punctuation", ":"],
" Number",
["punctuation", ")"],
["operator", "="],
" a ",
["operator", "+"],
["number", "123"],

["keyword", "output"],
["mime-type", "application/json"],

["operator", "---"],

["punctuation", "{"],
["punctuation", "}"],
["keyword", "match"],
["punctuation", "{"],

["keyword", "case"],
" a ",
["keyword", "is"],
" String ",
["operator", "->"],
" x ",
["keyword", "as"],
" String\n",

["punctuation", "}"],

["keyword", "update"],
["punctuation", "{"],

["keyword", "case"],
" a ",
["keyword", "at"],
["punctuation", "."],
"name ",
["operator", "->"],

["punctuation", "}"],

["function", "if"],
["punctuation", "("],
["boolean", "true"],
["keyword", "or"],
["boolean", "false"],
["keyword", "and"],
["keyword", "not"],
["boolean", "true"],
["punctuation", ")"],
["keyword", "do"],
["punctuation", "{"],

["punctuation", "}"],

["keyword", "else"],

" \npayload ",
["keyword", "match"],
["punctuation", "{"],

["keyword", "case"],
" a ",
["keyword", "is"],
" String ",
["operator", "->"],
" x ",
["keyword", "as"],
" String\n",

["punctuation", "}"]
]
----------------------------------------------------
Check for keywords
9 changes: 9 additions & 0 deletions tests/languages/dataweave/null_feature.test
@@ -0,0 +1,9 @@
null

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

[
["keyword", "null"]
]
----------------------------------------------------
Check for null
25 changes: 25 additions & 0 deletions tests/languages/dataweave/number_feature.test
@@ -0,0 +1,25 @@
0
123
3.14159
5.0e8
0.2E+2
47e-5
-1.23
-2.34E33
-4.34E-33

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

[
["number", "0"],
["number", "123"],
["number", "3.14159"],
["number", "5.0e8"],
["number", "0.2E+2"],
["number", "47e-5"],
["number", "-1.23"],
["number", "-2.34E33"],
["number", "-4.34E-33"]
]
----------------------------------------------------
Check for number