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
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@
"require": "clike",
"owner": "Golmote"
},
"dataweave": {
"title": "DataWeave",
"owner": "machaval"
},
"dax": {
"title": "DAX",
"owner": "peterbud"
Expand Down
48 changes: 48 additions & 0 deletions components/prism-dataweave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(function (Prism) {
var keywords = /\b(?:match|input|output|ns|type|update|null|if|else|using|unless|at|is|as|case|do|fun|var|not|and|or)\b/;
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved

Prism.languages.dataweave = {
"url": {
pattern:/(?:[A-z])+:\/\/(?:[A-z0-9/:\.\-_?=&])+|urn:(?:[A-z0-9:\-_\.?=&])+/
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
},
'property': {
pattern: /(?:[A-z0-9_]+#)?(?:"(?:\\.|[^\\"\r\n])*"|(?:[A-z0-9_]+))(?=\s*(?::|@))/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
greedy: true
},
'string': {
pattern: /(["'`])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\])*\1/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
greedy: true
},
"mime-type": {
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
pattern: /(?:text|audio|video|application|multipart|image)\/(?:[A-z-_+0-9])+/
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
},
'regex': {
pattern: /\/[^ ](?:[^\\\/\r\n]|\\[^\r\n])+\//,
greedy: true
},
'date': {
pattern: /\|[^ ](?:[^\\\|\r\n]|\\[^\r\n])+\|/,
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
},
{
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true
}
],
'function': /[a-z_]\w*(?=\s*\()/i,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
'punctuation': /[{}[\];(),.:@]/,
'operator': /[<>~]=?|[!=]=?=?|--?|\+|\!/,
'boolean': /\b(?:true|false)\b/,
'keyword': {
pattern: keywords
}
};

}(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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
true
false

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

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

----------------------------------------------------
Check for boolean
15 changes: 15 additions & 0 deletions tests/languages/dataweave/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Line comment ""
/* Block comment */
/**
* MultiLine Comment
**/

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

[
["comment", "// Line comment \"\"\t"],
["regex", "/* Block comment */"],
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
["comment", "/**\r\n\t* MultiLine Comment\r\n\t**/"]
]
----------------------------------------------------
Check for comment
11 changes: 11 additions & 0 deletions tests/languages/dataweave/dates_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
|12-12-2001-T12:00:00|
|P1D|

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

[
["date", "|12-12-2001-T12:00:00|"],
["date", "|P1D|"]
]
----------------------------------------------------
Check for date
78 changes: 78 additions & 0 deletions tests/languages/dataweave/keywords_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
%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
update
case
if(true) do {

}
else

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

[
"%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", "--"],
["operator", "-"],

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

["keyword", "update"],

["keyword", "case"],

["function", "if"],
["punctuation", "("],
["boolean", "true"],
["punctuation", ")"],
["keyword", "do"],
["punctuation", "{"],

["punctuation", "}"],
["keyword", "else"]
]
----------------------------------------------------
Check for keywords
9 changes: 9 additions & 0 deletions tests/languages/dataweave/null_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
null

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

[
["keyword", "null"]
]
----------------------------------------------------
Check for null
25 changes: 25 additions & 0 deletions tests/languages/dataweave/number_feature.test
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions tests/languages/dataweave/property_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
a: 123,
"My Name": true,
t#test : true,
"test" @(a: true): 2,
test#"test" @(a: true): 3
}

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

[
["punctuation", "{"],

["property", "a"],
["punctuation", ":"],
["number", "123"],
["punctuation", ","],

["property", "\"My Name\""],
["punctuation", ":"],
["boolean", "true"],
["punctuation", ","],

["property", "t#test"],
["punctuation", ":"],
["boolean", "true"],
["punctuation", ","],

["property", "\"test\""],
["punctuation", "@"],
["punctuation", "("],
["property", "a"],
["punctuation", ":"],
["boolean", "true"],
["punctuation", ")"],
["punctuation", ":"],
["number", "2"],
["punctuation", ","],

["property", "test#\"test\""],
["punctuation", "@"],
["punctuation", "("],
["property", "a"],
["punctuation", ":"],
["boolean", "true"],
["punctuation", ")"],
["punctuation", ":"],
["number", "3"],

["punctuation", "}"]
]
----------------------------------------------------
Check for properties
9 changes: 9 additions & 0 deletions tests/languages/dataweave/regex_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/(asd)+?[a-Z]/

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

[
["regex", "/(asd)+?[a-Z]/"]
]
----------------------------------------------------
Check for regex
25 changes: 25 additions & 0 deletions tests/languages/dataweave/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
""
"foo"
"foo\"bar\"baz"
"\u2642\\"
`hello`
'test'
"this is a multiline
test
that
can
be long"

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

[
["string", "\"\""],
["string", "\"foo\""],
["string", "\"foo\\\"bar\\\"baz\""],
["string", "\"\\u2642\\\\\""],
["string", "`hello`"],
["string", "'test'"],
["string", "\"this is a multiline\r\ntest\r\nthat \r\ncan \r\nbe long\""]
]
----------------------------------------------------
Check for strings