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 = TCPSocket.open(hostname, port.chop)
|
||||||
|
|
||||||
s.print("{\"request\": \"define\"}")
|
s.print(" __boot")
|
||||||
|
|
||||||
while true
|
while true
|
||||||
line = s.gets # Read lines from the socket
|
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).
|
-module(ggs_protocol).
|
||||||
-export([parse/1]).
|
-export([parse/1]).
|
||||||
|
|
||||||
parse(JSONData) ->
|
parse(Data) ->
|
||||||
{struct, Struct} = js_mochijson2:decode(JSONData),
|
Message = string:tokens(Data, " "),
|
||||||
io:format("~p~n", [Struct]),
|
case Message of
|
||||||
[{RequestType, Rest}] = Struct,%proplists:get_value(<<"request">>, Struct),
|
[RefID, "__error", Message ] ->
|
||||||
case RequestType of
|
{ok, you_said_error};
|
||||||
<<"define">> ->
|
[_, "__boot" ] ->
|
||||||
%Name = proplists:get_value(<<"name">>, Rest),
|
{ok, you_said_boot};
|
||||||
%{struct, Name} = proplists:get_value(<<"name">>, Rest),
|
[RefID, "__stop"] ->
|
||||||
{struct, Rest2} = Rest,
|
{ok, you_said_stop};
|
||||||
io:format("~p", [Rest2]),
|
[RefID, "__start"] ->
|
||||||
ok_you_said_define;
|
{ok, you_said_start};
|
||||||
<<"call">> ->
|
[_, "__hello" , _ ] ->
|
||||||
ok_you_said_call;
|
{ok, you_said_hello};
|
||||||
|
[RefID, "__define", JavaScript ] ->
|
||||||
|
{ok, you_said_define};
|
||||||
|
[RefID, Command, Parameter ] ->
|
||||||
|
{cmd, Command, Parameter};
|
||||||
Other ->
|
Other ->
|
||||||
io:format("~p", [RequestType]),
|
{out_of_bounds, Other}
|
||||||
ok_i_dont_understand
|
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -72,10 +72,10 @@ handle_cast(stop, State) ->
|
||||||
{stop, normal, State}.
|
{stop, normal, State}.
|
||||||
|
|
||||||
handle_info({tcp, Socket, RawData}, State) ->
|
handle_info({tcp, Socket, RawData}, State) ->
|
||||||
%do_JSCall(Socket, RawData),
|
do_JSDefine(Socket, RawData),
|
||||||
Parsed = ggs_protocol:parse(RawData),
|
%Parsed = ggs_protocol:parse(RawData),
|
||||||
RequestCount = State#state.request_count,
|
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}};
|
{noreply, State#state{request_count = RequestCount + 1}};
|
||||||
|
|
||||||
handle_info(timeout, #state{lsock = LSock} = State) ->
|
handle_info(timeout, #state{lsock = LSock} = State) ->
|
||||||
|
@ -94,8 +94,17 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
|
|
||||||
do_JSDefine(Socket, Data) ->
|
do_JSDefine(Socket, Data) ->
|
||||||
JSVM = js_runner:boot(),
|
JSVM = js_runner:boot(),
|
||||||
Ret = js_runner:define(JSVM, Data),
|
js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"),
|
||||||
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Ret])).
|
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) ->
|
do_JSCall(Socket, Function, Parameters) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -10,4 +10,4 @@ define(Port, Data) ->
|
||||||
ok = js:define(Port, list_to_binary(Data)).
|
ok = js:define(Port, list_to_binary(Data)).
|
||||||
|
|
||||||
call(Port, Func, Params) ->
|
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
|
#!/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