Created
February 19, 2013 17:09
-
-
Save ferd/4987814 to your computer and use it in GitHub Desktop.
Parse transform to support -spec and behaviour_info in Erlang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(behaviour_parse). | |
| -export([parse_transform/2]). | |
| -define(CUTOFF, "2.15"). % R15B | |
| parse_transform(AST, _Opts) -> | |
| [Vsn] = [X || {kernel,_,X} <- application:which_applications()], | |
| walk_ast(if Vsn >= ?CUTOFF -> spec; | |
| Vsn < ?CUTOFF -> func | |
| end, | |
| AST). | |
| walk_ast(_, []) -> | |
| []; | |
| walk_ast(func, [{attribute, _Ln, callback, _}|T]) -> | |
| walk_ast(func, T); | |
| walk_ast(spec, [{attribute, Ln, export, List}|T]) -> | |
| [{attribute, Ln, export, List -- [{behaviour_info,1},{behavior_info,1}]} | |
| | walk_ast(spec, T)]; | |
| walk_ast(spec, [{function, _Ln, behaviour_info,1,_Clauses}|T]) -> | |
| walk_ast(spec, T); | |
| walk_ast(spec, [{function, _Ln, behavior_info,1,_Clauses}|T]) -> | |
| walk_ast(spec, T); | |
| walk_ast(Type, [H|T]) -> | |
| [H|walk_ast(Type, T)]. |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will obviously break with versions of the kernel < 2.10, but that should be RB09 and prior, which I figure is fairly rare in the wild.