Skip to content

Commit

Permalink
Added support for DataWeave language (#2659)
Browse files Browse the repository at this point in the history
  • Loading branch information
machaval authored Nov 27, 2020
1 parent 2457440 commit 0803525
Show file tree
Hide file tree
Showing 18 changed files with 502 additions and 2 deletions.
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
41 changes: 41 additions & 0 deletions components/prism-dataweave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(function (Prism) {
Prism.languages.dataweave = {
'url': /\b[A-Za-z]+:\/\/[\w/:.?=&-]+|\burn:[\w:.?=&-]+/,
'property': {
pattern: /(?:\w+#)?(?:"(?:\\.|[^\\"\r\n])*"|\w+)(?=\s*[:@])/,
greedy: true
},
'string': {
pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
greedy: true
},
'mime-type': /\b(?:text|audio|video|application|multipart|image)\/[\w+-]+/,
'date': {
pattern: /\|[\w:+-]+\|/,
greedy: true
},
'comment': [
{
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
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
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
17 changes: 17 additions & 0 deletions tests/languages/dataweave/comment_feature.test
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
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
Loading

0 comments on commit 0803525

Please sign in to comment.