mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-01-24 11:22:52 +00:00
as: scan_state: replace filename/1 and linenr/1 with location/1
This commit is contained in:
parent
5c633b99f4
commit
273ce47561
@ -271,8 +271,7 @@ section_dot_text() -> % ".text"
|
||||
%% Error reporting -------------------------------------------------------------
|
||||
|
||||
fmterr(ScanState, Fmt, Args) ->
|
||||
{ok, FileName} = scan_state:filename(ScanState),
|
||||
{ok, LineNr} = scan_state:linenr(ScanState),
|
||||
{ok, {FileName, LineNr}} = scan_state:location(ScanState),
|
||||
{error, {?MODULE, {FileName, LineNr, Fmt, Args}}}.
|
||||
|
||||
-spec format_error(term()) -> io_lib:chars().
|
||||
|
||||
@ -351,8 +351,7 @@ badtok(ScanState, ErrMsg, {ok, Token}) ->
|
||||
fmterr(ScanState, ErrMsg ++ "; current token is ~s", [token:format(Token)]).
|
||||
|
||||
fmterr(ScanState, Fmt, Args) ->
|
||||
{ok, FileName} = scan_state:filename(ScanState),
|
||||
{ok, LineNr} = scan_state:linenr(ScanState),
|
||||
{ok, {FileName, LineNr}} = scan_state:location(ScanState),
|
||||
{error, {?MODULE, {FileName, LineNr, Fmt, Args}}}.
|
||||
|
||||
-spec format_error(term()) -> io_lib:chars().
|
||||
|
||||
@ -225,8 +225,7 @@ chval(Ch) ->
|
||||
end.
|
||||
|
||||
badchar(ScanState, Ch, Context) ->
|
||||
{ok, FileName} = scan_state:filename(ScanState),
|
||||
{ok, LineNr} = scan_state:linenr(ScanState),
|
||||
{ok, {FileName, LineNr}} = scan_state:location(ScanState),
|
||||
{error, {?MODULE, {FileName, LineNr, Ch, Context}}}.
|
||||
|
||||
-spec format_error(term()) -> io_lib:chars().
|
||||
|
||||
@ -29,8 +29,7 @@
|
||||
, stdin/0
|
||||
, ungetc/2
|
||||
% meta-data accessors
|
||||
, filename/1
|
||||
, linenr/1
|
||||
, location/1
|
||||
, format_error/1
|
||||
]).
|
||||
|
||||
@ -54,6 +53,7 @@
|
||||
}).
|
||||
|
||||
-type scan_state() :: pid().
|
||||
-type location() :: {FileName :: string(), LineNr :: pos_integer()}.
|
||||
|
||||
-export_type([scan_state/0]).
|
||||
|
||||
@ -85,13 +85,9 @@ do_fopen(File) ->
|
||||
ungetc(Ch, Pid) ->
|
||||
gen_server:call(Pid, {ungetc, Ch}, infinity).
|
||||
|
||||
-spec filename(scan_state()) -> {ok, string()}.
|
||||
filename(Pid) ->
|
||||
gen_server:call(Pid, filename, infinity).
|
||||
|
||||
-spec linenr(scan_state()) -> {ok, pos_integer()}.
|
||||
linenr(Pid) ->
|
||||
gen_server:call(Pid, linenr, infinity).
|
||||
-spec location(scan_state()) -> {ok, location()}.
|
||||
location(Pid) ->
|
||||
gen_server:call(Pid, location, infinity).
|
||||
|
||||
-spec format_error(term()) -> io_lib:chars().
|
||||
format_error(Reason) ->
|
||||
@ -131,10 +127,8 @@ handle_call(Req, _From, State) ->
|
||||
handle_fgetc(State);
|
||||
{ungetc, Ch} ->
|
||||
handle_ungetc(State, Ch);
|
||||
filename ->
|
||||
{reply, {ok, State#state.filename}, State};
|
||||
linenr ->
|
||||
{reply, {ok, State#state.linenr}, State};
|
||||
location ->
|
||||
{reply, {ok, {State#state.filename, State#state.linenr}}, State};
|
||||
_ ->
|
||||
{reply, {error, {?MODULE, {bad_request, Req}}}, State}
|
||||
end.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user