From 3a01f3074906d33368d9ba9d53c484380836acd3 Mon Sep 17 00:00:00 2001 From: Maxim Sokhatsky Date: Sat, 12 Apr 2014 22:09:17 +0300 Subject: [PATCH] shen --- priv/sample.js | 3 +-- src/shen.erl | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/priv/sample.js b/priv/sample.js index 160669f..82632b3 100644 --- a/priv/sample.js +++ b/priv/sample.js @@ -25,8 +25,7 @@ var start = pattern({ var fac = pattern({ '0': function(_0) { return 1; - }, - 'n': function(n) { + }, 'n': function(n) { return n * fac(n - 1); }}); start(); diff --git a/src/shen.erl b/src/shen.erl index f0f17ab..26260f7 100644 --- a/src/shen.erl +++ b/src/shen.erl @@ -63,7 +63,7 @@ compile(_Form,_) -> ":-)". function(Name,X,Args,Clauses,Type) -> case Type of compile -> [ io_lib:format("var ~s = pattern({~n", [ Name ]), - string:join([ clause(Args,C,Type) || C <- Clauses ],",\n"), + string:join([ clause(Args,C,Type) || C <- Clauses ],","), io_lib:format("~s~n",["});"]) ]; match -> [ io_lib:format("pattern({~n",[]), string:join([ clause(Args,C,{match,Name}) || C <- Clauses ],",\n"), @@ -124,12 +124,13 @@ normalize_list({cons,_X,Left,Right},L,Mode) -> [{exp(Left,Mode)},normalize_list( arg({integer,_X,_Value},_N) -> io_lib:format("_~s",[integer_to_list(_Value)]); arg({string,_X,_Value},N) -> io_lib:format("~s",[N]); -arg({atom,_X,_Value},N) -> io_lib:format("~p",[N]); +arg({atom,_X,_Value},N) -> io_lib:format("'~s'",[N]); arg({var,_X,Value},_N) -> io_lib:format("~s",[string:to_lower(atom_to_list(Value))]). par(List,Mode) -> io_lib:format("~s",[lists:flatten(string:join([exp(V,Mode)||V<-List],","))]). exp({integer,_X,Value},_) -> io_lib:format("~s",[integer_to_list(Value)]); +exp({binary,_X,Value},_) -> io_lib:format("~s",[binary_to_list(Value)]); exp({string,_X,Value},_) -> io_lib:format("'~s'",[Value]); exp({atom,_X,Value},{inline,_}) -> io_lib:format("'~w'",[Value]); exp({atom,_X,Value},_) -> io_lib:format("~w",[Value]);