Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing support for FUNCTION_NAME, FUNCTION_ARITY etc #25

Open
c-bik opened this issue Apr 19, 2018 · 1 comment
Open

missing support for FUNCTION_NAME, FUNCTION_ARITY etc #25

c-bik opened this issue Apr 19, 2018 · 1 comment

Comments

@c-bik
Copy link

c-bik commented Apr 19, 2018

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!

@AlexanderKai
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants