renaming more
This commit is contained in:
+1
-1
@@ -136,7 +136,7 @@
|
||||
string = none :: none | iolist(),
|
||||
extra = none :: none | any()}).
|
||||
|
||||
% @doc all errors SFC can return conveniently listed in
|
||||
% @doc all errors GSC can return conveniently listed in
|
||||
% one place
|
||||
-type gsc_err() :: #gsc_err_bcom_unterminated{}
|
||||
| #gsc_err_no_tokmatch{}
|
||||
|
||||
+31
-31
@@ -31,9 +31,9 @@
|
||||
% gulp means it must consume all input
|
||||
-spec gulp(AstTarget, SigTokens) -> Perhaps
|
||||
when AstTarget :: gulp_target(),
|
||||
SigTokens :: [sfc_token()],
|
||||
SigTokens :: [gsc_token()],
|
||||
Perhaps :: {gulp, ast()}
|
||||
| {error, sfc_err()}.
|
||||
| {error, gsc_err()}.
|
||||
|
||||
gulp(ast_file, Tokens) ->
|
||||
gulp_file(Tokens);
|
||||
@@ -46,11 +46,11 @@ gulp(ast_ct, Tokens) ->
|
||||
gulp(ast_nyi, Tokens) ->
|
||||
{gulp, #ast_nyi{tokens = Tokens}};
|
||||
gulp({block_of, X}, Tokens) ->
|
||||
{barf, ItemChunks, []} = sfc_token_chunks:barf(block_as_items, Tokens),
|
||||
{barf, ItemChunks, []} = gsc_token_chunks:barf(block_as_items, Tokens),
|
||||
gulp_block_of(X, ItemChunks);
|
||||
gulp(Nyi, Tokens) ->
|
||||
Msg = io_lib:format("sfc_ast:gulp/2: unknown target: ~p", [Nyi]),
|
||||
Err = #sfc_err{atom = gulp_nyi,
|
||||
Msg = io_lib:format("gsc_ast:gulp/2: unknown target: ~p", [Nyi]),
|
||||
Err = #gsc_err{atom = gulp_nyi,
|
||||
string = Msg,
|
||||
extra = [{target, Nyi}, {tokens, Tokens}]},
|
||||
{error, Err}.
|
||||
@@ -60,35 +60,35 @@ gulp(Nyi, Tokens) ->
|
||||
% FIXME: payable and main need to be in that order i think
|
||||
gulp_ct(Ast = #ast_ct{payable = none}, Tokens) ->
|
||||
case Tokens of
|
||||
[#sfc_token{string = "payable", type = kwd} | NewTokens] ->
|
||||
[#gsc_token{string = "payable", type = kwd} | NewTokens] ->
|
||||
gulp_ct(Ast#ast_ct{payable = payable}, NewTokens);
|
||||
_ ->
|
||||
gulp_ct(Ast#ast_ct{payable = false}, Tokens)
|
||||
end;
|
||||
gulp_ct(Ast = #ast_ct{main = none}, Tokens) ->
|
||||
case Tokens of
|
||||
[#sfc_token{string = "main", type = kwd} | NewTokens] ->
|
||||
[#gsc_token{string = "main", type = kwd} | NewTokens] ->
|
||||
gulp_ct(Ast#ast_ct{main = main}, NewTokens);
|
||||
_ ->
|
||||
gulp_ct(Ast#ast_ct{main = false}, Tokens)
|
||||
end;
|
||||
gulp_ct(Ast = #ast_ct{contract = none}, Tokens) ->
|
||||
case Tokens of
|
||||
[#sfc_token{string = "contract", type = kwd} | NewTokens] ->
|
||||
[#gsc_token{string = "contract", type = kwd} | NewTokens] ->
|
||||
gulp_ct(Ast#ast_ct{contract = contract}, NewTokens);
|
||||
% FIXME: reject logic applies to choice of branch, therefore
|
||||
% should be contained in branchpoint code
|
||||
_ ->
|
||||
reject
|
||||
%[#sfc_token{pos = P, string = S} | _] ->
|
||||
% {error, #sfc_err{atom = no_kwd_contract,
|
||||
%[#gsc_token{pos = P, string = S} | _] ->
|
||||
% {error, #gsc_err{atom = no_kwd_contract,
|
||||
% extra = [{pos, P},
|
||||
% {expecting, "contract"},
|
||||
% {got, S},
|
||||
% {ast, Ast},
|
||||
% {tokens, Tokens}]}};
|
||||
%[] ->
|
||||
% {error, #sfc_err{atom = no_kwd_contract,
|
||||
% {error, #gsc_err{atom = no_kwd_contract,
|
||||
% extra = [{pos, none},
|
||||
% {expecting, "contract"},
|
||||
% {got, eof},
|
||||
@@ -97,7 +97,7 @@ gulp_ct(Ast = #ast_ct{contract = none}, Tokens) ->
|
||||
end;
|
||||
gulp_ct(Ast = #ast_ct{name = none}, Tokens) ->
|
||||
case Tokens of
|
||||
[#sfc_token{string = Name, type = con} | NewTokens] ->
|
||||
[#gsc_token{string = Name, type = con} | NewTokens] ->
|
||||
gulp_ct(Ast#ast_ct{name = Name}, NewTokens);
|
||||
_ ->
|
||||
reject
|
||||
@@ -112,27 +112,27 @@ gulp_ct(Ast = #ast_ct{implements = none}, Tokens) ->
|
||||
end;
|
||||
gulp_ct(Ast = #ast_ct{eq = none}, Tokens) ->
|
||||
case Tokens of
|
||||
[#sfc_token{string = "=", type = op} | NewTokens] ->
|
||||
[#gsc_token{string = "=", type = op} | NewTokens] ->
|
||||
gulp_ct(Ast#ast_ct{eq = '='}, NewTokens);
|
||||
_ ->
|
||||
{error, #sfc_err{atom = no_eq}}
|
||||
{error, #gsc_err{atom = no_eq}}
|
||||
end;
|
||||
gulp_ct(Ast = #ast_ct{decls = none}, Tokens) ->
|
||||
Decls = [gulp(decl, Item) || Item <- sfc_token_chunks:unsafe_block_to_items(Tokens)],
|
||||
Decls = [gulp(decl, Item) || Item <- gsc_token_chunks:unsafe_block_to_items(Tokens)],
|
||||
{gulp, Ast#ast_ct{decls = Decls}};
|
||||
gulp_ct(_, _) ->
|
||||
reject.
|
||||
|
||||
|
||||
slurp_ct_impls([#sfc_token{string = ":", type = op},
|
||||
#sfc_token{string = Con1, type = con}
|
||||
slurp_ct_impls([#gsc_token{string = ":", type = op},
|
||||
#gsc_token{string = Con1, type = con}
|
||||
| Rest]) ->
|
||||
slurp_ct_impls2(Rest, [Con1]);
|
||||
slurp_ct_impls(_) ->
|
||||
reject.
|
||||
|
||||
slurp_ct_impls2([#sfc_token{string = ",", type = punct},
|
||||
#sfc_token{string = Con1, type = con}
|
||||
slurp_ct_impls2([#gsc_token{string = ",", type = punct},
|
||||
#gsc_token{string = Con1, type = con}
|
||||
| Rest],
|
||||
Acc) ->
|
||||
slurp_ct_impls2(Rest, [Con1 | Acc]);
|
||||
@@ -144,28 +144,28 @@ slurp_ct_impls2(Rest, Names) ->
|
||||
|
||||
|
||||
-spec gulp_file(SigTokens) -> Perhaps
|
||||
when SigTokens :: [sfc_token()],
|
||||
when SigTokens :: [gsc_token()],
|
||||
Perhaps :: {gulp, #ast_file{}}
|
||||
| {error, sfc_err()}.
|
||||
| {error, gsc_err()}.
|
||||
% @private
|
||||
% `file` enforces that the entire SigTokens is one
|
||||
% block, chokes otherwise
|
||||
|
||||
gulp_file([]) ->
|
||||
{error, #sfc_err{atom = empty_file}};
|
||||
gulp_file(FileTokens = [#sfc_token{pos = FilePos} | _]) ->
|
||||
case sfc_token_chunks:barf(block, FileTokens) of
|
||||
{error, #gsc_err{atom = empty_file}};
|
||||
gulp_file(FileTokens = [#gsc_token{pos = FilePos} | _]) ->
|
||||
case gsc_token_chunks:barf(block, FileTokens) of
|
||||
% happy path: got the whole file back
|
||||
{barf, FileTokens, []} ->
|
||||
gulp_full_file(FileTokens);
|
||||
% sad path: block terminated
|
||||
{barf, _, [#sfc_token{pos = EndPos}]} ->
|
||||
{barf, _, [#gsc_token{pos = EndPos}]} ->
|
||||
Msg = io_lib:format("block starting at ~p ends at ~p instead of EOF",
|
||||
[FilePos, EndPos]),
|
||||
{error, #sfc_err{atom = bad_file,
|
||||
{error, #gsc_err{atom = bad_file,
|
||||
string = Msg}};
|
||||
Nyi ->
|
||||
{error, #sfc_err{atom = bad_file_nyi, extra = Nyi}}
|
||||
{error, #gsc_err{atom = bad_file_nyi, extra = Nyi}}
|
||||
end.
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ gulp_file(FileTokens = [#sfc_token{pos = FilePos} | _]) ->
|
||||
|
||||
% file = block(top_decl)
|
||||
gulp_full_file(BlockTokens) ->
|
||||
ItemChunks = sfc_token_chunks:unsafe_block_to_items(BlockTokens),
|
||||
ItemChunks = gsc_token_chunks:unsafe_block_to_items(BlockTokens),
|
||||
gulp_file_decls([], [], ItemChunks).
|
||||
|
||||
|
||||
@@ -183,8 +183,8 @@ gulp_file_decls(Decls, Errs, [DeclTokens | Rest]) ->
|
||||
{gulp, NewDecl} ->
|
||||
gulp_file_decls([NewDecl | Decls], Errs, Rest);
|
||||
reject ->
|
||||
ErrPos = sfc_token_chunks:start_pos(DeclTokens),
|
||||
NewErr = #sfc_err{atom = bad_top_decl,
|
||||
ErrPos = gsc_token_chunks:start_pos(DeclTokens),
|
||||
NewErr = #gsc_err{atom = bad_top_decl,
|
||||
extra = [{tokens, DeclTokens},
|
||||
{pos, ErrPos}]},
|
||||
gulp_file_decls(Decls, [NewErr | Errs], Rest);
|
||||
@@ -195,5 +195,5 @@ gulp_file_decls(Decls, Errs, [DeclTokens | Rest]) ->
|
||||
gulp_file_decls(Decls, _Errs = [], _Input = []) ->
|
||||
{gulp, #ast_file{top_decls = lists:reverse(Decls)}};
|
||||
gulp_file_decls(_Decls, Errs, _Input = []) ->
|
||||
{error, #sfc_err{atom = many,
|
||||
{error, #gsc_err{atom = many,
|
||||
extra = Errs}}.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
%
|
||||
% generally assume no whitespace/comment tokens in
|
||||
% input stream
|
||||
-module(sfc_token_chunks).
|
||||
-module(gsc_token_chunks).
|
||||
|
||||
%-export_type([
|
||||
% chunk_shape/0,
|
||||
@@ -19,8 +19,8 @@
|
||||
% end_pos/1
|
||||
%]).
|
||||
%
|
||||
%% $sfc_include is so c() works from sfp eshell
|
||||
%-include("$sfc_include/sfc.hrl").
|
||||
%% $gsc_include is so c() works from sfp eshell
|
||||
%-include("$gsc_include/gsc.hrl").
|
||||
%
|
||||
%%------------------------------------------
|
||||
%% Types
|
||||
@@ -45,25 +45,25 @@
|
||||
%
|
||||
%take(block, []) ->
|
||||
% {[], []};
|
||||
%take(block, [Hd = #sfc_token{pos = {_, BCol}} | Tl]) ->
|
||||
% tw(fun(#sfc_token{pos = {_, TkCol}}) -> BCol =< TkCol end, [Hd], Tl);
|
||||
%take(block, [Hd = #gsc_token{pos = {_, BCol}} | Tl]) ->
|
||||
% tw(fun(#gsc_token{pos = {_, TkCol}}) -> BCol =< TkCol end, [Hd], Tl);
|
||||
%take(block_item, []) ->
|
||||
% {[], []};
|
||||
%take(block_item, [Hd = #sfc_token{pos = {_, ICol}} | Tl]) ->
|
||||
% tw(fun(#sfc_token{pos = {_, TkCol}}) -> ICol < TkCol end, Tl).
|
||||
%take(block_item, [Hd = #gsc_token{pos = {_, ICol}} | Tl]) ->
|
||||
% tw(fun(#gsc_token{pos = {_, TkCol}}) -> ICol < TkCol end, Tl).
|
||||
%
|
||||
%
|
||||
%
|
||||
%-spec start_pos([sfc_token()]) -> {value, sfc_pos()} | none.
|
||||
%-spec start_pos([gsc_token()]) -> {value, gsc_pos()} | none.
|
||||
%
|
||||
%start_pos([#sfc_token{pos = P}]) -> {value, P};
|
||||
%start_pos([#gsc_token{pos = P}]) -> {value, P};
|
||||
%start_pos([]) -> none.
|
||||
%
|
||||
%
|
||||
%-spec end_pos([sfc_token()]) -> {value, sfc_pos()} | none.
|
||||
%-spec end_pos([gsc_token()]) -> {value, gsc_pos()} | none.
|
||||
%
|
||||
%end_pos([#sfc_token{pos = Pos, string = Str}]) ->
|
||||
% {value, sfc_tokens:new_pos(Pos, Str)};
|
||||
%end_pos([#gsc_token{pos = Pos, string = Str}]) ->
|
||||
% {value, gsc_tokens:new_pos(Pos, Str)};
|
||||
%end_pos([_ | T]) ->
|
||||
% end_pos(T);
|
||||
%end_pos([]) ->
|
||||
@@ -79,7 +79,7 @@
|
||||
% | [[Token]], % block_as_items
|
||||
% Rest :: [Token],
|
||||
% Reason :: choke_reason(),
|
||||
% Token :: sfc_token().
|
||||
% Token :: gsc_token().
|
||||
%
|
||||
%% @doc
|
||||
%% slurp/barf terminology comes from paredit mode in
|
||||
@@ -93,23 +93,23 @@
|
||||
%
|
||||
%barf(_, []) ->
|
||||
% {barf, [], []};
|
||||
%barf(block, [H = #sfc_token{pos = {_, BlkCol}} | T]) ->
|
||||
%barf(block, [H = #gsc_token{pos = {_, BlkCol}} | T]) ->
|
||||
% Take =
|
||||
% fun(#sfc_token{pos = {_, TkCol}}) ->
|
||||
% fun(#gsc_token{pos = {_, TkCol}}) ->
|
||||
% BlkCol =< TkCol
|
||||
% end,
|
||||
% {A, B} = tw(Take, T),
|
||||
% {barf, [H | A], B};
|
||||
%barf(block_item, [H = #sfc_token{pos = {_, BlkCol}} | T]) ->
|
||||
%barf(block_item, [H = #gsc_token{pos = {_, BlkCol}} | T]) ->
|
||||
% Take =
|
||||
% fun(#sfc_token{pos = {_, TkCol}}) ->
|
||||
% fun(#gsc_token{pos = {_, TkCol}}) ->
|
||||
% BlkCol < TkCol
|
||||
% end,
|
||||
% {A, B} = tw(Take, T),
|
||||
% {barf, [H | A], B};
|
||||
%% not needed for our case, future-proofing. see unsafe_block_to_items
|
||||
%% for details
|
||||
%barf({block_item, Level}, Tokens = [#sfc_token{pos = {_, StartLevel}} | _]) ->
|
||||
%barf({block_item, Level}, Tokens = [#gsc_token{pos = {_, StartLevel}} | _]) ->
|
||||
% case Level =:= StartLevel of
|
||||
% false -> {barf, [], Tokens};
|
||||
% true -> barf(block_item, Tokens)
|
||||
@@ -124,7 +124,7 @@
|
||||
% {barf, BlockTokens, Rest} = barf(block, Tokens),
|
||||
% {barf, unsafe_block_to_items(BlockTokens), Rest};
|
||||
%barf(_, _) ->
|
||||
% {choke, #sfc_err_nyi{}}.
|
||||
% {choke, #gsc_err_nyi{}}.
|
||||
%
|
||||
%
|
||||
%
|
||||
@@ -132,7 +132,7 @@
|
||||
%
|
||||
%
|
||||
%-spec unsafe_block_to_items([Token]) -> [[Token]]
|
||||
% when Token :: sfc_token().
|
||||
% when Token :: gsc_token().
|
||||
%
|
||||
%% @doc
|
||||
%% PITFALL: this ASSUMES that the given list of tokens has the
|
||||
@@ -42,13 +42,13 @@
|
||||
% qid : Foo.Bar.baz
|
||||
% tvar : 'a
|
||||
-record(ast_te_name,
|
||||
{name = none :: none | sfc_token()}).
|
||||
{name = none :: none | gsc_token()}).
|
||||
|
||||
|
||||
% @doc
|
||||
% placeholder
|
||||
-record(ast_te_nyi,
|
||||
{tokens = none :: none | [sfc_token()]}).
|
||||
{tokens = none :: none | [gsc_token()]}).
|
||||
-type ast_te_nyi() :: #ast_nyi{}.
|
||||
|
||||
|
||||
@@ -64,14 +64,14 @@
|
||||
-record(ifx_stem_op,
|
||||
{left = none :: none | [ifx_tree_()],
|
||||
op = none :: none | infix_op(),
|
||||
op_token = none :: none | {value, sfc_token()},
|
||||
op_token = none :: none | {value, gsc_token()},
|
||||
right = none :: none | [ifx_tree_()]}).
|
||||
|
||||
-record(ifx_stem_plist,
|
||||
{items :: [any()]}).
|
||||
|
||||
-record(ifx_leaf_idtk,
|
||||
{token :: sfc_token()}).
|
||||
{token :: gsc_token()}).
|
||||
|
||||
-type ifx_tree()
|
||||
:: #ifx_stem_op{}
|
||||
@@ -80,7 +80,7 @@
|
||||
|
||||
|
||||
-spec slurp_ifx_tree(Tokens) -> SlurpedIfxTree when
|
||||
Tokens :: [sfc_token()],
|
||||
Tokens :: [gsc_token()],
|
||||
SlurpedIfxNode :: slurped(ifx_tree()).
|
||||
|
||||
slurp_ifx_tree(Tokens) ->
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
% @doc
|
||||
% type for an SFC AST
|
||||
% type for a GSC AST
|
||||
%
|
||||
% based on so_syntax.erl
|
||||
%
|
||||
|
||||
+6
-6
@@ -109,16 +109,16 @@ scan(SrcStr) ->
|
||||
SoTokens = to_so_tokens(SfLTokens),
|
||||
{ok, SoTokens};
|
||||
% fucking stupid
|
||||
{error, #gsc_err_bcom_unterminated{prev_tokens = SfcTokens}} ->
|
||||
{ok, to_so_tokens(SfcTokens)};
|
||||
{error, #gsc_err_bcom_unterminated{prev_tokens = GscTokens}} ->
|
||||
{ok, to_so_tokens(GscTokens)};
|
||||
Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
|
||||
|
||||
-spec to_so_tokens(SfcTokens) -> SoTokens
|
||||
when SfcTokens :: [tk()],
|
||||
-spec to_so_tokens(GscTokens) -> SoTokens
|
||||
when GscTokens :: [tk()],
|
||||
SoTokens :: [so_token()].
|
||||
|
||||
% @doc
|
||||
@@ -309,8 +309,8 @@ pass_types() ->
|
||||
|
||||
|
||||
|
||||
-spec to_so_token(SfcToken) -> MaybeSoToken
|
||||
when SfcToken :: tk(),
|
||||
-spec to_so_token(GscToken) -> MaybeSoToken
|
||||
when GscToken :: tk(),
|
||||
MaybeSoToken :: {true, SoToken}
|
||||
| false,
|
||||
SoToken :: so_token().
|
||||
|
||||
Reference in New Issue
Block a user