[m-rev.] for review: Document what whitespace means to library predicates.
Peter Wang
novalazy at gmail.com
Mon Oct 2 14:35:04 AEDT 2017
library/char.m:
Present list of whitespace characters for char.whitespace
in tabular form.
library/io.m:
library/lexer.m:
library/pprint.m:
library/stream.m:
library/string.m:
Mention char.is_whitespace in the documentation of predicates which
use that definition of whitespace characters.
Module qualify some calls to char.is_whitespace for clarity.
---
library/char.m | 10 ++++++++--
library/io.m | 10 ++++++++--
library/lexer.m | 6 ++++++
library/pprint.m | 3 +++
library/stream.m | 5 +++--
library/string.m | 23 +++++++++++++----------
6 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/library/char.m b/library/char.m
index b402784c5..9900ad5cc 100644
--- a/library/char.m
+++ b/library/char.m
@@ -118,8 +118,14 @@
%
:- pred is_ascii(char::in) is semidet.
- % True iff the character is a whitespace character in the ASCII range,
- % i.e. a space, tab, newline, carriage return, form-feed, or vertical tab.
+ % True iff the character is a whitespace character in the ASCII range:
+ %
+ % U+0020 space
+ % U+0009 tab
+ % U+000A line feed
+ % U+000B vertical tab
+ % U+000C form feed
+ % U+000D carriage return
%
:- pred is_whitespace(char::in) is semidet.
diff --git a/library/io.m b/library/io.m
index 108d12b26..3aaa67359 100644
--- a/library/io.m
+++ b/library/io.m
@@ -141,6 +141,9 @@
% Read a whitespace delimited word from the current input stream
% or from the specified stream.
%
+ % See `char.is_whitespace' for the definition of whitespace characters
+ % used by this predicate.
+ %
:- pred read_word(io.result(list(char))::out, io::di, io::uo) is det.
:- pred read_word(io.text_input_stream::in, io.result(list(char))::out,
io::di, io::uo) is det.
@@ -318,6 +321,9 @@
% - If it encounters an I/O error, then it also returns
% `error(Message, LineNumber)'.
%
+ % See `char.is_whitespace' for the definition of whitespace characters
+ % used by this predicate.
+ %
:- pred read(io.read_result(T)::out, io::di, io::uo) is det.
:- pred read(io.text_input_stream::in, io.read_result(T)::out,
io::di, io::uo) is det.
@@ -345,8 +351,8 @@
:- pred read_from_string(string::in, string::in, int::in,
read_result(T)::out, posn::in, posn::out) is det.
- % Discards all the whitespace from the current stream
- % or from the specified stream.
+ % Discards all the whitespace characters satisfying `char.is_whitespace'
+ % from the current stream or from the specified stream.
%
:- pred ignore_whitespace(io.result::out, io::di, io::uo) is det.
:- pred ignore_whitespace(io.text_input_stream::in, io.result::out,
diff --git a/library/lexer.m b/library/lexer.m
index 8ff116784..804be60d9 100644
--- a/library/lexer.m
+++ b/library/lexer.m
@@ -89,6 +89,9 @@
% Keep reading until we encounter either an `end' token
% (i.e. a full stop followed by whitespace) or the end-of-file.
%
+ % See `char.is_whitespace' for the definition of whitespace characters
+ % used by this predicate.
+ %
:- pred get_token_list(token_list::out, io::di, io::uo) is det.
:- pred get_token_list(io.text_input_stream::in, token_list::out,
io::di, io::uo) is det.
@@ -107,6 +110,9 @@
% Return the tokens scanned in Tokens, and return the position one
% character past the end of the last token in FinalPos.
%
+ % See `char.is_whitespace' for the definition of whitespace characters
+ % used by this predicate.
+ %
:- pred string_get_token_list_max(string::in, offset::in, token_list::out,
posn::in, posn::out) is det.
diff --git a/library/pprint.m b/library/pprint.m
index c39fab751..c24637cb4 100644
--- a/library/pprint.m
+++ b/library/pprint.m
@@ -340,6 +340,9 @@
% Performs word wrapping at the end of line, taking whitespace sequences
% as delimiters separating words.
%
+ % See `char.is_whitespace' for the definition of whitespace characters
+ % used by this predicate.
+ %
:- func word_wrapped(string) = doc.
% Convert arbitrary terms to docs. This requires std_util.functor/3 to work
diff --git a/library/stream.m b/library/stream.m
index 92d68338c..7fb206199 100644
--- a/library/stream.m
+++ b/library/stream.m
@@ -341,7 +341,8 @@
% Misc. operations on input streams.
%
- % Discard all the whitespace from the specified stream.
+ % Discard all the whitespace characters satisfying `char.is_whitespace'
+ % from the specified stream.
%
:- pred ignore_whitespace(Stream::in, result(Error)::out,
State::di, State::uo)
@@ -456,7 +457,7 @@ ignore_whitespace(Stream, Result, !State) :-
Result = eof
;
CharResult = ok(Char),
- ( if is_whitespace(Char) then
+ ( if char.is_whitespace(Char) then
ignore_whitespace(Stream, Result, !State)
else
unget(Stream, Char, !State),
diff --git a/library/string.m b/library/string.m
index 2a6071da7..67ffa342b 100644
--- a/library/string.m
+++ b/library/string.m
@@ -854,22 +854,22 @@
% strip(String):
%
- % Returns `String' minus any initial and trailing whitespace characters
- % in the ASCII range.
+ % Returns `String' minus any initial and trailing ASCII whitespace
+ % characters, i.e. characters satisfying `char.is_whitespace'.
%
:- func strip(string) = string.
% lstrip(String):
%
- % Return `String' minus any initial whitespace characters
- % in the ASCII range.
+ % Return `String' minus any initial ASCII whitespace characters,
+ % i.e. characters satisfying `char.is_whitespace'.
%
:- func lstrip(string) = string.
% rstrip(String):
%
- % Returns `String' minus any trailing whitespace characters
- % in the ASCII range.
+ % Returns `String' minus any trailing ASCII whitespace characters,
+ % i.e. characters satisfying `char.is_whitespace'.
%
:- func rstrip(string) = string.
@@ -914,6 +914,9 @@
% it will be broken over two (or more) lines. Sequences of whitespace
% characters are replaced by a single space.
%
+ % See `char.is_whitespace' for the definition of whitespace characters
+ % used by this predicate.
+ %
:- func word_wrap(string, int) = string.
% word_wrap_separator(Str, N, WordSeparator) = Wrapped:
@@ -4896,13 +4899,13 @@ chomp(S) = Chomp :-
).
strip(S0) = S :-
- L = prefix_length(is_whitespace, S0),
- R = suffix_length(is_whitespace, S0),
+ L = prefix_length(char.is_whitespace, S0),
+ R = suffix_length(char.is_whitespace, S0),
S = between(S0, L, length(S0) - R).
-lstrip(S) = lstrip_pred(is_whitespace, S).
+lstrip(S) = lstrip_pred(char.is_whitespace, S).
-rstrip(S) = rstrip_pred(is_whitespace, S).
+rstrip(S) = rstrip_pred(char.is_whitespace, S).
lstrip_pred(P, S) = right(S, length(S) - prefix_length(P, S)).
--
2.14.1
More information about the reviews
mailing list