gsc_test_ytree: task now fails successfully
i have realized that a lot of the complexity and cognitive overhead is downstream from trying to prematurely handle errors. so i'm going to do the erlang thing and just assert/assume everything worked perfectly and let the errors speak for themselves. so re "task fails successfully": now instead of getting an NYI that looks like a success result, we're now properly getting an error.
This commit is contained in:
+34
-17
@@ -23,8 +23,7 @@ main() ->
|
|||||||
| using
|
| using
|
||||||
.
|
.
|
||||||
|
|
||||||
-record(ct, {ok = ok :: ok | {error, any()},
|
-record(ct, {payable = none :: none | false | true,
|
||||||
payable = none :: none | false | true,
|
|
||||||
main = none :: none | false | true,
|
main = none :: none | false | true,
|
||||||
contract = none :: none | tk(),
|
contract = none :: none | tk(),
|
||||||
con = none :: none | tk(),
|
con = none :: none | tk(),
|
||||||
@@ -43,8 +42,7 @@ main() ->
|
|||||||
| contract_meta().
|
| contract_meta().
|
||||||
|
|
||||||
% @doc ys = syntax stem
|
% @doc ys = syntax stem
|
||||||
-record(ys, {ok = ok :: ok | {error, any()},
|
-record(ys, {target = signal :: syntax_target(),
|
||||||
target = signal :: syntax_target(),
|
|
||||||
signal :: [tk()],
|
signal :: [tk()],
|
||||||
stem_meta :: stem_meta(),
|
stem_meta :: stem_meta(),
|
||||||
forest :: [#ys{}]}).
|
forest :: [#ys{}]}).
|
||||||
@@ -58,6 +56,11 @@ handle_src_str(SrcStr) ->
|
|||||||
io:format("~tp~n", [Result]).
|
io:format("~tp~n", [Result]).
|
||||||
|
|
||||||
|
|
||||||
|
-spec gulp(Target, Signal) -> Result when
|
||||||
|
Target :: syntax_target(),
|
||||||
|
Signal :: [tk()],
|
||||||
|
Result :: {gulp, syntax_stem()} | {error, any()}.
|
||||||
|
|
||||||
gulp(file, Sig) ->
|
gulp(file, Sig) ->
|
||||||
gulp({block_of, top_decl}, Sig);
|
gulp({block_of, top_decl}, Sig);
|
||||||
gulp({block_of, X}, Sig) ->
|
gulp({block_of, X}, Sig) ->
|
||||||
@@ -96,11 +99,25 @@ gulp(contract, Sig) ->
|
|||||||
signal = Sig,
|
signal = Sig,
|
||||||
stem_meta = CtMeta,
|
stem_meta = CtMeta,
|
||||||
forest = Forest};
|
forest = Forest};
|
||||||
|
% Decl ::= 'type' Id ['(' TVar* ')'] '=' TypeAlias
|
||||||
|
% | 'record' Id ['(' TVar* ')'] '=' RecordType
|
||||||
|
% | 'datatype' Id ['(' TVar* ')'] '=' DataType
|
||||||
|
% | 'let' Id [':' Type] '=' Expr
|
||||||
|
% | (EModifier* 'entrypoint' | FModifier* 'function') Block(FunDecl)
|
||||||
|
% | Using
|
||||||
|
gulp(decl, Sig) ->
|
||||||
|
NewTarget =
|
||||||
|
case strings(1, Sig) of
|
||||||
|
["type"] -> type;
|
||||||
|
["record"] -> record;
|
||||||
|
["datatype"] -> datatype;
|
||||||
|
["let"] -> 'let';
|
||||||
|
["using"] -> using;
|
||||||
|
_ -> fn
|
||||||
|
end,
|
||||||
|
gulp(NewTarget, Sig);
|
||||||
gulp(NyiTarget, Sig) ->
|
gulp(NyiTarget, Sig) ->
|
||||||
#ys{target = NyiTarget,
|
error({nyi, [?MODULE, gulp, NyiTarget, Sig]}).
|
||||||
signal = Sig,
|
|
||||||
stem_meta = {nyi, NyiTarget},
|
|
||||||
forest = []}.
|
|
||||||
|
|
||||||
|
|
||||||
%% ['payable'] ['main'] 'contract' Con [Implement] '=' Block(Decl)
|
%% ['payable'] ['main'] 'contract' Con [Implement] '=' Block(Decl)
|
||||||
@@ -122,20 +139,20 @@ slurp(M = #ct{contract = none}, Sig) ->
|
|||||||
[Tk = #tk{str = "contract"} | Rest] ->
|
[Tk = #tk{str = "contract"} | Rest] ->
|
||||||
slurp(M#ct{contract = Tk}, Rest);
|
slurp(M#ct{contract = Tk}, Rest);
|
||||||
_ ->
|
_ ->
|
||||||
M#ct{ok = {error, no_keyword_contract}}
|
error(no_keyword_contract)
|
||||||
end;
|
end;
|
||||||
slurp(M = #ct{con = none}, Sig) ->
|
slurp(M = #ct{con = none}, Sig) ->
|
||||||
case Sig of
|
case Sig of
|
||||||
[Tk = #tk{shape = con} | Rest] ->
|
[Tk = #tk{shape = con} | Rest] ->
|
||||||
slurp(M#ct{con = Tk}, Rest);
|
slurp(M#ct{con = Tk}, Rest);
|
||||||
[Tk = #tk{str = Irregar} | _] ->
|
[#tk{str = Irregar} | _] ->
|
||||||
M#ct{ok = {error, {illegal_contract_name, Irregar}}};
|
error(illegal_contract_name, Irregar);
|
||||||
[] ->
|
[] ->
|
||||||
M#ct{ok = {error, no_contract_name}}
|
error(no_contract_name)
|
||||||
end;
|
end;
|
||||||
slurp(M = #ct{impls = none}, Sig) ->
|
slurp(M = #ct{impls = none}, Sig) ->
|
||||||
case Sig of
|
case Sig of
|
||||||
[Tk = #tk{str = ":"} | Rest] ->
|
[#tk{str = ":"} | Rest] ->
|
||||||
{slurp, Impls, NewRest} = slurp({sep1, con, ","}, Rest),
|
{slurp, Impls, NewRest} = slurp({sep1, con, ","}, Rest),
|
||||||
NewM = M#ct{impls = {true, Impls}},
|
NewM = M#ct{impls = {true, Impls}},
|
||||||
slurp(NewM, NewRest);
|
slurp(NewM, NewRest);
|
||||||
@@ -147,17 +164,17 @@ slurp(M = #ct{'=' = none}, Sig) ->
|
|||||||
[Tk = #tk{str = "="} | Rest] ->
|
[Tk = #tk{str = "="} | Rest] ->
|
||||||
{slurp, M#ct{'=' = Tk}, Rest};
|
{slurp, M#ct{'=' = Tk}, Rest};
|
||||||
_ ->
|
_ ->
|
||||||
M#ct{ok = {error, no_token_eq}}
|
error("where the fuck my = be at nigga")
|
||||||
end;
|
end;
|
||||||
slurp({sep1, TkShape, SepByStr}, Tks) ->
|
slurp({sep1, TkShape, SepByStr}, Tks) ->
|
||||||
case Tks of
|
case Tks of
|
||||||
[Tk = #tk{shape = TkShape} | Rest] ->
|
[Tk = #tk{shape = TkShape} | Rest] ->
|
||||||
slurp_sep1_ii([Tk], TkShape, SepByStr, Rest);
|
slurp_sep1_ii([Tk], TkShape, SepByStr, Rest);
|
||||||
_ ->
|
_ ->
|
||||||
{error, irregar}
|
error(irregar)
|
||||||
end;
|
end;
|
||||||
slurp(M, Tks) ->
|
slurp(BadMeta, BadTokens) ->
|
||||||
{slurp, {nyi, M}, Tks}.
|
error({nyi, [?MODULE, slurp, BadMeta, BadTokens]}).
|
||||||
|
|
||||||
|
|
||||||
slurp_sep1_ii(Stk, TkShape, SepByStr, Sig) ->
|
slurp_sep1_ii(Stk, TkShape, SepByStr, Sig) ->
|
||||||
|
|||||||
Reference in New Issue
Block a user