From fc1404985abb95d5bc33a0eba518724f1c3c252e Mon Sep 17 00:00:00 2001 From: Agustin Mendez Date: Thu, 7 Sep 2017 11:28:46 -0300 Subject: [PATCH] Add DataWeave language (#3804) * Add DataWeave language * Add Licence * Update to latest DataWeave revision --- .gitmodules | 3 ++ grammars.yml | 2 ++ lib/linguist/languages.yml | 12 +++++-- samples/DataWeave/customInterpolator.dwl | 12 +++++++ samples/DataWeave/directives.dwl | 9 +++++ samples/DataWeave/functions.dwl | 27 ++++++++++++++ samples/DataWeave/literals.dwl | 36 +++++++++++++++++++ samples/DataWeave/match.dwl | 33 +++++++++++++++++ vendor/README.md | 1 + vendor/grammars/data-weave-tmLanguage | 1 + .../grammar/data-weave-tmLanguage.txt | 27 ++++++++++++++ 11 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 samples/DataWeave/customInterpolator.dwl create mode 100644 samples/DataWeave/directives.dwl create mode 100644 samples/DataWeave/functions.dwl create mode 100644 samples/DataWeave/literals.dwl create mode 100644 samples/DataWeave/match.dwl create mode 160000 vendor/grammars/data-weave-tmLanguage create mode 100644 vendor/licenses/grammar/data-weave-tmLanguage.txt diff --git a/.gitmodules b/.gitmodules index e0830966..1eb6f1ef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -869,6 +869,9 @@ [submodule "vendor/grammars/sublime-nearley"] path = vendor/grammars/sublime-nearley url = https://github.com/Hardmath123/sublime-nearley +[submodule "vendor/grammars/data-weave-tmLanguage"] + path = vendor/grammars/data-weave-tmLanguage + url = https://github.com/mulesoft-labs/data-weave-tmLanguage [submodule "vendor/grammars/squirrel-language"] path = vendor/grammars/squirrel-language url = https://github.com/mathewmariani/squirrel-language diff --git a/grammars.yml b/grammars.yml index 50b64cb2..7adc070d 100755 --- a/grammars.yml +++ b/grammars.yml @@ -252,6 +252,8 @@ vendor/grammars/d.tmbundle: vendor/grammars/dartlang: - source.dart - source.yaml-ext +vendor/grammars/data-weave-tmLanguage: +- source.data-weave vendor/grammars/desktop.tmbundle: - source.desktop vendor/grammars/diff.tmbundle: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 2b333a74..11bcf11b 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -988,6 +988,14 @@ Dart: codemirror_mode: dart codemirror_mime_type: application/dart language_id: 87 +DataWeave: + type: programming + color: "#003a52" + extensions: + - ".dwl" + ace_mode: text + tm_scope: source.data-weave + language_id: 974514097 Diff: type: data extensions: @@ -1488,8 +1496,8 @@ Gerber Image: - ".gtp" - ".gts" interpreters: - - "gerbv" - - "gerbview" + - gerbv + - gerbview tm_scope: source.gerber ace_mode: text language_id: 404627610 diff --git a/samples/DataWeave/customInterpolator.dwl b/samples/DataWeave/customInterpolator.dwl new file mode 100644 index 00000000..746e176c --- /dev/null +++ b/samples/DataWeave/customInterpolator.dwl @@ -0,0 +1,12 @@ +fun SQL(literals, parts) = '' +--- +[ + SQL `SELECT * FROM table WHERE id = $(1) AND name = $('a')`, + SQL `$('p')`, + SQL `$('a')$('b')`, + SQL `$('a')---$('b')`, + SQL `---$('a')---$('b')---`, + SQL `$('p')bbb`, + SQL `aaa$('p')`, + SQL `aaa$('p')bbb` +] \ No newline at end of file diff --git a/samples/DataWeave/directives.dwl b/samples/DataWeave/directives.dwl new file mode 100644 index 00000000..a2456376 --- /dev/null +++ b/samples/DataWeave/directives.dwl @@ -0,0 +1,9 @@ +%dw 2.0 +var number = 1234 +fun foo(func,name="Mariano") = func(name) +input payload application/test arg="value" +output application/json +--- +{ + foo: "bar" +} \ No newline at end of file diff --git a/samples/DataWeave/functions.dwl b/samples/DataWeave/functions.dwl new file mode 100644 index 00000000..88957333 --- /dev/null +++ b/samples/DataWeave/functions.dwl @@ -0,0 +1,27 @@ +%dw 2.0 +var x=(param1, param2) -> { "$param1": param2 } +var y=(param1, param2 = "c") -> { "$param1": param2 } +var toUser = (user) -> { name: user.name, lastName: user.lastName } +fun z(param1, param2) = { "$param1": param2 } +var a = { name: "Mariano" , toUser: ((param1, param2) -> { "$param1": param2 }) } +var applyFirst = (array, func) -> (func(array[0]) ++ array[1 to -1]) + +var nested = (array, func) -> (a) -> (b) -> (c) -> array map func(a ++ b ++ c) + + +fun f2(a1, a2) = "" +fun f3(a1:String, a2:Number):String = a1 +fun f4(a1:String, a2:(a:Number) -> Number):String = a1 +--- +result: { + a: x("a", "b"), + b: y("a"), + c: y("a", "b"), + users: { (in1 map ((user) -> { user: (toUser(user) ++ user) })) }, + d: z("a", "b"), + e: a.toUser("name","Mariano"), + f: a.toUser("name","Mariano").name, + f: applyFirst("mariano", (s) -> upper(s) ), + g: [] map (s) -> upper(s), + h: 1 f2 2 +} diff --git a/samples/DataWeave/literals.dwl b/samples/DataWeave/literals.dwl new file mode 100644 index 00000000..ac02dbd4 --- /dev/null +++ b/samples/DataWeave/literals.dwl @@ -0,0 +1,36 @@ +%dw 2.0 +--- +{ + "boolean":{ + "true" : true, + "false": false + }, + "Number": { + "int": 123, + "decimal": 123.23 + }, + "string": { + "singleQuote" : 'A String', + "doubleQuote" : "A String" + }, + "regex": /foo/, + "date": { + a: |2003-10-01|, + b: |2005-045|, + c: |2003-W14-3|, + d: |23:57:59|, + e: |23:57:30.700|, + f: |23:50:30Z|, + g: |+13:00|, + h: |Z|, + i: |-02:00|, + j: |2005-06-02T15:10:16|, + k: |2005-06-02T15:10:16Z|, + l: |2005-06-02T15:10:16+03:00|, + m: |P12Y7M11D|, + n: |P12Y5M|, + o: |P45DT9H20M8S|, + p: |PT9H20M8S| + } +} + diff --git a/samples/DataWeave/match.dwl b/samples/DataWeave/match.dwl new file mode 100644 index 00000000..a831f6a8 --- /dev/null +++ b/samples/DataWeave/match.dwl @@ -0,0 +1,33 @@ +{ + // Regex Pattern Matching (Can be named or unnamed) + a: in0.phones map $ match { + case matches /\+(\d+)\s\((\d+)\)\s(\d+\-\d+)/ -> { country: $[0], area: $[1], number: $[2] } + case matches /\((\d+)\)\s(\d+\-\d+)/ -> { area: $[1], number: $[2] } + case phone matches /\((\d+)\)\s(\d+\-\d+)/ -> { area: phone[1], number: phone[2] } + }, + // Type Pattern Matching (Can be named or unnamed) + b: in0.object match { + case is Object -> { object: $ } + case is Number -> { number: $ } + // This is how you name variables if needed + case y is Boolean -> { boolean: y } + }, + // Literal Pattern Matching (Can be named or unnamed) + c: in0.value match { + case "Emiliano" -> { string: $ } + case 123 -> { number: $ } + // This is how you name variables if needed + case value: "Mariano" -> { name: value } + }, + // Boolean Expression Pattern Matching (Always named) + d: in0.value match { + case x if x > 30 -> { biggerThan30: x } + case x if x == 9 -> { nine: x } + }, + // Default matches + e: in0.value match { + case "Emiliano" -> "string" + case 3.14 -> number + else -> "1234" + } +} \ No newline at end of file diff --git a/vendor/README.md b/vendor/README.md index 29dbdc95..a9a08f50 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -85,6 +85,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **D:** [textmate/d.tmbundle](https://github.com/textmate/d.tmbundle) - **D-ObjDump:** [nanoant/assembly.tmbundle](https://github.com/nanoant/assembly.tmbundle) - **Dart:** [dart-atom/dartlang](https://github.com/dart-atom/dartlang) +- **DataWeave:** [mulesoft-labs/data-weave-tmLanguage](https://github.com/mulesoft-labs/data-weave-tmLanguage) - **desktop:** [Mailaender/desktop.tmbundle](https://github.com/Mailaender/desktop.tmbundle) - **Diff:** [textmate/diff.tmbundle](https://github.com/textmate/diff.tmbundle) - **DM:** [PJB3005/atomic-dreams](https://github.com/PJB3005/atomic-dreams) diff --git a/vendor/grammars/data-weave-tmLanguage b/vendor/grammars/data-weave-tmLanguage new file mode 160000 index 00000000..c20cee1c --- /dev/null +++ b/vendor/grammars/data-weave-tmLanguage @@ -0,0 +1 @@ +Subproject commit c20cee1c62664eef2aee68c4636e1bd1868620a9 diff --git a/vendor/licenses/grammar/data-weave-tmLanguage.txt b/vendor/licenses/grammar/data-weave-tmLanguage.txt new file mode 100644 index 00000000..5bec247e --- /dev/null +++ b/vendor/licenses/grammar/data-weave-tmLanguage.txt @@ -0,0 +1,27 @@ +--- +type: grammar +name: data-weave-tmLanguage +license: mit +--- +Copyright (c) Mulesoft inc +All rights reserved. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file