From 8b237edbeec8d4acde7c616cdaa23abad13ac709 Mon Sep 17 00:00:00 2001 From: Frederic Delbos Date: Tue, 19 Apr 2016 23:15:36 +0200 Subject: [PATCH] add ocaml language --- .travis.yml | 3 ++ CHANGELOG.md | 1 + .../ocaml/expected/js-pattern.ml | 51 +++++++++++++++++++ .../ocaml/original/js-pattern.ml | 51 +++++++++++++++++++ package.json | 4 ++ src/beautifiers/index.coffee | 1 + src/beautifiers/ocp-indent.coffee | 18 +++++++ src/languages/index.coffee | 1 + src/languages/ocaml.coffee | 22 ++++++++ 9 files changed, 152 insertions(+) create mode 100644 examples/nested-jsbeautifyrc/ocaml/expected/js-pattern.ml create mode 100644 examples/nested-jsbeautifyrc/ocaml/original/js-pattern.ml create mode 100644 src/beautifiers/ocp-indent.coffee create mode 100644 src/languages/ocaml.coffee 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: [] + +}