diff --git a/.travis.yml b/.travis.yml index 5a4fb5d..4dd191c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,3 +70,6 @@ before_install: # Elm - curl -L -o /tmp/elm-format.tgz https://github.com/avh4/elm-format/releases/download/0.2.0-alpha/elm-format-0.2.0-alpha-mac-x64.tgz - tar xvzf /tmp/elm-format.tgz -C /usr/local/bin + # OCaml + - brew install ocaml opam + - opam install ocp-indent diff --git a/CHANGELOG.md b/CHANGELOG.md index a4f84f0..8dcda17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # dev +- Add [ocp-indent](https://github.com/OCamlPro/ocp-indent) beautifier for the OCaml language. - Add [elm-format](https://github.com/avh4/elm-format) beautifier for the Elm language. - Add [clang-format](http://clang.llvm.org/docs/ClangFormat.html) beautifier for C/C++/Obj-C languages. - Add [yapf](http://github.com/google/yapf) beautifier for Python. diff --git a/examples/nested-jsbeautifyrc/ocaml/expected/js-pattern.ml b/examples/nested-jsbeautifyrc/ocaml/expected/js-pattern.ml new file mode 100644 index 0000000..8f53819 --- /dev/null +++ b/examples/nested-jsbeautifyrc/ocaml/expected/js-pattern.ml @@ -0,0 +1,51 @@ +let f = function + | _ -> 0 +;; + +let f x = match x with + | _ -> 0 +;; + +let f = + function + | _ -> 0 +;; + +let f x = + match x with + | _ -> 0 +;; + +let f x = + begin match x with + | _ -> 0 + end +;; + +let check_price t = function + | { Exec. + trade_at_settlement = (None | Some false); + } -> () + +let check_price t = function + | simpler -> () + | other -> () + +(* Sometimes we like to write big alternations like this, in which case the + comment should typically align with the following clause. *) +let 0 = + match x with + | A + (* a *) + -> a +let 0 = + match x with + A + (* a *) + -> a + +let _ = + a + || match a with + | a -> true + | b -> false diff --git a/examples/nested-jsbeautifyrc/ocaml/original/js-pattern.ml b/examples/nested-jsbeautifyrc/ocaml/original/js-pattern.ml new file mode 100644 index 0000000..c75d707 --- /dev/null +++ b/examples/nested-jsbeautifyrc/ocaml/original/js-pattern.ml @@ -0,0 +1,51 @@ +let f = function + | _ -> 0 +;; + +let f x = match x with + | _ -> 0 +;; + +let f = + function + | _ -> 0 +;; + +let f x = + match x with + | _ -> 0 +;; + +let f x = + begin match x with + | _ -> 0 + end +;; + +let check_price t = function + | { Exec. + trade_at_settlement = (None | Some false); + } -> () + +let check_price t = function + | simpler -> () + | other -> () + +(* Sometimes we like to write big alternations like this, in which case the + comment should typically align with the following clause. *) +let 0 = + match x with + | A + (* a *) + -> a +let 0 = + match x with + A + (* a *) + -> a + +let _ = + a + || match a with + | a -> true + | b -> false diff --git a/package.json b/package.json index cfbcb21..862f479 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,10 @@ { "name": "Dheepak Krishnamurthy", "url": "https://github.com/kdheepak89" + }, + { + "name": "Frederic Delbos", + "url": "https://github.com/fdelbos" } ], "engines": { diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 1021543..81f1289 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -48,6 +48,7 @@ module.exports = class Beautifiers extends EventEmitter 'fortran-beautifier' 'js-beautify' 'jscs' + 'ocp-indent' 'perltidy' 'php-cs-fixer' 'phpcbf' diff --git a/src/beautifiers/ocp-indent.coffee b/src/beautifiers/ocp-indent.coffee new file mode 100644 index 0000000..eb09e68 --- /dev/null +++ b/src/beautifiers/ocp-indent.coffee @@ -0,0 +1,18 @@ +### +Requires https://github.com/OCamlPro/ocp-indent +### + +"use strict" +Beautifier = require('./beautifier') + +module.exports = class OCPIndent extends Beautifier + name: "ocp-indent" + + options: { + OCaml: true + } + + beautify: (text, language, options) -> + @run("ocp-indent", [ + @tempFile("input", text) + ]) diff --git a/src/languages/index.coffee b/src/languages/index.coffee index b6980eb..afd2dad 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -43,6 +43,7 @@ module.exports = class Languages 'marko' "mustache" "objective-c" + "ocaml" "pawn" "perl" "php" diff --git a/src/languages/ocaml.coffee b/src/languages/ocaml.coffee new file mode 100644 index 0000000..7e62e72 --- /dev/null +++ b/src/languages/ocaml.coffee @@ -0,0 +1,22 @@ +module.exports = { + + name: "OCaml" + namespace: "ocaml" + + ### + Supported Grammars + ### + grammars: [ + "OCaml" + ] + + ### + Supported extensions + ### + extensions: [ + "ml" + ] + + options: [] + +}