% @doc bikeshed proctrastination head into vim warmup thing % sophia compiler from scratch by PRH % % based on original sophia compiler % % parse layers: % 1. gs_tokens: SrcStr -> (Tokens | SigTokens) % % SigTokens = not comment/whitespace % % layers: % a. gs_strmatch : matches string shapes % b. gso_scan : converts to so_scan shapes % % % terminology: % % - `slurp`/`barf` borrowed from emacs paredit mode: % % slurp : (a b) c -> (a b c) % barf : (a b c) -> a (b c) % % * `slurp` usually involves *transforming* input % into a new type (e.g. slurp a token from src % string); think of slurp as a verb meaning to % consume and then digest % * `barf` basically means blindly splitting off % input % % @end -module(gsc). -export_type([ token/0 ]). -export([ sigtokens_from_file/1, sigtokens_from_string/1, tokens_from_file/1, tokens_from_string/1 ]). -include("$gsc_include/gsc.hrl"). %----------------------------------------- % types %----------------------------------------- -type token() :: tk(). %----------------------------------------- % functions %----------------------------------------- sigtokens_from_file(X) -> case tokens_from_file(X) of {ok, Y} -> {ok, gs_tokens:filter_significant(Y)}; Err -> Err end. sigtokens_from_string(X) -> case tokens_from_string(X) of {ok, Y} -> {ok, gs_tokens:filter_significant(Y)}; Err -> Err end. -spec tokens_from_file(FilePath) -> Perhaps when FilePath :: string(), Perhaps :: {ok, Tokens} | {error, gsc_err() | any()}, Tokens :: [tk()]. tokens_from_file(FilePath) -> case file:read_file(FilePath) of {ok, FBytes} -> tokens_from_string(FBytes); Error -> Error end. -spec tokens_from_string(SrcStr) -> Result when SrcStr :: string(), Result :: {ok, Tokens} | {error, gsc_err()}, Tokens :: [tk()]. tokens_from_string(SrcStr) -> gs_tokens:tokens(SrcStr).