From 711710fe4b7fda0ce6fc11f13d4219f5e8e6bc7e Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Fri, 27 Dec 2019 17:36:34 +0100 Subject: [PATCH] as: scan: add API to wrap scan_state --- erlang/apps/as/src/scan.erl | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/erlang/apps/as/src/scan.erl b/erlang/apps/as/src/scan.erl index 330d874..97b3f58 100644 --- a/erlang/apps/as/src/scan.erl +++ b/erlang/apps/as/src/scan.erl @@ -22,13 +22,35 @@ -export([ token/1 , format_error/1 + , stdin/0 + , fopen/1 + , fclose/1 ]). -include("token.hrl"). +-type scan_state() :: scan_state:scan_state(). -type location() :: scan_state:location(). --spec token(scan_state:scan_state()) +-export_type([scan_state/0, location/0]). + +%% Scan State ------------------------------------------------------------------ + +-spec fclose(scan_state()) -> ok | {error, {module(), term()}}. +fclose(ScanState) -> + scan_state:fclose(ScanState). + +-spec fopen(string()) -> {ok, scan_state()} | {error, {module(), term()}}. +fopen(File) -> + scan_state:fopen(File). + +-spec stdin() -> {ok, scan_state()}. +stdin() -> + scan_state:stdin(). + +%% Scanner --------------------------------------------------------------------- + +-spec token(scan_state()) -> {ok, {location(), token()}} | {error, {module(), term()}}. token(ScanState) -> %% TODO: optimize