s/sfc/gsc/g

'
This commit is contained in:
2026-10-20 18:42:11 -07:00
parent 2e062bb8c9
commit 70a853ae99
27 changed files with 291 additions and 291 deletions
+31 -31
View File
@@ -31,9 +31,9 @@
% gulp means it must consume all input
-spec gulp(AstTarget, SigTokens) -> Perhaps
when AstTarget :: gulp_target(),
SigTokens :: [gsc_token()],
SigTokens :: [sfc_token()],
Perhaps :: {gulp, ast()}
| {error, gsc_err()}.
| {error, sfc_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, []} = gsc_token_chunks:barf(block_as_items, Tokens),
{barf, ItemChunks, []} = sfc_token_chunks:barf(block_as_items, Tokens),
gulp_block_of(X, ItemChunks);
gulp(Nyi, Tokens) ->
Msg = io_lib:format("gsc_ast:gulp/2: unknown target: ~p", [Nyi]),
Err = #gsc_err{atom = gulp_nyi,
Msg = io_lib:format("sfc_ast:gulp/2: unknown target: ~p", [Nyi]),
Err = #sfc_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
[#gsc_token{string = "payable", type = kwd} | NewTokens] ->
[#sfc_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
[#gsc_token{string = "main", type = kwd} | NewTokens] ->
[#sfc_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
[#gsc_token{string = "contract", type = kwd} | NewTokens] ->
[#sfc_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
%[#gsc_token{pos = P, string = S} | _] ->
% {error, #gsc_err{atom = no_kwd_contract,
%[#sfc_token{pos = P, string = S} | _] ->
% {error, #sfc_err{atom = no_kwd_contract,
% extra = [{pos, P},
% {expecting, "contract"},
% {got, S},
% {ast, Ast},
% {tokens, Tokens}]}};
%[] ->
% {error, #gsc_err{atom = no_kwd_contract,
% {error, #sfc_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
[#gsc_token{string = Name, type = con} | NewTokens] ->
[#sfc_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
[#gsc_token{string = "=", type = op} | NewTokens] ->
[#sfc_token{string = "=", type = op} | NewTokens] ->
gulp_ct(Ast#ast_ct{eq = '='}, NewTokens);
_ ->
{error, #gsc_err{atom = no_eq}}
{error, #sfc_err{atom = no_eq}}
end;
gulp_ct(Ast = #ast_ct{decls = none}, Tokens) ->
Decls = [gulp(decl, Item) || Item <- gsc_token_chunks:unsafe_block_to_items(Tokens)],
Decls = [gulp(decl, Item) || Item <- sfc_token_chunks:unsafe_block_to_items(Tokens)],
{gulp, Ast#ast_ct{decls = Decls}};
gulp_ct(_, _) ->
reject.
slurp_ct_impls([#gsc_token{string = ":", type = op},
#gsc_token{string = Con1, type = con}
slurp_ct_impls([#sfc_token{string = ":", type = op},
#sfc_token{string = Con1, type = con}
| Rest]) ->
slurp_ct_impls2(Rest, [Con1]);
slurp_ct_impls(_) ->
reject.
slurp_ct_impls2([#gsc_token{string = ",", type = sep},
#gsc_token{string = Con1, type = con}
slurp_ct_impls2([#sfc_token{string = ",", type = sep},
#sfc_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 :: [gsc_token()],
when SigTokens :: [sfc_token()],
Perhaps :: {gulp, #ast_file{}}
| {error, gsc_err()}.
| {error, sfc_err()}.
% @private
% `file` enforces that the entire SigTokens is one
% block, chokes otherwise
gulp_file([]) ->
{error, #gsc_err{atom = empty_file}};
gulp_file(FileTokens = [#gsc_token{pos = FilePos} | _]) ->
case gsc_token_chunks:barf(block, FileTokens) of
{error, #sfc_err{atom = empty_file}};
gulp_file(FileTokens = [#sfc_token{pos = FilePos} | _]) ->
case sfc_token_chunks:barf(block, FileTokens) of
% happy path: got the whole file back
{barf, FileTokens, []} ->
gulp_full_file(FileTokens);
% sad path: block terminated
{barf, _, [#gsc_token{pos = EndPos}]} ->
{barf, _, [#sfc_token{pos = EndPos}]} ->
Msg = io_lib:format("block starting at ~p ends at ~p instead of EOF",
[FilePos, EndPos]),
{error, #gsc_err{atom = bad_file,
{error, #sfc_err{atom = bad_file,
string = Msg}};
Nyi ->
{error, #gsc_err{atom = bad_file_nyi, extra = Nyi}}
{error, #sfc_err{atom = bad_file_nyi, extra = Nyi}}
end.
@@ -174,7 +174,7 @@ gulp_file(FileTokens = [#gsc_token{pos = FilePos} | _]) ->
% file = block(top_decl)
gulp_full_file(BlockTokens) ->
ItemChunks = gsc_token_chunks:unsafe_block_to_items(BlockTokens),
ItemChunks = sfc_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 = gsc_token_chunks:start_pos(DeclTokens),
NewErr = #gsc_err{atom = bad_top_decl,
ErrPos = sfc_token_chunks:start_pos(DeclTokens),
NewErr = #sfc_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, #gsc_err{atom = many,
{error, #sfc_err{atom = many,
extra = Errs}}.
+13 -13
View File
@@ -1,5 +1,5 @@
% @doc
% type for a GSC AST
% type for a SFC AST
%
% based on so_syntax.erl
%
@@ -56,7 +56,7 @@
% Domain ::= Type // Single argument
% | '(' Sep(Type, ',') ')' // Multiple arguments
% ```
-module(gsc_ast).
-module(sfc_ast).
%-compile([export_all,nowarn_export_all]).
%
@@ -71,10 +71,10 @@
% gulp_file/1
%]).
%
%-include("$gsc_include/gsc.hrl").
%-include("$sfc_include/sfc.hrl").
%
%%%-----------------------------
%%% TYPES: gsc_ast
%%% TYPES: sfc_ast
%%%-----------------------------
%
%
@@ -196,13 +196,13 @@
%gulp_file([]) ->
% {error, empty_file};
%gulp_file(Tokens) ->
% case gsc_tokens:take_block(Tokens) of
% case sfc_tokens:take_block(Tokens) of
% {Tokens, []} ->
% gulp_block(fun gulp_top_decl/1, Tokens);
% %gulp_file2([], [], Tokens);
% {A, B} ->
% StartPos = gsc_tokens:start_pos(A),
% ErrPos = gsc_tokens:start_pos(B),
% StartPos = sfc_tokens:start_pos(A),
% ErrPos = sfc_tokens:start_pos(B),
% Msg = efmt("gulp_file: block starting at ~p ends at ~p instead of EOF",
% [StartPos, ErrPos]),
% {error, #parse_error{pos = ErrPos, msg = Msg}}
@@ -212,7 +212,7 @@
%
%%gulp_file2(AccOks, AccErrs, Tokens = [_ | _]) ->
%% % ItemTokens will be nonempty
%% {ItemTokens, NewTokens} = gsc_tokens:take_block_item(Tokens),
%% {ItemTokens, NewTokens} = sfc_tokens:take_block_item(Tokens),
%% case gulp_top_decl(ItemTokens) of
%% {gulp, Ok} -> gulp_file2([Ok | AccOks], AccErrs, NewTokens);
%% Err -> gulp_file2(AccOks, [Err | AccErrs], NewTokens)
@@ -258,7 +258,7 @@
%
%gulp_block(GulpItem, AccOks, AccErrs, Tokens = [_ | _]) ->
% % ItemTokens will be nonempty
% {ItemTokens, NewTokens} = gsc_tokens:take_block_item(Tokens),
% {ItemTokens, NewTokens} = sfc_tokens:take_block_item(Tokens),
% case GulpItem(ItemTokens) of
% {gulp, Ok} -> gulp_block(GulpItem, [Ok | AccOks], AccErrs, NewTokens);
% Err -> gulp_block(GulpItem, AccOks, [Err | AccErrs], NewTokens)
@@ -284,7 +284,7 @@
%% | Using
%% @end
%gulp_top_decl(DeclTokens) ->
% case gsc_tokens:strings(3, DeclTokens) of
% case sfc_tokens:strings(3, DeclTokens) of
% ["payable", "contract", "interface"] ->
% gulp_nyi(DeclTokens);
% ["contract", "interface" | _] ->
@@ -410,7 +410,7 @@
%% | (EModifier* 'entrypoint' | FModifier* 'function') Block(FunDecl)
%% | Using
%gulp_decl(Tokens) ->
% case gsc_tokens:strings(1, Tokens) of
% case sfc_tokens:strings(1, Tokens) of
% ["type"] -> gulp_type_alias(Tokens);
% _ -> gulp_nyi(Tokens)
% end.
@@ -611,7 +611,7 @@
%% Type1 = {plist, Types} () (foo) (foo, bar)
%% | {token, #tk{}} foo Bar.baz 'quux
%slurp_type1(Tks) ->
% case gsc_tokens:slurp_plist(Tks) of
% case sfc_tokens:slurp_plist(Tks) of
% % head token is NOT open paren -> must be id/qid/tvar
% {slurp, [], [Tk | NewTks]} ->
% TkType = Tk#tk.type,
@@ -633,7 +633,7 @@
%
%
%%slurp_type_expr_plist(Tks) ->
%% case gsc_tokens:slurp_plist(Tks) of
%% case sfc_tokens:slurp_plist(Tks) of
%% % head token is NOT open paren -> must be id/qid/tvar
%% {slurp, [], [Tk | NewTks]} ->
%% TkType = Tk#tk.type,
+3 -3
View File
@@ -1,5 +1,5 @@
% @doc
% gsc_bst = ast second attempt but prefix so tab complete
% sfc_bst = ast second attempt but prefix so tab complete
%
% from docs/sophia/so_syntax.md:
%
@@ -38,10 +38,10 @@
% FModifier ::= 'stateful' | 'private'
%
% Args ::= '(' Sep(Pattern, ',') ')'
-module(gsc_bst).
-module(sfc_bst).
-compile([export_all, nowarn_export_all]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
%-record(bst_nyi, {tokens :: [tk()]).
%
+2 -2
View File
@@ -17,7 +17,7 @@ do_tests(List) ->
run_test(TestName) ->
% we have two candidate atoms
C1 = list_to_atom(TestName),
C2 = list_to_atom("gsc_test_" ++ TestName),
C2 = list_to_atom("sfc_test_" ++ TestName),
KnownMods = test_mods(),
IsC1 = lists:member(C1, KnownMods),
IsC2 = lists:member(C2, KnownMods),
@@ -44,7 +44,7 @@ rmm(X) -> run_mod_main(X).
test_mods() ->
known_modules_with_prefix("gsc_test").
known_modules_with_prefix("sfc_test").
known_modules_with_prefix(Pfx) ->
ModsZipBeamsZipLoaded = code:all_available(),
+5 -5
View File
@@ -1,4 +1,4 @@
-module(gsc_parse_type_expr).
-module(sfc_parse_type_expr).
%
%-export_type([
%]).
@@ -9,7 +9,7 @@
% take_until_ifx_op/1
%]).
%
%-include("$gsc_include/gsc.hrl").
%-include("$sfc_include/sfc.hrl").
%
%
%%------------------------------------------------------
@@ -43,7 +43,7 @@
%
%% @doc for testing
%unsafe_vtks_from_string(S) ->
% {ok, SigTks} = gsc_tokens:significant_tokens(S),
% {ok, SigTks} = sfc_tokens:significant_tokens(S),
% {gulp, Vtks} = gulp_vtks(SigTks),
% Vtks.
%
@@ -110,7 +110,7 @@
% end.
%
%slurp_plist_rec(Tokens = [#tk{string = "(" | _]) ->
% case gsc_tokens:slurp_plist(Tokens) of
% case sfc_tokens:slurp_plist(Tokens) of
% {slurp, [], _} ->
% barf;
% {slurp, PTokens, NewTokens} ->
@@ -156,7 +156,7 @@
% {_Pfx = Tks1_BeforeOpen,
% _Sfx = Tks2_OpenNAfter
% = [#tk{string = "("} | _]} ->
% case gsc_tokens:slurp_plist(Tks2_OpenNAfter) of
% case sfc_tokens:slurp_plist(Tks2_OpenNAfter) of
% {slurp, Tks2A_OpenToClose, Tks2B_AfterClose} ->
% NewAcc = [Acc,
% Tks1_BeforeOpen,
+20 -20
View File
@@ -4,7 +4,7 @@
%
% generally assume no whitespace/comment tokens in
% input stream
-module(gsc_token_chunks).
-module(sfc_token_chunks).
%-export_type([
% chunk_shape/0,
@@ -19,8 +19,8 @@
% end_pos/1
%]).
%
%% $gsc_include is so c() works from sfp eshell
%-include("$gsc_include/gsc.hrl").
%% $sfc_include is so c() works from sfp eshell
%-include("$sfc_include/sfc.hrl").
%
%%------------------------------------------
%% Types
@@ -45,25 +45,25 @@
%
%take(block, []) ->
% {[], []};
%take(block, [Hd = #gsc_token{pos = {_, BCol}} | Tl]) ->
% tw(fun(#gsc_token{pos = {_, TkCol}}) -> BCol =< TkCol end, [Hd], Tl);
%take(block, [Hd = #sfc_token{pos = {_, BCol}} | Tl]) ->
% tw(fun(#sfc_token{pos = {_, TkCol}}) -> BCol =< TkCol end, [Hd], Tl);
%take(block_item, []) ->
% {[], []};
%take(block_item, [Hd = #gsc_token{pos = {_, ICol}} | Tl]) ->
% tw(fun(#gsc_token{pos = {_, TkCol}}) -> ICol < TkCol end, Tl).
%take(block_item, [Hd = #sfc_token{pos = {_, ICol}} | Tl]) ->
% tw(fun(#sfc_token{pos = {_, TkCol}}) -> ICol < TkCol end, Tl).
%
%
%
%-spec start_pos([gsc_token()]) -> {value, tk_pos()} | none.
%-spec start_pos([sfc_token()]) -> {value, tk_pos()} | none.
%
%start_pos([#gsc_token{pos = P}]) -> {value, P};
%start_pos([#sfc_token{pos = P}]) -> {value, P};
%start_pos([]) -> none.
%
%
%-spec end_pos([gsc_token()]) -> {value, tk_pos()} | none.
%-spec end_pos([sfc_token()]) -> {value, tk_pos()} | none.
%
%end_pos([#gsc_token{pos = Pos, string = Str}]) ->
% {value, gsc_tokens:new_pos(Pos, Str)};
%end_pos([#sfc_token{pos = Pos, string = Str}]) ->
% {value, sfc_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 :: gsc_token().
% Token :: sfc_token().
%
%% @doc
%% slurp/barf terminology comes from paredit mode in
@@ -93,23 +93,23 @@
%
%barf(_, []) ->
% {barf, [], []};
%barf(block, [H = #gsc_token{pos = {_, BlkCol}} | T]) ->
%barf(block, [H = #sfc_token{pos = {_, BlkCol}} | T]) ->
% Take =
% fun(#gsc_token{pos = {_, TkCol}}) ->
% fun(#sfc_token{pos = {_, TkCol}}) ->
% BlkCol =< TkCol
% end,
% {A, B} = tw(Take, T),
% {barf, [H | A], B};
%barf(block_item, [H = #gsc_token{pos = {_, BlkCol}} | T]) ->
%barf(block_item, [H = #sfc_token{pos = {_, BlkCol}} | T]) ->
% Take =
% fun(#gsc_token{pos = {_, TkCol}}) ->
% fun(#sfc_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 = [#gsc_token{pos = {_, StartLevel}} | _]) ->
%barf({block_item, Level}, Tokens = [#sfc_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, #gsc_err_nyi{}}.
% {choke, #sfc_err_nyi{}}.
%
%
%
@@ -132,7 +132,7 @@
%
%
%-spec unsafe_block_to_items([Token]) -> [[Token]]
% when Token :: gsc_token().
% when Token :: sfc_token().
%
%% @doc
%% PITFALL: this ASSUMES that the given list of tokens has the
+5 -5
View File
@@ -42,13 +42,13 @@
% qid : Foo.Bar.baz
% tvar : 'a
-record(ast_te_name,
{name = none :: none | gsc_token()}).
{name = none :: none | sfc_token()}).
% @doc
% placeholder
-record(ast_te_nyi,
{tokens = none :: none | [gsc_token()]}).
{tokens = none :: none | [sfc_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, gsc_token()},
op_token = none :: none | {value, sfc_token()},
right = none :: none | [ifx_tree_()]}).
-record(ifx_stem_plist,
{items :: [any()]}).
-record(ifx_leaf_idtk,
{token :: gsc_token()}).
{token :: sfc_token()}).
-type ifx_tree()
:: #ifx_stem_op{}
@@ -80,7 +80,7 @@
-spec slurp_ifx_tree(Tokens) -> SlurpedIfxTree when
Tokens :: [gsc_token()],
Tokens :: [sfc_token()],
SlurpedIfxNode :: slurped(ifx_tree()).
slurp_ifx_tree(Tokens) ->
+11 -11
View File
@@ -1,17 +1,17 @@
-spec mktree(Signal) -> Tree when
Signal :: gsc:signal(),
Tree :: gsc_ntree:ntree().
Signal :: sfc:signal(),
Tree :: sfc_ntree:ntree().
% @doc make into a tree
mktree(Sig) ->
Tree0 = gsc_ntree:nstem(vtokens, Sig),
Tree0 = sfc_ntree:nstem(vtokens, Sig),
Tree1 = rerootl_tkstr("=>", Tree0),
Tree2 = rerootl_tkstr("*", Tree1),
Tree2.
rerootl_tkstr(S, Tree0 = #ns{val = Root0}) ->
Kids0 = gsc_ntree:deleaf0(Tree0),
Kids0 = sfc_ntree:deleaf0(Tree0),
IsntS = fun(Tk) -> isnt_str(S, Tk) end,
case lists:splitwith(IsntS, Kids0) of
% found
@@ -28,11 +28,11 @@ rerootl_tkstr(S, Tree0 = #ns{val = Root0}) ->
% +-- *s Root0 -- .l Bar
{LHS1, [Tk0 | RHS1]} ->
Root1 = Root0,
LTree1 = gsc_ntree:releaf0(Root1, LHS1),
RTree1 = rerootl_tkstr(S, gsc_ntree:releaf0(Root1, RHS1)),
LTree1 = sfc_ntree:releaf0(Root1, LHS1),
RTree1 = rerootl_tkstr(S, sfc_ntree:releaf0(Root1, RHS1)),
NewRoot0 = {op, Tk0},
NewKids0 = [LTree1, RTree1],
NewTree = gsc_ntree:releaf0(NewRoot0, NewKids0),
NewTree = sfc_ntree:releaf0(NewRoot0, NewKids0),
NewTree;
% not found, nothing to do
{Kids0, []} ->
@@ -41,17 +41,17 @@ rerootl_tkstr(S, Tree0 = #ns{val = Root0}) ->
%reroot_mapsto(Tree0 = #ns{val = Root0}) ->
% Kids0 = gsc_ntree:deleaf0(Tree0),
% Kids0 = sfc_ntree:deleaf0(Tree0),
% IsntMapsto = fun(DL) -> isnt_str("=>", Tk) end,
% case lists:splitwith(IsntMapsto, Kids0) of
% % found
% {LHS1, [Tk0 | RHS1]} ->
% Root1 = Root0,
% LTree1 = gsc_ntree:releaf0(Root1, LHS1),
% RTree1 = reroot_mapsto(gsc_ntree:releaf0(Root1, RHS1)),
% LTree1 = sfc_ntree:releaf0(Root1, LHS1),
% RTree1 = reroot_mapsto(sfc_ntree:releaf0(Root1, RHS1)),
% NewRoot0 = {op, Tk0},
% NewKids0 = [LTree1, RTree1],
% NewTree = gsc_ntree:releaf0(NewRoot0, NewKids0),
% NewTree = sfc_ntree:releaf0(NewRoot0, NewKids0),
% NewTree;
% % nothing to do
% {Kids0, []} ->