Skip to content
This repository

Syntax checker for Erlang

branch: master
README.md

Build Status

SyntaxErl

SyntaxErl is a syntax checker tool for Erlang. The syntax checker currently supports erlang source files (.erl), erlang header files (.hrl), erlang configs (.config, .rel, .script, .app, .app.src), and erlang script files (.erl, .escript). Its main purpose is to be used by tools like Emacs's flymake http://www.emacswiki.org/emacs/FlymakeErlang and Vim's syntastic https://github.com/scrooloose/syntastic. SyntaxErl uses the Rebar https://github.com/basho/rebar config file to determine correct deps and libs paths. Some generic compile options are hardcoded, others, project specific, are read from the rebar config file. To make it possible for the syntax checker to work its magic, make sure that your project is compiled first (using the Rebar or something) and all the deps are at their places. Sinan https://github.com/erlware/sinan and Emakefile http://www.erlang.org/doc/man/make.html support is also possible to incorporate. Pull requests are welcome.

Building

Information on building and installing Erlang/OTP can be found here (more info).

Dependencies

To build SyntaxErl you will need a working installation of Erlang, git, and GNU make.

Building SyntaxErl

$ git clone git://github.com/ten0s/syntaxerl.git
$ cd syntaxerl
$ make

After performing the steps above in the current working directory you now have a script called `syntaxerl'. Place this script anywhere in your path.

Usage

Command line

$ syntaxerl
Usage: syntaxerl [-d] filename
Usage: syntaxerl [-h]
Syntax checker for Erlang (0.7.0)

  -d, --debug    Enable debug output
  -h, --help     Show this message

Emacs

Flymake

;;;----------------------------------------
;;; erlang-mode
;;;----------------------------------------

(setq erlang-root-dir "/opt/otp-r15b01/lib/erlang")
(setq load-path (cons (car (file-expand-wildcards (concat erlang-root-dir "/lib/tools-*/emacs"))) load-path))
(setq erlang-electric-commands nil)
(require 'erlang-start)

(add-hook 'erlang-mode-hook
  '(lambda()
     (imenu-add-to-menubar "Imenu")))

; define auto erlang mode for these files/extensions.
(add-to-list 'auto-mode-alist '(".*\\.app\\'" . erlang-mode))
(add-to-list 'auto-mode-alist '(".*app\\.src\\'" . erlang-mode))
(add-to-list 'auto-mode-alist '(".*\\.config\\'" . erlang-mode))
(add-to-list 'auto-mode-alist '(".*\\.rel\\'" . erlang-mode))
(add-to-list 'auto-mode-alist '(".*\\.script\\'" . erlang-mode))
(add-to-list 'auto-mode-alist '(".*\\.escript\\'" . erlang-mode))

; add include directory to default compile path.
(defvar erlang-compile-extra-opts
  '(bin_opt_info debug_info (i . "../include") (i . "../deps") (i . "../../") (i . "../../../deps")))

; define where put beam files.
(setq erlang-compile-outdir "../ebin")

;;;----------------------------------------
;;; flymake
;;;----------------------------------------

(require 'flymake)
(setq flymake-log-level 3)

(defun flymake-compile-script-path (path)
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
    (list path (list local-file))))

(defun flymake-syntaxerl ()
  (flymake-compile-script-path "~/bin/syntaxerl"))

(add-hook 'erlang-mode-hook
  '(lambda()
     (add-to-list 'flymake-allowed-file-name-masks '("\\.erl\\'" flymake-syntaxerl))
     (add-to-list 'flymake-allowed-file-name-masks '("\\.hrl\\'" flymake-syntaxerl))
     (add-to-list 'flymake-allowed-file-name-masks '("\\.app\\'" flymake-syntaxerl))
     (add-to-list 'flymake-allowed-file-name-masks '("\\.app.src\\'" flymake-syntaxerl))
     (add-to-list 'flymake-allowed-file-name-masks '("\\.config\\'" flymake-syntaxerl))
     (add-to-list 'flymake-allowed-file-name-masks '("\\.rel\\'" flymake-syntaxerl))
     (add-to-list 'flymake-allowed-file-name-masks '("\\.script\\'" flymake-syntaxerl))
     (add-to-list 'flymake-allowed-file-name-masks '("\\.escript\\'" flymake-syntaxerl))

     ;; should be the last.
     (flymake-mode 1)
))

Erlang-flymake

Your help is welcome.

Vim

Syntastic

Setup everything as described here. Then add

let g:syntastic_erlang_checkers=['syntaxerl']

to your vimrc.

Thanks locojay for that.

Something went wrong with that request. Please try again.