Added rudimentary parser, and connected to JS
Added rudimentary parser, and connected to JS squash! Added rudimentary parser, and connected to JS
This commit is contained in:
parent
1f3f7daa9a
commit
f8cf749e5f
10 changed files with 15501 additions and 23 deletions
8
build_test
Executable file
8
build_test
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
./build
|
||||
|
||||
for i in `find tests -name "*.erl"`
|
||||
do
|
||||
erlc -o ebin_test $i
|
||||
done
|
|
@ -10,7 +10,7 @@ port = gets
|
|||
|
||||
s = TCPSocket.open(hostname, port.chop)
|
||||
|
||||
s.print("{\"request\": \"define\"}")
|
||||
s.print(" __boot")
|
||||
|
||||
while true
|
||||
line = s.gets # Read lines from the socket
|
||||
|
|
15446
erl_crash.dump
Normal file
15446
erl_crash.dump
Normal file
File diff suppressed because one or more lines are too long
|
@ -4,20 +4,23 @@
|
|||
-module(ggs_protocol).
|
||||
-export([parse/1]).
|
||||
|
||||
parse(JSONData) ->
|
||||
{struct, Struct} = js_mochijson2:decode(JSONData),
|
||||
io:format("~p~n", [Struct]),
|
||||
[{RequestType, Rest}] = Struct,%proplists:get_value(<<"request">>, Struct),
|
||||
case RequestType of
|
||||
<<"define">> ->
|
||||
%Name = proplists:get_value(<<"name">>, Rest),
|
||||
%{struct, Name} = proplists:get_value(<<"name">>, Rest),
|
||||
{struct, Rest2} = Rest,
|
||||
io:format("~p", [Rest2]),
|
||||
ok_you_said_define;
|
||||
<<"call">> ->
|
||||
ok_you_said_call;
|
||||
parse(Data) ->
|
||||
Message = string:tokens(Data, " "),
|
||||
case Message of
|
||||
[RefID, "__error", Message ] ->
|
||||
{ok, you_said_error};
|
||||
[_, "__boot" ] ->
|
||||
{ok, you_said_boot};
|
||||
[RefID, "__stop"] ->
|
||||
{ok, you_said_stop};
|
||||
[RefID, "__start"] ->
|
||||
{ok, you_said_start};
|
||||
[_, "__hello" , _ ] ->
|
||||
{ok, you_said_hello};
|
||||
[RefID, "__define", JavaScript ] ->
|
||||
{ok, you_said_define};
|
||||
[RefID, Command, Parameter ] ->
|
||||
{cmd, Command, Parameter};
|
||||
Other ->
|
||||
io:format("~p", [RequestType]),
|
||||
ok_i_dont_understand
|
||||
{out_of_bounds, Other}
|
||||
end.
|
||||
|
|
|
@ -72,10 +72,10 @@ handle_cast(stop, State) ->
|
|||
{stop, normal, State}.
|
||||
|
||||
handle_info({tcp, Socket, RawData}, State) ->
|
||||
%do_JSCall(Socket, RawData),
|
||||
Parsed = ggs_protocol:parse(RawData),
|
||||
do_JSDefine(Socket, RawData),
|
||||
%Parsed = ggs_protocol:parse(RawData),
|
||||
RequestCount = State#state.request_count,
|
||||
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Parsed])),
|
||||
%gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Parsed])),
|
||||
{noreply, State#state{request_count = RequestCount + 1}};
|
||||
|
||||
handle_info(timeout, #state{lsock = LSock} = State) ->
|
||||
|
@ -94,8 +94,17 @@ code_change(_OldVsn, State, _Extra) ->
|
|||
|
||||
do_JSDefine(Socket, Data) ->
|
||||
JSVM = js_runner:boot(),
|
||||
Ret = js_runner:define(JSVM, Data),
|
||||
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Ret])).
|
||||
js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"),
|
||||
Parsed = ggs_protocol:parse(Data),
|
||||
case Parsed of
|
||||
{cmd, Command, Parameter} ->
|
||||
Ret = js_runner:call(JSVM, "userCommand",
|
||||
[list_to_binary(Command),
|
||||
list_to_binary(Parameter)]),
|
||||
gen_tcp:send(Socket, io_lib:fwrite("JS says: ~p~n", [Ret]));
|
||||
Other ->
|
||||
ok
|
||||
end.
|
||||
|
||||
do_JSCall(Socket, Function, Parameters) ->
|
||||
ok.
|
||||
|
|
|
@ -10,4 +10,4 @@ define(Port, Data) ->
|
|||
ok = js:define(Port, list_to_binary(Data)).
|
||||
|
||||
call(Port, Func, Params) ->
|
||||
js:call(Port, list_to_binary(Func), [Params]).
|
||||
js:call(Port, list_to_binary(Func), Params).
|
||||
|
|
2
start
2
start
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
erl -boot start_sasl -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src -eval 'ggs_server:start_link(9000).'
|
||||
erl -boot start_sasl -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src -eval "ggs_server:start_link($1)."
|
||||
|
|
3
start_test
Executable file
3
start_test
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
erl -boot start_sasl -pa ebin_test -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src -eval 'ggs_protocol_test:test_parse().'
|
3
start_test_shell
Executable file
3
start_test_shell
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
erl -boot start_sasl -pa ebin_test -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src
|
6
tests/ggs_protocol_test.erl
Normal file
6
tests/ggs_protocol_test.erl
Normal file
|
@ -0,0 +1,6 @@
|
|||
-module(ggs_protocol_test).
|
||||
-export([test_parse/0]).
|
||||
|
||||
test_parse() ->
|
||||
Ret = ggs_protocol:parse("<> __define JavaScript"),
|
||||
io:format("~p~n", [Ret]).
|
Reference in a new issue