aleppo icon indicating copy to clipboard operation
aleppo copied to clipboard

missing support for FUNCTION_NAME, FUNCTION_ARITY etc

Open c-bik opened this issue 7 years ago • 1 comments

FUNCTION_NAME

Mod =

-module(test).
-export([t/0]).
-define(Y, 1).
t(A, B) when A > B ->
    {?Y, ?FUNCTION_NAME}.
> {ok, Tokens, _} = erl_scan:string(Mod, {0,1}).
{ok,
[{'-',{2,1}},{atom,{2,2},module}, {'(',{2,8}}, {atom,{2,9},test}, {')',{2,13}}, {dot,{2,14}},
 {'-',{4,1}}, {atom,{4,2},export}, {'(',{4,8}}, {'[',{4,9}}, {atom,{4,10},t}, {'/',{4,11}},
 {integer,{4,12},0}, {']',{4,13}}, {')',{4,14}}, {dot,{4,15}}, {'-',{6,1}}, {atom,{6,2},define},
 {'(',{6,8}}, {var,{6,9},'Y'}, {',',{6,10}}, {integer,{6,12},1}, {')',{6,13}}, {dot,{6,14}},
 {atom,{8,1},t}, {'(',{8,2}}, {var,{8,3},'A'}, {',',{8,4}}, {var,{8,6},'B'}, {')',{8,7}},
 {'when',{8,9}}, {var,{8,14},'A'}, {'>',{8,16}}, {var,{8,18},'B'}, {'->',{8,20}}, {'{',{10,5}},
 {'?',{10,6}}, {var,{10,7},'Y'}, {',',{10,8}},
 {'?',{10,10}}, {var,{10,11},'FUNCTION_NAME'},
 {'}',{10,24}}, {dot,{10,25}}],
    {12,13}}

> aleppo:process_tokens(Tokens).
** exception error:
 no function clause matching aleppo:legacy_location({var,{10,11},'FUNCTION_NAME'}) 
(.../aleppo/_build/default/lib/aleppo/src/aleppo.erl, line 462)
     in function  aleppo:reverse_and_normalize_token_locations_helper/2 
(.../aleppo/_build/default/lib/aleppo/src/aleppo.erl, line 474)
     in call from aleppo:process_tree/2
(.../aleppo/_build/default/lib/aleppo/src/aleppo.erl, line 81)

FUNCTION_ARITY

Mod =

-module(test).
-export([t/0]).
-define(Y, 1).
t(A, B) when A > B ->
    {?Y, ?FUNCTION_ARITY}.
> {ok, Tokens, _} = erl_scan:string(Mod, {0,1}).
{ok,
[{'-',{2,1}},{atom,{2,2},module}, {'(',{2,8}}, {atom,{2,9},test}, {')',{2,13}}, {dot,{2,14}},
 {'-',{4,1}}, {atom,{4,2},export}, {'(',{4,8}}, {'[',{4,9}}, {atom,{4,10},t}, {'/',{4,11}},
 {integer,{4,12},0}, {']',{4,13}}, {')',{4,14}}, {dot,{4,15}}, {'-',{6,1}}, {atom,{6,2},define},
 {'(',{6,8}}, {var,{6,9},'Y'}, {',',{6,10}}, {integer,{6,12},1}, {')',{6,13}}, {dot,{6,14}},
 {atom,{8,1},t}, {'(',{8,2}}, {var,{8,3},'A'}, {',',{8,4}}, {var,{8,6},'B'}, {')',{8,7}},
 {'when',{8,9}}, {var,{8,14},'A'}, {'>',{8,16}}, {var,{8,18},'B'}, {'->',{8,20}}, {'{',{10,5}},
 {'?',{10,6}}, {var,{10,7},'Y'}, {',',{10,8}},
 {'?',{10,10}}, {var,{10,11},'FUNCTION_ARITY'},
 {'}',{10,24}}, {dot,{10,25}}],
    {12,13}}

> aleppo:process_tokens(Tokens).
** exception error:
 no function clause matching aleppo:legacy_location({var,{10,11},'FUNCTION_ARITY'}) 
(.../aleppo/_build/default/lib/aleppo/src/aleppo.erl, line 462)
     in function  aleppo:reverse_and_normalize_token_locations_helper/2 
(.../aleppo/_build/default/lib/aleppo/src/aleppo.erl, line 474)
     in call from aleppo:process_tree/2
(.../aleppo/_build/default/lib/aleppo/src/aleppo.erl, line 81)

String concatenation

Mod =

-module(test).
-export([t/0]).
-define(Y(_X), "Hello "_X).
t(A, B) when A > B ->
    {?Y("World")}.
> {ok, Tokens, _} = erl_scan:string(Mod, {0,1}).
{ok,
[{'-',{2,1}}, {atom,{2,2},module}, {'(',{2,8}}, {atom,{2,9},test}, {')',{2,13}}, {dot,{2,14}},
 {'-',{4,1}}, {atom,{4,2},export}, {'(',{4,8}}, {'[',{4,9}}, {atom,{4,10},t}, {'/',{4,11}},
 {integer,{4,12},0}, {']',{4,13}}, {')',{4,14}}, {dot,{4,15}}, {'-',{6,1}}, {atom,{6,2},define},
 {'(',{6,8}}, {var,{6,9},'Y'}, {'(',{6,10}}, {var,{6,11},'_X'}, {')',{6,13}}, {',',{6,14}},
 {string,{6,16},"Hello "}, {var,{6,24},'_X'}, {')',{6,26}}, {dot,{6,27}}, {atom,{8,1},t},
 {'(',{8,2}}, {var,{8,3},'A'}, {',',{8,4}}, {var,{8,6},'B'}, {')',{8,7}}, {'when',{8,9}},
 {var,{8,14},'A'}, {'>',{8,16}}, {var,{8,18},'B'}, {'->',{8,20}}, {'{',{10,5}}, {'?',{10,6}},
 {var,{10,7},'Y'}, {'(',{10,8}}, {string,{10,9},"World"}, {')',{10,16}}, {'}',{10,17}},
 {dot,{10,18}}],
    {12,13}}

> {ok, Tokens1} = aleppo:process_tokens(Tokens).
{ok,
[{'-',{2,1}}, {atom,{2,2},module}, {'(',{2,8}}, {atom,{2,9},test}, {')',{2,13}}, {dot,{2,14}},

 {'-',{4,1}}, {atom,{4,2},export}, {'(',{4,8}}, {'[',{4,9}}, {atom,{4,10},t}, {'/',{4,11}},
 {integer,{4,12},0}, {']',{4,13}}, {')',{4,14}}, {dot,{4,15}},

 {atom,{8,1},t}, {'(',{8,2}}, {var,{8,3},'A'}, {',',{8,4}}, {var,{8,6},'B'}, {')',{8,7}},
 {'when',{8,9}}, {var,{8,14},'A'}, {'>',{8,16}}, {var,{8,18},'B'}, {'->',{8,20}},
 {'{',{10,5}}, {'(',{10,7}}, {'fun',{10,7}}, {'(',{10,7}}, {var,{6,11},'_X'}, {')',{10,7}},
 {'->',{10,7}}, {string,{6,16},"Hello "}, {var,{6,24},'_X'}, {'end',{10,7}}, {')',{10,7}},
 {'(',{10,7}}, {string,{10,9},"World"}, {')',{10,7}}, {'}',{10,17}}, {dot,{10,18}}, {eof,0}]}

> erl_parse:parse_form([{'-',{2,1}}, {atom,{2,2},module}, {'(',{2,8}}, {atom,{2,9},test},
                        {')',{2,13}}, {dot,{2,14}}]).
{ok,{attribute,{2,2},module,test}}

> erl_parse:parse_form([{'-',{4,1}}, {atom,{4,2},export}, {'(',{4,8}}, {'[',{4,9}},
                        {atom,{4,10},t}, {'/',{4,11}}, {integer,{4,12},0}, {']',{4,13}},
                        {')',{4,14}}, {dot,{4,15}}]).
{ok,{attribute,{4,2},export,[{t,0}]}}

> erl_parse:parse_form([{atom,{8,1},t}, {'(',{8,2}},
 {var,{8,3},'A'}, {',',{8,4}}, {var,{8,6},'B'}, {')',{8,7}}, {'when',{8,9}}, {var,{8,14},'A'},
 {'>',{8,16}}, {var,{8,18},'B'}, {'->',{8,20}}, {'{',{10,5}}, {'(',{10,7}}, {'fun',{10,7}},
 {'(',{10,7}}, {var,{6,11},'_X'}, {')',{10,7}}, {'->',{10,7}}, {string,{6,16},"Hello "},
 {var,{6,24},'_X'}, {'end',{10,7}}, {')',{10,7}}, {'(',{10,7}}, {string,{10,9},"World"},
 {')',{10,7}}, {'}',{10,17}}, {dot,{10,18}}]).

{error,{{6,24},erl_parse,["syntax error before: ",["_X"]]}}

I can offer a PR soon for FUNCTION_NAME if interested!

c-bik avatar Apr 19 '18 15:04 c-bik

@c-bik Hello. Can you share code for FUNCTION_NAME?

AlexanderKai avatar Feb 28 '19 13:02 AlexanderKai