2013-04-04 176 views
0

我想弄清楚這段代碼有什麼問題,因爲它給了我錯誤,使它無法正確編譯成波束文件。我沒有看到語法有什麼問題。有沒有可以幫助我的IDE?Erl文件由於語法錯誤而無法編譯

這些都是錯誤的:

[email protected]:/var/backend/ejabberd_modules# erlc -I   /var/tmp/ejabberd/src/ mod_stanza_ack.erl 
    ./mod_stanza_ack.erl:97: syntax error before: '.' 
    ./mod_stanza_ack.erl:98: syntax error before: Body 
    ./mod_stanza_ack.erl:16: function route/3 undefined 
    ./mod_stanza_ack.erl:3: Warning: behaviour gen_mod undefined 
    ./mod_stanza_ack.erl:111: Warning: function strip_bom/1 is unused 
    ./mod_stanza_ack.erl:114: Warning: function send_presence/3 is unused 
    ./mod_stanza_ack.erl:120: Warning: function echo/3 is unused 
    ./mod_stanza_ack.erl:123: Warning: function send_message/4 is unused 

這是代碼:

-module(mod_stanza_ack). 
-behavior(gen_server). 
-behavior(gen_mod). 

-export([start_link/2]). 

-export([start/2, 
     stop/1, 
     init/1, 
     handle_call/3, 
     handle_cast/2, 
     handle_info/2, 
     terminate/2, 
     code_change/3]). 

-export([route/3]). 

-include("ejabberd.hrl"). 

-define(PROCNAME, ejabberd_mod_stanza_ack). 
-define(BOTNAME, stanza_ack). 

start_link(Host, Opts) -> 
    Proc = gen_mod:get_module_proc(Host, ?PROCNAME), 
    gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []). 

start(Host, Opts) -> 
    Proc = gen_mod:get_module_proc(Host, ?PROCNAME), 
    ChildSpec = {Proc, 
     {?MODULE, start_link, [Host, Opts]}, 
     temporary, 
     1000, 
     worker, 
     [?MODULE]}, 
    supervisor:start_child(ejabberd_sup, ChildSpec). 

stop(Host) -> 
    Proc = gen_mod:get_module_proc(Host, ?PROCNAME), 
    gen_server:call(Proc, stop), 
    supervisor:terminate_child(ejabberd_sup, Proc), 
    supervisor:delete_child(ejabberd_sup, Proc). 

init([Host, Opts]) -> 
    ?DEBUG("ECHO_BOT: Starting echo_bot", []), 
    % add a new virtual host/subdomain "echo".example.com 
    MyHost = gen_mod:get_opt_host(Host, Opts, "[email protected]@"), 
    ejabberd_router:register_route(MyHost, {apply, ?MODULE, route}), 
    {ok, Host}. 

handle_call(stop, _From, Host) -> 
    {stop, normal, ok, Host}. 

handle_cast(_Msg, Host) -> 
    {noreply, Host}. 

handle_info(_Msg, Host) -> 
    {noreply, Host}. 

terminate(_Reason, Host) -> 
    ejabberd_router:unregister_route(Host), 
    ok. 

code_change(_OldVsn, Host, _Extra) -> 
    {ok, Host}. 

% Checks a presence /subscription/ is a part of this. 
% we may want to impliment blacklisting/some kind of 
% protection here to prevent malicious users 
%route(From, #jid{luser = ?BOTNAME} = To, {xmlelement, "presence", _, _} = Packet) -> 
route(From, To, {xmlelement, "presence", _, _} = Packet) -> 
    case xml:get_tag_attr_s("type", Packet) of 
     "subscribe" -> 
      send_presence(To, From, "subscribe"); 
     "subscribed" -> 
      send_presence(To, From, "subscribed"), 
      send_presence(To, From, ""); 
     "unsubscribe" -> 
      send_presence(To, From, "unsubscribed"), 
      send_presence(To, From, "unsubscribe"); 
     "unsubscribed" -> 
      send_presence(To, From, "unsubscribed"); 
     "" -> 
      send_presence(To, From, ""); 
     "unavailable" -> 
      ok; 
     "probe" -> 
      send_presence(To, From, ""); 
     _Other -> 
      ?INFO_MSG("Other kind of presence~n~p", [Packet]) 
    end, 
    ok; 

%route(From, #jid{luser = ?BOTNAME} = To, {xmlelement, "message", _, _} = Packet) -> 
route(From, To, {xmlelement, "message", _, _} = Packet) -> 
    case xml:get_subtag_cdata(Packet, "body") of 
    "" -> 
     ok. 
    Body -> 
     case xml:get_tag_attr_s("type", Packet) of 

     "error" -> 
      ?ERROR_MSG("Received error message~n~p -> ~p~n~p", [From, To, Packet]); 
     _ -> 
      echo(To, From, strip_bom(Body)) 
     end 
    end, 
    ok. 

%% HELPER FUNCTIONS 

strip_bom([239,187,191|C]) -> C; 
strip_bom(C) -> C. 

send_presence(From, To, "") -> 
    ejabberd_router:route(From, To, {xmlelement, "presence", [], []}); 

send_presence(From, To, TypeStr) -> 
    ejabberd_router:route(From, To, {xmlelement, "presence", [{"type", TypeStr}], []}). 

echo(From, To, Body) -> 
    send_message(From, To, "chat", Body). 

send_message(From, To, TypeStr, BodyStr) -> 
    XmlBody = {xmlelement, "message", 
      [{"type", TypeStr}, 
     {"from", jlib:jid_to_string(From)}, 
     {"to", jlib:jid_to_string(To)}], 
      [{xmlelement, "body", [], 
     [{xmlcdata, BodyStr}]}]}, 
    ejabberd_router:route(From, To, XmlBody). 

回答

3

./mod_stanza_ack.erl:97: syntax error before: '.'是說的錯誤是在線路97 在線路97改變ok.ok;。這將解決這個問題。

eclipse的Erlide插件是一個很好的IDE嘗試。

3

論功能route/3case的第一條線97是

"" -> 
     ok. 

.的結束這裏這在case中間非法的功能,它應該是一個;。這也意味着解析器假定下一行中的變量Body啓動一個新函數,該函數也是非法的,因爲函數名稱不能是變量。

眼看功能route/3尚未定義它不能被出口這是未定義的功能誤差對線16

原因有時編譯器錯誤消息是有點神祕但行號通常幫助。

相關問題