Macro syntax parsing doesn't work for incomplete Erlang expressions #159

sergeyevstifeev opened this Issue Jan 12, 2013 · 10 comments


None yet
6 participants

Macros in Erlang allow for some pretty ugly code in them, though it can be perfectly legal from the language perspective. However, plugin doesn't handle some tricky cases. For example, the following code is compiled correctly by erlc, but is treated as invalid by the plugin (example partially taken from ).


-export([ foo/0
        , bar/0
        , baz/0

        {baz = 0

-define(LPAREN, ().
-define(RPAREN, )).

-define(ARROW, ->).
-define(COLON, :).
-define(COMMA, ,).

-define(LBRACKET, [).
-define(RBRACKET, ]).

-define(LCURLY, {).
-define(RCURLY, }).

-define(macro2(X, Y), {a,X,b,Y).


-define(increment_rec(Record, Field, Val), Record{Field=Record.Field + (Val)}).

bar() ->
  Foo = #foo{},
  ?increment_rec(Foo#foo, baz, 1).

baz() ->

ignatov commented Jan 12, 2013

For macros support we need improve lexer: at least correctly substitute all macros definitions. It's very time-consuming feature. Guys from AppCode have a lot of performance problems with projects with user defined macroses.

Are you really write production code like this?


@ignatov No, this is just a showcase of course, that's why I said in the description that macros allow for some quite ugly code. Though ?increment_rec macro was taken from a real Erlang project (proprietary). I am trying to use the plugin for it and simply report some issues that I found. Other examples in this case are made up.


ignatov commented Jan 12, 2013

@sergeyevstifeev ?increment_rec is a good candidate to improvement.
I also trained my parser on some open source projects, especially for good macros support. And I was a little bit surprised when I realized that most of macros definitions a pretty simple.
BTW, please report another issues with macros from production code. I'll fix them as well.

@ignatov agree, macros should normally be simple and overusing them in a project is definitely not a good sign.
Sure I'll report issues, I'm really looking forward to using Idea for Erlang programming (mostly because of the great refactoring possibilities in intellij).

This is actual riak/riak_core production code showing that bug:
intellij record bug

I consider this bug to be of high priority if you wish to attract riak / riak_core users into using intellij-erlang


horkhe commented Apr 22, 2013

Joe Armstrong says "do not use marcroses" :)

I wonder how Joe Armstrong would suggest writing the above code (which allows having different versions of a record running on the same platform transparently) without using macroses. I can only think of parse transforms but that's like shooting a mouse with an elephant gun.

There are cases where it is just impossible not to use macros for dynamic syntax generation.


ignatov commented Apr 27, 2013

@diegollarrull initial riak support is available in 7c7b898.

develop7 commented Dec 1, 2014

I'm affected by this issue too, here's relevant code:
screenshot from 2014-12-01 17 38 04
inb4: there is -include("netflow_v9.hrl"). in file below. Is this the case worth handling by plugin or it is me doing it wrong?


deadok22 commented Dec 1, 2014

Hi @develop7,

you're doing it right, it's just the erlang preprocessor is not supported by the plugin yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment