renaming more

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