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
+2 -2
View File
@@ -10,8 +10,8 @@
# TODONE
- undo gs_ naming fuckery.. everything is `gsc_*`. it's just
needlessly confusing. for now let's name new things gsc_* and then
- undo gs_ naming fuckery.. everything is `sfc_*`. it's just
needlessly confusing. for now let's name new things sfc_* and then
go back and undo the stupidity
# TODONT
+3 -3
View File
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
# Bash harness for GSC command line tool
# Bash harness for sfc command line tool
#
# based on similar harness for sfp
#
# gsc foo bar baz
# -> zx rundir /home/pharpend/src/ioecs/gsc \
# sfc foo bar baz
# -> zx rundir /home/pharpend/src/ioecs/sfc \
# foo bar baz
zx_exists() {
-11
View File
@@ -1,11 +0,0 @@
{application,gsc,
[{description,"Exploratory sophia compiler rewrite"},
{registered,[]},
{included_applications,[]},
{applications,[stdlib,kernel]},
{vsn,"0.1.0"},
{modules,['ast-gulp',gsc_ast,gsc_bst,gsc_parse_type_expr,
gsc_token_chunks,ifarith,parse_type_expr,test_ntree,
unicode,gsc,gsc_cli,gsc_ntree,gsc_signal,gsc_strmatch,
gsc_tokens,gso_scan,gsc_test_file,gsc_test_ntree,
gsc_test_tokens,ts_utils]}]}.
+11
View File
@@ -0,0 +1,11 @@
{application,sfc,
[{description,"Exploratory sophia compiler rewrite"},
{registered,[]},
{included_applications,[]},
{applications,[stdlib,kernel]},
{vsn,"0.1.0"},
{modules,['ast-gulp',sfc_ast,sfc_bst,sfc_parse_type_expr,
sfc_token_chunks,ifarith,parse_type_expr,test_ntree,
unicode,sfc,sfc_cli,sfc_ntree,sfc_signal,sfc_strmatch,
sfc_tokens,gso_scan,sfc_test_file,sfc_test_ntree,
sfc_test_tokens,ts_utils]}]}.
+19 -19
View File
@@ -1,8 +1,8 @@
% This is a header file that contains gsc's record types
% This is a header file that contains sfc's record types
%
% This is in order to
% 1. share records across modules; and,
% 2. allow external modules to just use the gsc records
% 2. allow external modules to just use the sfc records
-type tk_shape()
:: bcom % /* ... */
@@ -83,13 +83,13 @@
% lists = (_, _, _)
% | [_, _, _]
% | {_, _, _}
%-record(gsc_ast1_block,
%-record(sfc_ast1_block,
% {indent = none :: none | pos_integer(),
% decls = none :: [gsc_ast1_decl()]}).
% decls = none :: [sfc_ast1_decl()]}).
%
%-type gsc_ast() ::
%-type sfc_ast() ::
%
%-type gsc_list_group() :: {'(', [tk()], ')'}
%-type sfc_list_group() :: {'(', [tk()], ')'}
% | {'[', [tk()], ']'}
% | {'{', [tk()], '}'}
% | {proof,
@@ -102,47 +102,47 @@
% record type: unterminated block comments at the end
% of files. these are ok in legacy sophia, so we have to
% specifically account for this error
-record(gsc_err_bcom_unterminated,
-record(sfc_err_bcom_unterminated,
{prev_tokens :: [tk()],
break_pos :: tk_pos(),
rest :: string()}).
-record(gsc_err_no_tokmatch,
-record(sfc_err_no_tokmatch,
{prev_tokens :: [tk()],
break_pos :: tk_pos(),
rest :: string()}).
-record(gsc_err_delims,
-record(sfc_err_delims,
{past :: [tk()],
open_stack :: [tk()],
bad_close :: tk(),
future :: [tk()]}).
% FIXME
-record(gsc_err_nyi, {}).
-record(gsc_err_empty_file, {}).
-record(sfc_err_nyi, {}).
-record(sfc_err_empty_file, {}).
%-record(src_parse_error,
% {atom = none :: none | atom(),
% string =
%j-record(gsc_err_gulp_ct,
%j-record(sfc_err_gulp_ct,
%j {gulped ::
% @doc
% generic placeholder error for now
-record(gsc_err,
-record(sfc_err,
{atom :: atom(),
str = none :: none | iolist(),
extra = none :: none | any()}).
% @doc all errors GSC can return conveniently listed in
% @doc all errors SFC can return conveniently listed in
% one place
-type gsc_err() :: #gsc_err_bcom_unterminated{}
| #gsc_err_no_tokmatch{}
| #gsc_err_nyi{}
| #gsc_err_empty_file{}
| #gsc_err{}.
-type sfc_err() :: #sfc_err_bcom_unterminated{}
| #sfc_err_no_tokmatch{}
| #sfc_err_nyi{}
| #sfc_err_empty_file{}
| #sfc_err{}.
%----------------------------
+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, []} ->
+13 -13
View File
@@ -7,7 +7,7 @@
% 0.1 is to match behavior exactly
% @end
-module(gsc).
-module(sfc).
% token and tokens
-export_type([
@@ -45,7 +45,7 @@
very_stable_file/1
]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
%-----------------------------------------
% types
@@ -85,20 +85,20 @@ unsafe_signal_from_string(S) ->
%
filter_signal(X) -> gsc_tokens:filter_significant(X).
filter_signal(X) -> sfc_tokens:filter_significant(X).
signal_from_file(X) -> sigtokens_from_file(X).
signal_from_string(X) -> sigtokens_from_string(X).
% @doc legacy name for signal
sigtokens_from_file(X) ->
case tokens_from_file(X) of
{ok, Y} -> {ok, gsc_tokens:filter_significant(Y)};
{ok, Y} -> {ok, sfc_tokens:filter_significant(Y)};
Err -> Err
end.
sigtokens_from_string(X) ->
case tokens_from_string(X) of
{ok, Y} -> {ok, gsc_tokens:filter_significant(Y)};
{ok, Y} -> {ok, sfc_tokens:filter_significant(Y)};
Err -> Err
end.
@@ -106,7 +106,7 @@ sigtokens_from_string(X) ->
-spec tokens_from_file(FilePath) -> Perhaps
when FilePath :: string(),
Perhaps :: {ok, Tokens}
| {error, gsc_err() | any()},
| {error, sfc_err() | any()},
Tokens :: [tk()].
tokens_from_file(FilePath) ->
@@ -120,11 +120,11 @@ tokens_from_file(FilePath) ->
-spec tokens_from_string(SrcStr) -> Result
when SrcStr :: string(),
Result :: {ok, Tokens}
| {error, gsc_err()},
| {error, sfc_err()},
Tokens :: [tk()].
tokens_from_string(SrcStr) ->
gsc_tokens:tokens(SrcStr).
sfc_tokens:tokens(SrcStr).
@@ -132,7 +132,7 @@ tokens_from_string(SrcStr) ->
FilePath :: string(),
Result :: {ok, GsoTks} | {error, Reason},
GsoTks :: [gso_scan:so_token()],
Reason :: gsc_err() | any().
Reason :: sfc_err() | any().
gso_tokens_from_file(FilePath) ->
case file:read_file(FilePath) of
@@ -146,10 +146,10 @@ gso_tokens_from_file(FilePath) ->
Str :: iolist(),
Result :: {ok, GsoTks} | {error, Reason},
GsoTks :: [gso_scan:so_token()],
Reason :: gsc_err() | any().
Reason :: sfc_err() | any().
gso_tokens_from_string(Evil) ->
Str = gsc_tokens:very_stable_codepoints(Evil),
Str = sfc_tokens:very_stable_codepoints(Evil),
gso_scan:scan(Str).
@@ -161,7 +161,7 @@ gso_tokens_from_string(Evil) ->
%% @doc normalize string to utf8 NFC list form
very_stable_codepoints(X) ->
gsc_tokens:very_stable_codepoints(X).
sfc_tokens:very_stable_codepoints(X).
@@ -171,7 +171,7 @@ very_stable_codepoints(X) ->
%% @doc alias for `very_stable_codepoints/1'
very_stable_string(X) ->
gsc_tokens:very_stable_codepoints(X).
sfc_tokens:very_stable_codepoints(X).
+29 -29
View File
@@ -1,8 +1,8 @@
%%% @doc
%%% GSC CLI: explorer/harness for gsc iteration
%%% SFC CLI: explorer/harness for sfc iteration
%%% @end
-module(gsc_cli).
-module(sfc_cli).
-vsn("0.1.0").
-author("Peter Harpending <peterharpending@qpq.swiss>").
-copyright("Peter Harpending <peterharpending@qpq.swiss>").
@@ -15,7 +15,7 @@
-export([start/1]).
-export([do_help/0]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
-include("ansi.hrl").
do_help() ->
@@ -23,14 +23,14 @@ do_help() ->
help_screen() ->
"""
Usage: gsc <command> [args]
Usage: sfc <command> [args]
COMMANDS
(no args)
shell
eshell
Start an Erlang shell with GSC loaded.
Start an Erlang shell with SFC loaded.
tokens <file>
Print GSC tokens from <file>, one per line.
Print SFC tokens from <file>, one per line.
tokens -c <file>
tokens --color <file>
tcat <file>
@@ -43,30 +43,30 @@ help_screen() ->
Print sophia-compatible (so_scan) tokens from <file>,
one per line.
rmm <file>
Compile <file> and call its main/0 with GSC context loaded.
Compile <file> and call its main/0 with SFC context loaded.
Useful for running scratch scripts.
TEST HARNESS (gsc test ...)
gsc test -l
gsc test --list
TEST HARNESS (sfc test ...)
sfc test -l
sfc test --list
List available named tests.
gsc test -a
gsc test --all
sfc test -a
sfc test --all
Run all named tests.
gsc test so tokens <file>
gsc test so_tokens <file>
sfc test so tokens <file>
sfc test so_tokens <file>
Print sophia-original (so_scan) tokens from <file>,
one per line.
gsc test tokenizers_agree <file>
Check whether gsc and so_scan produce identical tokens
sfc test tokenizers_agree <file>
Check whether sfc and so_scan produce identical tokens
for <file>. Prints 'true' or 'false'.
<file> is resolved relative to cwd.
Example:
gsc test tokenizers_agree foo.aes
gsc test <name>
Run a named test module. 'gsc test foo' and
'gsc test gsc_test_foo' are equivalent.
Use 'gsc test --list' to see available names.
sfc test tokenizers_agree foo.aes
sfc test <name>
Run a named test module. 'sfc test foo' and
'sfc test sfc_test_foo' are equivalent.
Use 'sfc test --list' to see available names.
""".
@@ -89,7 +89,7 @@ start(ArgV) ->
do(["test" | Tests]) ->
do_test(Tests);
% slowly phasing out shitty names like lctokens
% tokens = native gsc token representation
% tokens = native sfc token representation
do(["tokens", Foo]) -> do_tokens(Foo);
% print source file to screen with token boundaries
% highlighted
@@ -119,12 +119,12 @@ do_doi() ->
do_test(Args) ->
GscTestsMod = gsc_tests_mod(),
GscTestsMod:cli_args(Args).
SfcTestsMod = sfc_tests_mod(),
SfcTestsMod:cli_args(Args).
gsc_tests_mod() ->
FilePath = zx:get_home() ++ "/test/gsc_tests.erl",
sfc_tests_mod() ->
FilePath = zx:get_home() ++ "/test/sfc_tests.erl",
case compile:file(FilePath) of
{ok, Mod} -> Mod;
Error -> error(Error)
@@ -164,7 +164,7 @@ less_file(Less, FilePath) ->
% @doc start an erlang shell
do_eshell() ->
io:format("Welcome to the GSC shell!~n", []),
io:format("Welcome to the SFC shell!~n", []),
case shell:start_interactive() of
ok -> ok;
{error, already_started} -> ok;
@@ -197,12 +197,12 @@ gso_tokens(FilePath) ->
tokens(FilePath) ->
{ok, Tokens} = gsc:tokens_from_file(FilePath),
{ok, Tokens} = sfc:tokens_from_file(FilePath),
Tokens.
do_color_tokens(File) ->
case gsc:tokens_from_file(File) of
case sfc:tokens_from_file(File) of
{ok, Tokens} ->
ColorizedSrcStr = colorize_tokens(chunk_color_wheel(), Tokens, ""),
Full = [?ANSI_INVERT, ColorizedSrcStr, ?ANSI_UNINVERT],
+2 -2
View File
@@ -1,4 +1,4 @@
-module(gsc_ntree).
-module(sfc_ntree).
-export([
nstem/2, meta/1, kids/1,
@@ -6,7 +6,7 @@
]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
%%=====================================================
+3 -3
View File
@@ -1,5 +1,5 @@
% signal = non-noisy tokens
-module(gsc_signal).
-module(sfc_signal).
-export([
from_tokens/1,
@@ -9,7 +9,7 @@
take_block_item/1
]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
-spec from_tokens(Tokens) -> Signal when
@@ -18,7 +18,7 @@
% @doc filter out comments/whitespace
from_tokens(Tokens) ->
gsc_tokens:filter_significant(Tokens).
sfc_tokens:filter_significant(Tokens).
@@ -65,12 +65,12 @@
% KW = string:join(Keywords, "|"),
%
% There is a lot going on in that code. This is purely the part that matches
% strings specifically, . The *tokenizer* (gsc_tokenizer) knows the hierarchy
% strings specifically, . The *tokenizer* (sfc_tokenizer) knows the hierarchy
% of sophia tokens (e.g. it knows to match keywords before identifiers, so that
% `contract` gets tokenized as a keyword and not a variable name), and then
% calls into this module in order to match the string shape it's looking for.
% @end
-module(gsc_strmatch).
-module(sfc_strmatch).
%-compile([export_all, nowarn_export_all]).
+35 -35
View File
@@ -7,16 +7,16 @@
% For MVP it mimics the behavior of so_scan exactly, in terms of like what its
% definition of a token is and so on.
%
% gsc_so_scan.erl contains a compatibility layer that should agree with so_scan
% sfc_so_scan.erl contains a compatibility layer that should agree with so_scan
% exactly. It converts the data types here to the shapes that so_scan outputs.
%
% This is for two reasons:
%
% 1. in order to enable testing the two modules against each other, and
% 2. to future-proof in case we decide to incrementally incorporate the gsc
% 2. to future-proof in case we decide to incrementally incorporate the sfc
% code into the legacy sophia compiler
% @end
-module(gsc_tokens).
-module(sfc_tokens).
% meta
-export([
@@ -51,7 +51,7 @@
new_pos/2
]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
%=======================================================
@@ -316,7 +316,7 @@ indent_level(#tk{pos = {_, IndentLevel}}) ->
-spec significant_tokens(SrcStr) -> Result
when SrcStr :: iolist(),
Result :: {ok, Tokens}
| {error, gsc_err()},
| {error, sfc_err()},
Tokens :: [tk()].
significant_tokens(SrcStr) ->
@@ -373,7 +373,7 @@ very_stable_codepoints(S) ->
-spec tokens_from_iolist(SrcStr) -> Result when
SrcStr :: iolist(),
Result :: {ok, Tokens}
| {error, gsc_err()},
| {error, sfc_err()},
Tokens :: [tk()].
%% @equiv `tokens/1'
@@ -383,7 +383,7 @@ tokens_from_iolist(S) -> tokens(S).
-spec tokens_from_string(SrcStr) -> Result when
SrcStr :: iolist(),
Result :: {ok, Tokens}
| {error, gsc_err()},
| {error, sfc_err()},
Tokens :: [tk()].
%% @equiv `tokens/1'
@@ -395,7 +395,7 @@ tokens_from_string(S) -> tokens(S).
-spec tokens(SrcStr) -> Result
when SrcStr :: iolist(),
Result :: {ok, Tokens}
| {error, gsc_err()},
| {error, sfc_err()},
Tokens :: [tk()].
% @doc
% Recursively parse all tokens off the front end of the
@@ -416,7 +416,7 @@ tokens(Stack, Pos, SrcStr) ->
tokens([NewToken | Stack], NewPos, NewSrcStr);
no_tokmatch ->
PrevTokens = lists:reverse(Stack),
Err = #gsc_err_no_tokmatch{prev_tokens = PrevTokens,
Err = #sfc_err_no_tokmatch{prev_tokens = PrevTokens,
break_pos = Pos,
rest = SrcStr},
{error, Err};
@@ -428,7 +428,7 @@ tokens(Stack, Pos, SrcStr) ->
% for now we're just going to agree with so_scan
{ierr, unterminated_block_comment} ->
PrevTokens = lists:reverse(Stack),
Err = #gsc_err_bcom_unterminated{prev_tokens = PrevTokens,
Err = #sfc_err_bcom_unterminated{prev_tokens = PrevTokens,
break_pos = Pos,
rest = SrcStr},
{error, Err};
@@ -520,7 +520,7 @@ next_tabstop8(Col0) when Col0 >= 0 ->
SrcStr :: string(),
Result :: {tokmatch, Token, Rest}
| no_tokmatch
| {error, gsc_err()}
| {error, sfc_err()}
| {ierr, unterminated_block_comment},
Token :: tk(),
Rest :: string().
@@ -540,7 +540,7 @@ slurp_token(Pos, SrcStr) ->
SrcStr :: string(),
Result :: {tokmatch, Token, Rest}
| no_tokmatch
| {error, gsc_err()}
| {error, sfc_err()}
| {ierr, unterminated_block_comment},
Token :: tk(),
Rest :: string().
@@ -565,7 +565,7 @@ slurp_token_shapes([], _Pos, _SrcStr) ->
SrcStr :: string(),
MaybeToken :: {tokmatch, Token, Rest}
| no_tokmatch
| {error, gsc_err()}
| {error, sfc_err()}
| {ierr, unterminated_block_comment},
Token :: tk(),
Rest :: string().
@@ -608,8 +608,8 @@ slurp_token_of_shape(bcom, Pos, SrcStr0) ->
no_tokmatch
end;
slurp_token_of_shape(ws, Pos, SrcStr) ->
WhitespaceMatcher = gsc_strmatch:smr_sf_ws(),
case gsc_strmatch:match(WhitespaceMatcher, SrcStr) of
WhitespaceMatcher = sfc_strmatch:smr_sf_ws(),
case sfc_strmatch:match(WhitespaceMatcher, SrcStr) of
no_strmatch ->
no_tokmatch;
{strmatch, WS, Rest} ->
@@ -643,7 +643,7 @@ slurp_token_of_shape(kwd, Pos, SrcStr) ->
no_tokmatch
end;
slurp_token_of_shape(op, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_op(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_op(), SrcStr) of
{strmatch, Str, Rest} ->
Token = #tk{shape = op, pos = Pos, str = Str},
{tokmatch, Token, Rest};
@@ -651,7 +651,7 @@ slurp_token_of_shape(op, Pos, SrcStr) ->
no_tokmatch
end;
slurp_token_of_shape(sep, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_sep(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_sep(), SrcStr) of
{strmatch, Str, Rest} ->
Token = #tk{shape = sep, pos = Pos, str = Str},
{tokmatch, Token, Rest};
@@ -660,7 +660,7 @@ slurp_token_of_shape(sep, Pos, SrcStr) ->
end;
% SOPHIA VARIABLE NAMES: id, con, qid, qcon, tvar
slurp_token_of_shape(id, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_id(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_id(), SrcStr) of
{strmatch, IdStr, Rest} ->
Token = #tk{shape = id, pos = Pos, str = IdStr},
{tokmatch, Token, Rest};
@@ -668,7 +668,7 @@ slurp_token_of_shape(id, Pos, SrcStr) ->
no_tokmatch
end;
slurp_token_of_shape(con, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_con(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_con(), SrcStr) of
{strmatch, Str, Rest} ->
Token = #tk{shape = con, pos = Pos, str = Str},
{tokmatch, Token, Rest};
@@ -676,7 +676,7 @@ slurp_token_of_shape(con, Pos, SrcStr) ->
no_tokmatch
end;
slurp_token_of_shape(qid, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_qid(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_qid(), SrcStr) of
{strmatch, Str, Rest} ->
Token = #tk{shape = qid, pos = Pos, str = Str},
{tokmatch, Token, Rest};
@@ -684,7 +684,7 @@ slurp_token_of_shape(qid, Pos, SrcStr) ->
no_tokmatch
end;
slurp_token_of_shape(qcon, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_qcon(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_qcon(), SrcStr) of
{strmatch, Str, Rest} ->
Token = #tk{shape = qcon, pos = Pos, str = Str},
{tokmatch, Token, Rest};
@@ -692,7 +692,7 @@ slurp_token_of_shape(qcon, Pos, SrcStr) ->
no_tokmatch
end;
slurp_token_of_shape(tvar, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_tvar(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_tvar(), SrcStr) of
{strmatch, Str, Rest} ->
Token = #tk{shape = tvar, pos = Pos, str = Str},
{tokmatch, Token, Rest};
@@ -700,7 +700,7 @@ slurp_token_of_shape(tvar, Pos, SrcStr) ->
no_tokmatch
end;
slurp_token_of_shape(int16, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_int16(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_int16(), SrcStr) of
{strmatch, Str, Rest} ->
Token = #tk{shape = int16, pos = Pos, str = Str},
{tokmatch, Token, Rest};
@@ -708,7 +708,7 @@ slurp_token_of_shape(int16, Pos, SrcStr) ->
no_tokmatch
end;
slurp_token_of_shape(int10, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_int10(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_int10(), SrcStr) of
{strmatch, Str, Rest} ->
Token = #tk{shape = int10, pos = Pos, str = Str},
{tokmatch, Token, Rest};
@@ -720,8 +720,8 @@ slurp_token_of_shape(int10, Pos, SrcStr) ->
%
% char: sophia char literal
slurp_token_of_shape(ak, Pos, SrcStr) ->
StringMatcher = gsc_strmatch:smr_sf_ak(),
case gsc_strmatch:match(StringMatcher, SrcStr) of
StringMatcher = sfc_strmatch:smr_sf_ak(),
case sfc_strmatch:match(StringMatcher, SrcStr) of
no_strmatch ->
no_tokmatch;
{strmatch, TokenStr, Rest} ->
@@ -729,8 +729,8 @@ slurp_token_of_shape(ak, Pos, SrcStr) ->
{tokmatch, Token, Rest}
end;
slurp_token_of_shape(ct, Pos, SrcStr) ->
StringMatcher = gsc_strmatch:smr_sf_ct(),
case gsc_strmatch:match(StringMatcher, SrcStr) of
StringMatcher = sfc_strmatch:smr_sf_ct(),
case sfc_strmatch:match(StringMatcher, SrcStr) of
no_strmatch ->
no_tokmatch;
{strmatch, TokenStr, Rest} ->
@@ -738,8 +738,8 @@ slurp_token_of_shape(ct, Pos, SrcStr) ->
{tokmatch, Token, Rest}
end;
slurp_token_of_shape(sg, Pos, SrcStr) ->
StringMatcher = gsc_strmatch:smr_sf_sg(),
case gsc_strmatch:match(StringMatcher, SrcStr) of
StringMatcher = sfc_strmatch:smr_sf_sg(),
case sfc_strmatch:match(StringMatcher, SrcStr) of
no_strmatch ->
no_tokmatch;
{strmatch, TokenStr, Rest} ->
@@ -747,8 +747,8 @@ slurp_token_of_shape(sg, Pos, SrcStr) ->
{tokmatch, Token, Rest}
end;
slurp_token_of_shape(char, Pos, SrcStr) ->
StringMatcher = gsc_strmatch:smr_sf_char(),
case gsc_strmatch:match(StringMatcher, SrcStr) of
StringMatcher = sfc_strmatch:smr_sf_char(),
case sfc_strmatch:match(StringMatcher, SrcStr) of
no_strmatch ->
no_tokmatch;
{strmatch, TokenStr, Rest} ->
@@ -756,7 +756,7 @@ slurp_token_of_shape(char, Pos, SrcStr) ->
{tokmatch, Token, Rest}
end;
slurp_token_of_shape(string, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_str(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_str(), SrcStr) of
no_strmatch ->
no_tokmatch;
{strmatch, TokenStr, Rest} ->
@@ -764,7 +764,7 @@ slurp_token_of_shape(string, Pos, SrcStr) ->
{tokmatch, Token, Rest}
end;
slurp_token_of_shape(bytes, Pos, SrcStr) ->
case gsc_strmatch:match(gsc_strmatch:smr_sf_bytes(), SrcStr) of
case sfc_strmatch:match(sfc_strmatch:smr_sf_bytes(), SrcStr) of
no_strmatch ->
no_tokmatch;
{strmatch, TokenStr, Rest} ->
@@ -773,7 +773,7 @@ slurp_token_of_shape(bytes, Pos, SrcStr) ->
end;
slurp_token_of_shape(NyiType, Pos, SrcStr) ->
Message = io_lib:format("cannot slurp token of shape: ~p", [NyiType]),
error(#gsc_err{atom = nyi,
error(#sfc_err{atom = nyi,
str = Message,
extra = [{token_shape, NyiType},
{pos, Pos},
+19 -19
View File
@@ -1,6 +1,6 @@
% @doc compatibility layer to test against so_scan
%
% converts gsc_tokens data to so_scan tokens
% converts sfc_tokens data to so_scan tokens
%
% Ref: so_scan.erl
-module(gso_scan).
@@ -19,7 +19,7 @@
ken_barson_rises/2
]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
%================================
% API: types
@@ -93,36 +93,36 @@
% API: functions
%================================
-spec scan(SrcStr) -> {ok, SoTokens} | {error, gsc_err()}
-spec scan(SrcStr) -> {ok, SoTokens} | {error, sfc_err()}
when SrcStr :: iolist(),
SoTokens :: [so_token()].
% @doc
% this is meant to agree with so_scan:scan/1 in all cases
%
% this converts gsc's internal representation of tokens into the format that
% this converts sfc's internal representation of tokens into the format that
% so_scan outputs
% @end
scan(SrcStr) ->
case gsc_tokens:tokens(SrcStr) of
case sfc_tokens:tokens(SrcStr) of
{ok, SfLTokens} ->
SoTokens = to_so_tokens(SfLTokens),
{ok, SoTokens};
% fucking stupid
{error, #gsc_err_bcom_unterminated{prev_tokens = GscTokens}} ->
{ok, to_so_tokens(GscTokens)};
{error, #sfc_err_bcom_unterminated{prev_tokens = SfcTokens}} ->
{ok, to_so_tokens(SfcTokens)};
Error ->
Error
end.
-spec to_so_tokens(GscTokens) -> SoTokens
when GscTokens :: [tk()],
-spec to_so_tokens(SfcTokens) -> SoTokens
when SfcTokens :: [tk()],
SoTokens :: [so_token()].
% @doc
% most gsc tokens map 1-to-1 with so_tokens. the
% most sfc tokens map 1-to-1 with so_tokens. the
% exception is ak/ct/sg literals. this is a
% many-to-one-mapping, and therefore ak, sg, ct need to
% be handled at the list level.
@@ -133,7 +133,7 @@ scan(SrcStr) ->
% stage computes the pubkey that corresponds to.
%
% as a result, if we have ak_GHI, I is not a valid
% base58 char, so WE (gsc) end up lexing that as
% base58 char, so WE (sfc) end up lexing that as
%
% [{ak, "ak_GH"}, {con, "I"}]
%
@@ -252,8 +252,8 @@ to_so_tokens([]) ->
%
% When any of these appear AFTER at least one valid
% base58 char in a `ak_`/`ct_`/`sg_` prefixed
% identifier, `gsc` splits what `so_scan` sees as one
% `id` token into 2+ gsc tokens.
% identifier, `sfc` splits what `so_scan` sees as one
% `id` token into 2+ sfc tokens.
%
% **No split if non-base58 char is immediately after
% `_`**: `smr_plus` requires >=1 base58 char to
@@ -309,8 +309,8 @@ pass_types() ->
-spec to_so_token(GscToken) -> MaybeSoToken
when GscToken :: tk(),
-spec to_so_token(SfcToken) -> MaybeSoToken
when SfcToken :: tk(),
MaybeSoToken :: {true, SoToken}
| false,
SoToken :: so_token().
@@ -369,8 +369,8 @@ to_so_token(#tk{shape = SfTokenType,
int10 -> {true, {int, Pos, so_parse_int(SfTokenStr)}};
bytes -> {true, {bytes, Pos, so_parse_bytes(SfTokenStr)}};
NYI ->
Msg = io_lib:format("gsc_so_scan:to_so_token/1: unhandled token shape: ~p", [NYI]),
error(#gsc_err{atom = nyi,
Msg = io_lib:format("sfc_so_scan:to_so_token/1: unhandled token shape: ~p", [NYI]),
error(#sfc_err{atom = nyi,
str = Msg})
end.
@@ -392,7 +392,7 @@ so_parse_char([$' | Chars]) ->
case unicode:characters_to_nfc_list(unescape($', Chars, [])) of
[Char] -> Char;
_Bad ->
error(#gsc_err{atom = bad_token,
error(#sfc_err{atom = bad_token,
str = "Bad character literal: '" ++ Chars})
end.
@@ -434,7 +434,7 @@ unescape(Delim, [$\\, Code | Chars], Acc) ->
$r -> Ok($\r);
$t -> Ok($\t);
$v -> Ok($\v);
_ -> error(#gsc_err{atom = bad_escape_char,
_ -> error(#sfc_err{atom = bad_escape_char,
str = "Bad control sequence: \\" ++ [Code]}) %% TODO
end;
unescape(Delim, [C | Chars], Acc) ->
@@ -1,11 +1,11 @@
% @doc experiment centering around the file syntax node using ntree approach
-module(gsc_test_file).
-module(sfc_test_file).
-export([
main/0
]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
-record(ct,
@@ -64,7 +64,7 @@ main() ->
HelloN = "hello.aes",
HelloP = ts_utils:ct_file_abspath(HelloN),
{ok, HelloS} = file:read_file(HelloP),
S0 = gsc:unsafe_signal_from_file(HelloP),
S0 = sfc:unsafe_signal_from_file(HelloP),
T1 = s2t(file, S0),
io:format("hello.aes:~n", []),
io:format("```~n", []),
@@ -103,7 +103,7 @@ s2t(file, Signal) ->
% | Using
s2t(top_decl, Signal) ->
NewTarget =
case gsc_tokens:strings(3, Signal) of
case sfc_tokens:strings(3, Signal) of
["payable", "contract", "interface"] -> iface;
["contract", "interface" | _] -> iface;
["payable", "main", "contract"] -> ct;
@@ -127,7 +127,7 @@ s2t(ct, S0) ->
% | Using
s2t(decl, S0) ->
NewTarget =
case gsc_tokens:strings(3, S0) of
case sfc_tokens:strings(3, S0) of
["type" | _] -> decl_type;
["record" | _] -> decl_record;
["datatype" | _] -> decl_datatype;
@@ -161,7 +161,7 @@ s2t(NYI, Signal) ->
Forest :: asf().
s2f({block_of, TreeTarget}, S0) ->
{gulp, Items} = gsc_signal:gulp_block_items(S0),
{gulp, Items} = sfc_signal:gulp_block_items(S0),
[s2t(TreeTarget, I) || I <- Items].
@@ -209,7 +209,7 @@ s2s_sm_ct(Ct = #ct{con = none}, S0) ->
error({no_contract_name, Ct, S0})
end;
s2s_sm_ct(Ct = #ct{impls = none}, S0) ->
case gsc_tokens:strings(1, S0) of
case sfc_tokens:strings(1, S0) of
[":"] ->
{slurp, Impls, S1} = s2f_slurp_impls(S0),
s2s_sm_ct(Ct#ct{impls = Impls}, S1);
@@ -1,10 +1,10 @@
-module(gsc_test_ntree).
-module(sfc_test_ntree).
-export([
main/0
]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
% just parsing type expressions right now, so only need
% to worry about round parens
@@ -37,8 +37,8 @@ x00() ->
% sample type expr, tokens, signal
x00_src() -> "(foo => (bar) * baz)".
x00_tks() -> gsc:unsafe_tokens_from_string(x00_src()).
x00_sgl() -> gsc:filter_signal(x00_tks()).
x00_tks() -> sfc:unsafe_tokens_from_string(x00_src()).
x00_sgl() -> sfc:filter_signal(x00_tks()).
x00_fst() -> parse(x00_sgl()).
@@ -1,11 +1,11 @@
% gsc tokenizer tests
-module(gsc_test_tokens).
% sfc tokenizer tests
-module(sfc_test_tokens).
-export([
main/0, ct_dir/0
%tokens_match/1
]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
-include_lib("eunit/include/eunit.hrl").
main() ->
@@ -24,13 +24,13 @@ agreement_tests_dir() ->
ct_dir() ++ "/tokenizers_agree".
% the divergences claude found between gsc tokenizer and so tokenizer
% the divergences claude found between sfc tokenizer and so tokenizer
%
% mostly stupid corner cases like a string crossing a line boundary
% or unterminated block comment
%
% divergence files: "divergence" means so_scan disagrees with
% gsc_so_scan in one of the following ways:
% sfc_so_scan in one of the following ways:
%
% - one succeeds when the other errors
% - disagree on success case
@@ -117,12 +117,12 @@ tokstr_concat_test_() ->
concat_property(FileName, FilePath) ->
%?debugFmt("concat_property(~p, _)", [FileName]),
FileChars = gsc:very_stable_file(FilePath),
FileChars = sfc:very_stable_file(FilePath),
{FileName ++ ": file = sum(tokens)",
fun() ->
case gsc:tokens_from_file(FileChars) of
{ok, GscTokens} ->
ConcatStr = concat_token_strs(GscTokens, []),
case sfc:tokens_from_file(FileChars) of
{ok, SfcTokens} ->
ConcatStr = concat_token_strs(SfcTokens, []),
?assertEqual(FileChars, ConcatStr);
_Error ->
ok
@@ -147,7 +147,7 @@ tokens_match(FileName, FilePath) ->
% extracting data to be tested
% i hate this so much but lazy and this is test code so who really cares.
SoTokens = so_tokens_from_file(FilePath),
SfTokens = gsc:gso_tokens_from_file(FilePath),
SfTokens = sfc:gso_tokens_from_file(FilePath),
{FileName ++ ": tokenizers_agree",
fun() ->
case {SoTokens, SfTokens} of
@@ -1,7 +1,7 @@
-module(gsc_test_ytree).
-module(sfc_test_ytree).
-export([main/0]).
-include("$gsc_include/gsc.hrl").
-include("$sfc_include/sfc.hrl").
main() ->
Src =
@@ -51,7 +51,7 @@ main() ->
handle_src_str(SrcStr) ->
Sig = gsc:unsafe_signal_from_string(SrcStr),
Sig = sfc:unsafe_signal_from_string(SrcStr),
Result = gulp(file, Sig),
io:format("~tp~n", [Result]).
@@ -64,7 +64,7 @@ handle_src_str(SrcStr) ->
gulp(file, Sig) ->
gulp({block_of, top_decl}, Sig);
gulp({block_of, X}, Sig) ->
{gulp, BlockItems} = gsc_signal:gulp_block_items(Sig),
{gulp, BlockItems} = sfc_signal:gulp_block_items(Sig),
#ys{target = {block_of, X},
signal = Sig,
stem_meta = none,
@@ -77,7 +77,7 @@ gulp(top_decl, Sig) ->
% | 'include' String
% | Using
NewTarget =
case gsc_tokens:strings(3, Sig) of
case sfc_tokens:strings(3, Sig) of
["namespace", _, _] -> namespace;
["@compiler", _, _] -> '@compiler';
["include", _, _] -> include;
@@ -93,7 +93,7 @@ gulp(top_decl, Sig) ->
gulp(NewTarget, Sig);
gulp(contract, Sig) ->
{slurp, CtMeta, BlockSignal} = slurp(#ct{}, Sig),
{gulp, BlockItems} = gsc_signal:gulp_block_items(BlockSignal),
{gulp, BlockItems} = sfc_signal:gulp_block_items(BlockSignal),
Forest = [gulp(decl, Item) || Item <- BlockItems],
#ys{target = contract,
signal = Sig,
@@ -124,7 +124,7 @@ gulp(NyiTarget, Sig) ->
slurp(Meta = #ct{payable = none, main = none}, Sig) ->
%% nato phonetic alphabet
{Pa, Mi, No} =
case gsc_tokens:strings(2, Sig) of
case sfc_tokens:strings(2, Sig) of
["payable", "main"] -> {true, true, 2};
["main", "payable"] -> {true, true, 2};
["payable", _] -> {true, false, 1};
@@ -186,7 +186,7 @@ slurp_sep1_ii(Stk, TkShape, SepByStr, Sig) ->
end.
strings(N, Tks) ->
gsc_tokens:strings(N, Tks).
sfc_tokens:strings(N, Tks).
take(N, [_ | Rest]) when N >= 1 -> take(N-1, Rest);
+15 -15
View File
@@ -1,5 +1,5 @@
% dynamic hacky module that loads all the tests
-module(gsc_tests).
-module(sfc_tests).
-export([
main/0,
@@ -21,26 +21,26 @@ cli_args(TestNames) ->
end,
% this loads the test deps and then cleans up any
% beam files afterwards
ts_utils:tidily(fun() -> do_gsc_test(TestNames) end).
ts_utils:tidily(fun() -> do_sfc_test(TestNames) end).
%do_gsc_test(["-h" | _]) -> do_help();
%do_gsc_test(["--help" | _]) -> do_help();
do_gsc_test(["-l" | _]) -> do_list();
do_gsc_test(["--list" | _]) -> do_list();
do_gsc_test(["-a" | _]) -> do_all();
do_gsc_test(["--all" | _]) -> do_all();
do_gsc_test(["so_tokens", X]) -> do_so_tokens(X);
do_gsc_test(["so", "tokens", X]) -> do_so_tokens(X);
do_gsc_test(["tokenizers_agree", X]) ->
%do_sfc_test(["-h" | _]) -> do_help();
%do_sfc_test(["--help" | _]) -> do_help();
do_sfc_test(["-l" | _]) -> do_list();
do_sfc_test(["--list" | _]) -> do_list();
do_sfc_test(["-a" | _]) -> do_all();
do_sfc_test(["--all" | _]) -> do_all();
do_sfc_test(["so_tokens", X]) -> do_so_tokens(X);
do_sfc_test(["so", "tokens", X]) -> do_so_tokens(X);
do_sfc_test(["tokenizers_agree", X]) ->
do_tokenizers_agree(X);
do_gsc_test([TestName]) ->
do_sfc_test([TestName]) ->
case ts_utils:test_exists_by_name(TestName) of
true -> ts_utils:run_test_by_name(TestName);
false -> gsc_cli:do_help()
false -> sfc_cli:do_help()
end;
do_gsc_test(_) ->
gsc_cli:do_help().
do_sfc_test(_) ->
sfc_cli:do_help().
+13 -13
View File
@@ -32,7 +32,7 @@ tokenizers_agree(Relpath) ->
% extracting data to be tested
% i hate this so much but lazy and this is test code so who really cares.
SoTokens = so_tokens(FilePath),
SfTokens = gsc:gso_tokens_from_file(FilePath),
SfTokens = sfc:gso_tokens_from_file(FilePath),
case {SoTokens, SfTokens} of
{{ok, So}, {ok, Sf}} -> So =:= Sf;
{{error, _}, {error, _}} -> true;
@@ -82,7 +82,7 @@ load_dep(D) ->
Result :: any().
% @doc
% run Fun(), delete gsc/test/*.beam afterward even if
% run Fun(), delete sfc/test/*.beam afterward even if
% Fun() errors
% @end
clean_after(Fun) ->
@@ -156,7 +156,7 @@ rmm(Mod) ->
find_test_by_name(Name) ->
C1 = list_to_atom(Name),
C2 = list_to_atom("gsc_test_" ++ Name),
C2 = list_to_atom("sfc_test_" ++ Name),
{Gd, Bd} = runnable_test_mods(),
C1Gd = lists:member(C1, Gd),
C2Gd = lists:member(C2, Gd),
@@ -185,7 +185,7 @@ rtns(Acc, [TestMod | Rest]) ->
rtns([{TestName, TestMod} | Acc], Rest).
test_mod_name(TestModAtom) ->
"gsc_test_" ++ Name = atom_to_list(TestModAtom),
"sfc_test_" ++ Name = atom_to_list(TestModAtom),
Name.
@@ -206,7 +206,7 @@ runnable_test_mods() ->
is_runnable(ModAtom) ->
case atom_to_list(ModAtom) of
"gsc_test_" ++ _ -> true;
"sfc_test_" ++ _ -> true;
_ -> false
end.
@@ -253,9 +253,9 @@ abspath_to_name(FP) ->
-spec ls_test_erls() -> AbsPaths when
AbsPaths :: [string()].
% @doc ["/path/to/gsc/test/foo.erl",
% "/path/to/gsc/test/bar.erl",
% "/path/to/gsc/test/baz.erl"]
% @doc ["/path/to/sfc/test/foo.erl",
% "/path/to/sfc/test/bar.erl",
% "/path/to/sfc/test/baz.erl"]
ls_test_erls() ->
lists:filter(fun is_erl/1, ls_test()).
@@ -306,9 +306,9 @@ is_erl(Filename) ->
% @doc
% Includes junk/irrelevant files:
%
% ["/path/to/gsc/test/foo.erl",
% "/path/to/gsc/test/.foo.erl.swp",
% "/path/to/gsc/test/bar.erl"]
% ["/path/to/sfc/test/foo.erl",
% "/path/to/sfc/test/.foo.erl.swp",
% "/path/to/sfc/test/bar.erl"]
ls_test() ->
TD = test_dir(),
@@ -324,7 +324,7 @@ ls_pwd() ->
-spec test_dir() -> AbsPath when
AbsPath :: string().
% @doc "/path/to/gsc/test"
% @doc "/path/to/sfc/test"
test_dir() ->
zx_daemon:get_home() ++ "/test".
@@ -334,7 +334,7 @@ test_dir() ->
-spec ct_dir() -> AbsPath when
AbsPath :: string().
% @doc "/path/to/gsc/test/ct"
% @doc "/path/to/sfc/test/ct"
%
% directory containing the tests for the tokenizer
ct_dir() ->
+6 -6
View File
@@ -1,18 +1,18 @@
{name,"Gajumaru Sophia Compiler"}.
{type,cli}.
{modules,[]}.
{mod, "gsc_cli"}.
{mod, "sfc_cli"}.
{author,"Peter Harpending"}.
{prefix,"gsc"}.
{prefix,"sfc"}.
{desc,"Exploratory sophia compiler rewrite"}.
{package_id,{"otpr","gsc",{0,1,0}}}.
{package_id,{"otpr","sfc",{0,1,0}}}.
{deps,[]}.
{key_name,none}.
{a_email,"peterharpending@qpq.swiss"}.
{c_email,"peterharpending@qpq.swiss"}.
{copyright,"2026 QPQ AG"}.
{copyright,"2026 QPQ IaaS AG"}.
{file_exts,[]}.
{license,"GPL-3.0-only"}.
{repo_url,"https://git.qpq.swiss/QPQ-AG/gsc"}.
{repo_url,"https://git.harpending.org/pharpend/sfc"}.
{tags,[]}.
{ws_url,"https://git.qpq.swiss/QPQ-AG/gsc"}.
{ws_url,"https://git.harpending.org/pharpend/sfc"}.