-1

Erlang syntax highlighting error (with potential fix!)

Anselm Eickhoff 12 year бұрын 0

In Erlang, fun is not only a keyword for lambdas, but can also be used in -spec macro directives.


Example:

-spec for_house_of(Type :: row|column|box,
  Pos :: integer(),
  AccStart :: X,
  Fun :: fun((Pos :: integer(), Acc::X) -> (Y))
) -> [Y].

This breaks syntax highlighting afterwards though (because Sublime text thinks we're in an anonymous function that has never been ended).

(multiline or single line -spec doesn't matter).


It can be fixed by ignoring the fun keyword if it follows two colons in this case:


Erlang.tmLanguage, line 699


Before

<string>\b(fun)\b</string>

After

<string>\b^(?!.*::).*$\b(fun)\b</string>

This is only a hack though, because the parameter spec could also be unnamed:


-spec for_house_of(Type :: row|column|box,
  integer(),
  X,
  fun((integer(), X) -> (Y))
) -> [Y].